%This chapter was modified on 4/2/97.
%\setcounter{chapter}{6}
\chapter[Sums of Random Variables]{Sums of Independent Random Variables}\label{chp 7}

\section{Sums of Discrete Random Variables}\label{sec 7.1}

In this chapter we turn to the important question of determining the
distribution of a sum of independent random variables in terms of the
distributions of the individual constituents.  In this section we consider only
sums of discrete random variables, reserving the case of continuous random
variables for the next section.

We consider here only random variables whose values are integers.  Their distribution
functions are then defined on these integers.  We
shall find it convenient to assume here that these distribution functions are
defined for \emx {all} integers, by defining them to be~0 where they are not
otherwise defined.

\subsection*{Convolutions}

\par
Suppose $X$ and $Y$ are two independent discrete random variables with distribution functions
$m_1(x)$ and $m_2(x)$.  Let $Z = X+Y$.  We would like to determine the distribution
function $m_3(x)$ of $Z$.  To do this, it is enough to determine the probability that $Z$
takes on the value $z$, where $z$ is an arbitrary integer.  Suppose that $X = k$, where $k$
is some integer.  Then $Z = z$ if and only if $Y = z-k$.  So the event $Z = z$ is the union
of the pairwise disjoint events
$$(X = k)\  \mbox{and\ }(Y = z-k)\ ,$$
where $k$ runs over the integers.  Since these events are pairwise disjoint, we have
$$P(Z = z) = \sum_{k = -\infty}^\infty P(X = k)\cdot P(Y = z - k)\ .$$
Thus, we have found the distribution function of the random variable $Z$.  This
leads to the following definition.

\begin{definition}\label{defn 7.1}
Let $X$ and $Y$ be two independent integer-valued random variables, with
distribution functions $m_1(x)$~and~$m_2(x)$ respectively.  Then the {\em
convolution}\index{convolution} of
$m_1(x)$~and~$m_2(x)$ is the distribution function $m_3 = m_1*m_2$ given by
$$ m_3(j) = \sum_k m_1(k) \cdot m_2(j - k)\ ,$$
for $j = \ldots,\ -2,\ -1,\ 0,\ 1,\ 2,\ \ldots$.  The function $m_3(x)$ is the distribution
function of the random variable $Z = X + Y$.
\end{definition}

\par
It is easy to see that the convolution operation is commutative, and it is straightforward to
show that it is also associative.
\par
Now let $S_n = X_1 + X_2 +\cdots+ X_n$ be the sum of $n$
independent random variables of an independent trials process with common distribution
function $m$ defined on the integers.  Then the distribution function of $S_1$ is $m$.  We can
write
$$
S_n = S_{n - 1} + X_n\ .
$$
Thus, since we know the distribution function of $X_n$ is $m$, we can find the distribution
function of $S_n$ by induction.

\begin{example}
A die is rolled twice.  Let $X_1$ and $X_2$ be the outcomes, and let $S_2 = X_1
+ X_2$ be the sum of these outcomes.  Then $X_1$ and $X_2$ have the common
distribution function:
$$
m = \pmatrix{
1 & 2 & 3 & 4 & 5 & 6 \cr
1/6 & 1/6 & 1/6 & 1/6 & 1/6 & 1/6\cr}.
$$
The distribution function of $S_2$ is then the convolution of this distribution with itself.
Thus,

\begin{eqnarray*}
P(S_2 = 2) &=& m(1)m(1) \\
           &=& \frac 16 \cdot \frac 16 = \frac 1{36}\ , \\
P(S_2 = 3) &=& m(1)m(2) + m(2)m(1) \\
           &=& \frac 16 \cdot \frac 16 + \frac 16 \cdot \frac 16 = \frac 2{36}\ ,\\
P(S_2 = 4) &=& m(1)m(3) + m(2)m(2) + m(3)m(1) \\
           &=& \frac 16 \cdot \frac 16 + \frac 16 \cdot \frac 16 + \frac 16
\cdot \frac 16 = \frac 3{36}\ .\\
\end{eqnarray*}
Continuing in this way we would find $P(S_2 = 5) = 4/36$, $P(S_2 = 6) = 5/36$,
$P(S_2 = 7) = 6/36$, $P(S_2 = 8) = 5/36$, $P(S_2 = 9) = 4/36$, $P(S_2 = 10) =
3/36$, $P(S_2 = 11) = 2/36$, and $P(S_2 = 12) = 1/36$.

The distribution for $S_3$ would then be the convolution of the distribution for $S_2$
with the distribution for $X_3$.  Thus
\begin{eqnarray*}
P(S_3 = 3) &=& P(S_2 = 2)P(X_3 = 1) \\
           &=& \frac 1{36} \cdot \frac 16 = \frac 1{216}\ , \\
P(S_3 = 4) &=& P(S_2 = 3)P(X_3 = 1) + P(S_2 = 2)P(X_3 = 2) \\
           &=& \frac 2{36} \cdot \frac 16 + \frac 1{36} \cdot \frac 16 = \frac
3{216}\ ,\\
\end{eqnarray*}
and so forth.
\par
This is clearly a tedious job, and a program should be written to carry out this calculation.
To do this we first write a program to form the convolution of two densities $p$~and~$q$ and
return the density $r$.  We can then write a program to find
the density for the sum $S_n$ of $n$ independent random variables with a common
density $p$, at least in the case that the random variables have a finite number of possible
values.
\putfig{3.5truein}{PSfig7-1}{Density of $S_n$ for rolling a die $n$ times.}{fig 7.1}
\par
Running this program for the example of
rolling a die $n$ times for~$n = 10,\ 20,\ 30$ results in the distributions shown in
Figure~\ref{fig 7.1}.  We see that, as in the case of Bernoulli trials, the distributions
become bell-shaped.  We shall discuss in Chapter~\ref{chp 9} a very general theorem called
the {\em Central Limit Theorem} that will explain this phenomenon.
\end{example}

\begin{example}
A well-known method for evaluating a bridge\index{bridge} hand is: an ace is assigned a value
of~4, a king~3, a queen~2, and a jack~1.  All other cards are assigned a value
of~0.  The \emx {point count}\index{point count} of the hand is then the sum of the values of the
cards in the hand.  (It is actually more complicated than this, taking into
account voids in suits, and so forth, but we consider here this simplified form
of the point count.)  If a card is dealt at random to a player, then the point
count for this card has distribution
$$
p_X = \pmatrix{
0 & 1 & 2 & 3 & 4 \cr
36/52 & 4/52 & 4/52 & 4/52 & 4/52\cr}.
$$

Let us regard the total hand of 13~cards as 13 independent trials with this
common distribution.  (Again this is not quite correct because we assume here
that we are always choosing a card from a full deck.)  Then the distribution for the
point count $C$ for the hand can be found from the program {\bf
NFoldConvolution}\index{NFoldConvolution (program)} by using the distribution for a single
card and choosing
$n = 13$.  A player with a point count of~13 or more is said to have an  \emx {opening bid.}
The probability of having an opening bid is then
$$
P(C \geq 13)\ .
$$

Since we have the distribution of $C$, it is easy to compute this probability.  Doing this we
find that
$$
P(C \geq 13) = .2845\ ,
$$
so that about one in four hands should be an opening bid according to this
simplified model.  A more realistic discussion of this problem can be found in
Epstein,\index{EPSTEIN, R.}  \emx {The Theory of Gambling and Statistical Logic.}\footnote{R.~A.
Epstein,  \emx {The Theory of Gambling and Statistical Logic,} rev.~ed.\ (New
York: Academic Press, 1977).}
\end{example}
\par
For certain special distributions it is possible to find an expression for the
distribution that results from convoluting the distribution with itself $n$~times.
\par
The convolution of two binomial distributions,\index{convolution!of binomial distributions} one with
parameters
$m$ and
$p$ and the other with parameters $n$ and $p$, is a binomial distribution with parameters $(m+n)$
and
$p$.  This fact follows easily from a consideration of the experiment which consists of first
tossing a coin $m$ times, and then tossing it $n$ more times.
\par
The convolution of $k$ geometric distributions\index{convolution!of geometric distributions} with
common parameter
$p$ is a negative binomial distribution with parameters $p$ and $k$.  This can be seen by
considering the experiment which consists of tossing a coin until the $k$th head appears.

\exercises
\begin{LJSItem}

\i\label{exer 7.1.1} A die is rolled three times.  Find the probability that the sum of
the outcomes is
\begin{enumerate}
\item greater than 9.

\item an odd number.
\end{enumerate}

\i\label{exer 7.1.2} The price of a stock on a given trading day changes according to the
distribution
$$
p_X = \pmatrix{
-1 & 0 & 1 & 2 \cr
1/4 & 1/2 & 1/8 & 1/8\cr}.$$
Find the distribution for the change in stock price after two (independent) trading
days.

\i\label{exer 7.1.3} Let $X_1$ and $X_2$ be independent random variables with common
distribution
$$
p_X = \pmatrix{
0 & 1 & 2 \cr
1/8 & 3/8 & 1/2\cr}.$$
Find the distribution of the sum $X_1 + X_2$.

\i\label{exer 7.1.4} In one play of a certain game you win an amount $X$ with distribution
$$
p_X = \pmatrix{
1 & 2 & 3 \cr
1/4 & 1/4 & 1/2\cr}.$$
Using the program {\bf NFoldConvolution} find the distribution for your total winnings
after ten (independent) plays.  Plot this distribution.

\i\label{exer 7.1.5} Consider the following two experiments: the first has outcome $X$ taking
on the values~0,~1, and~2 with equal probabilities; the second results in an
(independent) outcome $Y$ taking on the value~3 with probability 1/4 and~4
with probability 3/4.  Find the distribution of
\begin{enumerate}
\item $Y + X$.

\item $Y - X$.
\end{enumerate}

\i\label{exer 7.1.6} People arrive at a queue according to the following scheme: During each
minute of time either 0~or~1 person arrives.  The probability that 1 person
arrives is $p$ and that no person arrives is $q = 1 - p$.  Let $C_r$ be the
number of customers arriving in the first $r$~minutes.  Consider a Bernoulli
trials process with a success if a person arrives in a unit time and failure
if no person arrives in a unit time.  Let $T_r$ be the number of failures
before the $r$th success.
\begin{enumerate}
\item What is the distribution for $T_r$?

\item What is the distribution for $C_r$?

\item Find the mean and variance for the number of customers arriving in the
first $r$ minutes.
\end{enumerate}

\i\label{exer 7.1.7}
\begin{enumerate}
\item A die is rolled three times with outcomes $X_1$,~$X_2$, and~$X_3$.  Let
$Y_3$ be the maximum of the values obtained.  Show that
$$
P(Y_3 \leq j) = P(X_1 \leq j)^3\ .
$$
Use this to find the distribution of~$Y_3$.  Does $Y_3$ have a bell-shaped distribution?
\item
Now let $Y_n$ be the maximum value when $n$ dice are rolled.  Find the distribution of
$Y_n$.  Is this distribution bell-shaped for large values of $n$?
\end{enumerate}

\i\label{exer 7.1.10} A baseball player is to play in the World Series.  Based upon his season
play, you estimate that if he comes to bat four times in a game the number of
hits he will get has a distribution
$$
p_X = \pmatrix{
0 & 1 & 2 & 3 & 4 \cr
.4 & .2 & .2 & .1 & .1\cr}.$$

Assume that the player comes to bat four times in each game of the series.
\begin{enumerate}
\item
Let $X$ denote the number of hits that he gets in a series.  Using the program {\bf
NFoldConvolution}, find the distribution of $X$ for each of the possible series lengths:
four-game, five-game, six-game, seven-game.

\item
Using one of the distribution found in part (a), find the probability that his batting average
exceeds .400 in a four-game series.  (The batting average is the number of hits divided by the
number of times at bat.)

\item Given the distribution $p_X$, what is his long-term batting average?
\end{enumerate}

\i\label{exer 7.1.11} Prove that you cannot load two dice in such a way that
the probabilities for any sum from 2~to~12 are the same.  (Be sure to consider
the case where one or more sides turn up with probability zero.)

\i\label{exer 7.1.12} (L\'evy\footnote{See M. Krasner and B. Ranulae, ``Sur une Propriet\'e
des Polynomes de la Division du Circle"; and the following note by J.
Hadamard, in  \emx {C.\ R.\ Acad.\ Sci.,} vol.~204 (1937), pp.~397--399.}) Assume
that $n$ is an integer, not prime.  Show that you can find two distributions
$a$~and~$b$ on the nonnegative integers such that the convolution of
$a$~and~$b$ is the equiprobable distribution on the set 0, 1, 2, \dots, $n - 1$.  If
$n$ is prime this is not possible, but the proof is not so easy.  (Assume that
neither $a$~nor~$b$ is concentrated at 0.)

\i\label{exer 7.1.13} Assume that you are playing craps with dice that are loaded in the
following way: faces two, three, four, and five all come up with the same
probability $(1/6) + r$.  Faces one and six come up with probability $(1/6) - 2r$,
with $0 < r < .02$.  Write a computer program to find the probability of
winning at craps with these dice, and using your program find which values
of~$r$ make craps a favorable game for the player with these dice.
\end{LJSItem}

\choice{}{\section{Sums of Continuous Random Variables}\label{sec 7.2}
In this section we consider the continuous version of the problem posed in the
previous section: How are sums of independent random variables distributed?

\subsection*{Convolutions}
\begin{definition} Let $X$ and $Y$ be two continuous random variables with density
functions $f(x)$ and $g(y)$, respectively.  Assume that both $f(x)$ and $g(y)$ are defined for
all real numbers.  Then the  \emx {convolution}\index{convolution} $f*g$ of
$f$~and~$g$ is the function given by
\begin{eqnarray*} (f*g)(z) &=& \int_{-\infty}^{+\infty} f(z - y) g(y)\,dy \\
         &=& \int_{-\infty}^{+\infty} g(z - x) f(x)\, dx\ .
\end{eqnarray*}
\end{definition}

This definition is analogous to the definition, given in Section~\ref{sec 7.1}, of the
convolution of two distribution functions.  Thus it should not be surprising that if $X$ and
$Y$ are independent, then the density of their sum is the convolution of their densities.
This fact is stated as a theorem below, and its proof is left as an exercise (see
Exercise~\ref{exer 7.2.0.5}).

\begin{theorem} Let $X$ and $Y$ be two independent random variables with density functions
$f_X(x)$ and $f_Y(y)$ defined for all~$x$.  Then the sum $Z = X + Y$ is a random variable with
density function $f_Z(z)$, where $f_Z$ is the convolution of $f_X$~and~$f_Y$.
\end{theorem}
\par
To get a better understanding of this important result, we will look at some examples.
\pagebreak[4]
\subsection*{Sum of Two Independent Uniform Random Variables}
\begin{example}\label{exam 7.6}
Suppose we choose independently two numbers at random from the interval
$[0,1]$ with uniform probability density\index{convolution!of uniform densities}.  What is the
density of their sum?

Let $X$ and $Y$ be random variables describing our choices and $Z = X + Y$
their sum.  Then we have

$$
f_X(x) = f_Y(x) = \left \{ \begin{array}{ll}
                               1 & \;\mbox{if $0 \leq x \leq 1$,} \\
                               0 & \;\mbox{otherwise;}
                  \end{array}
         \right.
$$
and the density function for the sum is given by
$$
f_Z(z) = \int_{-\infty}^{+\infty} f_X(z - y) f_Y(y)\,dy\ .
$$
Since $f_Y(y) = 1$ if $0 \leq y \leq 1$ and 0 otherwise, this becomes
$$
f_Z(z) = \int_0^1 f_X(z - y)\,dy\ .
$$
Now the integrand is 0 unless $0 \leq z - y \leq 1$ (i.e., unless $z - 1 \leq y
\leq z$) and then it is~1.  So if $0 \leq z \leq 1$, we have
$$
f_Z(z) = \int_0^z \, dy = z\ ,
$$
while if $1 < z \leq 2$, we have
$$
f_Z(z) = \int_{z - 1}^1\, dy = 2 - z\ ,
$$
and if $z < 0$ or $z > 2$ we have $f_Z(z) = 0$ (see Figure~\ref{fig 7.5}).  Hence,
$$
f_Z(z) = \left \{ \begin{array}{ll}
                               z,          & \;\mbox{if $0 \leq z \leq 1,$} \\
                               2-z,        & \;\mbox{if $1 < z \leq 2,$} \\
                               0,          & \;\mbox{otherwise.}
\end{array}
\right.
$$
\putfig{3.5truein}{PSfig7-5}{Convolution of two uniform densities.}{fig 7.5} %4.5truein
Note that this result agrees with that of Example~\ref{exam 2.1.4.5}.
\end{example}

\subsection*{Sum of Two Independent Exponential Random Variables}
\begin{example}\label{exam 7.7}
Suppose we choose two numbers at random from the interval $[0,\infty)$ with
an  \emx {exponential} density\index{convolution!of exponential densities} with parameter $\lambda$.
What is the density of their sum?

Let $X$, $Y$, and $Z = X + Y$ denote the relevant random variables, and
$f_X$,~$f_Y$, and~$f_Z$ their densities.  Then
$$
f_X(x) = f_Y(x) = \left \{ \begin{array}{ll}
           \lambda e^{-\lambda x}, & \;\mbox{if $x \geq 0$},\\
                                 0, & \;\mbox{otherwise;}
                  \end{array}
         \right.
$$
and so, if $z > 0$,
\begin{eqnarray*}
f_Z(z) &=& \int_{-\infty}^{+\infty} f_X(z - y) f_Y(y)\, dy \\
       &=& \int_0^z \lambda e^{-\lambda(z - y)} \lambda e^{-\lambda y}\, dy \\
       &=& \int_0^z \lambda^2 e^{-\lambda z}\, dy \\
       &=& \lambda^2 z e^{-\lambda z},\\
\end{eqnarray*}
while if $z < 0$, $f_Z(z) = 0$ (see Figure~\ref{fig 7.6}).  Hence,
\putfig{3.5truein}{PSfig7-6}
{Convolution of two exponential densities with $\lambda = 1$.}{fig 7.6}
$$
f_Z(z) = \left \{ \begin{array}{ll}
                       \lambda^2 z e^{-\lambda z},
                                          & \;\mbox{if $z \geq 0$},\\
                                      0,  & \;\mbox{otherwise.}
                  \end{array}
         \right.
$$
\end{example}

\subsection*{Sum of Two Independent Normal Random Variables}
\begin{example}\label{exam 7.8}
It is an interesting and important fact that the convolution of two normal
densities with means $\mu_1$~and~$\mu_2$ and variances $\sigma_1$~and~$\sigma_2$ is
again a normal density, with mean $\mu_1 + \mu_2$ and variance $\sigma_1^2 + \sigma_2^2$.
We will show this in the special case that both random variables are standard normal.
The general case can be done in the same way, but the calculation is messier.  Another
way to show the general result is given in Example~\ref{exam 10.3.3}.
\par
Suppose $X$ and $Y$ are two independent random variables, each with the standard {\em
normal}\index{convolution!of normal densities} density (see Example~\ref{exam 5.16}).
We have
$$
f_X(x) = f_Y(y) = \frac 1{\sqrt{2\pi}} e^{-x^2/2}\ ,
$$
and so
\begin{eqnarray*}
f_Z(z) &=& f_X * f_Y(z) \\
&=& \frac 1{2\pi} \int_{-\infty}^{+\infty} e^{-(z -
y)^2/2} e^{-y^2/2}\, dy \\
       &=& \frac 1{2\pi} e^{-z^2/4} \int_{-\infty}^{+\infty} e^{-(y - z/2)^2}\,
dy \\
       &=& \frac 1{2\pi} e^{-z^2/4}\sqrt {\pi} \biggl[\frac 1{\sqrt {\pi}}\int_{-\infty}^\infty
e^{-(y-z/2)^2}\,dy\ \biggr]\ .\\
\end{eqnarray*}
The expression in the brackets equals 1, since it is the integral of the normal density
function with $\mu = 0$ and $\sigma = \sqrt 2$.  So, we have
$$
f_Z(z) = \frac 1{\sqrt{4\pi}} e^{-z^2/4}\ .
$$
\end{example}

\subsection*{Sum of Two Independent Cauchy Random Variables}
\begin{example}\label{exam 7.9}
Choose two numbers at random from the interval
$(-\infty,+\infty)$ with the Cauchy\index{convolution!of Cauchy densities} density
with parameter $a = 1$ (see Example~\ref{exam 5.20}).  Then
$$
f_X(x) = f_Y(x) = \frac 1{\pi(1 + x^2)}\ ,
$$
and $Z = X + Y$ has density
$$
f_Z(z) = \frac 1{\pi^2} \int_{-\infty}^{+\infty} \frac {1}{1 + (z - y)^2} \frac
{1}{1 + y^2} \, dy\ .
$$
This integral requires some effort, and we give here only the result
(see Section~\ref{sec 10.3}, or Dwass\footnote{M. Dwass, ``On the Convolution of Cauchy
Distributions,"  \emx {American Mathematical Monthly,} vol.~92, no.~1, (1985),
pp.~55--57; see also R.~Nelson, letters to the Editor, ibid., p.~679.}):
$$
f_Z(z) = \frac {2}{\pi(4 + z^2)}\ .
$$
\par
Now, suppose that we ask for the density function of the \emx {average}
$$
A = (1/2)(X + Y)
$$
of $X$~and~$Y$.  Then $A = (1/2)Z$.  Exercise~\ref{sec 5.2}.\ref{exer
5.2.18} shows that if $U$ and $V$ are two continuous random variables  with density functions
$f_U(x)$ and $f_V(x)$, respectively, and if $V = aU$, then
$$
f_V(x) = \biggl(\frac 1a\biggr)f_U\biggl(\frac xa\biggr)\ .
$$
Thus, we have
$$
f_A(z) = 2f_Z(2z) = \frac 1{\pi(1 + z^2)}\ .
$$
Hence, the density function for the average of two random variables, each
having a Cauchy density, is again a random variable with a Cauchy density; this
remarkable property is a peculiarity of the Cauchy density.  One consequence of
this is if the error in a certain measurement process had a Cauchy
density and you averaged a number of measurements, the average could not be
expected to be any more accurate than any one of your individual measurements!
\end{example}

\subsection*{Rayleigh Density}\index{density function!Rayleigh}\index{Rayleigh
density}
\begin{example}\label{exam 7.10}
Suppose $X$ and $Y$ are two independent standard normal random variables.
Now suppose we locate a point~$P$ in the $xy$-plane with coordinates $(X,Y)$ and
ask: What is the density of the square of the distance of~$P$ from the origin?
(We have already simulated this problem in Example~\ref{exam 5.19}.)  Here, with the preceding
notation, we have
$$
f_X(x) = f_Y(x) = \frac 1{\sqrt{2\pi}} e^{-x^2/2}\ .
$$
Moreover, if $X^2$ denotes the square of $X$, then (see Theorem~\ref{thm 5.1} and the
discussion following)

\begin{eqnarray*}
f_{X^2}(r) &=& \left \{ \begin{array}{ll}
        \frac{1}{2\sqrt r} (f_X(\sqrt r) + f_X(-\sqrt r))  & \;\mbox{if $r > 0,$} \\
                                     0                     & \;\mbox{otherwise.}
\end{array}
\right. \\
           &=& \left \{ \begin{array}{ll}
        \frac{1}{\sqrt {2 \pi r}} (e^{-r/2}) \hspace{.8in} & \;\mbox{if $r > 0,$} \\
                                       0                   & \;\mbox{otherwise.}
\end{array}
\right. \\
\end{eqnarray*}
This is a gamma density with $\lambda = 1/2$, $\beta = 1/2$ (see
Example~\ref{exam 7.7}).  Now let $R^2 = X^2 + Y^2$.  Then
\begin{eqnarray*}
f_{R^2}(r) &=& \int_{-\infty}^{+\infty} f_{X^2}(r - s) f_{Y^2}(s)\, ds \\
           &=& \frac 1{4\pi} \int_{-\infty}^{+\infty} e^{-(r - s)/2}
{\frac{r-s}{2}}^{-1/2} e^{-s} {\frac{s}{2}}^{-1/2}\, ds\ , \\
           &=& \left \{\begin{array}{ll}
                       {\frac {1}{2}} e^{-r^2/2}, & \;\mbox{if $r \geq 0,$} \\
                               0,                 & \;\mbox{otherwise.}
                  \end{array}
         \right.
\end{eqnarray*}
Hence, $R^2$ has a gamma density with $\lambda = 1/2$, $\beta = 1$.  We can
interpret this result as giving the density for the square of the distance
of~$P$ from the center of a target if its coordinates are normally distributed.

The density of the random variable $R$ is obtained from that of $R^2$ in the
usual way (see Theorem~\ref{thm 5.1}), and we find
$$
f_R(r) = \left \{ \begin{array}{ll}
                       \frac 12 e^{-r^2/2} \cdot 2r = re^{-r^2/2},
                                          & \;\mbox{if $r \geq 0,$} \\
                               0,         & \;\mbox{otherwise.}
                  \end{array}
         \right.
$$

Physicists will recognize this as a Rayleigh density.  Our
result here agrees with our simulation in Example~\ref{exam 5.19}.
\end{example}

\subsection*{Chi-Squared Density}\index{chi-squared density}\index{density function!chi-squared}
More generally, the same method shows that the sum of the squares of~$n$
independent normally distributed random variables with mean~0 and standard
deviation~1 has a gamma density with $\lambda = 1/2$ and $\beta = n/2$.  Such a
density is called a  \emx {chi-squared density} with $n$ degrees of freedom.  This
density was introduced in Chapter~\ref{chp 5}.  In Example~\ref{exam 5.20}, we
used this density to test the hypothesis that two traits were independent.
\par
Another important use of the chi-squared density is in comparing experimental data
with a theoretical discrete distribution, to see whether the data supports the
theoretical model.  More specifically, suppose that we have an experiment with a
finite set of outcomes.  If the set of outcomes is countable, we group them into
finitely many sets of outcomes.  We propose a theoretical distribution which we think
will model the experiment well.  We obtain some data by repeating the  experiment a
number of times.  Now we wish to check how well the theoretical distribution fits the
data.
\par
Let $X$ be the random variable which represents a theoretical outcome in the model
of the experiment, and let $m(x)$ be the distribution function of $X$.  In a manner
similar to what was done in Example~\ref{exam 5.20}, we calculate the value of the
expression
$$
V = \sum_x \frac{(o_x - n \cdot m(x))^2}{n \cdot m(x)}\ ,
$$
where the sum runs over all possible outcomes $x$, $n$ is the number of data
points, and $o_x$ denotes the number of outcomes of type $x$ observed
in the data.  Then for moderate or large values of $n$, the quantity $V$ is
approximately chi-squared distributed, with $\nu - 1$ degrees of freedom, where
$\nu$ represents the number of possible outcomes.  The proof of this is beyond the
scope of this book, but we will illustrate the reasonableness of this statement in
the next example.  If the value of $V$ is very large, when compared with the
appropriate chi-squared density function, then we would tend to reject the hypothesis
that the model is an appropriate one for the experiment at hand.  We now give an
example of this procedure.

\begin{example}
Suppose we are given a single die.  We wish to test the hypothesis that the die is
fair.  Thus, our theoretical distribution is the uniform distribution on the integers
between 1 and 6.  So, if we roll the die $n$ times, the expected number of data
points of each type is $n/6$.  Thus, if $o_i$ denotes the actual number of data
points of type $i$, for $1 \le i \le 6$, then the expression
$$V = \sum_{i = 1}^6 \frac{(o_i - n/6)^2}{n/6}$$
is approximately chi-squared distributed with 5 degrees of freedom.
\par
Now suppose that we actually roll the die 60 times and obtain the
data in Table~\ref{table 7.1}.
\begin{table}
\centering
\begin{tabular}{|c|c|}
\hline
 Outcome & Observed Frequency \\
\hline 1 & 15\\
\hline 2 & \hspace{.08in}8 \\
\hline 3 & \hspace{.08in}7 \\
\hline 4 & \hspace{.08in}5 \\
\hline 5 & \hspace{.08in}7 \\
\hline 6 & 18 \\
\hline
\end{tabular}
\caption{Observed data.}
\label{table 7.1}
\end{table}
If we calculate $V$ for this data, we obtain the value 13.6.  The graph of the
chi-squared density with 5 degrees of freedom is shown in Figure~\ref{fig 7.7}.  One
sees that values as large as 13.6 are rarely taken on by $V$ if the die is fair, so we
would reject the hypothesis that the die is fair.   (When using this test, a
statistician will reject the hypothesis if the data gives a value of $V$ which is
larger than 95\% of the values one would expect to obtain if the hypothesis is true.)
\putfig{3.5truein}{PSfig7-7}{Chi-squared density with 5 degrees of freedom.}{fig 7.7}
\par
In Figure~\ref{fig 7.8}, we show the results of rolling a die 60 times, then
calculating $V$, and then repeating this experiment 1000 times.  The program that performs
these calculations is called {\bf DieTest}.\index{DieTest (program)}  We
have  superimposed the chi-squared density with 5 degrees of freedom; one can see
that the data values fit the curve fairly well, which supports the statement
that the chi-squared density is the correct one to use.
\putfig{4.5truein}{PSfig7-8}{Rolling a fair die.}{fig 7.8}
\end{example}

So far we have looked at several important special cases for which the
convolution integral can be evaluated explicitly.  In general, the convolution
of two continuous densities cannot be evaluated explicitly, and we must resort
to numerical methods.  Fortunately, these prove to be remarkably effective, at
least for bounded densities.

\subsection*{Independent Trials}
We now consider briefly the distribution of the sum of~$n$ independent random
variables, all having the same density function.  If $X_1$,~$X_2$, \dots,~$X_n$
are these random variables and $S_n = X_1 + X_2 +\cdots+ X_n$ is their sum, then we
will have
$$
f_{S_n}(x) = \left( f_{X_1} * f_{X_2} *\cdots* f_{X_n} \right)(x)\ ,
$$
where the right-hand side is an $n$-fold convolution.  It is possible to
calculate this density for general values of~$n$ in certain simple cases.

\begin{example}\label{exam 7.12}
Suppose the $X_i$ are uniformly distributed\index{convolution!of uniform densities} on the interval
$[0,1]$.  Then
$$
f_{X_i}(x) = \left \{ \begin{array}{ll}
                         1,         & \;\mbox{if $0 \leq x \leq 1,$} \\
                         0,         & \;\mbox{otherwise,}
                   \end{array}
          \right.
$$
and $f_{S_n}(x)$ is given by the formula\index{USPENSKY, J. B.}\footnote{J.~B. Uspensky,
{\em Introduction to Mathematical Probability} (New York: McGraw-Hill, 1937),
p.~277.}
$$
f_{S_n}(x) = \left \{ \begin{array}{ll}
                         \frac 1{(n - 1)!} \sum_{0 \leq j \leq x} (-1)^j
 { n \choose j} (x - j)^{n - 1},     & \;\mbox{if $0 < x < n,$} \\
                         0,          & \;\mbox{otherwise.}
                   \end{array}
          \right.
$$
The density $f_{S_n}(x)$ for~$n = 2$,~4, 6, 8,~10 is shown in Figure~\ref{fig 7.9}.

\putfig{4.5truein}{PSfig7-9}{Convolution of $n$ uniform densities.}{fig 7.9}

If the $X_i$ are distributed normally,\index{convolution!of standard normal densities} with mean~0
and variance~1, then (cf.~Example~\ref{exam 7.8})
$$
f_{X_i}(x) = \frac 1{\sqrt{2\pi}} e^{-x^2/2}\ ,
$$
and
$$
f_{S_n}(x) = \frac 1{\sqrt{2\pi n}} e^{-x^2/2n}\ .
$$
Here the density $f_{S_n}$ for~$n = 5$,~10, 15, 20,~25 is shown in Figure~\ref{fig 7.10}.

\putfig{4.5truein}{PSfig7-10}{Convolution of $n$ standard normal densities.}{fig 7.10}

If the $X_i$ are all exponentially distributed,\index{convolution!of exponential densities}
with mean~$1/\lambda$, then
$$
f_{X_i}(x) = \lambda e^{-\lambda x}\ ,
$$
and
$$
f_{S_n}(x) = \frac {\lambda e^{-\lambda x}(\lambda x)^{n - 1}}{(n - 1)!}\ .
$$
In this case the density $f_{S_n}$ for~$n = 2$,~4, 6, 8,~10 is shown in
Figure~\ref{fig 7.11}.
\putfig{4.5truein}{PSfig7-11}
{Convolution of $n$ exponential densities with $\lambda = 1$.}{fig 7.11}
\end{example}

\exercises
\begin{LJSItem}

\i\label{exer 7.2.0.5}  Let $X$ and $Y$ be independent real-valued random variables
with density functions $f_X(x)$ and $f_Y(y)$, respectively.  Show that the density
function of the sum $X + Y$ is the convolution of the functions $f_X(x)$ and $f_Y(y)$.
\emx {Hint}:  Let $\bar X$ be the joint random variable $(X, Y)$.  Then the joint
density function of $\bar X$ is $f_X(x)f_Y(y)$, since $X$ and $Y$ are independent.  Now
compute the probability that $X+Y \le z$, by integrating the joint density function over the
appropriate region in the plane.  This gives the cumulative distribution function of $Z$.
Now differentiate this function with respect to $z$ to obtain the density function of $z$.

\i\label{exer 7.2.1} Let $X$ and $Y$ be independent random variables defined
on the space $\Omega$, with density functions $f_X$~and~$f_Y$, respectively.
Suppose that $Z = X + Y$.  Find the density $f_Z$ of~$Z$ if
\begin{enumerate}
\item $$f_X(x) = f_Y(x) = \left \{ \begin{array}{ll}
                              1/2,   & \;\mbox{if $-1 \leq x \leq +1,$} \\
                              0,     & \;\mbox{otherwise.}
                  \end{array}
         \right. $$

\item $$f_X(x) = f_Y(x) = \left \{ \begin{array}{ll}
                              1/2,   & \;\mbox{if $3 \leq x \leq 5,$} \\
                              0,     & \;\mbox{otherwise.}
                  \end{array}
         \right. $$

\item $$f_X(x) = \left \{ \begin{array}{ll}
                              1/2,   & \;\mbox{if $-1 \leq x \leq 1,$} \\
                              0,     & \;\mbox{otherwise.}
                  \end{array}
         \right. $$
\smallskip
$$f_Y(x) = \left \{ \begin{array}{ll}
                              1/2,   & \;\mbox{if $3 \leq x \leq 5,$} \\
                              0,     & \;\mbox{otherwise.}
                  \end{array}
         \right. $$
\item What can you say about the set $E = \{\,z : f_Z(z)> 0\,\}$ in each
case?
\end{enumerate}

\i\label{exer 7.2.2} Suppose again that $Z = X + Y$.  Find $f_Z$ if
\begin{enumerate}
\item $$f_X(x) = f_Y(x) = \left \{ \begin{array}{ll}
                    x/2, & \mbox{if $0 < x < 2,$} \\
                      0, & \mbox{otherwise}.
                  \end{array}
         \right. $$

\item $$f_X(x) = f_Y(x) = \left \{ \begin{array}{ll}
                 (1/2)(x - 3), & \mbox{if $3 < x < 5,$} \\
                            0, & \mbox{otherwise}.
                  \end{array}
         \right. $$

\item $$f_X(x) = \left \{ \begin{array}{ll}
                       1/2,    & \mbox{if $0 < x < 2,$} \\
                            0, & \mbox{otherwise},
                  \end{array}
         \right. $$
\smallskip
 $$f_Y(x) = \left \{ \begin{array}{ll}
                          x/2, & \mbox{if $0 < x < 2,$} \\
                            0, & \mbox{otherwise}.
                  \end{array}
         \right. $$
\item What can you say about the set $E = \{\,z : f_Z(z)> 0\,\}$ in each
case?
\end{enumerate}

\i\label{exer 7.2.3} Let $X$, $Y$, and $Z$ be independent random variables
with
$$f_X(x) = f_Y(x) = f_Z(x)  = \left \{ \begin{array}{ll}
                              1,     & \mbox{if $0 < x < 1,$} \\
                              0,     & \mbox{otherwise.}
                  \end{array}
         \right. $$
\noindent Suppose that $W = X + Y + Z$.  Find $f_W$ directly, and compare your answer
with that given by the formula in Example~\ref{exam 7.12}.   \emx {Hint}:  See
Example~\ref{exam 7.6}.

\i\label{exer 7.2.3.5} Suppose that $X$ and $Y$ are independent and $Z = X + Y$.  Find
$f_Z$ if

\begin{enumerate}
\item $$f_X(x) = \left \{ \begin{array}{ll}
                              \lambda e^{-\lambda x}, & \mbox{if $x > 0,$} \\
                               0,                     & \mbox{otherwise.}
                  \end{array}
         \right. $$
\smallskip
$$f_Y(x) = \left \{ \begin{array}{ll}
                              \mu e^{-\mu x}, & \mbox{if $x > 0,$} \\
                              0,              & \mbox{otherwise.}
                  \end{array}
         \right. $$
\item $$\ \ \ f_X(x) = \left \{ \begin{array}{ll}
                              \lambda e^{-\lambda x}, & \mbox{if $x > 0,$} \\
                              0,                      & \mbox{otherwise.}
                  \end{array}
         \right. $$

\smallskip
$$f_Y(x) = \left \{ \begin{array}{ll}
                    1, & \mbox{if $0 < x < 1,$} \\
                    0, & \mbox{otherwise.}
                  \end{array}
         \right. $$
\end{enumerate}

\i\label{exer 7.2.100} Suppose again that $Z = X + Y$.  Find $f_Z$ if
\begin{eqnarray*}
f_X(x) &=& \frac 1{\sqrt{2\pi}\sigma_1} e^{-(x - \mu_1)^2/2\sigma_1^2} \\
f_Y(x) &=& \frac 1{\sqrt{2\pi}\sigma_2} e^{-(x - \mu_2)^2/2\sigma_2^2}\ .
\end{eqnarray*}

%********The next problem is too hard.
\istar\label{exer 7.2.101} Suppose that $R^2 = X^2 + Y^2$.  Find $f_{R^2}$ and $f_R$ if
\begin{eqnarray*}
f_X(x) &=& \frac 1{\sqrt{2\pi}\sigma_1} e^{-(x - \mu_1)^2/2\sigma_1^2} \\
f_Y(x) &=& \frac 1{\sqrt{2\pi}\sigma_2} e^{-(x - \mu_2)^2/2\sigma_2^2}\ .
\end{eqnarray*}

\i\label{exer 7.2.101.5} Suppose that $R^2 = X^2 + Y^2$.  Find $f_{R^2}$ and $f_R$ if
$$
f_X(x) = f_Y(x) = \left \{ \begin{array}{ll}
                    1/2, & \mbox{if $-1 \leq x \leq 1,$} \\
                    0,   & \mbox{otherwise.}
                  \end{array}
         \right.
$$

\i\label{exer 7.2.102} Assume that the service time for a customer at a bank is
exponentially distributed with mean service time 2~minutes.  Let $X$ be the total service
time for 10 customers.  Estimate the probability that $X > 22$ minutes.

\i\label{exer 7.2.9} Let $X_1$,~$X_2$, \dots,~$X_n$ be $n$ independent random
variables each of which has an exponential density with mean~$\mu$.  Let $M$ be
the \emx {minimum} value of the $X_j$.  Show that the density for~$M$ is
exponential with mean $\mu/n$.   \emx {Hint}:  Use cumulative distribution functions.

\i\label{exer 7.2.103} A company buys 100 lightbulbs, each of which has an exponential
lifetime of 1000 hours.  What is the expected time for the first of these bulbs to burn
out?  (See Exercise~\ref{exer 7.2.9}.)

\i\label{exer 7.2.104} An insurance company assumes that the time between claims from
each of its homeowners' policies is exponentially distributed with mean~$\mu$.  It
would like to estimate $\mu$ by averaging the times for a number of policies,
but this is not very practical since the time between claims is about
30~years.  At Galambos'\index{GALAMBOS, J.}\footnote{J. Galambos,  \emx {Introductory
Probability Theory} (New York: Marcel Dekker, 1984), p.~159.} suggestion the company puts
its customers in groups of~50 and observes the time of the first claim within
each group.  Show that this provides a practical way to estimate the value
of~$\mu$.

\i\label{exer 7.2.105} Particles are subject to collisions that cause them to split into
two parts with each part a fraction of the parent.  Suppose that this fraction is
uniformly distributed between 0~and~1.  Following a single particle through
several splittings we obtain a fraction of the original particle $Z_n = X_1
\cdot X_2 \cdot\dots\cdot X_n$ where each $X_j$ is uniformly distributed
between 0~and~1.  Show that the density for the random variable $Z_n$ is
$$
f_n(z) = \frac 1{(n - 1)!}( -\log z)^{n - 1}.
$$
 \emx {Hint}: Show that $Y_k = -\log X_k$ is exponentially distributed.  Use
this to find the density function for $S_n = Y_1 + Y_2 +\cdots+ Y_n$, and
from this the cumulative distribution and density of $Z_n = e^{-S_n}$.

\i\label{exer 7.2.106} Assume that $X_1$ and $X_2$ are independent random variables, each
having an exponential density with parameter~$\lambda$.  Show that $Z = X_1 - X_2$ has
density
$$
f_Z(z) = (1/2)\lambda e^{-\lambda |z|}\ .
$$

\i\label{exer 7.2.107} Suppose we want to test a coin for fairness.  We flip the coin $n$
times and record the number of times $X_0$ that the coin turns up tails and the
number of times $X_1 = n - X_0$ that the coin turns up heads.  Now we set
$$
Z= \sum_{i = 0}^1 \frac {(X_i - n/2)^2}{n/2}\ .
$$
Then for a fair coin $Z$ has approximately a chi-squared distribution with $2 -
1 = 1$ degree of freedom.  Verify this by computer simulation first for a fair
coin ($p~=~1/2$) and then for a biased coin ($p~=~1/3$).

\i\label{exer 7.2.108} Verify your answers in Exercise~\ref{exer 7.2.1}(a) by computer
simulation: Choose $X$ and $Y$ from $[-1,1]$ with uniform density and calculate
$Z = X + Y$.  Repeat this experiment 500 times, recording the outcomes in a bar
graph on $[-2,2]$ with 40~bars.  Does the density $f_Z$ calculated in Exercise~\ref{exer
7.2.1}(a) describe the shape of your bar graph?  Try this for Exercises~
\ref{exer 7.2.1}(b)~and~Exercise~\ref{exer 7.2.1}(c), too.

\i\label{exer 7.2.109} Verify your answers to Exercise~\ref{exer 7.2.2} by computer
simulation.

\i\label{exer 7.2.110} Verify your answer to Exercise~\ref{exer 7.2.3} by computer
simulation.

\i\label{exer 7.2.18} The  \emx {support} of a function $f(x)$ is defined to be the set
$$
\{x\ :\ f(x) > 0\}\ .$$
Suppose that $X$ and $Y$ are two continuous random variables with
density functions $f_X(x)$ and $f_Y(y)$, respectively, and suppose that the supports of these
density functions are the intervals $[a, b]$ and $[c, d]$, respectively.  Find the support of the
density function of the random variable $X+Y$.

\i\label{exer 7.2.111} Let $X_1$,~$X_2$, \dots,~$X_n$ be a sequence of independent random
variables, all having a common density function $f_X$ with support $[a,b]$ (see
Exercise~\ref{exer 7.2.18}).  Let $S_n = X_1 + X_2 +\cdots+ X_n$, with density
function $f_{S_n}$.  Show that the support of~$f_{S_n}$ is the interval
$[na,nb]$.   \emx {Hint}: Write $f_{S_n} = f_{S_{n - 1}} * f_X$.  Now use
Exercise~\ref{exer 7.2.18} to establish the desired result by induction.

\i\label{exer 7.2.112} Let $X_1$,~$X_2$, \dots,~$X_n$ be a sequence of independent random
variables, all having a common density function $f_X$.  Let $A = S_n/n$ be
their average.  Find $f_A$ if
\begin{enumerate}
\item $f_X(x) = (1/\sqrt{2\pi}) e^{-x^2/2}$ (normal density).

\item $f_X(x) = e^{-x}$ (exponential density).
\par
\noindent \emx {Hint}: Write $f_A(x)$ in terms of $f_{S_n}(x)$.
\end{enumerate}

\end{LJSItem}}


\section{Convolutions}
\subsection{Motivation}
Taking Laplace transforms can be difficult.
We already have some basic formulas derived from linearity properties of integrals that allow us to not evaluate an integral every time.\\

\noindent
One sort of formula that would be nice to have is one relating products of functions.
If we know that
\begin{equation*}
	H(s) = F(s)G(s),
\end{equation*}
where $F$ and $G$ are the Laplace transforms of $f$ and $g$, it'd be nice if we could find the inverse Laplace transform of $H$ to get $h$.
This is one way to define the convolution.

\subsection{Definition \& Convolution Theorem}
\begin{definition}
	Let $F(s)$ and $G(s)$ be the Laplace transforms of functions $f(t)$ and $g(t)$.
	Then
	\begin{equation*}
		F(s)G(s) = \Laplace{f \star g}.
	\end{equation*}
\end{definition}
\noindent
Note how using this definition we can see that $\star$, the convolution operator, is commutative.

\noindent
Defining this function that works like multiplication over Laplace transforms is only really useful if we have a formula for it, so let's derive one.
Starting from the left-hand side of the equation in the definition and applying the integral definition of the Laplace transform,
\begin{equation*}
	F(s)G(s) = \int_{0}^{\infty}{e^{-su}f(u)\d{u}} \cdot \int_{0}^{\infty}{e^{-sv}f(v)\d{v}}.
\end{equation*}
Making this product of integrals into a double integral (we usually do this in reverse when simplifying a double integral),
\begin{equation*}
	= \int_{0}^{\infty}{\int_{0}^{\infty}{e^{-s(u+v)}f(u)g(v)\d{u}}\d{v}}.
\end{equation*}
Letting $t = u+v$,
\begin{equation*}
	= \int_{0}^{\infty}{\int_{0}^{t}{e^{-st}f(u)g(t-u)\d{u}}\d{t}}.
\end{equation*}
Bringing $e^{-st}$ outside of the innermost integral,
\begin{equation*}
	= \int_{0}^{\infty}{e^{-st}\left[\int_{0}^{t}{f(u)g(t-u)\d{u}}\right]\d{t}}.
\end{equation*}
We see that we have the Laplace transform of the expression in the square brackets.
So,
\begin{equation*}
	f \star g = \int_{0}^{t}{f(u)g(t-u)\d{u}}.
\end{equation*}
This is an equivalent way to define the convolution.

\begin{example}
	Compute the convolution of $t^2$ with $t$.
\end{example}
\noindent
Applying the formula we just derived,
\begin{align*}
	t^2 \star t &= \int_{0}^{t}{u^2(t-u)\d{u}} \\
	&= t\frac{u^3}{3} - \frac{u^4}{4} \bigg\rvert_{0}^{t} \\
	&= \frac{t^4}{3} - \frac{t^4}{4} \\
	&= \frac{t^4}{12}.
\end{align*}

\subsection{Properties}
Convolution inherits all the linearity properties of integration.
Let $f(t)$, $g(t)$, and $h(t)$ be piecewise continuous on $[0,\infty)$.
Let $a$ be a real constant.
Then
\begin{enumerate}[label=]
	\item \textbf{Commutativity} -- $f \star = g \star f$
	\item \textbf{Associativity} -- $(f \star g) \star h = f \star (g \star h)$
	\item \textbf{Distributivity over Addition} -- $f \star (g + h) = (f \star g) + (f \star h)$
	\item \textbf{Associativity over Scalar Multiplication} -- $a(f \star g) = (af) \star g$
\end{enumerate}

\subsection{Applications}
When we're using Laplace transforms to solve a differential equation, if we recognize $\Laplace{y}$ as the product of two functions for which we know the inverse Laplace transforms, we can compute a convolution to find $y$.

\begin{example}
	Solve the following differential equation using Laplace transforms and convolutions.
	Let $a$ and $c$ be real constants where $a \neq c$.
	\begin{equation*}
		y' - ay = e^{ct}.\footnotemark
	\end{equation*}
\end{example}
\footnotetext{When we're taking the Laplace transform of both sides, we implicitly use that $y(0)=0$.}
\noindent
Taking the Laplace transform of both sides,
\begin{align*}
	s\Laplace{y} - a\Laplace{y} &= \frac{1}{s-c} \\
	\Laplace{y}(s-a) &= \frac{1}{s-c}.
\end{align*}
Solving for $\Laplace{y}$,
\begin{equation*}
	\Laplace{y} = \frac{1}{s-c} \cdot \frac{1}{s-a}.
\end{equation*}
Recognizing the right-hand side of the equation as the product of the Laplace transforms of $e^{ct}$ and $e^{at}$, we can solve for $y$ by finding the convolution of $e^{ct}$ and $e^{at}$.
Applying our formula,
\begin{align*}
	F(s) = \frac{1}{s-c} &\text{ and } G(s) = \frac{1}{s-a} \\
	f(t) = e^{ct} &\text{ and } g(t) = e^{at}. \\
	y(t) &= f(t) \star g(t) \\
	&= \int_{0}^{t}{e^{cu}e^{a(t-u)}\d{u}} \\
	&= e^{at}\int_{0}^{t}{e^{u(c-a)}\d{u}} \\
	&= e^{at}\left(\frac{e^{(c-a)t}}{c-a} - \frac{1}{c-a}\right) \\
	&= \frac{e^{ct} - e^{at}}{c-a}.
\end{align*}


\subsection{GRASP + Tabu Search}

In order to find a time optimal algorithm to solve the multidimensional precedence-constrained knapsack problem (MPKP), we propose a comparative analysis of an implementation of a Integer Linear Program to solve MPKP and a near optimal algorithm utilizing GRASP and Tabu Search as GRASP's local search.

\begin{algorithm}[ht!]
    \caption{GRASP Pseudocode}
    \begin{algorithmic}[1]
        \Require{$MaxIterations, Seed$}
        \For{$k=1,\ldots,MaxIterations$}
            \State{$Solution \leftarrow Greedy Randomized Construction(Seed);$}
            \If{Solution is not feasible}
                \State{$Solution \leftarrow Repair(Solution)$;}
            \EndIf
            \State{$Solution \leftarrow LocalSearch(Solution);$}
            \State{$UpdateSolution(Solution, BestSolution);$}
        \EndFor
        \\\Return{$BestSolution$}
    \end{algorithmic}
\end{algorithm}
where the candidate list is build greedily utilizing the current maximal elements on our input graph(as long as they fit).
There's no need to use any repair method as the solution built from the candidate list will always fit in the knapsack.
That way, we do a local search and update our solution with the best one seen to far.

The trick here is to use a Tabu Search, instead of a naive local search method, to both avoid falling in local optima and utilizing the tabu list in order to avoid repeating moves and other. We use GRASP as a diversification strategy.

We now define exactly how this search is proposed.

Let $n \in \mathbb N$ be the number of binary variables of an input instance. The tabu list, let's call it $Tabu$ is a mapping $Tabu : StrN \rightarrow \mathbb N$, with pre-defined $Tabu.size$ capacity, where $StrN$ is an arrangement of $n$ bits let's call it $Arr$, where $n$ is the number of binary variables of our instance, and the $i$-th bit represents the state of $x_i$, where $Arr[i] = x_i$.

We also utilize a heap structure to get the earliest added tabu in $O(1)$ time.

During the local search, at each iteration we add the current state of our binary variables an element of $Tabu$. If the total number of tabus is equal to $Tabu.size$ we pop the earliest added tabu from our heap and remove that tabu from $Tabu$ while adding the new move to $Tabu$.

Each time that the Tabu Search tries to do a tabu move the integer in $Tabu$ associated with this move is looked up by the search, if the tabu exists, and if it equals $1$, that tabu is removed from the mapping.

Each move in the Tabu Search is a bit flip operation of a variable in a randomly selected, at every search iteration, subset $BinVars$ of the set of all binary variables of the input instance, such that $|BinVars| = k <= n$, where $k \in \mathbb{N}$ is a pre-defined parameter, as a way to limit the search space of the Tabu Search.

The best values for $k$ and $Tabu.size$ will be determined by tests.


\subsection{Exponents}
Eigenmath requires parentheses around negative exponents.
For example,

\begin{Verbatim}[formatcom=\color{blue}]
10^(-3)
\end{Verbatim}

instead of

\begin{Verbatim}[formatcom=\color{blue}]
10^-3
\end{Verbatim}

The reason for this is that the binding of the negative sign is not always
obvious.
For example, consider

\begin{Verbatim}[formatcom=\color{blue}]
x^-1/2
\end{Verbatim}

It is not clear whether the exponent should be $-1$ or $-1/2$.
So Eigenmath requires

\begin{Verbatim}[formatcom=\color{blue}]
x^(-1/2)
\end{Verbatim}

which is unambiguous.
In general, parentheses are always required when the exponent
is an expression.
For example, \verb$x^1/2$ is evaluated as $(x^1)/2$ which
is probably not the desired result.

\begin{Verbatim}[formatcom=\color{blue}]
x^1/2
\end{Verbatim}

$\displaystyle \frac{1}{2}x$

Using \verb$x^(1/2)$ yields the desired result.

\begin{Verbatim}[formatcom=\color{blue}]
x^(1/2)
\end{Verbatim}

$\displaystyle x^{1/2}$


\documentclass{article}
\usepackage{amsmath}
\usepackage[margin=1.0in]{geometry}
\usepackage{xcolor}

\begin{document}

\noindent
Does $\displaystyle \sum_{n=2}^\infty \frac{2n}{n^2-1}$
diverge, converge absolutely, or converge conditionally?

\subsection*{Solution 1}

The function $f(x)=\frac{2x}{x^2-1}$ is continuous, positive, and decreasing on $[2,\infty)$.
\begin{align*}
\int_2^\infty \frac{2x}{x^2-1}\,dx
&= \lim_{t \to \infty} \int_2^t \frac{2x}{x^2-1}\,dx\\
&= \lim_{t \to \infty} (\ln|t^2-1| - \ln |2^2-1|)\\
&= \infty
\end{align*}
Since the integral $\displaystyle \int_2^\infty \frac{2x}{x^2-1}\,dx$ diverges, the series $\displaystyle \sum_{n=2}^\infty \frac{2n}{n^2-1}$ diverges by the Integral Test.

\subsection*{Solution 2}

The series $\sum \frac1{n}$ diverges by the $p$-test. Let $a_n = \frac{2n}{n^2-1}$ and $b_n=\frac1{n}$. Then
\begin{align*}
\lim_{n \to \infty} \frac{a_n}{b_n}
&= \lim_{n \to \infty} \frac{2n^2}{n^2-1}\\
&= \lim_{n \to \infty} \frac{4n}{2n} \text{ by L'hopital}\\
&= \lim_{n \to \infty} 2 \\
&= 2
\end{align*}
Since this limit is a finite, positive number, by the Limit Comparison Test, the series $\displaystyle \sum_{n=2}^\infty \frac{2n}{n^2-1}$ diverges.

\subsection*{Solution 3}

This series can also be examined using the Direct Comparison Test, but we skip this method for this series.

\end{document}%%%%%%%%%%%%%%%%%

\begin{align*}
L&=\lim_{n \to \infty} \sqrt[n]{|a_n|}\\
&= \lim_{n \to \infty} \sqrt[n]{\left| \right|}\\
\end{align*}

\begin{align*}
L&=\lim_{n \to \infty} \left|\frac{a_{n+1}}{a_n}\right|\\
&= \lim_{n \to \infty} \left| \right|\\
\end{align*}

\begin{align*}
\lim_{n \to \infty} a_n
&= \lim_{n \to \infty} \\
\end{align*}

\begin{align*}
\lim_{n \to \infty} \frac{a_n}{b_n}
&= \lim_{n \to \infty} \\
\end{align*}

Since $\sum |a_n| = \sum a_n$, the series $\displaystyle \sum_{n=1}^\infty AAAAAAAAAAAAAA$ converges absolutely.

Since $|r| < 1$, the series ...  converges by the Geometric Series Test.

Since $|r| \geq 1$, the series ...  diverges by the Geometric Series Test.

The function $f(x)=\frac{}{}$ is continuous, positive, and decreasing on $[1,\infty)$.

\subsection*{Solution}


\section{Inverses of functions}
Riemann surfaces naturally arise when trying to invert complex functions. As in the real case, the inverse of the function $f(x) = x^2$ is not well-defined. There are multiple ways to remedy this, but the most \emph{geometric} solution is to study the graph $y = x^2$ as a subset of $\bbr^2$ and use this to construct inverses wherever they make sense.

We do the same for complex functions. Let $p(z)$ be a polynomial of degree $n$. Finding the inverse function is equivalent to solving
\begin{align*}
  w = p(z)
\end{align*}
to get $z$ in terms of $w$.
This is almost never possible, so instead we study the graph
\begin{align*}
  \Gamma_{p(z)} :=
  \set{ (z,w): w = p(z)} \subseteq \bbc^2
\end{align*}
Denote by $\pi: \bbc^2$ the projection onto the $w$- coordinate axis\footnote{We are working over complex numbers, so everything is twice the dimension of real numbers. So a complex axis is complex dimension 1 but real dimension 2.}.
$\Gamma_{p(z)}$ is an example of a Riemann surface!
Our first goal is to undestand the geometry of this object. We'll do this using the projection $\pi$.

\subsection{Ramified coverings}
Consider the restriction of $\pi$ to $\Gamma_{p(z)}$.
\begin{align*}
  \pi : \Gamma_{p(z)} \rightarrow \bbc
\end{align*}
\begin{qbox}
  Show that this map is surjective.
\end{qbox}
The inverse set $\pi^{-1}(w)$ (called the \emph{fiber} over $w$) is the set of roots of $p(z) - w$.
\begin{qbox}
  Prove that there are only finitely many values of $w$ for which $\pi^{-1}(w)$ has size $< n$. And that outside this set the fiber has size exactly $n$.
\end{qbox}

\begin{definition}
  For $w \in \bbc$, if the polynomial $p(z) - w$ has distinct roots, then $w$ is called \emph{unramified}.
  This is equivalent to requiring that the fiber $\pi^{-1}(w)$ has size $n$.
  If $p(z) - w$ has repeated roots then, if $z$ is a repeated root of $p(z) - w$ of order $k$ we say that the \emph{ramification index} $e_P$ of $P = (z,w)$ is $k$.
\end{definition}
\begin{qbox}
  For $w_0 \in \bbc$, let $\pi^{-1}(w_0) = \set{P_1, \dots, P_l}$, then
  \begin{align*}
    e_{P_1} + \dots + e_{P_l} = n
  \end{align*}
\end{qbox}
\begin{figure}[H]
\centering
  \includegraphics[width=5cm]{example-image}
  % \includegraphics[width=]{}
  \caption{Picture of ramification}
  \label{figure:ramification}
\end{figure}

A much stronger statement is true on the topological level.
Let $w$ be an unramified value. Then $p(z) - w$ has $n$ distinct roots $z_1, \dots, z_n$. If we perturb $w$ slightly then the corresponding roots $z_i$ will also get perturbed slightly.

For $\epsilon \in \bbr$ let $B_\epsilon(w) \subset \bbc$ denote a ball of radius $\epsilon$ around $w$.
\begin{theorem}
  \label{theorem:coveringMap}
  For an unramified value $w \in \bbc$, let $z_1, \dots, z_n$ be the distinct roots of $p(z) - w$.
  Then there exists an $\epsilon$ such that $\pi^{-1}(B_\epsilon(w))$ has the following properties.
  \begin{enumerate}
    \item $\pi^{-1}(B_\epsilon(w))$ has $n$-connected components $U_1, \dots, U_n$,
    \item $z_i \in U_i$,
    \item the projections $\pi: U_i \rightarrow B_\epsilon(w)$ are a homeomorphism.
  \end{enumerate}
\end{theorem}

Theorem \ref{theorem:coveringMap} is saying that the map $\pi$ restricted to the fibers of unramified values is a \emph{covering map}
\begin{align*}
  \pi: \pi^{-1}(\mbox{\{unramified values\}}) \longrightarrow \mbox{\{unramified values\}}.
\end{align*}

In Figure \ref{figure:ramification} the ramified points appear to be singular, but

A graph is always homeomorphic to the base i.e. the
\begin{align*}
  \bbc &\rightarrow \Gamma_{p(z)}
  z \mapsto (z, p(z))
\end{align*}
is always a homeomorphism.
So the Riemann surface we have constructed is homeomorphic to $\bbc$ itself!
We'll improve upon this in the following sections.

\subsection{Sections as inverse functions}
We now have a way of constructing inverse functions, which relies on the following theorem from topology.

A space is said to be \emph{simply-connected} if it is path-connected and every loop in $X$ can be continuously deformed to a point.

\begin{theorem}
  If $X$ is a simply-connected space and $\pi:Y \rightarrow X$ is a finite covering of $X$ of degree $n$ then $Y$ is homeomorphic to $n$-disjoint copies of $X$ and the projection map on each connected component is a homeomorphism.
  \begin{equation*}
    \begin{tikzcd}
      Y \cong X_1 \sqcup \dots \sqcup X_n\\
      X_i
      \ar[d, "\cong", "\pi"'] \\
      X
    \end{tikzcd}
  \end{equation*}
  This statement is also true when the covering is not finite. In this case, $Y$ is a disjoint union of infinitely many components.
\end{theorem}

Now we have a meaninful procedure to construct inverse functions of ramified coverings of $\bbc$.
Consider the ramified covering $\pi: \Gamma_{p(z)} \rightarrow \bbc$ with ramified values $w_1, \dots, w_l$ (these are called the \emph{branch points}).
\begin{enumerate}
  \item Consider the set of unramified points $\bbc \setminus \set{w_1, \dots, w_l}$. This set is never simply-connected (unless $l = 0$).
  \item Pick an arbitrary open subset $U$ of $\bbc \setminus \set{w_1, \dots, w_l}$ which is simply-connected. This is usually done by removing rays (called \emph{branch cuts}) emanating from the points $w_i$.
  \item The restriction $\pi: p^{-1}(U) \rightarrow U$ is a finite covering of a simply-connected connected space $U$, hence $U \cong U_1 \sqcup \dots \sqcup U_n$.
  \item Pick an aribtrary connected component $U_i$ so that $\pi:U_i \rightarrow U$ is a homeomorphism. Because this is a homeomorphism it has an inverse $\pi_i^{-1}: U \rightarrow U_i$.
  \item The function $\pi_i^{-1}$ followed by projection onto the $z$-coordinate is then an inverse of the function $p$. It is called a \emph{branch} of the inverse function (and so there are $n$ possible branches).
\end{enumerate}
We need to choose \emph{branch cuts} and a \emph{branch} to define an inverse function.
\begin{ex}
  \todo{add an example here.}
\end{ex}


\section{The univalence axiom}

\subsection{Equivalent forms of the univalence axiom}

The univalence axiom characterizes the identity type of the universe. Roughly speaking, it asserts that equivalent types are equal. It is considered to be an \emph{extensionality principle}\index{extensionality principle!types} for types. In the following theorem we introduce the univalence axiom and give two more equivalent ways of stating this.

\begin{defn}
  The \define{univalence axiom}\index{univalence axiom|textbf} on a universe $\UU$ is the statement that for any $A:\UU$ the family of maps\index{equiv_eq@{$\mathsf{equiv\usc{}eq}$}|textbf}
\begin{equation*}
\mathsf{equiv\usc{}eq}\defeq \mathsf{path\usc{}ind}_A(\idfunc[A]) : \prd{B:\UU} (\id{A}{B})\to(\eqv{A}{B}).
\end{equation*}
is a family of equivalences.\index{identity type!universe} A universe satisfying the univalence axiom is referred to as a \define{univalent universe}. If $\UU$ is a univalent universe we will write
$\mathsf{eq\usc{}equiv}$\index{eq equiv@{$\mathsf{eq\usc{}equiv}$}|textbf}
for the inverse of $\mathsf{equiv\usc{}eq}$.
\end{defn}

The following theorem is a special case of \cref{thm:id_fundamental}. Subsequently we will assume that any type is contained in a univalent universe.

\begin{thm}\label{thm:univalence}
The following are equivalent:
\begin{enumerate}
\item The univalence axiom holds.
\item The type
\begin{equation*}
\sm{B:\UU}\eqv{A}{B}
\end{equation*}
is contractible for each $A:\UU$.
\item The principle of \define{equivalence induction}\index{equivalence induction}\index{induction principle!for equivalences}: for every $A:\UU$ and for every type family
\begin{equation*}
P:\prd{B:\UU} (\eqv{A}{B})\to \mathsf{Type},
\end{equation*}
the map
\begin{equation*}
\Big(\prd{B:\UU}{e:\eqv{A}{B}}P(B,e)\Big)\to P(A,\idfunc[A])
\end{equation*}
given by $f\mapsto f(A,\idfunc[A])$ has a section.
\end{enumerate}
\end{thm}

\subsection{Univalence implies function extensionality}
One of the first applications of the univalence axiom was Voevodsky's theorem that the univalence axiom on a universe $\UU$ implies function extensionality for types in $\UU$. The proof uses the fact that weak function extensionality implies function extensionality.

We will also make use of the following lemma. Note that this statement was also part of \cref{lem:postcomp_equiv}. That exercise is solved using function extensionality. Since our present goal is to derive function extensionality from the univalence axiom, we cannot make use of that exercise.

\begin{lem}\label{lem:postcomp-equiv}
  For any equivalence $e:\eqv{X}{Y}$ in a univalent universe $\UU$, and any type $A$, the post-composition map
  \begin{equation*}
    e\circ\blank : (A \to X) \to (A\to Y)
  \end{equation*}
  is an equivalence.
\end{lem}

\begin{proof}
  The statement is obvious for the identity equivalence $\idfunc : \eqv{X}{X}$. Therefore the claim follows by equivalence induction, which is by \cref{thm:univalence} one of the equivalent forms of the univalence axiom.
\end{proof}

\begin{thm}
  For any universe $\UU$, the univalence axiom on $\UU$ implies function extensionality on $\UU$.
\end{thm}

\begin{proof}
Note that \cref{thm:funext_wkfunext} also holds when it is restricted to small types.
Therefore it suffices to show that univalence implies the weak principle of function extensionality.

Suppose that $B:A\to \UU$ is a family of contractible types. Our goal is to show that the product $\prd{x:A}B(x)$ is contractible.
Since each $B(x)$ is contractible, the projection map $\proj 1:\big(\sm{x:A}B(x)\big)\to A$ is an equivalence by \cref{ex:proj_fiber}.

Now it follows by \cref{lem:postcomp-equiv} that $\proj1\circ\blank$ is an equivalence. Consequently, it follows from \cref{thm:contr_equiv} that the fibers of
\begin{equation*}
\proj 1\circ\blank : \Big(A\to \sm{x:A}B(x)\Big)\to (A\to A)
\end{equation*}
are contractible. In particular, the fiber at $\idfunc[A]$ is contractible. Therefore it suffices to show that $\prd{x:A}B(x)$ is a retract of $\sm{f:A\to\sm{x:A}B(x)}\proj 1\circ f=\idfunc[A]$. In other words, we will construct
\begin{equation*}
\begin{tikzcd}
\Big(\prd{x:A}B(x)\Big) \arrow[r,"i"] & \Big(\sm{f:A\to\sm{x:A}B(x)}\proj 1\circ f=\idfunc[A]\Big) \arrow[r,"r"] & \Big(\prd{x:A}B(x)\Big),
\end{tikzcd}
\end{equation*}
and a homotopy $r\circ i\htpy \idfunc$.

We define the function $i$ by
\begin{equation*}
  i(f) \defeq (\lam{x}(x,f(x)),\refl{\idfunc}).
\end{equation*}
To see that this definition is correct, we need to know that
\begin{equation*}
  \lam{x}\proj 1(x,f(x))\jdeq \idfunc.
\end{equation*}
This is indeed the case, by the $\eta$-rule for $\Pi$-types.

Next, we define the function $r$. Let $h:A\to \sm{x:A}B(x)$, and let $p:\proj 1 \circ h = \idfunc$. Then we have the homotopy $H\defeq\mathsf{htpy\usc{}eq}(p):\proj 1 \circ h \htpy \idfunc$. Then we have $\proj 2(h(x)):B(\proj 1(h(x)))$ and we have the identification $H(x):\proj 1(h(x))=x$. Therefore we define $r$ by
\begin{equation*}
  r((h,p),x)\defeq \mathsf{tr}_B(H(x),\proj 2(h(x))).
\end{equation*}

We note that if $p\jdeq \refl{\idfunc}$, then $H(x)\jdeq\refl{x}$. In this case we have the judgmental equality $r((h,\refl{}),x)\jdeq\proj 2 (h(x))$. Thus we see that $r\circ i\jdeq \idfunc$ by another application of the $\eta$-rule for $\Pi$-types.
\end{proof}

\subsection{Propositional extensionality, posets, and subuniverses}

\begin{thm}\label{thm:propositional-extensionality}
  Propositions satisfy \define{propositional extensionality}:
  for any two propositions $P$ and $Q$, the canonical map
  \begin{equation*}
    (P=Q)\to (P\leftrightarrow Q)
  \end{equation*}
  is an equivalence. It follows that the type $\prop$ of propositions in $\UU$ is a set.
\end{thm}

Note that for any $P:\prop$, we usually also write $P$ for the underlying type of the proposition $P$. If we would be more formal about it we would have to write $\proj 1(P)$ for the underlying type, since $\prop$ is the $\Sigma$-type $\sm{X:\UU}\mathsf{is\usc{}prop}(X)$. In the following proof it is clearer if we use the more formal notation $\proj 1(P)$ for the underlying type of a proposition $P$.

\begin{proof}
  We note that the identity type $P=Q$ is an identity type in $\prop$. However, since $\mathsf{is\usc{}prop}(X)$ is a proposition for any type $X$, it follows that the map
  \begin{equation*}
    \apfunc{\proj 1} : (P = Q) \to (\proj 1(P) = \proj 1(Q))
  \end{equation*}
  is an equivalence. Now we observe that we have a commuting square
  \begin{equation*}
    \begin{tikzcd}[column sep=huge]
      (P=Q) \arrow[d,swap,"\apfunc{\proj 1}"] \arrow[r] & (P\leftrightarrow Q) \\
      (\proj 1(P)=\proj 1(Q)) \arrow[r,swap,"\mathsf{equiv\usc{}eq}"] & (\proj 1(P)\simeq\proj 1(Q)) \arrow[u,swap,"\simeq"]
    \end{tikzcd}
  \end{equation*}
  Since the left, bottom, and right map are equivalences, it follows that the top map is an equivalence.
\end{proof}

\begin{defn}
  A \define{partially ordered set (poset)} is a set $P$ equipped with a relation
  \begin{equation*}
    \blank\leq\blank : P \to (P \to \prop)
  \end{equation*}
  that is \define{reflexive} (for every $x:P$ we have $x\leq x$), \define{transitive} (for every $x,y,z:P$ such that $x\leq y$ and $y\leq z$ we have $x\leq z$), and \define{anti-symmetric} (for every $x,y:P$ such that $x\leq y$ and $y\leq x$ we have $x=y$).
\end{defn}

\begin{rmk}
  The condition that $X$ is a set can be omitted from the definition of a poset. Indeed, if $X$ is any type that comes equipped with a $\prop$-valued ordering relation $\leq$ that is reflexive and anti-symmetric, then $X$ is a set by \cref{lem:prop_to_id}.
\end{rmk}

\begin{eg}
  The type $\prop$ is a poset, where the ordering relation is given by implication: $P$ is less than $Q$ if $P\to Q$. The fact that $P\to Q$ is a proposition is a special case of \cref{cor:funtype_trunc}. The relation $P\to Q$ is reflexive by the identity function, and transitive by function composition. Moreover, the relation $P\to Q$ is anti-symmetric by \cref{thm:propositional-extensionality}.
\end{eg}

\begin{eg}
  The type of natural numbers comes equipped with at least two important poset structures. The first is given by the usual ordering relation $\leq$, and the second is given by the relation $d\mid n$ that $d$ divides $n$.
\end{eg}

\begin{thm}
  For any poset $P$ and any type $X$, the set $P^X$ is a poset. In particular the type of subtypes of any type is a poset.
\end{thm}

\begin{proof}
  Let $P$ be a poset with ordering $\leq$, and let $X$ be a type. Then $P^X$ is a set by \cref{cor:funtype_trunc}. For any $f,g:X\to P$ we define
  \begin{equation*}
    (f\leq g) \defeq \prd{x:X}f(x)\leq g(x).
  \end{equation*}
  Reflexivity and transitivity follow immediately from reflexivity and transitivity of the original relation. Moreover, by the anti-symmetry of the orignal relation it follows that
  \begin{equation*}
    (f\leq g)\times (g\leq f) \to (f\htpy g).
  \end{equation*}
  Therefore we obtain an identification $f=g$ by function extensionality. The last claim follows immediately from the fact that a subtype of $X$ is a map $X\to\prop$, and the fact that $\prop$ is a poset.
\end{proof}

Another important application of the univalence axiom is that any subuniverse is closed under equivalences. In this section we let $\UU$ be a univalent universe.

\begin{thm}
  Let $P:\UU\to\prop$ be a subuniverse of $\UU$. Then we have
  \begin{equation*}
    (X\simeq Y)\to (P(X) \to P(Y))
  \end{equation*}
  for any two types $X,Y:\UU$.
\end{thm}

\begin{proof}
  We define the map $(X\simeq Y)\to (P(X)\to P(Y))$ as the composite
  \begin{equation*}
    \begin{tikzcd}
      (X\simeq Y) \arrow[r,"\mathsf{eq\usc{}equiv}"] &[2em] (X=Y) \arrow[r,"\mathsf{tr}_P"] & (P(X)\to P(Y)).
    \end{tikzcd}\qedhere
  \end{equation*}
\end{proof}

\subsection{Groups in univalent mathematics}

In this section we exhibit a typical way to use the univalence axiom, showing that isomorphic groups can be identified.
This is an instance of the \emph{structure identity principle}\index{structure identity principle}, which is described in more detail in section 9.8 of \cite{hottbook}.
We will see that in order to establish the fact that isomorphic groups can be identified, it has to be part of the definition of a group that its underlying type is a set. This is an important observation: in many branches of algebra the objects of study are \emph{set-level} structures\footnote{A notable exception is that of categories, which are objects at truncation level $1$, i.e., at the level of \emph{groupoids}. For more on this, see Chapter 9 of \cite{hottbook}.}.

\subsubsection{Semi-groups and groups}
We introduce the type of groups in two stages: first we introduce the type of \emph{semi-groups}, and then we introduce groups as semi-groups that possess further structure. It will turn out that this further structure is in fact a property, and this fact will help us to prove that isomorphic grous are equal.

\begin{defn}
  A \define{semi-group} consists of a set $G$ and an associative binary operation on $G$, i.e., a binary function
  \begin{equation*}
    \mu_G : G \to (G \to G)
  \end{equation*}
  equipped with a homotopy
  \begin{equation*}
    \mathsf{assoc}_G : \prd{x,y.z:G}\mu_G(\mu_G(x,y),z)=\mu_G(x,\mu_G(y,z)).
  \end{equation*}
  We write $\mathsf{Semi\usc{}Group}$ for the type of all semi-groups.
\end{defn}

\begin{defn}
  A semi-group $G$ is said to be \define{unital} if it comes equipped with a \define{unit} $e_G:G$ that satisfies the left and right unit laws
  \begin{align*}
    \mathsf{left\usc{}unit}_G : \prd{y:G}\mu_G(e_G,y)=y \\
    \mathsf{right\usc{}unit}_G : \prd{x:G}\mu_G(x,e_G)=x.
  \end{align*}
  We write $\mathsf{is\usc{}unital}(G)$ for the type of such triples $(e_G,\mathsf{left\usc{}unit}_G,\mathsf{right\usc{}unit}_G)$. Unital semi-groups are also called \define{monoids}.
\end{defn}

The unit of a semi-group is of course unique once it exists. In univalent mathematics we express this fact by asserting that the type $\mathsf{is\usc{}unital}(G)$ is a proposition for each semi-group $G$. In other words, being unital is a \emph{property} of semi-groups rather than structure on it. This is typical for univalent mathematics: we express that a structure is a property by proving that this structure is a proposition.

\begin{lem}
  For a semi-group $G$ the type $\mathsf{is\usc{}unital}(G)$ is a proposition.
\end{lem}

\begin{proof}
  Let $G$ be a semi-group. Note that since $G$ is a set, it follows that the types of the left and right unit laws are propositions. Therefore it suffices to show that any two terms $e,e':G$ satisfying the left and right unit laws can be identified. This is easy:
  \begin{equation*}
    e = \mu_G(e,e') = e'.\qedhere
  \end{equation*}
\end{proof}

\begin{defn}
  Let $G$ be a unital semi-group. We say that $G$ has inverses if it comes equipped with an operation $x\mapsto x^{-1}$ of type $G\to G$, satisfying the left and right inverse laws
  \begin{align*}
    \mathsf{left\usc{}inv}_G : \prd{x:G}\mu_G(x^{-1},x)=e_G \\
    \mathsf{right\usc{}inv}_G : \prd{x:G}\mu_G(x,x^{-1}) = e_G.
  \end{align*}
  We write $\mathsf{is\usc{}group}'(G,e)$ for the type of such triples $((\blank)^{-1},\mathsf{left\usc{}inv}_G,\mathsf{right\usc{}inv}_G)$, and we write
  \begin{equation*}
    \mathsf{is\usc{}group}(G)\defeq\sm{e:\mathsf{is\usc{}unital}(G)}\mathsf{is\usc{}group}'(G,e)
  \end{equation*}
  A \define{group} is a unital semi-group with inverses. We write $\mathsf{Group}$ for the type of all groups.
\end{defn}

\begin{lem}
  For any semi-group $G$ the type $\mathsf{is\usc{}group}(G)$ is a proposition.
\end{lem}

\begin{proof}
  We have already seen that the type $\mathsf{is\usc{}unital}(G)$ is a proposition. Therefore it suffices to show that the type $\mathsf{is\usc{}group}'(G,e)$ is a proposition for any $e:\mathsf{is\usc{}unital}(G)$.

  Since a semi-group $G$ is assumed to be a set, we note that the types of the inverse laws are propositions. Therefore it suffices to show that any two inverse operations satisfying the inverse laws are homotopic.

  Let $x\mapsto x^{-1}$ and $x\mapsto \bar{x}^{-1}$ be two inverse operations on a unital semi-group $G$, both satisfying the inverse laws. Then we have the following identifications
  \begin{align*}
    x^{-1} & = \mu_G(e_G,x^{-1}) \\
    & = \mu_G(\mu_G(\bar{x}^{-1},x),x^{-1}) \\
    & = \mu_G(\bar{x}^{-1},\mu_G(x,x^{-1})) \\
    & = \mu_G(\bar{x}^{-1},e_G) \\
    & = \bar{x}^{-1}
  \end{align*}
  for any $x:G$. Thus the two inverses of $x$ are the same, so the claim follows.
\end{proof}

\begin{eg}
  An important class of examples consists of \define{loop spaces}\index{loop space|textbf} $x=x$ of a $1$-type $X$, for any $x:X$.
  We will write $\loopspace{X,x}$ for the loop space of $X$ at $x$.
  Since $X$ is assumed to be a $1$-type, it follows that the type $\loopspace{X,x}$ is a set. Then we have
  \begin{align*}
    \refl{x} & : \loopspace{X,x} \\
    \mathsf{inv} & : \loopspace{X,x} \to \loopspace{X,x} \\
    \mathsf{concat} & : \loopspace{X,x} \to (\loopspace{X,x}\to \loopspace{X,x}),
  \end{align*}
  and these operations satisfy the group laws, since the group laws are just a special case of the groupoid laws for identity types, constructed in \cref{sec:groupoid}.

  Using higher inductive types we will show in \cref{chap:image} that \emph{every} group is of this form.
\end{eg}

\begin{eg}
  The type $\Z$ of integers\index{Z@{$\Z$}!is a group} can be given the structure of a group, with the group operation being addition. The fact that $\Z$ is a set follows from \cref{thm:eq_nat,ex:set_coprod}. The group laws were shown in \cref{ex:int_group_laws}.
\end{eg}

\begin{eg}
  Our last class of examples consists of the \define{automorphism groups} on sets. Given a set $X$, we define
  \begin{equation*}
    \mathsf{Aut}(X)\defeq (X\simeq X).
  \end{equation*}
  The group operation of $\mathsf{Aut}(X)$ is just composition of equivalences, and the unit of the group is the identity function. Note however, that although function composition is strictly associative and satisfies the unit laws strictly, composition of equivalences only satisfies the group laws up to identification because the proof that composites are equivalences is carried along.

  Important special cases of the automorphism groups are the symmetry groups
  \begin{equation*}
    \mathcal{S}_n\defeq \mathsf{Aut}(\mathsf{Fin}(n)).
  \end{equation*}
\end{eg}

\subsubsection{Homomorphisms of semi-groups and groups}

\begin{defn}
  Let $G$ and $H$ be semi-groups. A homomorphism $f:G\to H$ of semi-groups is a pair $(f,\mu_f)$ consisting of a function $f:G\to H$ between their underlying types, and a term
  \begin{equation*}
    \mu_f:\prd{x,y:G} f(\mu_G(x,y))=\mu_H(f(x),f(y))
  \end{equation*}
  witnessing that $f$ preserves the binary operation of $G$. We will write
  \begin{equation*}
    \mathsf{hom}(G,H)
  \end{equation*}
  for the type of all semi-group homomorphisms from $G$ to $H$.
\end{defn}

\begin{rmk}\label{rmk:is-set-hom-semi-group}
  Since it is a property for a function to preserve the multiplication of a semi-group, it follows easily that equality of semi-group homomorphisms is equivalent to the type of homotopies between their underlying functions. In particular, it follows that the type of homomorphisms of semi-groups is a set.
\end{rmk}

\begin{rmk}
  The \define{identity homomorphism} on a semi-group $G$ is defined to be the pair consisting of
  \begin{align*}
    \idfunc & : G \to G \\
    \lam{x}{y}\refl{xy} & : \prd{x,y:G} xy = xy.
  \end{align*}
  Let $f:G\to H$ and $g:H\to K$ be semi-group homomorphisms. Then the composite function $g\circ f:G\to K$ is also a semi-group homomorphism, since we have the identifications
  \begin{equation*}
    \begin{tikzcd}
      g(f(xy)) \arrow[r,equals] & g(f(x)f(y)) \arrow[r,equals] & g(f(x))g(f(y)).
    \end{tikzcd}
  \end{equation*}
  Since the identity type of semi-group homomorphisms is equivalent to the type of homotopies between semi-group homomorphisms it is easy to see that semi-group homomorphisms satisfy the laws of a category, i.e., that we have the identifications
  \begin{align*}
    \idfunc\circ f & = f \\
    g\circ \idfunc & = g \\
    (h\circ g) \circ f & = h \circ (g \circ f)
  \end{align*}
  for any composable semi-group homomorphisms $f$, $g$, and $h$. Note, however that these equalities are not expected to hold judgmentally, since preservation of the semi-group operation is part of the data of a semi-group homomorphism.
\end{rmk}

\begin{defn}
  A homomorphism $f:G\to H$ of groups is defined to be a semi-group homomorphism between their underlying semi-groups. We will write
  \begin{equation*}
    \mathsf{hom}(G,H)
  \end{equation*}
  for the type of all group homomorphisms from $G$ to $H$.
\end{defn}

\begin{rmk}
  Since a group homomorphism is just a semi-group homomorphism between the underlying semi-groups, we immediately obtain the identity homomorphism, composition, and the category laws are satisfied.
\end{rmk}

\subsubsection{Isomorphic semi-groups are equal}

\begin{defn}
Let $h:\mathrm{hom}(\mathcal{G},\mathcal{H})$ be a group homomorphism. Then $h$ is said to be an \define{isomorphism}\index{group homomorphism!isomorphism}\index{isomorphism!of groups} if there is a group homomorphism $h^{-1}:\mathrm{hom}(\mathcal{H},\mathcal{G})$ such that
\begin{equation*}
h^{-1}\circ h=\idfunc[\mathcal{G}]\qquad\text{and}\qquad h\circ h^{-1}=\idfunc[\mathcal{H}].
\end{equation*}
We write $\mathcal{G}\cong\mathcal{H}$ for the type of all group isomorphisms from $\mathcal{G}$ to $\mathcal{H}$, i.e.,
\begin{equation*}
\mathcal{G}\cong\mathcal{H} \defeq \sm{h:\mathrm{hom}(\mathcal{G},\mathcal{H})}{k:\mathrm{hom}(\mathcal{H},\mathcal{G})} (k\circ h = \idfunc[\mathcal{G}])\times (h\circ k=\idfunc[\mathcal{H}]).
\end{equation*}
\end{defn}

If $f$ is an isomorphism, then its inverse is unique. In other words, being an isomorphism is a property.

\begin{lem}
  For any semi-group homomorphism $h:\mathsf{hom}(G,H)$, the type
  \begin{equation*}
    \mathsf{is\usc{}iso}(h)
  \end{equation*}
  is a proposition. It follows that the type $G\cong H$ is a set for any two semi-groups $G$ and $H$.
\end{lem}

\begin{proof}
  Let $k$ and $k'$ be two inverses of $h$. In \cref{rmk:is-set-hom-semi-group} we have observed that the type of semi-group homomorphisms between any two semi-groups is a set. Therefore it follows that the types $h\circ k=\idfunc$ and $k\circ h=\idfunc$ are propositions, so it suffices to check that $k=k'$. In \cref{rmk:is-set-hom-semi-group} we also observed that the equality type $k=k'$ is equivalent to the type of homotopies $k\htpy k'$ between their underlying functions. We construct a homotopy $k\htpy k'$ by the usual argument:
  \begin{equation*}
    \begin{tikzcd}
      k(y) \arrow[r,equals] & k(h(k'(y)) \arrow[r,equals] & k'(y).
    \end{tikzcd}\qedhere
  \end{equation*}
\end{proof}

\begin{lem}\label{lem:grp_iso}
  A semi-group homomorphism $h:\mathsf{hom}(G,H)$ is an isomorphism if and only if its underlying map is an equivalence. Consequently, there is an equivalence
  \begin{equation*}
    (G\cong H)\simeq \sm{e:G\simeq H}\prd{x,y:G}e(\mu_G(x,y))=\mu_H(e(x),e(y))
  \end{equation*}
\end{lem}

\begin{proof}
  If $h:\mathsf{hom}(G,H)$ is an isomorphism, then the inverse semi-group homomorphism also provides an inverse of the underlying map of $h$. Thus we obtain that $h$ is an equivalence. The standard proof showing that if the underlying map $f:G\to H$ of a group homomorphism is invertible then its inverse is again a group homomorphism also works in type theory.
\end{proof}

\begin{defn}
Let $\mathcal{G}$ and $\mathcal{H}$ be a semi-groups. We define the map\index{iso_eq@{$\mathsf{iso\usc{}eq}$}|textbf}
\begin{equation*}
\mathsf{iso\usc{}eq} : (\mathcal{G}=\mathcal{H})\to (\mathcal{G}\cong\mathcal{H})
\end{equation*}
by path induction, taking $\refl{\mathcal{G}}$ to isomorphism $\idfunc[\mathcal{G}]$.
\end{defn}

\begin{thm}\label{thm:iso-eq-semi-group}
The map
\begin{equation*}
\mathsf{iso\usc{}eq} : (\mathcal{G}=\mathcal{H})\to (\mathcal{G}\cong\mathcal{H})
\end{equation*}
is an equivalence for any two semi-groups $\mathcal{G}$ and $\mathcal{H}$.
\end{thm}

\begin{proof}
By \cref{thm:id_fundamental} it suffices to show that the total space
\begin{equation*}
\sm{\mathcal{G}':\mathsf{Semi\usc{}Grp}}\mathcal{G}\cong\mathcal{G}'
\end{equation*}
is contractible. Since the type of isomorphisms from $\mathcal{G}$ to $\mathcal{G}'$ is equivalent to the type of equivalences from $\mathcal{G}$ to $\mathcal{G}'$ it suffices to show that the type
\begin{equation*}
  \sm{\mathcal{G}':\mathsf{Semi\usc{}Grp}}\sm{e:\eqv{G}{G'}}\prd{x,y:G}e(\mu_G(x,y))=\mu_{G'}(e(x),e(y)))
\end{equation*}
is contractible\footnote{In order to show that a type of the form
  \begin{equation*}
    \sm{(x,y):\sm{x:A}B(x)}\sm{z:C(x)}D(x,y,z)
  \end{equation*}
  is contractible, a useful strategy is to first show that the type $\sm{x:A}C(x)$ is contractible. Once this is established, say with center of contraction $(x_0,z_0)$, it suffices to show that the type $\sm{y:B(x_0)}D(x_0,y,z_0)$ is contractible.}. Since $\mathsf{Semi\usc{}Grp}$ is the $\Sigma$-type
\begin{equation*}
  \sm{G':\mathsf{Set}}\mathsf{has\usc{}associative\usc{}mul}(G'),
\end{equation*}
it suffices to show that the types
\begin{align*}
  & \sm{G':\mathsf{Set}}\eqv{G}{G'} \\
  & \sm{\mu':\mathsf{has\usc{}associative\usc{}mul}(G)}\prd{x,y:G}\mu_G(x,y)=\mu'(x,y)
\end{align*}
is contractible. The first type is contractible by the univalence axiom. The second type is contractible by function extensionality.
\end{proof}

\begin{cor}
The type $\mathsf{Semi\usc{}Grp}$ is a $1$-type.\index{Semi-Grp@{$\mathsf{Semi-Grp}$}!is a $1$-type|textit}
\end{cor}

\begin{proof}
It is straightforward to see that the type of group isomorphisms $\mathcal{G}\cong\mathcal{H}$ is a set, for any two groups $\mathcal{G}$ and $\mathcal{H}$.
\end{proof}

\subsubsection{Isomorphic groups are equal}

Analogously to the map $\mathsf{iso\usc{}eq}$ of semi-groups, we have a map $\mathsf{iso\usc{}eq}$ of groups. Note, however, that the domain of this map is now the identity type $G=H$ of the \emph{groups} $G$ and $H$, so the maps $\mathsf{iso\usc{}eq}$ of semi-groups and groups are not exactly the same maps.

\begin{defn}
  Let $G$ and $H$ be groups. We define the map
  \begin{equation*}
    \mathsf{iso\usc{}eq} : (G=H)\to (G\cong H)
  \end{equation*}
  by path induction, taking $\refl{G}$ to the identity isomorphism $\idfunc:G\cong G$.
\end{defn}

\begin{thm}
  For any two groups $G$ and $H$, the map
  \begin{equation*}
    \mathsf{iso\usc{}eq}:(G=H)\to (G\cong H)
  \end{equation*}
  is an equivalence.
\end{thm}

\begin{proof}
  Let $G$ and $H$ be groups, and write $UG$ and $UH$ for their underlying semi-groups, respectively. Then we have a commuting triangle
  \begin{equation*}
    \begin{tikzcd}
      (G=H) \arrow[rr,"\apfunc{\proj 1}"] \arrow[dr,swap,"\mathsf{iso\usc{}eq}"] & & (UG=UH) \arrow[dl,"\mathsf{iso\usc{}eq}"] \\
      & (G\cong H)
    \end{tikzcd}
  \end{equation*}
  Since being a group is a property of semi-groups it follows that the projection map $\mathsf{Grp}\to\mathsf{Semi\usc{}Grp}$ forgetting the unit and inverses, is an embedding. Thus the top map in this triangle is an equivalence. The map on the right is an equivalence by \cref{thm:iso-eq-semi-group}, so the claim follows by the 3-for-2 property.
\end{proof}

\begin{cor}
  The type of groups is a $1$-type.
\end{cor}

\subsection{Categories in univalent mathematics}

In our proof of the fact that isomorphic groups are equal we have made extensive use of the notion of group homomorphism. What we have shown, in fact, is that there is a category of groups which is \emph{Rezk complete} in the sense that the type of isomorphisms between two objects is equivalent to the type of identifications between those objects. In this final section we briefly introduce the notion of Rezk complete category. There are many more examples of categories, such as the categories of rings, or modules over a ring.

\begin{defn}
  A \define{pre-category} $\mathcal{C}$ consists of
  \begin{enumerate}
  \item A type $A$ of \define{objects}.
  \item For every two objects $x,y:A$ a set
    \begin{equation*}
      \mathsf{hom}(x,y)
    \end{equation*}
    of \define{morphisms} from $x$ to $y$.
  \item For every object $x:A$ an \define{identity morphism}
    \begin{equation*}
      \idfunc : \mathsf{hom}(x,x)
    \end{equation*}
  \item For every two morphisms $f:\mathsf{hom}(x,y)$ and $g:\mathsf{hom}(y,z)$, a morphism
    \begin{equation*}
      g\circ f :\mathsf{hom}(x,z)
    \end{equation*}
    called the \define{composite} of $f$ and $g$.
  \item the following terms
    \begin{align*}
      \mathsf{left\usc{}unit}_{\mathcal{C}} & : \idfunc \circ f = f \\
      \mathsf{right\usc{}unit}_{\mathcal{C}} & : g \circ \idfunc = g \\
      \mathsf{assoc}_{\mathcal{C}} & : (h \circ g) \circ f = h \circ (g \circ f)
    \end{align*}
    witnessing that the category laws are satisfied.
  \end{enumerate}
\end{defn}

\begin{eg}
  By \cref{rmk:category-semi-group,rmk:category-group} we have pre-categories of semi-groups and of groups.
\end{eg}

\begin{eg}
  A pre-category satisfying the condition that every hom-set is a proposition is a \define{preorder}.
\end{eg}

\begin{defn}
  Given a pre-category $\mathcal{C}$, a morphism $f:\mathsf{hom}(x,y)$ is said to be an \define{isomorphism} if there exists a morphism $g:\mathsf{hom}(y,x)$ such that
  \begin{align*}
    g\circ f & = \idfunc \\
    f \circ g & \idfunc.
  \end{align*}
  We will write $\mathsf{iso}(x,y)$ for the type of all isomorphisms in $\mathcal{C}$ from $x$ to $y$.
\end{defn}

\begin{rmk}
  Just as in the case for semi-groups and groups, the condition that $f:\mathsf{hom}(x,y)$ is an isomorphism is a property of $f$.
\end{rmk}

\begin{defn}
  A pre-category $\mathcal{C}$ is said to be \define{Rezk-complete} if the canonical map
  \begin{equation*}
    (x=y)\to \mathsf{iso}(x,y)
  \end{equation*}
  is an equivalence for any two objects $x$ and $y$ of $\mathcal{C}$. Rezk-complete pre-categories are also called \define{categories}.
\end{defn}

\begin{eg}
  The pre-category of sets is Rezk complete by the univalence axiom, so it is a category.
\end{eg}

\begin{eg}
  The pre-categories of semi-groups and groups are Rezk-complete. Therefore they form categories.
\end{eg}

\begin{eg}
  A pre-order is Rezk-complete if and only if it is anti-symmetric. In other words, a poset is precisely a category for which all the hom-sets are propositions. Thus, we see that the anti-symmetry axiom can be seen as a univalence axiom for pre-orders.
\end{eg}

\begin{exercises}
\item Let $X$ be a set. Show that the map
  \begin{equation*}
    \mathsf{equiv\usc{}eq} : (X=X)\to (\eqv{X}{X})
  \end{equation*}
  is a group isomorphism.
%\item \label{ex:tr_ap} Show that for any $P:X\to \UU$ and any $p:x=y$ in $X$, we have\index{equiv_eq@{$\mathsf{equiv\usc{}eq}$}}\index{transport}
%\begin{equation*}
%\mathsf{equiv\usc{}eq}(\ap{P}{p})\htpy \mathsf{tr}_P(p).
%\end{equation*}
\item \label{ex:istrunc_UUtrunc}
\begin{subexenum}
\item Use the univalence axiom to show that the type $\sm{A:\UU}\iscontr(A)$ of all contractible types in $\UU$ is contractible.\index{universe!of contractible types}
\item Use \cref{cor:emb_into_ktype,cor:funtype_trunc,ex:isprop_isequiv} to show that if $A$ and $B$ are $(k+1)$-types, then the type $\eqv{A}{B}$ is also a $(k+1)$-type.\index{equiv@{$\eqv{A}{B}$}!truncatedness}
\item Use univalence to show that the universe of $k$-types\index{universe!of k-types@{of $k$-types}}\index{U leq k@{$\UU^{\leq k}$}|textbf}
\begin{equation*}
\UU^{\leq k}\defeq \sm{X:\UU}\mathsf{is\usc{}trunc}_k(X)
\end{equation*}
is a $(k+1)$-type, for any $k\geq -2$.
\item It follows that the universe of propositions $\UU^{\leq-1}$ is a set. However, show that $\UU^{\leq-1}$ is not a proposition.\index{universe!of propositions}
\item Show that $\eqv{(\eqv{\bool}{\bool})}{\bool}$, and conclude by the univalence axiom that the universe of sets\index{universe!of sets} $\UU^{\leq 0}$ is not a set.
\end{subexenum}
\item Use the univalence axiom to show that the type $\sm{P:\prop}P$ is contractible.
\item Let $A$ and $B$ be small types.
\begin{subexenum}
\item Construct an equivalence
\begin{equation*}
\eqv{(A\to (B\to\UU))}{\Big(\sm{S:\UU} (S\to A)\times (S\to B)\Big)}
\end{equation*}
\item We say that a relation $R:A\to (B\to\UU)$ is \define{functional}\index{relation!functional} if it comes equipped with a term of type\index{is_function(R)@{$\mathsf{is\usc{}function}(R)$}|textbf}
\begin{equation*}
\mathsf{is\usc{}function}(R) \defeq \prd{x:A}\iscontr\Big(\sm{y:B}R(x,y)\Big)
\end{equation*}
For any function $f:A\to B$, show that the \define{graph}\index{graph!of a function|textbf} of $f$
\begin{equation*}
\mathsf{graph}_f:A\to (B\to \UU)
\end{equation*}
given by $\mathsf{graph}_f(a,b)\defeq (f(a)=b)$ is a functional relation from $A$ to $B$.
\item Construct an equivalence
\begin{equation*}
\eqv{\Big(\sm{R:A\to (B\to\UU)}\mathsf{is\usc{}function}(R)\Big)}{(A\to B)}
\end{equation*}
\item Given a relation $R:A\to (B\to \UU)$ we define the \define{opposite relation}\index{relation!opposite relation|textbf}\index{opposite relation|textbf}\index{op R@{$R^{\mathsf{op}}$}|textbf}
\begin{equation*}
R^{\mathsf{op}} : B\to (A\to\UU)
\end{equation*}
by $R^{\mathsf{op}}(y,x)\defeq R(x,y)$. Construct an equivalence\index{equiv@{$\eqv{A}{B}$}!as relation}
\begin{equation*}
\eqv{\Big(\sm{R:A\to (B\to \UU)}\mathsf{is\usc{}function}(R)\times\mathsf{is\usc{}function}(R^{\mathsf{op}})\Big)}{(\eqv{A}{B})}.
\end{equation*}
\end{subexenum}
\item
  \begin{subexenum}
  \item Show that $\mathsf{is\usc{}decidable}(P)$ is a proposition, for any proposition $P$.
  \item Show that $\mathsf{classical\usc{}Prop}$ is equivalent to $\bool$.
  \end{subexenum}
\item
  \begin{subexenum}
  \item Consider a group $G$. Show that the function
    \begin{equation*}
      \mu_G:G\to (G\simeq G)
    \end{equation*}
    is an injective group homomorphism.
  \item Consider a type $A$. Show that the concatenation function
    \begin{equation*}
      \mathsf{concat}:\loopspace{A}\to (\loopspace{A}\simeq\loopspace{A})
    \end{equation*}
    is an embedding.
  \end{subexenum}
\item Let $f:\mathsf{hom}(G,H)$ be a group homomorphism. Show that $f$ preserves units and inverses, i.e., show that
  \begin{align*}
    f(e_G) & = e_H \\
    f(x^{-1}) & = f(x)^{-1}.
  \end{align*}
\item Give a direct proof and a proof using the univalence axiom of the fact that all semi-group isomorphisms between unital semi-groups preserve the unit. Conclude that isomorphic monoids are equal.
\item Recall that $\UU_\ast$ is the universe of pointed types. Construct for any pointed type $(X,x_0)$ an equivalence
  \begin{equation*}
    \Big(\sm{P:X\to \UU}P(x_0)\Big)\simeq \sm{(A,a_0):\UU_\ast}(A,a_0)\to_\ast(X,x_0).
  \end{equation*}
\end{exercises}


\documentclass[../PHYS306Notes.tex]{subfiles}

\begin{document}
\section{Lecture 12}
\subsection{Lecture Notes - Weakly Coupled Oscillators}
Recall from our work two lectures ago that for the 2-mass 3-springs problem, the eigenfrequencies were determined to be:
\[\omega_1 = \sqrt{\frac{k+2k_{12}}{m}}, \quad \omega_2 = \sqrt{\frac{k}{m}}\]
Now, we make the assumption that $k_{12} \ll k$, i.e. that the middle spring joining the masses is quite weak. In this limit, we can clearly see that $\omega_1 \approx \omega_2$. This generates an interesting physical case; here we can define a "middle frequency" which is the average of the two eigenfrequencies above:
\[\omega_0 = \frac{\omega_1 + \omega_2}{2}\]
We could then rewrite $\omega_1, \omega_2$ in terms of $\omega_0$ and a small parameter $\e$:
\[\omega_1 = \omega_0 + \e\]
\[\omega_2 = \omega_0 - \e\]
The general solution could then be written as:
\[\v{z}(t) = C_1\m{1 \\ -1}\exp(i(\omega_0 + \e)t) + C_2\m{1\\1}\exp(i(\omega_0 - \e)t)\]
We can factor this expression, recognizing common terms:
\[\v{z}(t) = \left(C_1\m{1 \\ -1}\exp(i\e t) + C_2\m{1\\1}\exp(-i\e t)\right)\exp(i\omega_0 t)\]
Now, suppose that $C_1 = C_2 = \frac{A}{2}$ (i.e. the two modes are excited to be the same amplitude). We then have that:
\[\v{z}(t) = \frac{A}{T}\m{\exp(i\e t) + \exp(-i\e t) \\ \exp(-i\e t) - \exp(i \e t)}\exp(i\omega_0 t)\]
Then using Euler's formula:
\[\v{z}(t) = A\m{\cos(\e t) \\ -i\sin(\e t)}\exp(i\omega_0 t)\]
Now taking the real part of this:
\[\Re\v{z}(t) = \v{x}(t) = \m{x_1 \\ x_2} = \m{A\cos(\e t)\cos(\omega_0 t) \\ A\sin(\e t)\sin(\omega_0 t)}\]
This result corresponds to a fast oscillation (e.g. at frequency $\omega_0$) modulated by a slower oscillation (at frequency $\e$ which is small by assumption). When graphed, this looks like:
\begin{center}
    \includegraphics[scale=0.5]{Lecture-12/l12-img1.png}
\end{center}
Where we see "beats"! Exactly like with AM radio waves, we see the frequency stay constant but the amplitude going up and down with time.
\end{document}