I was messing around today and I found a few wierd ways to calculate
If you compute the Chebyshev polynomial approximation for the absolute value function over you get
Where as usual. If you combine the fractions you get
Which converges like .
To compute plug in , since and we have so our series becomes
Multiply by to get a series for .
See it on desmos.
Via euler's formula
We know , and is easy to compute via its taylor series. meaning we can treat computing as finding a root of
We can use newton's method, first notice then our update equation is
Geometrically this equation is extracting the height on the circle as a correction term
In : from cmath import exp In : exp(-3 * 1j) Out: (-0.9899924966004454-0.1411200080598672j) In : 1 + exp(-3 * 1j) Out: (0.010007503399554585-0.1411200080598672j) In : i * (1 + exp(-3 * 1j)) Out: (0.1411200080598672+0.010007503399554585j)
from cmath import exp x = 3 for i in range(5): x = x + 1j*(1 + exp(-1j*x)) print(x.real) # => 3.141592653589793
All digits correct after 5 iterations!
Of course, using
exp from the standard library is cheating. But the point of this method is that computing
exp(x) is a lot easier then computing directly (you can use the taylor series for instance).