Præface: Okay, having somehow survived without proper Unicode input (Ctrl-Shift-U) for five(?) months, I still feel like killing myself every time I have to type in Greek stuff or mathematical operators, or whatever. (Also, “everytime” is wrong, and “every time” is definitely spelt as two words, yet I constantly see some people using it. I’m not really interested in derailing every conversation by being a grammar nazi, but gosh.)
Let’s start with the factorial-over-double-odd-factorial series for π/2. You know, the one that Euler guy came up with centuries ago.
Now let’s work modulo 2. Notice that the terms from onwards have even numerator and odd denominator, so they’re congruent to 0.
Now, it seems that we can even use this series to calculate the 2-adic representation of π/2 (and hence π or any other rational multiple thereof), because not only does it converge under the usual metric, it also converges under the 2-adic metric, as the number of times 2 divides into the numerator increases by at least one every two terms, while the denominator stays odd forever.
Just as an aside, there’s one pretty cool algorithm for calculating the inverse of a nonzero number modulo a prime, which is kinda related to the Euclidean algorithm if you stare at it enough. See pages 131-132 of The Book of Numbers. To wit, in code:
def modinv(a,p): '''Calculate the multiplicative inverse of a modulo p.''' inv = 1 a %= p while a != 1: q = (p+a-1)//a # ceil(p/a) a = a*q-p inv = inv*q%p return inv
Because the modulus is prime (and by the loop condition, ), , so the algorithm is guaranteed to terminate. By instead rounding to the nearest integer, rather than ceiling, can be guaranteed to halve every iterate; in other words, it converges a lot faster (on average). Now, this algorithm doesn’t directly work with nonprime moduli, but we can easily tweak it to work for prime power moduli by simply choosing the closest integer coprime to the modulus instead of just floor/ceiling. (This modification does not necessarily work for not-prime-power moduli because the closest coprime number might be too far away.)
Working out the first sixteen terms of the series,
we get π/2=…10111110001011102. What an utterly fascinating result. we get π/2=…0000000000000002. (I fixed something wrong with my calculation.) Does it actually tend to all zeroes?
Not every series for π converges with the 2-adic metric though (obviously). The Gregory-Leibniz series reduces to Grandi’s series modulo 2, which can hardly be called convergent. On the other hand, there (probably?) are other series with only odd denominators that converge under the 2-adic metric, and converge to in the usual Euclidean metric, but do they necessarily converge to the same value in the 2-adic metric?
Stealth edit: fixed the value of above.
Edit #2: tried using the Euler-transformed series for arctan(1/2)+arctan(1/3), which also seemed to give a few thousand binary digits of 0s. Now, why exactly would it converge to zero, if it actually does?