---
title: "Math 342 -- Homework X solutions"
author: "Tim Chumley"
date: "January 22, 2040"
output:
  pdf_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tinytex)
```

## Problem XYZ

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. Modify XYZ above to be the exercise number you are working on. Delete this text and write the exercise statement here.

#### Solution. 

Write your solution here.

Proposition 1.2: For events A, B, and C,
\begin{align*}
P(A \cup B \cup C)
     &= P(A) + P(B) + P(C) -  \\
&\hspace{1em} - P(AB) - P(AC) - P(BC)+ P(ABC)
\end{align*}


## Problem UVW

Write the next question here. It's useful to have the question statement here when you're studying later.

#### Solution.

Write your solution here.

# Markdown tips

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r chunk1}
# this is a comment, no code gets run on this line
set.seed(1) # setting the seed guarantees we all get the same "random" number
sample(1:6, size = 2, replace = TRUE) # simulation of rolling a die twice
sample(1:6, size = 2, replace = FALSE) # simulation of sampling without replacement
```

## Including Plots

You can also embed plots, for example:

```{r chunk2, echo=FALSE}
plot(x = 1:10, y = (1:10)^2, xlab = "input", ylab = "output")
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

# \LaTeX tips

Markdown documents support \LaTeX, a syntax for writing mathematical notation. Here are some useful commands for writing math.
This is how you can use math mode within a sentence, 
which is sometimes called in-line mode: $A\subseteq \Omega$. 
We can also make math appear centered and on its own line. 
This is often called a *displayed* equation: $$P(A) = \frac{1}{2}.$$
Remember, when writing math, punctuation matters. 
Even displayed equations should have a period if they end a sentence. 
For example, we have $$\int_{-\infty}^{\infty} e^{-x^2/2} = \sqrt{2\pi}.$$
Notice that
you need
a blank space in between lines of code to start a new paragraph.

## Align environment
For equations that span several lines, we use the align environment. The \texttt{\&} symbol tells where to anchor each line of the equation. The double backslash makes a new line.


We claim that when $X \sim Bin(n,p)$ is binomially distributed with parameters $n$ and $p$, its expection is given by $E[X] = np$. Indeed, observe that
\begin{align*}
E[X]	 &= \sum_{k = 1}^n k P(X = k) \\
		 &= \sum_{k = 1}^n k {n \choose k} p^k (1-p)^{n-k} \\
		 &= \sum_{k = 1}^n \frac{n!}{(k-1)!(n-k)!} p^k (1-p)^{n-k} \\
		 &= np.
\end{align*}

### Long equations

Sometimes you have an expression that's too long and cannot fit on one line.
The align environment is good for putting it on two separate lines and having
everything line up nicely. Notice that the command \texttt{\char`\\hspace\char`\{1em}} inserts a horizontal space that is as wide as the capital M letter.

\begin{align*}
P(A \cup B \cup C)
     &= P(A) + P(B) - P(AB)\\
		 &\hspace{1em} + P(C) - [P(AC) + P(BC) - P(ABC)]
\end{align*}

## Equation labels

For equations that you'd like to label and refer back to, there are a couple of options. The first is the \texttt{equation} environment, along with the \texttt{label} and \texttt{eqref} commands:

\begin{equation}
|\sin x|\leq 1 \label{eq:sine-bound}
\end{equation}

The displayed expression \eqref{eq:sine-bound} gets labeled with a numbered value, so that you can refer back to in the main body discussion.
You can do this with the \texttt{align} environment as well. Notice that leaving out the asterisk introduces number labels to each line:

\begin{align}
|a+b|^2 	&= (a+b)^2 \label{eq:square-abs-val} \\
		&= a^2 + 2ab + b^2 \nonumber \\ 
		&= |a|^2 + 2ab + |b|^2 \nonumber \\
		&\leq |a|^2 + 2|a||b| + |b|^2 \label{eq:abs-val-inequality} \\
		&= (|a|+|b|)^2.  \nonumber
\end{align}

This way, you can again reference expressions \eqref{eq:abs-val-inequality} and \eqref{eq:square-abs-val} and not worry about keeping track of the numbers. 

\newpage

## Problem ABC

You can start a new page with the \texttt{\char`\\newpage} command.

