Machin's formula and cousins There exists a well-known formula by John Machin: 
$$\frac{\pi}{4} = 4 \arctan \left(\frac{1}{5}\right) - \arctan \left(\frac{1}{239}\right).$$ Actually, it belongs to the family of Machin-like formulas of the form
$$\frac{\pi}4 = \sum_k a_k \arctan {b_k}^{-1}\quad\text{for some integers}\quad(a_k,b_k)$$ 
For example:
$$\frac{\pi}{4} = \arctan \left(\frac{1}{2}\right) + \arctan \left(\frac{1}{3}\right) = 2 \arctan \left(\frac{1}{2}\right) - \arctan \left(\frac{1}{7}\right)$$ and so forth.
These formulas are quite easy to prove, but is there any easy way to generate such $(a_n, b_n)$?
 A: The best way to understand identities like this is in terms of Gaussian integers -- complex numbers whose real and imaginary parts are integers.. I'll do some examples, and then explain the general setup.
For example, notice that we have the identity:
$$(5+i)^4 = 476+480 i = 2 (1+i) (239+i). \quad (*)$$
(Just multiply it out and see.)
Multiplying complex numbers adds their arguments1. So
$$4 \arg(5+i) = \arg(1+i) + \arg(239+i)$$
or
$$4 \tan^{-1} \frac15 = \frac{\pi}{4} + \tan^{-1} \frac1{239}$$
as desired. Similarly, $(2+i)(3+i) = 5(1+i)$ explains another one of your identities.
In general, whenever we have $\prod (a_k+i)^{b_k} = r (1+i)$ for $r$ a positive real, we get $\sum b_k \tan^{-1} a_k^{-1} = \pi/4$.

So, how do we find formulas like $(*)$? The key point is that Gaussian integers, like ordinary integers, have unique factorization into primes. The primes in the Gaussian integers come in three flavors: (a) The prime $1+i$ (b) If $p$ is an integer prime which is $3 \mod 4$, then $p$ is also a prime in the Gaussian integers. (c) If $p$ is an integer prime which is $1 \mod 4$, then we can write $p$ as $(q+ri)(q-ri)$, and $q+ri$ and $q-ri$ will be both prime in the Gaussian integers. Also, the powers of $i$ are units which should be ignored in prime factorizations, just like $-1$ in the ordinary integers.
Whenever we have an identity like $(*)$, we must have the same prime factors on both sides. For example, $(239+i) = (3-2i)^4 (1+i) \cdot i$, $5+i = (3-2i)(1+i)$ and $2 = (1+i)^2 (-i)$, so both sides of $(*)$ are $(3-2i)^4 (1+i)^4$.
The way that I would find more identities like this would be to take a whole bunch of numbers of the form $a_k+i$ and factor them in the Gaussian integers. Then I'd look for some way to multiply them together so that the resulting power of $1+i$ is odd, and such that the exponent of $q+ri$ is equal to the exponent of $q-ri$ for all primes $q \pm ri$ of type (c). This will make $\prod (a_k+i)^{b_k}$ into something of the form $(1+i)^{\mathrm{odd}} (\mbox{something real})$. Using $(1+i)^2 = 2i$, we can turn this into $\prod (a_k+i)^{b_k} = (1+i) (\mbox{something either purely real or purely imaginary})$, and thus find a new formula for $\pi/4$.
Note that finding $b$'s with the specified properties is a matter of linear algebra, as I will show in the example below.

Example: Suppose I wanted a formula involving $\tan^{-1} (1/2)$, $\tan^{-1} (1/5)$ and $\tan^{-1}(1/8)$. (I'm cheating: I happen to know such a thing exists. A more realistic example would be to start out with $\tan^{-1}(1/b)$, for $b$ ranging from $2$ to $10$, and then see which subset works. But that would be too time consuming to write up here.)
Here are the factorizations in the Gaussian integers:
$$2+i \ \mbox{is prime}$$
$$5+i = (1+i)(3-2i)$$
$$8+i = (3+2i)(2-i)$$
So 
$$(2+i)^{b_1} (5+i)^{b_2} (8+i)^{b_3} = (1+i)^{b_2} (2+i)^{b_1} (2-i)^{b_3} (3-2i)^{b_2} (3+2i)^{b_3}.$$
I want $b_2$ to be odd, $b_1=b_3$ and $b_2=b_3$. A little bit of linear algebra finds the solution $b_1=b_2=b_3 =1$. So I discover the identity
$$(2+i)(5+i)(8+i) = 65 (1+i)$$
and
$$\tan^{-1} \frac12 + \tan^{-1} \frac15 + \tan^{-1} \frac18 = \frac{\pi}{4}.$$
1 This formula might be off by an integer multiple of $2\pi$. See Joel Cohen's comment below. But I assume you are just as happy with a formula for $\pi/4+2 k \pi$.
A: The identity $\cot^{-1} x = 2 \cot^{-1} 2x - \cot^{-1} (4x^3 + 3x)$ can be used to generate an infinite number of these identities. (Got from the mathworld page: http://mathworld.wolfram.com/Machin-LikeFormulas.html, see equation 29)
A: For 2-terms formulas, I've computed a generalized formula which is, I think, more efficient than any other existing Machin's formula. see my post:
generalized 2-terms Machin's formula (an efficient way to compute $\pi$)
A: How about this machin like:
$$2(tan^{-1}\frac{1}{4}-tan^{-1}(-4))=\pi$$
