Pi Day MMXVII

Every year on March the 14th, for one day the world gets irrationally excited about the famous constant $\pi$. As is tradition, you try to calculate $\pi$ in unusual ways, demonstrating the constant’s ubiquity as it crops up in the most unexpected circumstances.

                        lnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
nJw
v$$n$$$$z u$$mnn:       Y$$i .@$$$$,$$n           )$$* W$$$$m -n[$$$$. ]$$
h$$w$$Y
[         X$$"$$$$n '$${
.$8$$*$$$$} :$$+ #u $$% t$$ ;$$ u$$! $$W Y$$M .$$, f$$$$. Z$$$$Z nn w$$$$|$$( v$z
n$W $$1 'X8 Y$$ *$$8nnnn$$$p
$@. W$n
_$${ x$$$0> -n{. !|nt_.  A fairly well-known way to approximate pi is to randomly choose points in a square (often thought of as throwing darts at a square piece of cardboard), determine their distance to a circle’s center and do a division, as I did in my π Generator post. However, $\pi$ does not only appear in the formula for a circle’s area, $A=\pi \cdot r^2$, yet also in the formula for a sphere’s volume, $V=\frac{4}{3} \cdot \pi \cdot r^3$, and for all the infinite hyperspheres above dimension three (view this Wikipedia article for more about volumes of higher-dimensional spheres). In particular, the formula for the hypervolume of a hypersphere in four dimensions is defined as being $V=\frac{\pi^2}{2} \cdot r^4$. Using this formula, my Python script randomly chooses four-dimensional points (each in the interval $\left[0, 1\right)$), calculates their distance to the point $\left(0.5, 0.5, 0.5, 0.5\right)$ and determines if they are in the hypersphere around that point with radius $0.5$. By dividing the number of random points which lie in the hypersphere by the number of iterations used ($10^6$ in the example below), the script approximates the hypersphere’s hypervolume. By then rearranging the equation $V=\frac{\pi^2}{2} \cdot r^4$ with $r=0.5$ to $\pi=\sqrt{V\cdot 32}$, the desired constant can be approximated. $ python pi.py
3.14196371717

# Python 2.7.7 Code
# Jonathan Frech, 13th of March 2017

Look-and-Say Sequence

An interesting nonmathematical sequence which yet has interesting mathematical properties is the Look-and-say sequence.
As every good sequence it starts with a 1. From there you get each next entry by looking at the previous and saying it. The next entry will thus be “one 1” or 11. From there “two 1” or 21, then “one 2; one 1” or 1211, “one 1; one 2; two 1” or 111221 and so on.

Generating the sequence

The mathematical property although does not lie in the entry’s value, but rather in its length.

Calculating the length of each entry

The interesting thing about the length is, that it approximately grows by λ each time. $\big( \lambda = 1.303577269034\dots \big)$
This constant λ can be calculated by getting the real root of a degree 71 polynomial (see Nathaniel Johnston’s post for further information) or be approximated by dividing entrys. $\big( \lambda = \frac{\text{entry}_{n+1}}{\text{entry}_{n}} \text{ for } n \rightarrow \infty \big)$

Approximating λ

# Python 2.7.7 Code
# Jonathan Frech 25th of February, 2016
#         edited 26th of February, 2016
#         edited 28th of February, 2016
#         edited  4th of March   , 2016

π Approximation

Using an infinite series shown by Euler, π can be approximated.
The series goes as follows: $\sum\limits_{n=1}^{\infty} \frac{1}{n^2} = \frac{1}{1^2} + \frac{1}{2^2} + \frac{1}{3^2} + \frac{1}{4^2} + \dots = \frac{\pi^2}{6}$
By rearranging the equation, you get the following: $\pi = \sqrt{6\cdot\big(\frac{1}{1^2} + \frac{1}{2^2} + \frac{1}{3^2} + \frac{1}{4^2} + \dots\big)}$

# Python 2.7.7 Code
# Jonathan Frech 14th of December, 2015

e Generator

By using the formula $\big(1 + \frac{1}{n}\big)^n$ for a big number $n$, you can approximate the mathematical constant $e$.

# Python 2.7.7 Code
# Jonathan Frech 23rd of October, 2015`