---
title: "William Tell"
author: "Marek Rychlik"
date: "11/2/2021"
output:
  pdf_document: default
  html_document: default
---

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

Problem 10, Section 5.8
-----------------------

William Tell is a very bad shot. In practice, he places a small green apple on top of a straight wall which stretches to infinity in both directions. He then takes up position at a distance of one perch from the apple, so that his line of sight to the target is perpendicular to the wall. He now selects an angle uniformly at random from his entire field of view and shoots his arrow in this direction. Assuming that his arrow hits the wall somewhere, what is the distribution function of the horizontal distance (measured in perches) between the apple and the point which the arrow strikes? There is no wind.

Solution
--------

Let $\Theta$ be the angle. Lacking other assumptions, we assume that the arrow moves along a straight line. Then the horizontal distance between the apple and point of impact is given by the formula $$ X = \tan(\Theta)$$ where $\Theta$ is uniformly distributed in the range $(-\pi/2,\pi/2)$. Note that the wall is horizontal and we assume the angle is measured from the vertical axis pointing straight down.

The function $f(\theta)=\tan \theta$ is 1:1 and onto $(-\infty,\infty)$. Also, we find that $$ g^{-1}(x) = \arctan(x)$$ Therefore, the change of variables formula implies that $X$ has the pdf $$ 
\begin{aligned}
h(x)&=f(g^{-1}(x))\cdot |(g^{-1})'(x)|\\
    &= \frac{1}{\pi} \frac{1}{1+x^2}
\end{aligned}
$$ This is the Cauchy distribution and thus has $\mathbb{E}(X)=\infty$. This underscores how bad a shot William Tell is. On the average, he will not hit the fruit, even if it is a really long banana.

How often will William Tell hit an apple of a given size?
---------------------------------------------------------

Suppose the apple extends from $-x$ up to $x$. The freqeuency should be $$ \Pr(-x < X < x) = F(x)-F(-x)$$ where $$ F(x)=\frac{1}{\pi}\int_{-\infty}^x \frac{1}{1+u^2}du = \frac{1}{\pi}\arctan x |_{-\infty}^x = \frac{1}{\pi}\arctan x + \frac{1}{2} $$ Hence $$ \Pr(-x < X < x) = F(x)-F(-x)=\frac{2}{\pi}\arctan x\approx \frac{2}{\pi} x$$ where the approximation holds for small $x$.

What is the average distance in many trials?
--------------------------------------------

Let $X_n$ be a Cauchy distributed IID variables, $n=1,2,\ldots$. The average is $$ A_n = \frac{1}{n} \sum_{k=1}^n |X_k|$$ (average absolute distance). We claim that $$ \lim_{n\to\infty} A_n = \infty$$ almost surely.

Rather than proving this theorem, we develop numerical evidence by performing an R experiment.

```{r Theta, echo=TRUE}
n=100000
k=100
skip=100
N=1:n
C=seq()
for(i in 1:k) {
  Theta = runif(n, min = -pi / 2, max = pi / 2)
  X = tan(Theta)
  C=C+cumsum(abs(X))/k
}
N=N[skip:n]
C=C[skip:n]
plot(N, C/(N),pch='.')
```

The evidence is not as clear-cut as it would be for coin tosses.
