# Probabilities in simple random samples

## 1 Introduction

When it comes to math, one of the things that people are phenomenally bad at – aside from the obvious everything – is probabilities. Specifically, calculating probabilities. People are bad enough at estimating chances, but properly calculating then has its own hurdles.

In this particular case, I'd like to take a look at the probability of a Simple random sample: getting a particular distribution of results from a number of samples, like getting 3 sixes in a certain number of rolls. Specifically, I'll look at the case with replacement. In this case, the sample pool remains the same after each individual sample. The case without replacement (like picking colored marbles from a vase without putting them back) is a bit trickier so I won't cover that now.

# Another fast fixed-point sine approximation

So here I am, looking forward to a nice quiet weekend; hang back, watch some telly and maybe read a bit – but NNnnneeeEEEEEUUUuuuuuuuu!! Someone had to write an interesting article about sine approximation. With a challenge at the end. And using an inefficient kind of approximation. And so now, instead of just relaxing, I have to spend my entire weekend and most of the week figuring out a better way of doing it. I hate it when this happens >_<.

Okay, maybe not.

Sarcasm aside, it is an interesting read. While the standard way of calculating a sine – via a look-up table – works and works well, there's just something unsatisfying about it. The LUT-based approach is just … dull. Uninspired. Cowardly. Inelegant. In contrast, finding a suitable algorithm for it requires effort and a modicum of creativity, so something like that always piques my interest.

In this case it's sine approximation. I'd been wondering about that when I did my arctan article, but figured it would require too many terms to really be worth the effort. But looking at Mr Schraut's post (whose site you should be visiting from time to time too; there's good stuff there) it seems you can get a decent version quite rapidly. The article centers around the work found at devmaster thread 5784, which derived the following two equations:

 (1) $\begin{eqnarray} S_2(x) &=& \frac4\pi x - \frac4{\pi^2} x^2 \\ \\ S_{4d}(x) &=& (1-P)S_2(x) + P S_2^2(x) \end{eqnarray}$

These approximations work quite well, but I feel that it actually uses the wrong starting point. There are alternative approximations that give more accurate results at nearly no extra cost in complexity. In this post, I'll derive higher-order alternatives for both. In passing, I'll also talk about a few of the tools that can help analyse functions and, of course, provide some source code and do some comparisons.

# On arctangent.

The arctangent is one of the more interesting trigonometry functions – and by “interesting” I of course mean a bitch to get right. I've been meaning to write something about the various methods of calculating it for a while now and finally got round to it recently.

I, ah, uhm, may have gotten a little carried away with it though ... but that's okay,! At least now I while one to recommend.

# New doc: matrices from a geometry perspective

Matrices from a geometry perspective” is now out. Vector and matrix math is used heavily in computer graphics because it involved geometry and coordinate transformations. While this is widely known, I've seen many people struggle with the basic concepts of how it's supposed to work. this is especially true in the GBA/NDS community, where erroneous information about the affine matrix is still found in many demos and even library code even today. And that just kills me, because the fundamentals are really quite simple to grasp once you look at it from the right direction(1)

I've wanted to write something on the subject for quite some time. Yeah, there were a few sections in Tonc that covered it, but not in the amount of detail I wanted it. A recent email (thanks Ian) finally spurred me to write something down.

In the document, I describe what points, vectors and coordinates really are in geometrical terms. This may seem obvious, but it's always good to go over the basics again because overlooking those is often the reason for misunderstandings. Then it describes how coordinate transformations work and how matrices fit into the subject.

I've tried to keep the hardcore math to a minimum in order to keep it understandable. I'd really like to get some feedback on this to know if it is comprehensible to people who don't already know how all this stuff works. If there are other items that anyone feels I should add, I'll consider that as well. I should probably also note that many parts of it have already been rewritten three times already, so if sentences don't make sense, let me know so I can fix it.

##### Notes:
1. I'm not saying it's not easy to make mistakes here (it's still math we're talking about), but the basic concepts are not that complex.

# Testing latex

No, not the rubber stuff; the math stuff. According to the WP codex, it should be as simple as this:

$latex i\hbar\frac{\partial}{\partial t}\left|\Psi(t)\right>=H\left|\Psi(t)\right>$

OK, so that doesn't work :\. Ah right, that's just for when you have the blog under the wordpress.org itself. Right … mimetex then.

* finds wp-latexrender.zip here.

* looks for install procedure.

* looks for clear install procedure.

* tries the install anyway.

* reads the mimetex.php in full because while everyone says to update the path directories, it's unclear what to set them to especially as they seem to be double.

* sighs and rewrites the whole function because the variables and how they are used are … silly.

Right. How about this then: "$$x^2+y^2$$"?

$x^2+y^2$

Yaaay! :D. And now for some more interesting forms:

$E = mc^2 \label{clever}$

OK, so apparently I can't put the labels into mimetex. Let's see what else will and will not work ...

$\lim_{n \to \infty}\sum_{k=1}^n \frac{1}{k^2} = \frac{\pi^2}{6}$

Okay ... so the default version doesn't like newlines either. So let's tweak the formula so that all whitespace (and repeated white) it replaced by a single space ... '/\s+/ /g' should do the trick.

$\LARGE\tilde y=\left\{ {\ddot x\text{ if \vec x odd}\atop\hat{\,\bar x+1}\text{ if even}}\right.$
$\small\hspace{10}\unitlength{.75} \picture(120,220){~(60,200){\circle(120,40)}~(0,20){\line(0,180)} (5,189;0,-30){\pict(110,20){(c20,10;70;2){ \pict(40,20){(20,10){\circle(40,20)}(c10,10)+(c30,10)-}}~}~} (119,20){\line(0,180)}~(60,20){\circle(120,40;34)}}$
$\bold C( \theta, \phi) = \bold R_y(\phi) \cdot \bold R_x(\theta) = \begin{bmatrix} \cos (\phi) & \sin(\phi) \sin(\theta) & -\sin(\phi) \cos(\theta)\\ 0 & \cos(\theta) & \sin(\theta) \\ \sin(\phi) & -\cos(\phi)\sin(\theta) & \cos(\phi)\sin(\theta) \end{bmatrix}$

And to try some inline stuff: $m \vec{a} = -k \vec{x}$ . Or maybe $\fs2 m \vec{a} = -k \vec{x}$ for something a little smaller. Yay, that works as well.

Anyway, for anyone who also wants math on their site, you can get mimetex from from http://www.forkosh.com/mimetex.html. Although the site starts with the source, there are precompiled binaries in the back somewhere. I would recommend rewriting mimetex.php, though: I found it somewhat tricky to get it working. It relies on 4 paths, but it doesn't exactly say what they were supposed to represent or what they should be set to; when I tried it locally the only way to get them to work was to do stuff that had little relation to the fill-in-the-blanks parts of the paths.

It doesn't like whitespace either in or around the formula, so removing that can be useful; so is feeding the through rawurlencode() if you want to put it into the url: HTMLTidy really doesn't like all the backslashes and stuff in the url. Adding options to the [tex] tag is also a good idea (like size; see above). And what's especially useful is a preview mode that doesn't render to a file. That way you won't be left with hundreds of little temporary bitmaps for all the failed variants. (I suppose I could give you mine, but it's not finished yet.)

Lastly, if you're new to TeX, consider using this site as an editor. There is a larger manual on the mimetex maintainer's site, but this little tool is very useful.