This will look at first like a posting about trigonometry, then maybe about statistics, then finally about peculiarities of either

- a certain random process; or
- the pseudorandom number generator that I'm using; or
- other (specify!).

My question is: Which is it? And what's actually going on? I suspect it's the second alternative, but I'm not at all confident about that.

In the course of doing a bit of amateur cartography, I derived this little trigonometric relation:

If $(\cos\alpha,\sin\alpha)$ is in the **right half** of the unit circle (in other words, $\cos\alpha>0$), and $$\tan\gamma=\dfrac{\sin\alpha\sin\beta}{\cos\alpha+\cos\beta},$$ and $\cos\gamma$ is also positive, then
$$\tan\dfrac\gamma2=\tan\dfrac\alpha2\cdot\tan\dfrac\beta2.$$
Numerical evidence bore out what I had derived, so now I should live happily ever after.

(And I was moderately intrigued by the resemblance to the simpler and more familiar tangent half-angle formula $\dfrac{\sin\alpha+\sin\beta}{\cos\alpha+\cos\beta}=\tan\dfrac{\alpha+\beta}{2}$.)

But then I asked what happens in the **left half** of the circle, where the cosine is negative. The answer turns out to be
$$
-\cot\frac\gamma2 = \tan\frac\alpha2\cdot\tan\frac\beta2.
$$
[But see the "later note" below.]

But instead of deriving this by massaging trigonometric identities I got lazy and did some "experimental mathematics". Using R, I entered these commands:

```
a <- pi/180*(runif(1000)*(177 - 93) +93)
b <- pi/180*(runif(1000)*(177 - 93) +93)
c <- atan( sin(a)*sin(b)/(cos(a)+cos(b) ))
u <- -1/(tan(a/2)*tan(b/2))
coefficients(lm(tan(c/2) ~ u))
```

(Intercept) u

0 1

```
anova(lm(tan(c/2) ~ u))
```

Analysis of Variance Table

Response: tan(c/2)

Df Sum Sq Mean Sq F value Pr(>F)

u 1 29.222 29.222 2.1747e+34 < 2.2e-16 ***
Residuals 998 0.000 0.000
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Warning message:

In anova.lm(lm(tan(c/2) ~ u)) :

ANOVA F-tests on an essentially perfect fit are unreliable

```
plot(u,residuals(lm(tan(c/2) ~ u)))
```

So this puts $a$ and $b$ between $\pi/2$ and $\pi$, or more precisely, between $93\cdot\frac{\pi}{180}$ and $177\cdot\frac{\pi}{180}$, and chooses 1000 such pairs $(a,b)$ independently, and they're uniformly distributed in that region. Then it sets $c=\arctan(\sin a\sin b/(\cos a+\cos b))$, and $u=-1/(\tan a\tan b)$. Then we look at coefficients from a simple linear regression of $\tan(c/2)$ on $u$, and the software reports $0$ for the intercept and $1$ for the slope. An analysis of variance gives $0$ as the sum of squares of residuals, so it seems we have a perfect fit.

Finally, I plotted $u$ on the horizontal axis and the residuals on the vertical axis, and I got the following! If real numbers rather than approximations could be used, they would of course all be $0$, so this is about rounding errors, but still I wouldn't expect to see a pattern like this. I tried it a dozen or so times with pretty much the same result, and I tried it with the angles in the first quadrant and the identity that holds in that quadrant, with the same result again.

**LATER NOTE:** Well, haste makes waste, I guess. I *should* have let $\gamma$ be the "other value of" the arctangent once I moved into the second quadrant, i.e. $\gamma=\arctan(\cdots\cdots\cdots)+\pi$ as soon as the argument to the arctangent function was more than $\pi/2$. That way we still have the identity $\tan\frac\gamma2=\tan\frac\alpha2\cdot\tan\frac\beta2$. However, this doesn't upset the main point of this question. As I said, this already works in the *first* quadrant; I simply hadn't yet noticed it because at that point I was still doing things intelligently rather than numerically.