[EN] Approximating pi by Binomial Averaging
Consider this generator, which implements the Taylor series for arctan(1): function* piTaylor() { let res = 0; let sign = 1; for (let i = 1; true; i += 2) { res += sign / i; sign = -sign; yield 4 * res; } } This function generates successive approximations of pi using the formula: π/4 = 1 - 1/3 + 1/5 - 1/7 + 1/9 - ... Each term alternates between positive and negative, and we multiply the result by 4 to get pi. The sequence converges quite slowly. Here's what the first few terms look like (showing the difference from the actual value of pi): 0 0.8584073464102069 1 -0.4749259869231261 2 0.3250740130768736 3 -0.2463545583516975 4 0.1980898860927471 5 -0.1655464775436166 ... As we can see, the error alternates between being positive and negative, with the absolute value getting smaller. This means that the sequence alternates between being too high and too low, while slowly getting closer to pi. Since the sequence goes ...