\documentclass[12pt]{article}

\include{preamble}

\newtoggle{professormode}
\toggletrue{professormode} %STUDENTS: DELETE or COMMENT this line

\title{MATH 241 Fall 2017 Homework \#6}

\author{Professor Adam Kapelner} %STUDENTS: write your name here

\iftoggle{professormode}{
\date{Due 11:59PM KY 604 (under the door), Thursday, Nov 30, 2017 \\ \vspace{0.5cm} \small (this document last updated \today ~at \currenttime)}
}

\renewcommand{\abstractname}{Instructions and Philosophy}

\begin{document}
\maketitle

\iftoggle{professormode}{
\begin{abstract}
The path to success in this class is to do many problems. Unlike other courses, exclusively doing reading(s) will not help. Coming to lecture is akin to watching workout videos; thinking about and solving problems on your own is the actual ``working out''.  Feel free to \qu{work out} with others; \textbf{I want you to work on this in groups.}

Reading is still \textit{required}. For this homework set, read the section about the continuous r.v.'s --- the exponential, the uniform and the normal / Gaussian in Ross as well as moment generating functions and their basic properties.

The problems below are color coded: \ingreen{green} problems are considered \textit{easy} and marked \qu{[easy]}; \inorange{yellow} problems are considered \textit{intermediate} and marked \qu{[harder]}, \inred{red} problems are considered \textit{difficult} and marked \qu{[difficult]} and \inpurple{purple} problems are extra credit. The \textit{easy} problems are intended to be ``giveaways'' if you went to class. Do as much as you can of the others; I expect you to at least attempt the \textit{difficult} problems.

This homework is worth 100 points but the point distribution will not be determined until after the due date. See syllabus for the policy on late homework.

Up to 15 points are given as a bonus if the homework is typed using \LaTeX. Links to instaling \LaTeX~and program for compiling \LaTeX~is found on the syllabus. You are encouraged to use \url{overleaf.com}. If you are handing in homework this way, upload \texttt{hwxx.tex} and \texttt{preamble.tex}, read the comments in the code; there are two lines to comment out and you should replace my name with yours and write your section. If you are asked to make drawings, you can take a picture of your handwritten drawing and insert them as figures or leave space using the \qu{$\backslash$vspace} command and draw them in after printing or attach them stapled.

The document is available with spaces for you to write your answers. If not using \LaTeX, print this document and write in your answers. I do not accept homeworks not on this printout. Keep this first page printed for your records. Write your name and section below.

\end{abstract}

\thispagestyle{empty}
\vspace{1cm}
NAME: \line(1,0){200} ~~SECTION (A, B or C): \line(1,0){35}

}

\iftoggle{professormode}{
\paragraph{Fundamentals of Continuous r.v.'s} We will learn about this other type of r.v. \\ \\
}

\problem{This problem will focus on the continuous exponential r.v.}

\begin{enumerate}

\easysubproblem{Let $X \sim \exponential{\lambda}$ and let $\lambda = 2.92$. What is $\prob{T=2}$? }\spc{1}

\easysubproblem{Let $\lambda = 3.12$. What is $\prob{T \leq 2}$? }\spc{1}

\easysubproblem{Let $\lambda = 4.56$. What is $\prob{T \in \bracks{2, 2.7}}$? }\spc{1}

\easysubproblem{What is $\support{T}$? }\spc{1}

\easysubproblem{What is $\abss{\support{T}}$? That is, what is the size of this set?}\spc{1}

\easysubproblem{What is the parameter space of $T$? }\spc{1}

\easysubproblem{Run the following in \texttt{R}. It will generate 5 realizations from $T_1, \ldots, T_t \iid \exponential{\lambda = 6.56}$: \texttt{rexp(5, 6.56)} and write them below. }\spc{2}

\easysubproblem{Look at the first draw. Is this number really a draw? Or is it rounded? }\spc{1}

\hardsubproblem{Assume it's rounded from the decimal after the last decimal you see. Find the probability the computer spits out that number when realizing the r.v.  }\spc{2}

\easysubproblem{Derive the PDF $f(t)$ from the CDF.  }\spc{3}

\easysubproblem{Let $\lambda = 4.56$. Compute $p(0.1)$ using the PMF and $f(0.1)$ using the PDF.  }\spc{2}

\intermediatesubproblem{Interpret the PDF at 0.1, $f(0.1)$. What does that number mean?  }\spc{3}

\intermediatesubproblem{In the last problem you got an answer greater than 1. Why should it be possible that the PDF can yield numbers greater than 1?  }\spc{3}

\easysubproblem{What is $\prob{T=0.1} / \prob{T=0.2}$?  }\spc{3}

\easysubproblem{What is $f(0.1) / f(0.2)$?  }\spc{3}

\easysubproblem{Interpret the answer to the last question \textit{in English}. }\spc{3}

\hardsubproblem{Derive the CDF from the PDF. This will involve anti-differentiation. And you have to worry about the constant of integration and solve for it (somehow). Justify how you solve for the constant to arrive at the same CDF we did in class.  }\spc{4}

\easysubproblem{Run the following lines in \texttt{R} \textit{one at a time} which will plot the PDF for $T \sim \exponential{0.1}$, $T \sim \exponential{1}$, $T \sim \exponential{10}$ and $T \sim \exponential{100}$.

How do you design an exponential r.v. to give large numbers --- should $\lambda$ be big or small? }

\begin{verbatim}
par(mfrow = c(2, 2))
ts = seq(0, 4, 0.01)
plot(ts, dexp(ts, 0.1), type = "l", ylim = c(0, 1))
plot(ts, dexp(ts, 1), type = "l", ylim = c(0, 1))
plot(ts, dexp(ts, 10), type = "l", ylim = c(0, 1))
plot(ts, dexp(ts, 100), type = "l", ylim = c(0, 1))
#last line placeholder
\end{verbatim}

\easysubproblem{Let $\lambda = 4.56$, compute $\prob{T \in \zeroonecl}$ using integration on the PDF. }\spc{2}

\easysubproblem{Let $\lambda = 4.56$, compute $\prob{T \in \zeroonecl}$ using a difference of CDF values.  }\spc{2}

\easysubproblem{What theorem describes why the last two problems should be equal? Write the statement of this theorem below.  }\spc{1}

\easysubproblem{Let $\lambda = 4.56$, what is $\prob{T = 1}$ using the integral definition of probability?  }\spc{0}

%\hardsubproblem{Let $T \sim \exponential{\lambda}$. Show that $\expe{T} = 1/\lambda$ using the definition of expectation for continuous r.v.'s. }\spc{10}

\easysubproblem{Let's say $\lambda = 2$, what is $\expe{T}$? Pretend the unit of time is seconds.  }\spc{0.5}

%\hardsubproblem{Pretend you are approximating the exponential with a geometric r.v.. Let $n = 1000$ and $p = 0.002$ to have $\lambda = 2$. Show that the expectation of that geometric r.v. is the same as $\expe{T}$ in the previous problem.  }\spc{3}

\hardsubproblem{Let $T \sim \exponential{\lambda}$. Show that $\var{T} = 1/\lambda^2$ using the definition of expectation for continuous r.v.'s. Very googlable.  }\spc{10}

\easysubproblem{Let $T \sim \exponential{\lambda}$. Show that $\se{T} = 1/\lambda$ \textit{by assuming the answer of the last question}. I marked it easy for this reason. }\spc{3}

\easysubproblem{Assume $T \sim \exponential{\lambda}$ and $Y = 10sec + 5T$. What is $\expe{Y}$ and $\se{Y}$? }\spc{3}

\hardsubproblem{For a discrete r.v., we defined the mode as:

\beqn
\mode{X} := \argmax_{x \in \support{X}} \braces{p(x)}
\eeqn

where $p(x)$ was the PMF. For continuous r.v.'s, keep the definition the same but replace the PMF with the PDF. Using this definition, find the mode of $T \sim \exponential{\lambda}$. Does this make sense and why?  }\spc{4}

\hardsubproblem{ Let $T \sim \exponential{\lambda}$.  Show that the $\median{T} = \natlog{2} / \lambda$. }\spc{5}

%\extracreditsubproblem{Is time really continuous?}
%\extracreditsubproblem{Is space really continuous?}

\intermediatesubproblem{Prove the memorylessness property of the exponential r.v.}\spc{6.5}
%
%\extracreditsubproblem{The convolution of two continuous r.v.'s occurs when you are trying to find the density of $T = X_1 + X_2$. It is denoted by the $*$ symbol and its formula is below:
%
%\beqn
%f_T(x) = f_{X_1}(x) * f_{X_2}(x) := \int_\reals f_{X_1}(s) f_{X_2}(x - s) ds
%\eeqn
%
%For $X_1$ and $X_2$ only supported on $[0,\infty)$ such as the exponential r.v., the formula becomes:
%
%\beqn
%f_T(x) = f_{X_1}(x) * f_{X_2}(x) = \int_0^{x} f_{X_1}(s) f_{X_2}(x - s) ds
%\eeqn
%
%Prove that the sum of $\iid$ $\exponential{\lambda}$ r.v.'s are distributed as an $\text{Erlang}(r, \lambda)$ which is the continuous analogue of the discrete negative binomial distribution.
%
%That is, prove the convolution of $r$ $\iid$ $\exponential{\lambda}$ has the Erlang \qu{footprint,} defined by its density:
%
%\beqn
%f_T(x) = \frac{\lambda^r x^{r-1} e^{-\lambda x}}{(r - 1)!}
%\eeqn
%
%You should use induction. Do this on a separate piece of paper.}\spc{3}

\end{enumerate}

\problem{We will now get our feet wet with the Uniform r.v.}

\begin{enumerate}
\easysubproblem{Let $X \sim U(0,1)$, the standard uniform r.v. What is the support of $X$? }\spc{1}

\easysubproblem{Let $X \sim U(0,1)$. What is the PDF of $X$? }\spc{4}

\intermediatesubproblem{Let $X \sim U(0,1)$. Draw the CDF of $X$. }\spc{5}

\easysubproblem{Let $X \sim U(a,b)$, the general uniform r.v. What is the PDF of $X$? }\spc{4}

\intermediatesubproblem{Let $X \sim U(a,b)$. Solve for the CDF of $X$ by finding the correct antiderivative of $f(x)$, the PDF from the last problem (see notes). }\spc{5}

\easysubproblem{Let $X \sim U(a,b)$. Find the $\median{X}$ using the CDF from the previous problem. }\spc{4}

\hardsubproblem{ Let $X \sim U(a,b)$. Find the arbitrary $\text{Quantile}[X, p]$ where $p \in \zeroonecl$. }\spc{5}

\extracreditsubproblem{Let $X \sim U(a,b)$. Compute the arbitrary $n$th moment, $\expe{X^n}$. Do this on a separate piece of paper.}

\end{enumerate}

\problem{This is an introduction to the normal r.v. We will do more with it for next homework assignment.}

\begin{enumerate}
\easysubproblem{Let $Z \sim \stdnormnot$. Write the density $f_Z(x)$ and verify that its value is positive for all real numbers. }\spc{2}

\easysubproblem{What is the $\support{Z}$? }\spc{1}

\easysubproblem{Write $F_Z(1.2345)$ using an integral ($F_Z$ is the CDF of the standard normal). }\spc{1}

\easysubproblem{What is $\prob{Z \in \bracks{-1, 1}}$? }\spc{1}

\easysubproblem{What is $\prob{Z \in \bracks{-2, 2}}$? }\spc{1}

\easysubproblem{What is $\prob{Z \in \bracks{-3, 3}}$? }\spc{4}

\intermediatesubproblem{Draw the density $f_Z(x)$ and be careful to denote the x-axis like we did in class. Then illustrate the empirical rule just like we did in class. I want to see the 68, 95, 99.7\%'s denoted as areas. }\spc{5}

\intermediatesubproblem{Draw $\Phi(x) := F_Z(x)$, i.e. the CDF of the standard normal r.v. Use the same scale as your drawing of the PDF of $Z$. }\spc{5}

\easysubproblem{What is $\prob{Z \notin \bracks{-1, 1}}$? }\spc{1}

\easysubproblem{What is $\prob{Z \notin \bracks{-2, 2}}$? }\spc{1}

\easysubproblem{What is $\prob{Z \notin \bracks{-3, 3}}$? }\spc{1}

\easysubproblem{What is $\prob{Z > 1}$? }\spc{1}

\easysubproblem{What is $\prob{Z > -1}$? }\spc{1}

\easysubproblem{What is $\prob{Z < -1}$? }\spc{1}

\easysubproblem{What is $\prob{Z < -2}$? }\spc{1}

\easysubproblem{What is $\prob{Z > 3}$? }\spc{1}

\intermediatesubproblem{What is $\prob{Z \in \parens{-3, 1}}$? }\spc{1}

\intermediatesubproblem{What is $\prob{Z \in \parens{-3, 2}}$? }\spc{1}

\hardsubproblem{Using an online calculator, find the approximate value of the 30\%ile of $Z$. }\spc{1}

\hardsubproblem{Show that $\var{Z} = 1$. }\spc{10}

\intermediatesubproblem{Let $X \sim \normnot{\mu}{\sigsq}$. What is $\prob{Z \in \bracks{\mu - 2\sigma , \mu}}$? }\spc{2}

%\extracreditsubproblem{In class we proved that $\int f(x) dx = 1$ for the standard normal. Go through the proof line by line and explain why each line is correct and follows from the previous line in English.}

\extracreditsubproblem{Prove that

\beqn
\int_{-\infty}^{\infty}  e^{-a(x+b)^2}\,dx= \sqrt{\frac{\pi}{a}}.
\eeqn}

%\extracreditsubproblem{Prove that
%
%\beqn
%\int_0^\infty e^{-ax^b} dx = \frac{\Gamma\left(\frac{1}{b}\right)}{ba^{\frac{1}{b}}}.
%\eeqn}

\extracreditsubproblem{Explain why $F_Z$ is not available in closed form by using the Risch algorithm.}

\end{enumerate}

\iftoggle{professormode}{
\paragraph{Moment Generating Functions} There are a few facts to know for the exam. This is what you are responsible for.\\ \\
}

\problem{In this problem you will be introduced to mgf's and learn the three facts about them that we will make use of (1) that mgf's can give you moments easily and (2) it is easy to obtain the mgf of convolutions of r.v.'s. (3) r.v.'s with equivalent mgf's have equivalent CDF's, making them identically distributed.}

\begin{enumerate}

\easysubproblem{What is a moment generating function (mgf)? Read about it in the book and answer a few sentences \textit{in English}. }\spc{2}

\easysubproblem{Using the definition of expectation, write out what $\expe{g(X)}$ is for a discrete r.v. $X$. This can be found in the notes from previous lectures. }\spc{2}

\easysubproblem{Using the definition of expectation, write out what $\expe{g(X)}$ is for a continuous r.v. $X$. This can be found in the notes from previous lectures. }\spc{2}

\easysubproblem{For the mgf, what is the $g(X)$ transformation we are interested in finding the expectation of? Write $g(X) = $ something below. }\spc{2}

\easysubproblem{If $X$ is a discrete r.v., write the definition of the mgf, $M_X(t)$. If you use the notation $f(x)$ make sure you indicate what you are referring to. If you use the notation $\expe{\cdot}$, make sure you indicate the mathematical definition of the expectation. }\spc{2}

\easysubproblem{If $X$ is a continuous r.v., write the definition of the mgf, $M_X(t)$. If you use the notation $f(x)$ make sure you indicate what you are referring to. If you use the notation $\expe{\cdot}$, make sure you indicate the mathematical definition of the expectation.  }\spc{2}

\easysubproblem{Find $M'_X(t)$, the derivative of the mgf with respect to $t$, the dummy variable in the $t$ domain. Assume changing the order of differentiation with integration / summation is allowed.}\spc{1.5}

\easysubproblem{Find $M'_X(0)$, \ie the derivative of the mgf evaluated at $t=0$.}\spc{1}

\easysubproblem{Find $M''_X(t)$, the second derivative of the mgf with respect to $t$.}\spc{1}

\easysubproblem{Find $M''_X(0)$, \ie the second derivative of the mgf evaluated at $t=0$.}\spc{1}

\easysubproblem{Synthesize your answers to the last 4 parts and explain why the mgf is called the \qu{moment generating} function \textit{in English}.  }\spc{2}

\easysubproblem{Let $X_1$ and $X_2$ be two independent r.v's (not necessarily identically distributed). Show that $M_{X_1+X_2}(t) = M_{X_1}(t)M_{X_2}(t)$.  }\spc{2}

\intermediatesubproblem{Generalize this reasoning and show that for $X_1, X_2, \ldots, X_n$, a series of independent r.v.'s discrete or continuous and $T_n = \sum_{i=1}^n X_i$ that the following is true:

\beqn
M_{T_n}(t) = \prod_{i=1}^n M_{X_i}(t)
\eeqn  }\spc{3}

\hardsubproblem{In the previous two problems, why do we need independence to prove these facts? Write a couple sentences \textit{in English} referencing the lecture where we went over this.  }\spc{3}

\intermediatesubproblem{Let $Y = aX + c$ where $X$ is a r.v. either discrete or continuous and both $a$ and $c \in \reals$ are constants. Let $M_X(t)$ denote the mgf for the r.v. $X$. Find $M_Y(t)$, the mgf for the shifted r.v. $Y$ as a function of $M_X(t)$.  }\spc{5}

\end{enumerate}

\problem{Here, we will be deriving mgf's of some of our brand name r.v.'s and using them to prove cool things about distribution theory.}

\begin{enumerate}
%\easysubproblem{Let $X \sim \bernoulli{p}$. Show that $\expe{X^{37}} = p$ using the definition of expectation. I will begin the problem below for you:
%
%\beqn
%\expe{X^{37}} &=& \sum_{x \in \support{X}} x^{37} f(x) = \sum_{x=0}^1 x^{37} p^x (1-p)^{1-x} \\
%&=&
%\eeqn
%}\spc{4}

\intermediatesubproblem{Using the definition of the mgf, find $M_X(t)$, the mgf for a Bernoulli r.v.}\spc{2}

\hardsubproblem{Show that $\expe{X^{37}} = p$ using the mgf and the fact you proved in question 1(o). You may have to use English to explain what you're doing. I do not expect you to take 37 derivatives, but you should take at least two and see the pattern.}\spc{5}

\hardsubproblem{Let $T \sim \binomial{n}{p}$. Find the mgf of $X$ using the definition of the mgf. You will need to invoke the binomial theorem here (see class notes). }\spc{4}

\intermediatesubproblem{Using the fact you proved in 1(r), use mgf's to show that $T = X_1 + \ldots + X_n$ where $T$ is the binomial r.v. from the previous problem and $X_1, \ldots, X_n \iid \bernoulli{p}$. }\spc{4}

\hardsubproblem{Show that the sum of two independent r.v.'s $T_1 \sim \binomial{n_1}{p}$ and $T_2 \sim \binomial{n_2}{p}$ is a new r.v. which itself is a binomial and find its parameters. Does this make sense given what you proved in (e)? }\spc{8}

\hardsubproblem{Let $X \sim \poisson{\lambda}$ with mgf:

\beqn
M_X(t) = e^{\lambda (e^t - 1)}
\eeqn

Show that the sum of two independent r.v.'s $X_1 \sim \poisson{\lambda_1}$ and $X_2 \sim \poisson{\lambda_2}$ is itself a Poisson r.v. and find its parameter. You don't even need to know what the Poisson is for this question.}\spc{4}

%\hardsubproblem{You have shown previously that the mgf for the r.v. $X \sim \binomial{n}{p}$ was $M_X(t) = \tothepow{1-p+pe^t}{n}$. In the previous problem you were given the mgf for the r.v. $X \sim \poisson{\lambda}$ was $M_X(t) = e^{\lambda (e^t - 1)}$. Although we didn't cover it in class, the Poisson distribution is the limit of the Binomial distribution with $n \rightarrow \infty$ and the rate parameter pinned $\lambda = np$. Prove that the Poisson's mgf is this limit of the Binomial's mgf. Really not hard: just some algebraic manipulations. Let $p = \lambda / n$.}\spc{4}

\intermediatesubproblem{We proved in class that if $Z \sim \stdnormnot$ then $M_Z(t) = e^{t^2/2}$. We also showed that if $X = \sigma Z + \mu$, then $X \sim \normnot{\mu}{\sigsq}$. Show that the mgf of $X$ is $M_X(t) = e^{\mu t + \sigsq t^2 /2}$ using what you learned in 4(o) and the class notes.  }\spc{4}

\hardsubproblem{Let $X_1, X_2, \ldots, X_n$ be a sequence of independent normal random variables where $X_1$ has mean $\mu_1$ and variance $\sigsq_1$ and $X_2$ has mean $\mu_2$ and variance $\sigsq_2$, etc. Show that $X_1 + X_2 + \ldots + X_n$ is normally distributed and find its parameters.  }\spc{6}

\extracreditsubproblem{Let $X \sim \exponential{\lambda}$ with mgf:

\beqn
M_X(t) = \frac{\lambda}{\lambda - t}
\eeqn

Demonstrate that the sum of $X_1, \ldots, X_n \iid \exponential{\lambda}$ is an Erlang r.v. with parameters $n$ and $\lambda$, the continuous analogue of the Negative Binomial r.v.  (You will need to look up the mgf of the Erlang distribution). Do on a separate piece of paper.}

\extracreditsubproblem{The standard Cauchy distribution has center 0 and scale parameter 1 and its PDF is:

\beqn
f(x) = \oneover{\pi(1+x^2)}
\eeqn

The Cauchy distribution is a classic example of a pathological r.v. You'll see why. The standard Cauchy r.v. is actually the ratio of two independent standard normal r.v.'s: if $X \sim \stdnormnot$ and $Y \sim \stdnormnot$ then $X/Y$ has the PDF above.

Prove that the mgf for a standard Cauchy r.v. does not exist. This is really not hard but it looks menacing. Do on a separate piece of paper. }

\extracreditsubproblem{Prove $\Xbar \convd \mu$ which is a weak Law of Large Numbers. You will just need to copy from the class notes. Do on a separate piece of paper. }

\end{enumerate}

\end{document}


\documentclass[a4paper,12pt]{article}
%\documentclass[a4paper,12pt]{scrartcl}

\usepackage{xltxtra}

\input{../preamble.tex}

% \usepackage[spanish]{babel}

% \setromanfont[Mapping=tex-text]{Linux Libertine O}
% \setsansfont[Mapping=tex-text]{DejaVu Sans}
% \setmonofont[Mapping=tex-text]{DejaVu Sans Mono}

\title{Homework \#04: Random Variable and Discrete Distribution Functions}
\author{Isaac Ayala Lozano}
\date{2020-01-27}

\begin{document}
\maketitle

\section{Problem}
\begin{enumerate}
 \item Plot the behaviour of the Binomial, Geometric and Poisson distributions for the following values
    \begin{itemize}
     \item Binomial distribution: $n \in [10, 20, 30]$ and $p \in [0.1, 0.3, 0.5]$
     \item Geometric distribution: $p \in [0.1, 0.3, 0.5]$
     \item Poisson distribution: $\lambda \in [1, 2, 3]$
    \end{itemize}
\item Show that the Poisson distribution is a good approximation to the Binomial distribution for large values of n and small values of p.
\end{enumerate}

\section{Solution}

\subsection{Plots}
Figure \ref{fig: binomial plots} shows the plots for the Binomial distribution.\\

\begin{figure}[htb!]
\centering
\import{./img/}{hw04_binomial.tex}
\caption{Binomial distribution.}
\label{fig: binomial plots}
\end{figure}

\pagebreak

Figure \ref{fig: geometric plots} shows the plots for the Geometric distribution.\\

\begin{figure}
\centering
\import{./img/}{hw04_geometric.tex}
\caption{Geometric distribution}
\label{fig: geometric plots}
\end{figure}

\pagebreak

Figure \ref{fig: poisson plots} shows the plots for the Poisson distribution.\\

\begin{figure}[htb!]
\centering
\import{./img/}{hw04_poisson.tex}
\caption{Poisson distribution}
\label{fig: poisson plots}
\end{figure}

\pagebreak

\subsection{Proof}

From \cite{ross2006introduction} we obtain the equations for the Binomial and Poisson distributions, equations \eqref{eq: binomial} and \eqref{eq: poisson} respectively.

\begin{equation}
P (X) = \binom n i p^i (1 -p)^{n-i}
\label{eq: binomial}
\end{equation}

\begin{equation}
 P (X) = \exp(-\lambda) \dfrac{\lambda ^i}{i !}
 \label{eq: poisson}
\end{equation}

Let $\lambda = n p$ such that \eqref{eq: binomial} can written as follows

\begin{equation*}
 \binom n i p^i (1 -p)^{n-i} = \dfrac{n!}{(n-i)!  i!} \left (\frac{\lambda}{n} \right )^i \left(1 -\dfrac{\lambda}{n}\right)^{n-i}
\end{equation*}

Rewrite the last term of the equation.

\begin{equation}
 \dfrac{n!}{(n-i)!  i!} \left (\frac{\lambda}{n} \right )^i \dfrac{(1 - \lambda / n  )^n}{(1 - \lambda / n  )^i}
 \label{eq: binomial to poisson fraction}
\end{equation}

Recall that for large values of n the term $(1 - \lambda / n  )^n $ is approximately equal to $ exp(-\lambda)$.
Thus the equation above can be expressed as

 \begin{equation}
  \dfrac{n!}{(n-i)!  i!} \left (\frac{\lambda}{n} \right )^i \dfrac{exp(-\lambda)}{(1 - \lambda / n  )^i}
   \label{eq: binomial to poisson exp}
 \end{equation}

 The term $ \dfrac{n!}{(n-i)!  i!}$ can be expanded as follows

 \begin{equation*}
   \dfrac{n!}{(n-i)!  i!} =  \dfrac{n * (n-1)!}{(n-i)!  i!}
   =  \dfrac{n*(n-1)*(n-2)!}{(n-i)!  i!}
 \end{equation*}

 This expansion permits us to rewrite the term as

 \begin{equation*}
  \dfrac{n!}{(n-i)!  i!} =  \dfrac{n*(n-1)* (n-2) \dots (n-i+1)* (n-i)!}{(n-i)!  i!}
 \end{equation*}

 Notice how this new expression permits us to eliminate  $(n-i)!$ from the equation.

 \begin{equation*}
  \dfrac{n!}{(n-i)!  i!} = \dfrac{n*(n-1)* (n-2) \dots (n-i+1)}{i!}
 \end{equation*}

 Equation \eqref{eq: binomial to poisson exp} can now be rewritten as

 \begin{equation}
   \dfrac{n(n-1) (n-2) \dots (n-i+1)}{i!} \dfrac{\lambda ^i}{n ^i} \dfrac{exp(-\lambda)}{(1 - \lambda / n  )^i}
 \end{equation}

 For large values of n, the term $(1 - \lambda / n  )^i$ is approximately equal to one.
 This simplifies the equation once again.

 \begin{equation}
   \dfrac{n(n-1) (n-2) \dots (n-i+1)}{i!} \dfrac{\lambda ^i}{n ^i} exp(-\lambda)
 \end{equation}

 Exchanging the denominators in the fractions we obtain

 \begin{equation}
   \dfrac{n(n-1) (n-2) \dots (n-i+1)}{n^i} \dfrac{\lambda ^i}{i!} exp(-\lambda)
   \label{eq: binomial to poisson denominators}
 \end{equation}

 Expanding the polynomial equation from the terms $n(n-1)\dots (n-i+1)$

 \begin{equation*}
  \begin{cases}
   n (n-1) &= n^2 -n \\
   n (n-1) (n-2) &= n^3 -3 n^2 + 2n \\
   \vdots & \\
   n (n-1) (n-2) \dots (n-i+1) &= n^i - i n^{i-1} + (i-1)n^{i-2} \dots +  n
  \end{cases}
 \end{equation*}

 Rewriting the first term of the equation and evaluating the limit as n goes to infinity we have

 \begin{equation}
\lim_{n\to\infty}  \dfrac{n^i - \beta_1 n^{i-1} + \beta_2 n^{i-2} \dots +  \beta_n n}{n^i} = 1
 \end{equation}

 Equation \eqref{eq: binomial to poisson denominators} is now the equation for the Poisson distribution due to the result of the limit shown above.
 We conclude that for large values of n and small values of p, the Poisson distribution can approximate the result of the Binomial distribution.

 \begin{equation}
  P(X) = \binom n i (p)^i (1-p)^{n-i} \approx \dfrac{\lambda ^i}{i!} exp(-\lambda)
 \end{equation}

\printbibliography

\pagebreak
\appendix
\section{Código Octave}
\lstinputlisting[language=Matlab]{hw04_plots.m}

\end{document}


%%!TEX TS-program = latex

%This template gives a nice gray-sober environment.
\documentclass[red]{beamer}
\usepackage{etex}
\input ../AuxFiles/PreambleSlides.tex
\usepackage[utf8]{inputenc}

\title{{\scshape Econometrics I}}
\author{{\scshape Jos\'e Luis Montiel Olea}}
\date{}

%---------------------------------------------------Begin Document-------------------------------------
\begin{document}
\setbeamerfont{alerted text}{series=\normalfont}
\setbeamercolor{alerted text}{fg=blue}

\frame{\titlepage}

\frame{
\begin{center}
\textbf{Lectures 3 and 4}
\end{center}
}

\frame{
\begin{center}
\textbf{MV Distributions, Independence, and Conditional Probability}
\end{center}
}

\frame{
\frametitle{\normalsize {\scshape Overview}}
\begin{itemize}
\justifying
\item [$\star$] Define random vectors along with multivariate c.d.f.s\\
\textcolor{gray}{(mean, covariance matrix, moment generating function)} \vspace{.5cm}
\item[$\star$] Present some useful characterizations of independence \\
\textcolor{gray}{(general definition relegated to the appendix of the notes)} \vspace{.5cm}
\item [$\star$] Introduce conditional probability and conditional expectation
\textcolor{gray}{(general definition also in the appendix of the notes)}
\end{itemize}
}

\section{Random Vectors and MV distributions}

\frame{
\begin{center}
\textbf{1. Random Vectors and MV distributions}
\end{center}
}

\frame{
\frametitle{\normalsize {\scshape Introduction}}
\begin{itemize}
\justifying
\item [$\star$] So far, we have been working with \textcolor{blue}{real-valued} random variables:
$$X: \Omega \rightarrow \R $$
\item[$\star$] Consequently, we have learned to think about statements like:
$$P_{X}(X \leq x),$$
\item [$\star$] where $x$ is some \textcolor{blue}{real} number.
\end{itemize}
}

\frame{
\frametitle{\normalsize {\scshape Motivation}}
\begin{itemize}
\item [$\star$] Econ data usually involve more than one random variable\\
\textcolor{gray}{(think about cross-sectional or time series data)} \vspace{.5cm}
\item [$\star$] \text{Thus, we will work with } \textcolor{blue}{$X_s: \Omega \rightarrow \R, \quad s \in \{1, \ldots, S\} $} \vspace{.5cm}
\item [$\star$] We will introduce the following statements: \vspace{.5cm}
\begin{enumerate}
\item Joint Probability Statements.
\item[] $$\prob_{X} \Big[ X_1 \leq x_1, \ldots, X_S \leq x_s \Big] $$
\item Conditional Probability Statements.

\item[] $$\prob_{X} \Big[ X_1 \leq x_1 \: \Big | \: X_2 \leq x_2 \Big] $$
\end{enumerate}
\end{itemize}
}

\frame{
\frametitle{\normalsize {\scshape $\R^s$-valued random variable}}
\begin{itemize}
\item [$\star$] The $\mathbb{R}^{S}$-valued mapping defined over $(\Omega, \mathcal{F})$
\item [] $$\mathbf{X}(\omega) \equiv \Big( \: X_1(\omega),  \ldots, X_{S}(\omega) \: \Big)' $$
\item [] is a random vector if for all $A \in B(\mathbb{R}^{S})$
\item [] $$ \mathbf{X}^{-1}(A) \in \mathcal{F}.$$

\item [$\star$] The definition is analogous to real-valued case
\end{itemize}
}

\frame{
\frametitle {\normalsize {\scshape Multivariate Cumulative Distribution Functions}}
\justifying
\begin{itemize}
\item [$\star$] The c.d.f. of the $\mathbb{R}^{S}$ valued random vector $\textbf{X}(\omega)$ is a function
$$F_{X}: \R^S \rightarrow [0,1] $$
defined as
$$F_{X}(x_1, \ldots, x_S) \equiv \prob\{ \omega \in \Omega \: | \: X_i(\omega)\leq x_i \: \text{for all } i=1,\ldots, S. \} $$
\item [$\star$] Thus, the c.d.f. tell us how often each $X_i$ is below $x_i$.
\end{itemize}
}

\frame{
\begin{center}
We classify random vectors according to their c.d.f.s \\
(discrete and continuous)
\end{center}
}

\frame{
\frametitle {\normalsize {\scshape Absolutely Continuous Random Vector}}
\begin{enumerate}
\item [$\star$] An $\R^{S}$-valued random vector is absolutely continuous if:

$$F(x_1, x_2, \ldots x_S) = \int_{-\infty}^{x_1} \ldots  \int_{-\infty}^{x_S} \textcolor{blue}{f(z_1, \ldots z_S)} dz_1 \ldots  dz_S$$

\noindent for some nonnegative function $f:\R^{S} \rightarrow \R^{+}$ . \vspace{.3cm}
\item [$\star$] $f(x_1, \ldots, x_n) = \partial^n F(x_1, \ldots, x_n)/ \partial x_1 \ldots \partial x_n$ is the p.d.f. of $\mathbf{X}$.

\end{enumerate}
}

\frame{
\frametitle {\normalsize {\scshape Marginal Distributions of $\mathbf{X}$}}
$$ F_s: \mathbb{R} \rightarrow [0,1] $$
\vspace{.5cm}
$$F_s(x) \equiv \prob \Big[ \mathbf{X}^{-1} \Big( \R \times \ldots (-\infty, x ) \ldots \times \R \Big) \Big]  $$
}

\frame{
\frametitle{\normalsize {\scshape From joint to marginals}}
\begin{center}
How to recover a marginal p.d.f. from a joint p.d.f?
\end{center}
\begin{center}
Just integrate variables out.
\end{center}
}

\frame{
\frametitle{\normalsize {\scshape Moments of Random Vector}}
Let $g: \mathbb{R}^{S} \rightarrow \mathbb{R}^{m}$.  Write
$$g(\textbf{x})=(g_1(\textbf{x}), g_2(\textbf{x}), \ldots g_{m}(\textbf{x}))'$$
\noindent and let

\begin{eqnarray*}
\expec_{F}[g(\mathbf{X})] &=& \Big( \expec_{F}[g_1(\mathbf{X})], \expec_{F}[g_2(\mathbf{X})], \ldots, \expec_{F}[g_m(\mathbf{X})] \Big)' \\
&\equiv& \Big( \int_{\R^{S}} g_1(\mathbf{x})f(\mathbf{x})d\mathbf{x}, \ldots, \int_{\R^{S}} g_m(\mathbf{x})f(\mathbf{x})d\mathbf{x}\Big)'
\end{eqnarray*}
}

\frame{
\frametitle{\normalsize {\scshape Mean, Variance, Covariance}}
\begin{center}
$\mu \equiv \mathbb{E}[\mathbf{X}]$, $\Sigma \equiv \mathbb{E}[(\mathbf{X}-\mu)(\mathbf{X}-\mu)’]$
\end{center}
\begin{center}
$$\textrm{Cov}(X,Y) \equiv \mathbb{E}[ (X - \mu_x)(Y-\mu_y) ].$$
\end{center}
}

\frame{
\frametitle{\normalsize {\scshape Moment Generating Function of $\mathbf{X}$}}
The moment generating function of $m_{\mathbf{X}}: \R^{S} \rightarrow \R$ is given by:
$$m_{\mathbf{X}}(t) \equiv \expec_{F}[\exp(t’\mathbf{X})] \quad t \in \R^{S}  $$
}

\frame{
\frametitle{\normalsize {\scshape Remarks about the m.g.f.}}
\begin{enumerate}
\justifying
\item [$\star$] Vectors with the same m.g.f. have the same joint distribution \vspace{.3cm}
\item [$\star$] Vectors with the same distribution $\forall$ linear combinations have the same joint distribution \\
\textcolor{gray}{(see Cramer-Wold Theorem in the notes and problem 2)}
\end{enumerate}
}

\frame{
\begin{center}
\textbf{Examples of Bivariate Vectors}\\
(Bivariate Normal and Bivariate Bernoulli)
\end{center}
}

\frame{
\frametitle{\normalsize {\scshape Bivariate Normal}}
\begin{enumerate}
\item [$\star$] Let $\mu \in \R^2$ and let $\Sigma$ be a p.s.d. matrix of dimension $2 \times 2$. \vspace{.5cm}

\item [$\star$] $\mathbf{X} \sim \mathcal{N}_{2}(\mathbf{\mu}, \Sigma)$, if:
$$ \expec_{F}[\exp(t'\mathbf{X})]= \exp\Big(t'\mu + \frac{1}{2} t'\Sigma t \Big).$$
\end{enumerate}
}

\frame{
\frametitle{\normalsize {\scshape Some Properties of the Bivariate Normal}}
\begin{enumerate}
\item $\mu \in \mathbb{R}^2, A \in \mathbb{R}^{2 \times 2}$.
$$\mathbf{Z} \sim \mathcal{N}_2(0, \mathbb{I}_2) \implies \mu + A\mathbf{Z} \sim \mathcal{N}_2(\mu, AA’).$$
\vspace{.1cm}
\item $\mathbf{X} \sim \mathcal{N}(\mu,\Sigma) \iff c’\mathbf{X} \sim \mathcal{N}(c’\mu, c’\Sigma c)$ for all $c \in \mathbb{R}^2$. \vspace{.7cm}
\item $\mathbf{X} \sim \mathcal{N}(\mu,\Sigma)$, $\Sigma$ invertible. The p.d.f. of $\mathbf{X}$ is:
$$ f(\mathbf{x}) = \frac{1}{ (\textrm{det}\: 2\pi \Sigma)^{1/2} } \exp \Big( -\frac{1}{2} (\mathbf{x}-\mu)'\Sigma^{-1} (\mathbf{x}-\mu) \Big).$$
\end{enumerate}
}

\frame{
\frametitle{ \normalsize \scshape{Bivariate Bernoulli}}
$$\text{Supp} = \Big\{ (0,0), \: (0,1), \: (1,0), \: (1,1)  \Big\} $$
\begin{eqnarray*}
&\text{Y} \nonumber \\
& \left.\begin{array}{cc} 0 & \quad \quad 1  \end{array}\right. \nonumber\\
\text{X} \quad \left.\begin{array}{c} 0 \\ 1 \end{array}\right. & \left.\begin{array}{|c|c|}\hline \:\:p_1\:\:   & \:\:p_2\:\:  \\\hline \:\:p_3\:\:   & \:\: p_4\:\:   \\\hline \end{array}\right. \\ \nonumber
\end{eqnarray*}
$$\quad \quad \: \; p_1 + p_2 + p_3 + p_4 = 1 $$
\begin{center}
\quad (what are the marginal distributions?)
\end{center}
}

\frame{
\frametitle{ \normalsize {\scshape Remark: Joints are not `identified' by marginals}}
$$ X \sim \textrm{Bernoulli} (p_x), \quad Y \sim \textrm{Bernoulli}(p_y)  $$
\begin{eqnarray*}
&\text{Y} \nonumber \\
& \left.\begin{array}{cc} 0 & \quad \quad 1  \end{array}\right. \nonumber\\
\text{X} \quad \left.\begin{array}{c} 0 \\ 1 \end{array}\right. & \left.\begin{array}{|c|c|}\hline \:\:\  p_1  \:\:   & \:\:p_2 \:\:  \\\hline \:\: p_3 \:\:   & \:\: p_4 \:\:   \\\hline \end{array}\right. \\ \nonumber
\end{eqnarray*}
\begin{eqnarray*}
p_2 + p_4 &=& p_y\\
p_3+p_4 &=& p_x \\
p_1+p_2+p_3+p_4 &=& 1\\
\end{eqnarray*}

\begin{center}
\textcolor{blue}{Solve for $p_1, p_2, p_3, p_4$}.
\end{center}
}

\frame{
\frametitle{\normalsize {\scshape Best Linear Predictor (Practice Problem)}}

\begin{itemize}
\item [$\star$] Let $X, Y$ be real-valued random variables. \vspace{.3cm}
\item [$\star$] Assume $\mu = (\mu_x, \mu_y)’$ and $\Sigma$ are known. \vspace{.3cm}
\item [$\star$] ``Predict’’ $Y$ using using a linear function of $(X-\mu_x)$:
\[ \alpha + \beta (X-\mu_x)\]
\item [$\star$] The best linear predictor minimizes expected squared error
\[ \min_{\alpha, \beta} \mathbb{E} [ (Y - \alpha -\beta (X-\mu_x))^2] \]
\item [$\star$] Show that $\alpha^* = \mu_y$, $\beta^* = \textrm{Cov}(X,Y)/ V(X)$.
\end{itemize}

}

\section{Independence}

\frame{
\begin{center}
\textbf{2. Independence}
\end{center}
}

\frame{
\frametitle{\normalsize {\scshape (In)dependence}}
\begin{itemize}
\justifying
\item [$\star$] Important issue in the multivariate world: \vspace{.5cm}
\item []
\begin{center}How to summarize dependence or lack of dependence between random variables? \vspace{.5cm}
\end{center}
\item [$\star$] Say $X_1, \ldots, X_n$ are independent if for any $A_1, \ldots, A_n$
\[ \mathbb{P}( X_1 \in A_1, \ldots ,X_n \in A_n ) = \mathbb{P}(X_1 \in A_1)\ldots \mathbb{P}(X_n \in A_n).\]

\item [$\star$] i.e., \textcolor{blue}{joint distribution equals the product of the marginals.} \vspace{.5cm}
\end{itemize}
}

\frame{
\frametitle{\normalsize {\scshape Are $X$ and $Y$ independent?}}
\begin{eqnarray*}
&\text{Y} \nonumber \\
& \left.\begin{array}{cc} 0 & \quad \quad 1  \end{array}\right. \nonumber\\
\text{X} \quad \left.\begin{array}{c} 0 \\ 1 \end{array}\right. & \left.\begin{array}{|c|c|}\hline \:\:\  .3  \:\:   & \:\: .2 \:\:  \\\hline \:\: .5\:\:   & \:\: 0 \:\:   \\\hline \end{array}\right. \\ \nonumber
\end{eqnarray*}
}

\frame{
\frametitle{\normalsize {\scshape Useful Characterizations}}
\begin{itemize}
\justifying
\item [$\star$] Joint c.d.f is the product of the marginal c.d.f.s
$$F(X_1, \ldots, X_n) = F(X_1) \ldots F(X_n).$$
\item [$\star$] Joint p.d.f. is the product of marginal p.d.f.s
$$f(x_1, \ldots, x_n) = f(x_1) \ldots f(x_n).$$
\item [$\star$] Expectation of ``products’’ is the ``product’’ of expectations
$$\mathbb{E}[g_1(X_1), \ldots, g_n(X_n)] = \mathbb{E} [g_1(X_1)] \ldots \mathbb{E}[g_n(X_n)].$$
\item [$\star$] Joint m.g.f. is the product of the marginal m.g.f.s
$$ \mathbb{E}[ \exp (\mathbf{t}’\mathbf{X}) ] = \mathbb{E}[ \exp ( t_1 X_1 ) ] \ldots \mathbb{E}[ \exp ( t_n X_n ) ]   $$
\end{itemize}
}

\frame{
\frametitle{\normalsize {\scshape Independence implies zero Covariance}}

$$\textrm{Cov}(X,Y) \equiv \expec[(X-\mu_x)(Y-\mu_y)]  $$

$$ \implies $$

$$\textrm{Cov}(X,Y) \equiv \expec[XY]- \mu_x \mu_y.  $$
\vspace{.5cm}
\begin{center}
Therefore $(X,Y)$ independent $\implies$ $\textrm{Cov}(X,Y)=0$.
\end{center}
}

\frame{
\frametitle{\normalsize {\scshape Does zero covariance implies independence?}}
\begin{itemize}
\item [$\star$] In general, the answer is no. Consider:

\item []
\begin{eqnarray*}
&\text{Y} \nonumber \\
& \left.\begin{array}{rr} 0 & \quad \quad 1  \end{array}\right. \nonumber\\
\text{X} \quad \left.\begin{array}{r} -1 \\ 0 \\ +1 \end{array}\right. & \left.\begin{array}{|c|c|}\hline \:\:\  0  \:\:   & \:\: 3/9 \:\:  \\\hline \:\: 3/9  \:\:   & \:\: 0 \:\:   \\\hline \:\: 0 \:\: & \:\: 3/9 \:\:  \\\hline \end{array}\right. \\ \nonumber
\end{eqnarray*}
\item [$\star$] But in some cases like multivariate normals, the answer is yes. \\
\textcolor{gray}{(I will ask you to work this out in this week’s problem set)}
\end{itemize}
}

\section{Conditional Probability}

\frame{
\begin{center}
\textbf{3. Conditional Probability and Conditional Expectation} \vspace{.5cm} \\
\end{center}
}

\frame{
\frametitle{\normalsize {\scshape Definition of the conditional probability function}}
\begin{itemize}
\item [$\star$] $P(Y \in A | x)$: Conditional probability of $Y \in A$ given $x$. \vspace{.4cm}
\item [$\star$]  Defined as the \emph{function} such that
\[ \int_{B} P(Y \in A | x) f_X(x) dx = P(Y \in A, X \in B).  \]
\item [$\star$] When $X,Y$ have joint p.d.f. $f$ then
\[ P(Y \in A | x) = \int_{A} \frac{f(x,y)}{f_{X}(x)} dy  \]
\item [$\star$] The p.d.f. of $Y | X$ is defined as:
\[ f(y | x) \equiv \textcolor{blue}{\frac{f(x,y)}{f_{X}(x)}}. \]
\end{itemize}
}

\frame{
\frametitle{\normalsize {\scshape In our example}}
\begin{eqnarray*}
&\text{Y} \nonumber \\
& \left.\begin{array}{cc} 0 & \quad \quad 1  \end{array}\right. \nonumber\\
\textrm{X} \quad \left.\begin{array}{c} 0 \\ 1 \end{array}\right. & \left.\begin{array}{|c|c|}\hline \:\:\  p_1  \:\:   & \:\:p_2 \:\:  \\\hline \:\: p_3 \:\:   & \:\: p_4 \:\:   \\\hline \end{array}\right. \\
\end{eqnarray*}
$$P ( Y = 1 | X=1) = \frac{p_4}{p_3+p_4} $$
$$P ( Y = 1 | X=0) = \frac{p_2}{p_1+p_2} $$
}

\frame{
\frametitle{\normalsize \scshape{Conditional Expectation}}
\begin{itemize}
\justifying
\item [$\star$] If $(X,Y)$ have joint p.d.f. f(x,y):
$$\textcolor{blue}{\expec[g(Y) | x] \equiv \int g(y) \frac{f(x,y)}{f_{X}(x)}  dy.}  $$
\item [$\star$] Law of Iterated Expectations $\mathbb{E}[\mathbb{E}[g(Y)| x]] = \mathbb{E}[g(Y)]$
\end{itemize}
}

\frame{
\frametitle{\normalsize {\scshape Example}}
\begin{eqnarray*}
&\text{Y} \nonumber \\
& \left.\begin{array}{cc} 0 & \quad \quad 1  \end{array}\right. \nonumber\\
\text{X} \quad \left.\begin{array}{c} 0 \\ 1 \end{array}\right. & \left.\begin{array}{|c|c|}\hline \:\:\  p_1  \:\:   & \:\:p_2 \:\:  \\\hline \:\: p_3 \:\:   & \:\: p_4 \:\:   \\\hline \end{array}\right. \\ \nonumber
\end{eqnarray*}
$$\expec[Y | X=1] \equiv (0) \frac{p_3}{p_3+p_4} + (1) \frac{p_4}{p_3+p_4}  $$
}

\frame{
\frametitle{\normalsize {\scshape Bivariate Normal}}
\begin{center}
In the problem set I will ask you show that if $(X,Y)$ are bivariate normal:
\end{center}
$$ Y | X \sim  \mathcal{N}_1 ( \underbrace{\alpha^* + \beta^*(X-\mu_x)}_{\textrm{Best Linear Pred}} \:, \: \textrm{Var} ( \underbrace{(Y-\alpha^*-\beta^*(X-\mu_x) )}_{\textrm{Approximation Error}}  ) $$
}

\frame{
\frametitle{\normalsize {\scshape Signal and Noise}}
\begin{center}
In the problem set I also ask you to consider the model
$$ \underbrace{X}_{\textrm{Noisy Measure}} = \underbrace{\theta}_{\textrm{signal}} + \underbrace{\epsilon}_{\textrm{noise}}, $$
$$ \theta \sim \mathcal{N}(\mu, \sigma^2_{\theta}), \quad \epsilon \sim \mathcal{N}(0, \sigma^2_{\epsilon}), \quad \theta \bot \epsilon $$
\end{center}
\begin{center}
and to work-out the distribution of $\theta | X $.
\end{center}
}

\section{Sums of Random Variables}

\frame{
\begin{center}
\textbf{4. Sums of Random Variables}
\end{center}
}

\frame{
\frametitle{\normalsize {\scshape Let's go back to the example}}
\begin{eqnarray*}
&\text{Y} \nonumber \\
& \left.\begin{array}{cc} 0 & \quad \quad 1  \end{array}\right. \nonumber\\
\text{X} \quad \left.\begin{array}{c} 0 \\ 1 \end{array}\right. & \left.\begin{array}{|c|c|}\hline \:\:\  p_1  \:\:   & \:\: p_2 \:\:  \\\hline \:\: p_3  \:\:   & \:\: p_4 \:\:   \\\hline \end{array}\right. \\ \nonumber
\end{eqnarray*}
\begin{center}
For any $t_1, t_2 \in \R$ define
\end{center}
$$W = t_1 X + t_2 Y $$
}

\frame{
\frametitle{\normalsize {\scshape Distribution of $t_1 X + t_2 Y$}}
\begin{enumerate}
\justifying
\item [$\star$] What is the distribution of $W$?
\item [] $$\text{Supp}=\{0,t_1, t_2, t_1+t_2\} $$
\item [] $$\textcolor{blue}{\prob_{Z}(W=w) ?}  $$
\item [$\star$] Note that:
\item[] $$\prob_{Z}[W=t_1+t_2] = p_4, \quad  \prob_{Z}[W=t_2]=p_2, \quad \prob_{Z}[W=t_1]=p_3$$
\item [] $$\prob_{Z}[W=0] = p_1  $$
\end{enumerate}
}

\frame{
\frametitle{\normalsize {\scshape Sums of Independent Random Variables}}
\begin{itemize}
\justifying
\item [$\star$] The distribution of $X_1 + X_2$ need not be easy to obtain \vspace{.5cm}
\item [$\star$] If $X_1$ and $X_2$ are independent and have m.g.f.s, it is
$$\mathbb{E}[ \exp (t(X_1  + X_2))] = \mathbb{E}[\exp(t X_1 )] \mathbb{E}[\exp(t X_2 )]$$
\item [$\star$] Also, if $X_1$ and $X_2$ are independent and have p.d.f.s f and g;
\[ Z = X + Y \textrm{ has p.d.f. } \int f(z-y) g(y) dy  \]
\end{itemize}
}

\end{document}


\documentclass[20pts]{article}
\pagestyle{empty}

\title{\textbf{\huge Assignment-1}}
\author{ Rahul Bingumalla\\ sm21mtech12008}
\date{August 2021}

\begin{document}

\maketitle{}

\section{Chapter-2, Example II, Q.7}
\vspace{1cm}

\textbf{\textsl{1. Prove that the points (0,1),(1,4),(4,3),(3,0) are the vertices of a Square  :}}

\vspace{1cm}

 Answer-
 \\ Step1 : Find the distance between all the four points.
 \\ Distance between two points is :
 $$ distance = \sqrt{((x_2-x_1)^2+(y_2-y_1)^2)}$$
\\ From the above points , we get six distances between the points.
 and if four distances length are equal and two distance length are equal, then it is a square.
 \vspace{0.2cm}
 \\{3.1622776601683795,3.1622776601683795,3.1622776601683795,3.1622776601683795 4.47213595499958,4.47213595499958}
 \vspace{0.2cm}
\\ Conditions to be a Square :
\\ 1. All the lengths of the sides of Square must be equal.
$$ 2. diagonal \hspace{0.1cm} length =\sqrt{2} X Side length$$
 $$4.47213595499958 =\sqrt{2} X 3.1622776601683795$$
\\As these points obey above conditions , Hence they form a Square.
\end{document}


\documentclass[11pt]{article}
\usepackage{natbib,unatbib}
\usepackage[nohide,twocolumn]{ulecnot}

\usepackage{bussproofs}
%\usepackage{umut}
\usepackage{usynsem}
\usepackage{uling}

\pagestyle{fancy}
\lhead{COGS 543 -- Computational Semantics}
\chead{First-order logic}
\rhead{Updated \it \today}
\lfoot{Umut \"Ozge}
\cfoot{}
\rfoot{Page \thepage/\pageref{LastPage}}
\setlength{\headheight}{13.6pt}

\usepackage{tikz-qtree}

\begin{document}

\section{Syntax}
\ezimeti{
\item We pick our vocabulary from:
\ezimeti{
\item[i.] Sets of \uterm{constants}, each set specified for an \uterm{arity}. E.g.\ $C_0 = \crbr{a,b,c\ldots}$, $C_1 = \crbr{W,S,G\ldots}$, and so on. Again assume a subscripting scheme for constants in order not to run out of symbols no matter how complicated our formulas get.

\item[ii.] A set of \uterm{variables}, $V = \crbr{x,y,z,\ldots}$, again possibly with subscripts.

\item[iii.] A set of \uterm{quantifier} symbols $Q = \{\forall,\exists\}$.
\item[iv.] Two sets of \uterm{connective symbols} $K_1 = \crbr{\neg}$ and $K_2 = \crbr{\land,\lor,\cond}$.
\item[v.] We define a set of \uterm{terms} $T= C_0 \cup V$.
}

\item We will use upper and lower case Greek letters for variables over
predicate symbols and variables, respectively.

\item Now we can define the well-formed formulas (wff for short) first-order logic (FOL for short):

\begin{udefinition}[Well-formed formulas of FOL]
\ezimeti{
\item[]
\item[i.] $\Pi\alpha_1,\ldots,\alpha_n$ for $n \geq 1$ is a wff iff $\Pi \in C_n$ and $\alpha_1,\ldots,\alpha_n\in T$ .

\item[ii.] ($\phi \land \psi$) is a wff iff $\phi$ and $\psi$ are wff's;\\ likewise for, $(\phi \lor \psi)$, $(\phi \imp \psi)$, and $(-\phi)$.

\item[iii.] $\forall\alpha\phi$ and $\exists\alpha\phi$ are wff's iff $\phi$ is a wff and $\alpha \in V$.

\item[iv.] Nothing else is a wff.
}
\label{consdef}
\end{udefinition}

\begin{uexample}
Observe how the formula in \xref{constree} is constructed on the basis of definition \ref{consdef}.

\begin{align}
\label{constree}
\forall x((Sx\lor Wx)\imp \exists y(Ky\land Txy))
\end{align}

the tree on the right hand side is simplified by retaining only the structure forming operations as node labels, namely connectives and `.' sign for concatenation. Let us call it the \uterm{construction tree} of the formula in \xref{constree}.

\begin{center}
\Tree [.$\forall x((Sx\lor Wx)\imp \exists y(Ky\land Txy))$ [.$((Sx\lor Wx)\imp\exists y(Ky\land Txy))$
		[.$(Sx\lor Wx)$ [.$Sx$ $S$ $x$ ] [.$Wx$ $W$ $x$ ]]
		[.$\exists y(Ky\land Txy)$
							[.$(Ky\land Txy)$ [.$Ky$ $K$ $y$ ] [.$Txy$ $T$ $x$
							$y$ ] ]  ] ] ]
\hspace{20pt}
\Tree [.$\forall x$ [.$\imp$
		[.$\lor$ [.$.$ $S$ $x$ ] [.$.$ $W$ $x$ ]]
		[.$\exists y$
							[.$\land$ [.$.$ $K$ $y$ ] [.$.$ $T$ $x$
							$y$ ] ]  ] ] ]
\end{center}
\end{uexample}

\item To keep the number of parentheses manageable, we follow the following convention:

\ezimeti{
\item[] negation ($-$) and quantifiers ($\forall x$,$\exists v$, etc.) bind most tightly;
\item[] then comes conjunction ($\land$) and alternation ($\lor$)
\item[] finally conditional ($\imp$) binds least tightly.
}
}

\section{Occurrence, bondage, freedom, and substitution}
\ezimeti{

\item We call a \uterm{quantifier}, the expression formed by concatenating a quantifier symbol and a variable. E.g.\ $\forall x$, $\exists z$.

\item[] {\bf Occurrence:}

\item An \uterm{occurrence of a variable} in a formula is a leaf (terminal) node in the construction tree of that formula occupied by the variable. Question: how many occurrences does the variable $x$ have in formula \xref{constree}?

\item Similarly an \uterm{occurrence of a quantifier} in a formula is a node in the construction tree occupied by the quantifier.

\item[] {\bf Bondage versus freedom:}

\item An occurrence of a variable $\alpha$ is \uterm{bound} in a formula $\phi$ by an occurrence of a quantifier $\forall\alpha$ (or $\exists\alpha$) if there exists a path from $\alpha$ going up to $\forall\alpha$ (or $\exists\alpha$), and there exists no other occurrence of $\forall\alpha$ (or $\exists\alpha$) along the path.

% \begin{uexercise}
% Mark the scopes of the quantifiers below:
% \end{uexercise}

\item An occurrence of a variable $\alpha$ is \uterm{free} in a formula $\phi$ iff $\alpha$ is not bound (by any quantifier) in $\phi$.

\begin{uexercise}
State which occurrences of variables are free and bound in the following formula:

$$
((\exists x\, Fx \lor\forall x\, ((Gz \land Hx) \imp (\exists z\, Fz\lor Hz)))
\imp \exists z\, (Fy \lor Fz))
$$

\end{uexercise}

\item A formula is \uterm{closed} iff it has no free (occurrence of a) variable.

\item[] {\bf Substitution:}

\item Given a formula $\phi$,
$$\subs{\phi}{\beta}{\alpha}$$ is the formula obtained by substituting the variable $\beta$ to each and every \emph{free} occurrence of variable $\alpha$ in $\phi$.

\item[] {\bf Accidental bondage:}

\item When substituting a variable for another one in a formula, care should be taken NOT to introduce bondages that wouldn't be there if the substitution had not taken place.
\item[] Take for instance the formula

$$\exists y\, Lxy$$

with $L$ designating the binary predicate \emph{loves}, which says there is some entity that $x$ -- whatever that is -- loves. Substituting $y$ for $x$ in this formula, namely $\subs{(\exists y\, Lxy)}{y}{x}$, gives $\exists y\, Lyy$. This says that there exists a self-loving entity. Something different and more specific than our original formula. To avoid such situations we introduce the following definition.

\item Variable $\beta$ is \uterm{free for} $\alpha$ in formula $\phi$ if no free occurrence of $\alpha$ in $\phi$ stands along a path descending from a
quantifier $\forall \beta$  or $\exists \beta$.

\begin{uexercise}
Give $\subs{\phi}{y}{x}$ for the following $\phi$ and state whether $y$ is free for $x$ in $\phi$:

\begin{enumerate}
\item $\forall z\,(Px\imp Qz)$
\item $Fx \imp \forall x\, Fx$
\item $\exists z\,(\forall x\, Fx \imp Hx)$
\item $\forall y\,Fzy\imp \exists y\, Gxyz$
\end{enumerate}
\end{uexercise}

\section{Semantics}

\begin{udefinition}[Model]
A model $\mathcal{M}$ is a structure $\langle D,I,g,\crbr{0,1} \rangle$  where,
\begin{itemize}
\item $D$ is a set of individuals (or entities);
\item $I$ is some functional mapping $I: C_0 \mapsto D$  and $I: C_n \mapsto \mathcal{P}(D^n)$, where $\mathcal{P}$ is power set and $D^n = \overbrace{D\times\ldots\times D}^{n \text{ times}}$ (the $n$th order Cartesian product of $D$);
\item $g$,  the \uterm{assignment function}, is some functional mapping $g: V \mapsto D$.
\end{itemize}

\qed
\end{udefinition}

\begin{udefinition}[Extension of an assignment function]
Given a model $\mathcal{M} = \langle D,I,g,\crbr{0,1} \rangle$ with an assignment function $g: V \mapsto D$, for an $\nu \in V$ and $\delta \in D $, $\fnex{g}{\nu}{\gamma}$ is a function exactly like $g$, possibly except it maps $\nu$ to $\delta$.
\qed
\end{udefinition}

\begin{udefinition}[Semantics for FOL]
Given a model $\mathcal{M} = \langle D,I,g,\crbr{0,1} \rangle$,

\begin{itemize}
\item[i.]  \interp{$\alpha$}$^g$ $= {g(\alpha)}$, if $\alpha\in V$;
\item[ii.]  \interp{$\alpha$}$^g$ $=  I(\alpha)$, if $\alpha\in C_0$;
\item[iii.] \interp{$\Pi\alpha_1,\ldots,\alpha_n$}$^g$ $= 1$, iff $\langle\interp{$\alpha_1$},\ldots,\interp{$\alpha_n$}\rangle \in I \left( \Pi \right)$, and  0, otherwise;
\item[iv$^\prime$.] \interp{$(\neg\phi)$}$^g$ $= 1$, iff $\interp{$\phi$} = 0$, and 0, otherwise;
\item[iv$^{\prime\prime}$.] \interp{$(\phi \land \psi)$}$^g$ $= 1$, iff $\interp{$\phi$} = 1$  and $\interp{$\psi$} = 1$, and 0, otherwise;
\item[iv$^{\prime\prime\prime}$.] \interp{$(\phi \lor \psi)$}$^g$ $= 0$, iff $\interp{$\phi$} = 0$  and $\interp{$\psi$} = 0$, and 1, otherwise;
\item[iv$^{\prime\prime\prime\prime}$.] \interp{$(\phi \cond \psi)$}$^g$ $= 0$, iff $\interp{$\phi$} = 1$  and $\interp{$\psi$} = 0$, and 1, otherwise;
 \item[v$^\prime$.] \interp{$\forall\alpha\phi$}$^g$ $= 1$, iff for all $\delta\in D$, \interp{$\phi$}$^\fnex{g}{\alpha}{\delta} = 1$, and 0, otherwise;
 \item[v$^{\prime\prime}$.] \interp{$\exists\alpha\phi$}$^g$ $= 1$, iff there exists at least one $\delta\in D$ such that \interp{$\phi$}$^\fnex{g}{\alpha}{\delta} = 1$, and 0, otherwise;
\end{itemize}

\qed
\end{udefinition}

\begin{uexercise}
Express the following sentences in predicate logic:
\etaremune{
\item
A sample was contaminated.
\item
Everything ends.
\item
Every semester ends.
\item
Every student admires some movie.
\item
If an instructor fails, every student passes.
\item
No student failed.
\item Some humans love math, but not all who love math are humans.
\item No book is worth reading, except if it is written before 1900.
\item People without friends are unhappy unless they love reading.
\item Only people without friends are happy.
\item All but one student failed.
}
\end{uexercise}
}

\section{Natural deduction}

\ezimeti{

\item All the rules and techniques of natural deduction for propositional logic also apply to predicate logic.

\item In addition to them, we introduce introduction and elimination rules for the quantifiers.\footnote{Note that we do not cover terms and identity, therefore you may skip those parts in Huth\&Ryan.}

\item[] {\bf The universal quantifier:}

\item[] Elimination:

\begin{prooftree}
\AxiomC{$\forall x\, \phi$}
\RightLabel{\scriptsize{$\forall x$ e}}
\UnaryInfC{\subs{\phi}{u}{x}}
\end{prooftree}
provided that $u$ is free for $x$ in $\phi$.

\item[] Introduction:
\begin{prooftree}
\AxiomC{\fbox{\parbox{40pt}{\flushleft{$u$}$$\vdots$$\centering{$\subs{\phi}{u}{x}$}}}}
\RightLabel{\scriptsize{$\forall x$ i}}
\UnaryInfC{$\forall x\, \phi$}
\end{prooftree}

The logic of the rule is: if you can prove that a formula holds for an \emph{arbitrary} individual, then it holds for every individual. In order to guarantee that $u$ is arbitrary, it is required that it is ``fresh'' in the sense that it does not occur anywhere outside of the box.

\item[] {\bf The existential quantifier:}

\item[] Introduction:

\begin{prooftree}
\AxiomC{$\subs{\phi}{u}{x}$}
\RightLabel{\scriptsize{$\exists x$ i}}
\UnaryInfC{$\exists x\, \phi$}
\end{prooftree}

The idea is that if a formula holds for an individual, then you can deduce that there exists something that makes the formula hold.

\item[] Elimination:

\begin{prooftree}
\AxiomC{$\exists x\,\phi$}
\AxiomC{\fbox{\parbox[b]{60pt}{\flushleft{$u$}\quad\centering{$\subs{\phi}{u}{x}$}$$\vdots$$\centering{$\chi$}}}}
\RightLabel{\scriptsize{$\exists x$ e}}
\BinaryInfC{$\chi$}
\end{prooftree}
provided that $u$ is free for $x$ in $\phi$ and $u$  is ``fresh'' -- it does not
occur outside of the box.

Here the logic is similar to $\lor$-elimination. You know that $\phi$ holds for at least one individual, but you do not know which. You assume an arbitrary individual $u$ and that $\phi$ holds for it. If this assumption leads you to $\chi$, which does not include $u$, then you can deduce that $\chi$ holds.

Let's take a real-world example. Suppose you have 12 friends. You know that at least one of them betrayed you. You sit and think about each, James, Andrew, Matthew, Judas, and others. You find out that \emph{whichever} you pick as the traitor, there is a reason that you are in trouble. As you know that at least one of them \emph{did} betray you, you conclude that you are in trouble.

\newpage
\begin{uexercise}
Prove the following:
\begin{enumerate}
\item $\forall x\,(Px \imp Qx),\,\forall x\,Px\vdash\, \forall x\, Qx$
\item $\forall x\, \phi \vdash\, \exists x\, \phi$
\item $\forall x\, (Px \imp Qx),\,\exists x\, Px \vdash\, \exists x\, Qx$
\item $\forall x\, (Qx \imp Rx),\,\exists x\, (Px \land Qx) \vdash\, \exists x\, (Px \land Rx)$
\item $\exists x\, Px,\, \forall x\forall y\,(Px\imp Qy) \vdash\, \forall y\, Qy$
\item  $\vdash\,\exists x\, (Fx \imp \forall y\, Fy)$
\end{enumerate}
\end{uexercise}
}

% \renewcommand{\bibsep}{0pt}
% \renewcommand{\bibfont}{\small}
% \bibliography{ozge}
% \bibliographystyle{natgig}
\end{document}


%==============================================================================
\chapter{Tables}
\label{sec:table}
%==============================================================================

\LaTeX{} file: \url{./guide_tables.tex}\\[1ex]
\noindent
You almost certainly have tables with results that you want to include
in your thesis. You probably even know about the \Env{tabular}
environment, but what about fine-tuning to get the tables exactly in
the form that you want? How do you line up the decimal points in a
list of cross-sections and/or $\pm$ for the errors? How can you
handle a table that goes over more than one page and what if it is so
wide that you would like to rotate it by \ang{90}?

Also, how can you make your tables look more professional with for
example thick and thin lines in appropriate places? This is easy to
solve -- use \Macro{toprule}, \Macro{midrule} and \Macro{bottomrule}
commands from the \Package{booktabs} package. These commands also
produce much better spacing between these lines and the rows above and
below. The \Package{booktabs} package gives you some advice on how
good tables should look, as well as some guidelines on how to make your
tables look better.

The \Macro{rule} command is very useful for adding more space between
rows. Kopka has several examples of its usage. You can also use
\Macro{arraystretch}, e.g.\ \verb+\renewcommand{\arraystretch}{1.5}+ to
increase the spacing by \SI{50}{\percent}. This command is often useful if table
cells contain subscripts and/or superscripts. \Macro{toprule}
etc. mean that it is usually not needed in headers.

If you want columns of expandable width you can use the
\Package{tabularx} package. The environment \Env{tabular*} has instead
expandable intercolumn spacing.

Tables usually go inside the \Env{table} environment so their position
can \enquote{float}. In this chapter I use some tables inside \Env{table}
and some inline.

Trying to include footnotes in tables can be tricky. See
Section~\ref{sec:layout:footnote} for some guidance on how this can be done.

%------------------------------------------------------------------------------
\section{Use of \Macro{phantom}}
\label{sec:table:phantom}
%------------------------------------------------------------------------------

Although extra packages can help, a very useful command is
\Macro{phantom}. This inserts white space corresponding to the width
of the argument. Compare the results in the following table with two
numbers 0.76 and 83.1:

\begin{center}
\begin{tabular}{cc|rr}
  \multicolumn{2}{c|}{Centred} &
  \multicolumn{2}{c}{Right justified} \\
  & Phantom & & Phantom\\\hline
  0.76 & \phantom{0}0.76 & 0.76 & 0.76\\
  83.1 & 83.1\phantom{0} & 83.1 & 83.1\phantom{0}
\end{tabular}
\qquad
{\setlength{\extrarowheight}{0.5ex}
\begin{tabular}{cc|rr}
  \multicolumn{2}{c|}{Centred} &
  \multicolumn{2}{c}{Right justified} \\
  & Phantom & & Phantom\\\hline
  0.76 & \phantom{0}0.76 & 0.76 & 0.76\\
  83.1 & 83.1\phantom{0} & 83.1 & 83.1\phantom{0}
\end{tabular}
}
\end{center}
\par\noindent
The difference between the two tables is that the one on the right
has the length \Macro{extrarowheight} set to 0.5ex.  The first two
columns are centred, the last two are right justified.  This is
clearly a bit clumsy, but it does work!

%------------------------------------------------------------------------------
\section{Using \Package{siunitx} and the \Option{S} column option}
\label{sec:table:siunitx}
%------------------------------------------------------------------------------

The \Package{siunitx} package contains some nice tools that make the
correct alignment of numbers simpler. The syntax of some of the
options changed between version 1 ($\leq 2009$) and version 2 ($\geq 2011$). I
discuss the version 2 options in the main text and give the equivalent
version 1 options as a footnote. If you look at the \LaTeX\ code, the
\TeXLive 2009 version is inside \Macro{ifthenelse\{\textbackslash
texlive < 2011\}}, while the \TeXLive 2011 version is in the second
block.

A first simple example is shown
in Table~\ref{tab:viscosity}. In fact I show the table twice, once
with the language set to default and once with it set to German. The
\Env{tabular} contents are identical, the second tabular is inside a
\Macro{foreignlanguage}. Note the use of
\Option{table-format}\footnote{\Option{tabformat} in \TeXLive 2009} to
centre the temperatures as the heading is wider than the numbers.

\begin{table}[htbp]
  \centering
\ifthenelse {\texlive < 2011} {%
  \begin{tabular}{lS[tabformat = 4.2]S}
    \toprule
    Liquid & {Temp.} & {Viscosity $\eta$}\\
    &  {[\si{\celsius}]} & {(\si{\metre\pascal\second})} \\
    \midrule
    Blood     & 37 & 4.0 \\
    Glycerine &  0 & 10000 \\
    & 20 & 1410 \\
    & 60 & 81 \\
    Motor oil (SAE 10) & 30 & 200 \\
    Water   &  0 & 1.8 \\
    & 20 & 1.00 \\
    & 60 & 0.65 \\
    Air     & 20 & 0.018 \\
    \bottomrule
  \end{tabular}
}{%
  \begin{tabular}{lS[table-format = 4.2]S}
    \toprule
    Liquid & {Temp.} & {Viscosity $\eta$}\\
    &  {[\si{\celsius}]} & {(\si{\metre\pascal\second})} \\
    \midrule
    Blood     & 37 & 4.0 \\
    Glycerine &  0 & 10000 \\
    & 20 & 1410 \\
    & 60 & 81 \\
    Motor oil (SAE 10) & 30 & 200 \\
    Water   &  0 & 1.8 \\
    & 20 & 1.00 \\
    & 60 & 0.65 \\
    Air     & 20 & 0.018 \\
    \bottomrule
  \end{tabular}
}
  \quad
\ifthenelse {\texlive < 2011} {%
  \foreignlanguage{ngerman}{%
  \begin{tabular}{lS[tabformat = 4.2]S}
    \toprule
    Flüssigkeit & {Temp.} & {Viskosität $\eta$}\\
    &  {[\si{\celsius}]} & {(\si{\metre\pascal\second})} \\
    \midrule
    Blut     & 37 & 4.0 \\
    Glyzerin &  0 & 10000 \\
    & 20 & 1410 \\
    & 60 & 81 \\
    Motoröl (SAE 10) & 30 & 200 \\
    Wasser   &  0 & 1.8 \\
    & 20 & 1.00 \\
    & 60 & 0.65 \\
    Luft     & 20 & 0.018 \\
    \bottomrule
  \end{tabular}
  }
}{%
  \foreignlanguage{ngerman}{%
  \begin{tabular}{lS[table-format = 4.2]S}
    \toprule
    Flüssigkeit & {Temp.} & {Viskosität $\eta$}\\
    &  {[\si{\celsius}]} & {(\si{\metre\pascal\second})} \\
    \midrule
    Blut     & 37 & 4.0 \\
    Glyzerin &  0 & 10000 \\
    & 20 & 1410 \\
    & 60 & 81 \\
    Motoröl (SAE 10) & 30 & 200 \\
    Wasser   &  0 & 1.8 \\
    & 20 & 1.00 \\
    & 60 & 0.65 \\
    Luft     & 20 & 0.018 \\
    \bottomrule
  \end{tabular}
  }
}
  \caption{A table of viscosities in the default language and German.}
  \label{tab:viscosity}
\end{table}

Table~\ref{tab:xsect0} shows a more complicated table set using the
tools. You can either enclose all numbers in \Macro{num} or use the
\Option{S} column descriptor. If you use \Option{S}, note that it
usually centres the contents of the column. You can use the
\Option{table-number-alignment}\footnote{\Option{tabnumalign} in
  \TeXLive 2009} option to change this. \Option{S} and \Macro{num}
cannot generally be mixed in a single column though.
If you want to use \Macro{num} in an
\Option{S} column you have to enclose it in braces. You also need to
do this with regular text, such as column headings -- see
Table~\ref{tab:viscosity}.

\begin{table}[htbp]
  \centering
  \renewcommand{\arraystretch}{1.2}
\ifthenelse {\texlive < 2011} {%
  \begin{tabular}{%
      r@{\,:\,}S[tabnumalign=centredecimal]%
      r@{\,}c@{\,}l@{\,}l%
      S[tabformat=5.0]@{\,}l%
      l}
    \toprule
    \multicolumn{2}{c}{\etajet} & \multicolumn{4}{c}{\diffetab} & \multicolumn{2}{c}{\diffnloetab} & \Cbhad \\
    \multicolumn{2}{c}{} & \multicolumn{4}{c}{[\si{\pico\barn}]} &
    \multicolumn{2}{c}{[\si{\pico\barn\per\GeV}]} & \\
    \midrule
    \num{-1.6} & -1.1 & \num[dp=1]{57.4}  & $\pm$ & \num[dp=1]{9.4}  & $^{+13}_{ -3}$ &  72 & $^{+22}_{-13}$ & \num[dp=2]{0.704} \\
    \num{-1.1} & -0.8 & \num[dp=0]{121.3} & $\pm$ & \num[dp=0]{21.1} & $^{+16}_{-16}$ & 182 & $^{+50}_{-30}$ & \num[dp=2]{0.781} \\
    \num{-0.8} & -0.5 & \num[dp=0]{214.1} & $\pm$ & \num[dp=0]{21.9} & $^{+22}_{-12}$ & 255 & $^{+69}_{-42}$ & \num[dp=2]{0.791} \\
    \num{-0.5} & -0.2 & \num[dp=0]{232.6} & $\pm$ & \num[dp=0]{21.0} & $^{+28}_{-21}$ & 307 & $^{+83}_{-50}$ & \num[dp=2]{0.791} \\
    \num{-0.2} & +0.1 & \num[dp=0]{264.1} & $\pm$ & \num[dp=0]{22.0} & $^{+28}_{-23}$ & 342 & $^{+91}_{-55}$ & \num[dp=2]{0.808} \\
    \num{+0.1} & +0.5 & \num[dp=0]{316.0} & $\pm$ & \num[dp=0]{21.1} & $^{+23}_{-17}$ & 346 & $^{+96}_{-57}$ & \num[dp=2]{0.847} \\
    \num{+0.5} & +1.4 & \num[dp=0]{288.1} & $\pm$ & \num[dp=0]{15.4} & $^{+20}_{-30}$ & 265 & $^{+82}_{-48}$ & \num[dp=2]{0.926} \\
    \bottomrule
  \end{tabular}
}{%
  \sisetup{round-mode = places}
  \begin{tabular}{%
      r@{\,:\,}S[table-number-alignment=center-decimal-marker]%
      r@{\,}c@{\,}l@{\,}l%
      S[table-format=5.0]@{\,}l%
      l}
    \toprule
    \multicolumn{2}{c}{\etajet} & \multicolumn{4}{c}{\diffetab} & \multicolumn{2}{c}{\diffnloetab} & \Cbhad \\
    \multicolumn{2}{c}{} & \multicolumn{4}{c}{[\si{\pico\barn}]} &
    \multicolumn{2}{c}{[\si{\pico\barn\per\GeV}]} & \\
    \midrule
    \num{-1.6} & -1.1 & \num[round-precision=1]{57.4}  & $\pm$ & \num[round-precision=1]{9.4}  & $^{+13}_{-3}$  &  72 & $^{+22}_{-13}$ & \num[round-precision=2]{0.704} \\
    \num{-1.1} & -0.8 & \num[round-precision=0]{121.3} & $\pm$ & \num[round-precision=0]{21.1} & $^{+16}_{-16}$ & 182 & $^{+50}_{-30}$ & \num[round-precision=2]{0.781} \\
    \num{-0.8} & -0.5 & \num[round-precision=0]{214.1} & $\pm$ & \num[round-precision=0]{21.9} & $^{+22}_{-12}$ & 255 & $^{+69}_{-42}$ & \num[round-precision=2]{0.791} \\
    \num{-0.5} & -0.2 & \num[round-precision=0]{232.6} & $\pm$ & \num[round-precision=0]{21.0} & $^{+28}_{-21}$ & 307 & $^{+83}_{-50}$ & \num[round-precision=2]{0.791} \\
    \num{-0.2} & +0.1 & \num[round-precision=0]{264.1} & $\pm$ & \num[round-precision=0]{22.0} & $^{+28}_{-23}$ & 342 & $^{+91}_{-55}$ & \num[round-precision=2]{0.808} \\
    \num{+0.1} & +0.5 & \num[round-precision=0]{316.0} & $\pm$ & \num[round-precision=0]{21.1} & $^{+23}_{-17}$ & 346 & $^{+96}_{-57}$ & \num[round-precision=2]{0.847} \\
    \num{+0.5} & +1.4 & \num[round-precision=0]{288.1} & $\pm$ & \num[round-precision=0]{15.4} & $^{+20}_{-30}$ & 265 & $^{+82}_{-48}$ & \num[round-precision=2]{0.926} \\
    \bottomrule
  \end{tabular}
}
  \caption{A selection of cross-section measurements!}
  \label{tab:xsect0}
\end{table}

With \Macro{num} you can also specify the precision with which each
number is shown separately. With \Option{S} you specify the format for
the whole column. With \Package{siunitx} version 1 this is done using
the \Option{dp} option and gives the number of decimal places for the
rounding.  With \Package{siunitx} version 2 you should also make sure
that you specify the rounding mode in the preamble of the table (usually
\Option{figures} or \Option{places} -- you can also choose
\Option{off}).

If you know that you are going to make such a table, it is very easy
to use either of these options to write it out in this format using a
program. Using \Macro{num} solves the very common problem of your
program writing out the results with too many significant digits and
you have to correct them all by hand later (as well as every time they
get updated)!  A slightly different approach that one could follow is
to use \Option{S} for simple numbers in tables and \Macro{num} for
more complicated number typesetting.  For asymmetric errors you could
consider defining something similar to \Macro{numpmerr}, which
internally uses \Macro{num}.

A common and closely related problem that occurs is that your analysis
spits out a result such as $24.36789^{+0.36423}_{-0.45236}$. You copy
and paste this into a table and then a referee (or your supervisor)
complains that you clearly don't understand statistics, as you should
never quote an error to 5 significant digits. You can go ahead and
edit all the numbers by hand, but what do you do if you rerun your
analysis and all the numbers change. Reformatting by hand is then an
error prone and lengthy process. As discussed above, you can either
use options such as \Option{round-precision}\footnote{\Option{dp} in
  \TeXLive 2009} in the \Option{S} command or use the macro
\Macro{num} and \Option{dp}/\Option{round-precision} to do the
rounding\index{rounding} for you.

Table~\ref{tab:rounding} shows and compares two different approaches
on how this can be done, even for asymmetric errors. While the form
may appear to be a bit clumsy at first, it is easy enough to get your
program to write out the lines. In \Package{siunitx} version 1 you
should use option \Option{dp} for the rounding. In version 2 you
should use the options \Option{round-mode} and
\Option{round-precision}. In the first line of the left-hand part of
the table I show what to do if you need to change the precision of a
single number.  As you can see this is rather trivial. However, then
the alignment on the decimal point is no longer perfect. While this is
probably OK for internal notes etc., theses or papers (should) have
tougher requirements. Another way of achieving the same thing and
avoiding the use of \Option{round-mode} and
\Option{round-precision}\footnote{\Option{dp} in \TeXLive 2009. The
  \Option{round-mode} should be set in the preamble of the table and
  not for every number.} is shown in the right half. Note the use of
options for the \Option{S} command and the use of \Macro{num} enclosed
in braces to format the row that requires a different precision.

It takes a while to learn what the different options mean and their
consequences. I hope that these examples cover most problems and at
least give ideas as to what is possible.  In particular the solution
on the right-hand side of Table~\ref{tab:rounding} is very nice, as
all numbers except the one that requires an extra digit are written
without any special formatting!

\begin{table}[htbp]
  \centering
  \renewcommand{\arraystretch}{1.2}
\ifthenelse {\texlive < 2011} {%
  \sisetup{retainplus}
  \begin{tabular}{%
      S@{\,:\,}S
      r@{\,}@{$\pm$}@{\,}l@{\,}l
       }
    \toprule
    \multicolumn{2}{c}{\etajet} & \multicolumn{3}{c}{\diffetab} \\
    \multicolumn{2}{c}{} & \multicolumn{3}{c}{[\si{\pico\barn}]} \\
    \midrule
    {\num{-1.6}} & -1.1 & \num[dp=3]{0.574} & \num[dp=3]{0.094} & $^{\num[dp=3]{+0.131}}_{\num[dp=3]{-0.031}}$ \\
    {\num{-1.1}} & -0.8 & \num[dp=2]{1.213} & \num[dp=2]{0.211} & $^{\num[dp=2]{+0.162}}_{\num[dp=2]{-0.162}}$ \\
    {\num{-0.8}} & -0.5 & \num[dp=2]{2.141} & \num[dp=2]{0.219} & $^{\num[dp=2]{+0.223}}_{\num[dp=2]{-0.123}}$ \\
    {\num{-0.5}} & -0.2 & \num[dp=2]{2.326} & \num[dp=2]{0.210} & $^{\num[dp=2]{+0.284}}_{\num[dp=2]{-0.214}}$ \\
    {\num{-0.2}} & +0.1 & \num[dp=2]{2.641} & \num[dp=2]{0.220} & $^{\num[dp=2]{+0.283}}_{\num[dp=2]{-0.233}}$ \\
    {\num{+0.1}} & +0.5 & \num[dp=2]{3.160} & \num[dp=2]{0.211} & $^{\num[dp=2]{+0.232}}_{\num[dp=2]{-0.172}}$ \\
    {\num{+0.5}} & +1.4 & \num[dp=2]{2.881} & \num[dp=2]{0.154} & $^{\num[dp=2]{+0.201}}_{\num[dp=2]{-0.301}}$ \\
    \bottomrule
  \end{tabular}
}{%
  \sisetup{retain-explicit-plus}
  \sisetup{round-mode = places}
  \begin{tabular}{%
      S@{\,:\,}S
      r@{\,}@{$\pm$}@{\,}l@{\,}l
       }
    \toprule
    \multicolumn{2}{c}{\etajet} & \multicolumn{3}{c}{\diffetab} \\
    \multicolumn{2}{c}{} & \multicolumn{3}{c}{[\si{\pico\barn}]} \\
    \midrule
    {\num{-1.6}} & -1.1 & \num[round-precision=3]{0.574} & \num[round-precision=3]{0.094} & $^{\num[round-precision=3]{+0.035}}_{\num[round-precision=3]{-0.031}}$ \\
    {\num{-1.1}} & -0.8 & \num[round-precision=2]{1.213} & \num[round-precision=2]{0.211} & $^{\num[round-precision=2]{+0.162}}_{\num[round-precision=2]{-0.162}}$ \\
    {\num{-0.8}} & -0.5 & \num[round-precision=2]{2.141} & \num[round-precision=2]{0.219} & $^{\num[round-precision=2]{+0.223}}_{\num[round-precision=2]{-0.123}}$ \\
    {\num{-0.5}} & -0.2 & \num[round-precision=2]{2.326} & \num[round-precision=2]{0.210} & $^{\num[round-precision=2]{+0.284}}_{\num[round-precision=2]{-0.214}}$ \\
    {\num{-0.2}} & +0.1 & \num[round-precision=2]{2.641} & \num[round-precision=2]{0.220} & $^{\num[round-precision=2]{+0.283}}_{\num[round-precision=2]{-0.233}}$ \\
    {\num{+0.1}} & +0.5 & \num[round-precision=2]{3.160} & \num[round-precision=2]{0.211} & $^{\num[round-precision=2]{+0.232}}_{\num[round-precision=2]{-0.172}}$ \\
    {\num{+0.5}} & +1.4 & \num[round-precision=2]{2.881} & \num[round-precision=2]{0.154} & $^{\num[round-precision=2]{+0.201}}_{\num[round-precision=2]{-0.301}}$ \\
    \bottomrule
  \end{tabular}
}
  \quad
\ifthenelse {\texlive < 2011} {%
  \sisetup{dp = 2}
  \begin{tabular}{%
      S[tabformat=3.2, tabnumalign = right]@{\,:\,}S
      S[dp = 2,
      tabformat = 1.3, tabnumalign = right]
      @{$\,\pm\,$}
      S[dp = 2,
      tabformat = 1.3, tabnumalign = left]
      @{\,}l
       }
    \toprule
    \multicolumn{2}{c}{\etajet} & \multicolumn{3}{c}{\diffetab} \\
    \multicolumn{2}{c}{} & \multicolumn{3}{c}{[\si{\pico\barn}]} \\
    \midrule
    -1.6 & -1.1 & {\num[dp=3]{0.574}} & {\num[dp=3]{0.094}} & $^{\num[dp=3]{+0.035}}_{\num[dp=3]{-0.031}}$ \\
    -1.1 & -0.8 & 1.213 & 0.211 & $^{\num{+0.162}}_{\num{-0.162}}$ \\
    -0.8 & -0.5 & 2.141 & 0.219 & $^{\num{+0.223}}_{\num{-0.123}}$ \\
    -0.5 & -0.2 & 2.326 & 0.210 & $^{\num{+0.284}}_{\num{-0.214}}$ \\
    -0.2 & +0.1 & 2.641 & 0.220 & $^{\num{+0.283}}_{\num{-0.233}}$ \\
    +0.1 & +0.5 & 3.160 & 0.211 & $^{\num{+0.232}}_{\num{-0.172}}$ \\
    +0.5 & +1.4 & 2.881 & 0.154 & $^{\num{+0.201}}_{\num{-0.301}}$ \\
    \bottomrule
  \end{tabular}
}{%
  \sisetup{round-mode = places, round-precision = 2}
  \begin{tabular}{%
      S[table-format=3.2, table-number-alignment = right]@{\,:\,}S
      S[round-mode = places, round-precision = 2,
      table-format = 1.3, table-number-alignment = right]
      @{$\,\pm\,$}
      S[round-mode = places, round-precision = 2,
      table-format = 1.3, table-number-alignment = left]
      @{\,}l
       }
    \toprule
    \multicolumn{2}{c}{\etajet} & \multicolumn{3}{c}{\diffetab} \\
    \multicolumn{2}{c}{} & \multicolumn{3}{c}{[\si{\pico\barn}]} \\
    \midrule
    -1.6 & -1.1 & {\num[round-precision=3]{0.574}} & {\num[round-precision=3]{0.094}} & $^{\num[round-precision=3]{+0.035}}_{\num[round-precision=3]{-0.031}}$ \\
    -1.1 & -0.8 & 1.213 & 0.211 & $^{\num{+0.162}}_{\num{-0.162}}$ \\
    -0.8 & -0.5 & 2.141 & 0.219 & $^{\num{+0.223}}_{\num{-0.123}}$ \\
    -0.5 & -0.2 & 2.326 & 0.210 & $^{\num{+0.284}}_{\num{-0.214}}$ \\
    -0.2 & +0.1 & 2.641 & 0.220 & $^{\num{+0.283}}_{\num{-0.233}}$ \\
    +0.1 & +0.5 & 3.160 & 0.211 & $^{\num{+0.232}}_{\num{-0.172}}$ \\
    +0.5 & +1.4 & 2.881 & 0.154 & $^{\num{+0.201}}_{\num{-0.301}}$ \\
    \bottomrule
  \end{tabular}
}
  \caption{Another selection of cross-section measurements! Note the
    use of \Macro{sisetup} to keep the plus signs on the positive errors.}
  \label{tab:rounding}
\end{table}

Another example using \Package{siunitx} tools that contains a similar
problem is:

\begin{center}
\ifthenelse {\texlive < 2011} {%
  \begin{tabular}{%
    S[tabnumalign=centerdecimal]@{$\,\pm$}S[tabnumalign=centerdecimal]|%
    c%
    S[decimalsymbol=comma]@{$\,\pm\!\!$}S[decimalsymbol=comma]}
  \toprule
  \multicolumn{2}{c|}{English} &
  \multicolumn{1}{c}{German1} &
  \multicolumn{2}{c}{German2} \\
  {Value} & {Error} & {Wert} & \multicolumn{2}{c}{Messung}\\
  \midrule
  0.76 & 0.14 & \num[decimalsymbol=comma]{0.89(16)} & 0.89 & 0.16\\
  83.1 &  7.6 & \num[decimalsymbol=comma]{94.2(83)} & 94.2 & 8.3\\
  \bottomrule
  \end{tabular}
}{%
  \begin{tabular}{%
    S[table-number-alignment=center-decimal-marker]@{$\,\pm$}S[table-number-alignment=center-decimal-marker]|%
    c%
    S[output-decimal-marker={,}]@{$\,\pm\!\!$}S[output-decimal-marker={,}]}
  \toprule
  \multicolumn{2}{c|}{English} &
  \multicolumn{1}{c}{German1} &
  \multicolumn{2}{c}{German2} \\
  {Value} & {Error} & {Wert} & \multicolumn{2}{c}{Messung}\\
  \midrule
  0.76 & 0.14 & \num[output-decimal-marker={,}]{0.89(16)} & 0.89 & 0.16\\
  83.1 &  7.6 & \num[output-decimal-marker={,}]{94.2(83)} & 94.2 & 8.3\\
  \bottomrule
  \end{tabular}
}
\end{center}

As you can see, the \enquote{English} column formats things nicely using
the \Option{S} column descriptor. The \enquote{German1} column successfully
converts the decimal point to a comma and also the parentheses with
the error to $\pm$. However, the alignment of the numbers is now
messed up. The \enquote{German2} column looks better. I had to do some dirty
tricks with the formatting of the intercolumn separator
\verb+@{\,\pm\!\!}+ to get the spacing nice! This confirms my
statement above that the \Option{S} format is most useful for aligning
simple numbers easily, while \Macro{num} is very nice for rounding to
a given precision -- note that you can use either the \Option{dp} or
\Option{sf} options to achieve what you want.

%------------------------------------------------------------------------------
\section{Using \Package{dcolumn}}
\label{sec:tab:dcolumn}
%------------------------------------------------------------------------------

An alternative is the \Package{dcolumn} package. You can also use this
package to convert numbers written with \enquote{.} as the decimal point
into German-style numbers with \enquote{,}.\footnote{See
  Section~\protect\ref{sec:layout:german} for hints on how to get
  around problems with the \Package{ziffer} package} You can line up
measurements and errors by putting each of them in its own column. If
your errors are symmetric you can put $\pm$ as the intercolumn
separator:

\begin{center}
\begin{tabular}{cD{.}{.}{3}|cD{.}{,}{2}|rl|D{.}{.}{2}@{$\,\pm\,$}D{.}{.}{2}}
  \multicolumn{2}{c|}{English} &
  \multicolumn{2}{c|}{German} &
  \multicolumn{2}{c|}{Val $\pm$ Err} &
  \multicolumn{1}{c}{Val} & \multicolumn{1}{l}{Err}\\
  \midrule
  0.76 & 0.76 & 0,76 & 0.76 & 0.76 & $\pm$ 0.14 & 0.76 & 0.04\\
  83.1 & 83.1 & 83,1 & 83.1 & 83.1 & $\pm$ 4.2  & 83.1 & 4.2
\end{tabular}
\end{center}

Table~\ref{tab:xsect1} shows quite a complicated table
set in 2 different ways. It is rotated by \SI{90}{\degree} to
illustrate how that can be done.

\begin{table}[htbp]
  \begin{sideways}
    \centering
    \begin{tabular}{r@{ : }l|c|c|c}
      \toprule
      \multicolumn{2}{c|}{\pTjet} & \diffptb & \diffnloptb & \Cbhad \\
      \multicolumn{2}{c|}{(GeV)} & (pb/GeV) & (pb/GeV) & \\
      \midrule
      $\phantom{1}$6 & 11 & $95.6\phantom{2}\pm 4.9\phantom{4}^{+9.8\phantom{2}}_{-7.0\phantom{2}}$ &
      $109\phantom{.22}^{+31\phantom{.22}}_{-19\phantom{.22}}$ & 0.83 \\
      11 & 16 & $24.8\phantom{2}\pm 1.2\phantom{4}^{+1.8\phantom{2}}_{-1.4\phantom{2}}$ &
      $\phantom{1}29.1\phantom{2}^{+\phantom{1}7.9\phantom{2}}_{-\phantom{1}4.7\phantom{2}}$ & 0.89 \\
      16 & 21 & $\phantom{2}6.02\pm 0.49^{+0.6\phantom{2}}_{-0.6\phantom{2}}$ &
      $\phantom{10}7.1\phantom{2}^{+\phantom{1}2.0\phantom{2}}_{-\phantom{1}1.2\phantom{2}}$ & 0.92 \\
      21 & 27 & $\phantom{2}0.93\pm 0.22^{+0.31}_{-0.20}$ &
      $\phantom{10}1.87^{+\phantom{1}0.54}_{-\phantom{1}0.34}$ & 0.95 \\
      27 & 35 & $\phantom{2}0.30\pm 0.12^{+0.14}_{-0.12}$ &
      $\phantom{10}0.46^{+\phantom{1}0.13}_{-\phantom{1}0.08}$ & 1.05 \\
      \bottomrule
      \multicolumn{5}{c}{}\\
      \toprule
      \multicolumn{2}{c|}{\etajet} & \diffetab & \diffnloetab & \Cbhad \\
      \multicolumn{2}{c|}{} & (pb) & (pb) & \\
      \midrule
       $-1.6$ & $-1.1$ & $\phantom{2}57\pm 22^{+13}_{-\phantom{1}3}$ &
       $\phantom{1}72^{+22}_{-13}$ & 0.70 \\
       $-1.1$ & $-0.8$ & $121\pm 21^{+16}_{-16}$ &
       $182^{+50}_{-30}$ & 0.78 \\
       $-0.8$ & $-0.5$ & $214\pm 22^{+22}_{-12}$ &
       $255^{+69}_{-42}$ & 0.79 \\
       $-0.5$ & $-0.2$ & $233\pm 21^{+28}_{-21}$ &
       $307^{+83}_{-50}$ & 0.79 \\
       $-0.2$ & $\phantom{-}0.1$ & $264\pm 22^{+28}_{-23}$ &
       $342^{+91}_{-55}$ & 0.81 \\
       $\phantom{-}0.1$ & $\phantom{-}0.5$ & $316\pm 21^{+23}_{-17}$ &
       $346^{+96}_{-57}$ & 0.86 \\
       $\phantom{-}0.5$ & $\phantom{-}1.4$ & $288\pm 15^{+20}_{-30}$ &
       $265^{+82}_{-48}$ & 0.93 \\
       \bottomrule
    \end{tabular}

    \qquad

    \(\begin{array}{r@{\,:\,}l|D{.}{.}{2}@{\,}r@{}D{.}{.}{2}@{\,}l|D{.}{.}{2}@{\,}l|c}
      \toprule
      \multicolumn{2}{c|}{\pTjet} & \multicolumn{4}{c|}{\diffptb} & \multicolumn{2}{c|}{\diffnloptb} & \Cbhad \\
      \multicolumn{2}{c|}{[\si{\GeV}]} & \multicolumn{4}{c|}{[\si{\pico\barn\per\GeV}]} & \multicolumn{2}{c|}{[\si{\pico\barn\per\GeV}]} & \\
      \midrule
       6 & 11 & 95.6 & \pm & 4.9  & ^{+9.8}_{-7.0}  &  109  & ^{+31}_{-19} & 0.83 \\
      11 & 16 & 24.8 & \pm & 1.2  & ^{+1.8}_{-1.4}  & 29.1  & ^{+7.9}_{-4.7} & 0.89 \\
      16 & 21 & 6.02 & \pm & 0.49 & ^{+0.6}_{-0.6}  &  7.1  & ^{+2.0}_{-1.2} & 0.92 \\
      21 & 27 & 0.93 & \pm & 0.22 & ^{+0.31}_{-0.20} & 1.87 & ^{+0.54}_{-0.34} & 0.95 \\
      27 & 35 & 0.30 & \pm & 0.12 & ^{+0.14}_{-0.12} & 0.46 & ^{+0.13}_{-0.08} & 1.05 \\
      \bottomrule
      \multicolumn{9}{c}{}\\
      \toprule
      \multicolumn{2}{c|}{\etajet} & \multicolumn{4}{c|}{\diffetab} & \multicolumn{2}{c|}{\diffnloetab} & \Cbhad \\
      \multicolumn{2}{c|}{} & \multicolumn{4}{c|}{[\si{\pico\barn}]} & \multicolumn{2}{c|}{[\si{\pico\barn}]} & \\
      \midrule
       -1.6 & -1.1 &  57 & \pm & 22 & ^{+13}_{-3}  &  72 & ^{+22}_{-13} & 0.70 \\
       -1.1 & -0.8 & 121 & \pm & 21 & ^{+16}_{-16} & 182 & ^{+50}_{-30} & 0.78 \\
       -0.8 & -0.5 & 214 & \pm & 22 & ^{+22}_{-12} & 255 & ^{+69}_{-42} & 0.79 \\
       -0.5 & -0.2 & 233 & \pm & 21 & ^{+28}_{-21} & 307 & ^{+83}_{-50} & 0.79 \\
       -0.2 & +0.1 & 264 & \pm & 22 & ^{+28}_{-23} & 342 & ^{+91}_{-55} & 0.81 \\
       +0.1 & +0.5 & 316 & \pm & 21 & ^{+23}_{-17} & 346 & ^{+96}_{-57} & 0.86 \\
       +0.5 & +1.4 & 288 & \pm & 15 & ^{+20}_{-30} & 265 & ^{+82}_{-48} & 0.93 \\
       \bottomrule
    \end{array}\)
  \end{sideways}
  \caption{Cross-section measurements!}
  \label{tab:xsect1}
\end{table}

The 2nd version (right) is certainly simpler to typeset and does not
really use any tricks to line things up. Note the use of \Env{array}
rather than \Env{tabular} which means that the contents are typeset in
math mode rather than text mode. For tables of numbers this is often
preferred. You just have to enclose the array in
\texttt{\textbackslash(...\textbackslash)} or
\BegEnv{math}...\EndEnv{math}. Close inspection of the right-hand
table shows that it is, however, not perfect. It is questionable
whether one wants to to write $+0.5$ or just $0.5$. The fact that both
\pT as well as $\eta$ cross-sections are in a single tabular, but the
numerical values are so different makes it difficult to line things up
perfectly. An alternative, which uses the headers to fix the width of
the columns is given in Table~\ref{tab:xsect2}. Note that this uses
\Env{sidewaystable} rather than \Env{sideways} inside \Env{table},
which also rotates the caption.

\begin{sidewaystable}
  \centering
  \renewcommand{\arraystretch}{1.2}
  \begin{math}
    \begin{array}{D{.}{.}{4.0}@{\,:}D{.}{.}{3.1}|D{.}{.}{2}@{\,}r@{}D{.}{.}{2}@{\,}l|D{.}{.}{2}@{\,}l|c}
      \toprule
      \multicolumn{2}{p{2.0cm}|}{\rule[-1.5ex]{0pt}{4.0ex}\centering\pTjet} &
      \multicolumn{4}{p{3.0cm}|}{\centering\diffptb} &
      \multicolumn{2}{p{2.2cm}|}{\centering\diffnloptb} &
      \multicolumn{1}{p{1.5cm}}{\centering\Cbhad} \\
      \multicolumn{2}{c|}{[\si{\GeV}]} & \multicolumn{4}{c|}{[\si{\pico\barn\per\GeV}]} & \multicolumn{2}{c|}{[\si{\pico\barn\per\GeV}]} & \\
      \midrule
       6 & 11 & 95.6 & \pm & 4.9  & ^{+9.8}_{-7.0}  &  109  & ^{+31}_{-19} & 0.83 \\
      11 & 16 & 24.8 & \pm & 1.2  & ^{+1.8}_{-1.4}  & 29.1  & ^{+7.9}_{-4.7} & 0.89 \\
      16 & 21 & 6.02 & \pm & 0.49 & ^{+0.6}_{-0.6}  &  7.1  & ^{+2.0}_{-1.2} & 0.92 \\
      21 & 27 & 0.93 & \pm & 0.22 & ^{+0.31}_{-0.20} & 1.87 & ^{+0.54}_{-0.34} & 0.95 \\
      27 & 35 & 0.30 & \pm & 0.12 & ^{+0.14}_{-0.12} & 0.46 & ^{+0.13}_{-0.08} & 1.05 \\
      \bottomrule
    \end{array}
  \end{math}

  \vspace*{2ex}

  \begin{math}
    \begin{array}{D{.}{,}{1}@{\,:}D{.}{,}{1}|D{.}{,}{5.0}@{\,}r@{}D{.}{,}{0}@{\,}l|D{.}{,}{5.0}@{\,}l|D{.}{,}{4}}
      \toprule
      \multicolumn{2}{p{2.0cm}|}{\rule[-1.5ex]{0pt}{4.0ex}\centering\etajet} &
      \multicolumn{4}{p{3.0cm}|}{\centering\diffetab} &
      \multicolumn{2}{p{2.2cm}|}{\centering\diffnloetab} &
      \multicolumn{1}{p{1.5cm}}{\centering\Cbhad} \\
      \multicolumn{2}{c|}{} & \multicolumn{4}{c|}{[\si{\pico\barn}]} & \multicolumn{2}{c|}{[\si{\pico\barn}]} & \\
      \midrule
      -1.6 & -1.1 &  57 & \pm & 22 & ^{+13}_{-3}  &  72 & ^{+22}_{-13} & 0.70 \\
      -1.1 & -0.8 & 121 & \pm & 21 & ^{+16}_{-16} & 182 & ^{+50}_{-30} & 0.78 \\
      -0.8 & -0.5 & 214 & \pm & 22 & ^{+22}_{-12} & 255 & ^{+69}_{-42} & 0.79 \\
      -0.5 & -0.2 & 233 & \pm & 21 & ^{+28}_{-21} & 307 & ^{+83}_{-50} & 0.79 \\
      -0.2 &  0.1 & 264 & \pm & 22 & ^{+28}_{-23} & 342 & ^{+91}_{-55} & 0.81 \\
       0.1 &  0.5 & 316 & \pm & 21 & ^{+23}_{-17} & 346 & ^{+96}_{-57} & 0.86 \\
       0.5 &  1.4 & 288 & \pm & 15 & ^{+20}_{-30} & 265 & ^{+82}_{-48} & 0.93 \\
      \bottomrule
    \end{array}
  \end{math}
  \caption[Cross-sections using \Env{sidewaystable}, which also
  rotates the caption.]{Cross-sections using \Env{sidewaystable},
    which also rotates the caption. Just for fun the numbers
    indicating the $\eta$ range of the bins in the lower half have
    been converted to German format! Note also the dirty trick used to
    get the \Cbhad values nicely in the centre of the column.}
  \label{tab:xsect2}
\end{sidewaystable}

This version of the table also adds a few extra bells and whistles. It
uses a \Macro{rule} of zero width to give a bit more space above and
below the cross-sections. \texttt{p\{...\}} switches to paragraph
mode, so \Macro{centering} is needed to get centred headers. It adds a
bit more space between the rows using \Macro{arraystretch}.
You have to play around a bit with the column widths. If you set one
of them too small it gets expanded anyway, so the two parts of the
table would not line up. Just for fun the bottom half of the table
uses \enquote{,} instead of \enquote{.} for the decimal point!
Admittedly the header is a bit complicated, but the numbers are nice
and easy to write!

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "./thesis_guide"
%%% End: