Out of curiosity, I am considering an interesting XOR "sum" of all reciprocals: $$X := 1 \oplus \frac{1}{2} \oplus \frac{1}{3} \oplus \frac{1}{4} \oplus \cdots= \bigoplus_{n=1}^{\infty} \frac{1}{n}$$ where $\oplus$ denotes bitwise XOR and all numbers $1/n$ are fractions represented in binary. The convention is that if a fraction has a terminating representation, we use it, i.e. $1/4$ is $0.01_2$ and not $0.00\overline{1}_2$ (although it would be interesting to analyze both). An example calculation of XORing fractions looks like this: $$\frac{1}{2} \oplus \frac{1}{3} = 0.1_2 \oplus 0.\overline{01}_2 = 0.11\overline{01}_2 = \frac{5}{6}.$$ which (coincidentally) matches regular addition. Another example: $$\frac{1}{5} \oplus \frac{1}{7} = 0.\overline{0011}_2 \oplus 0.\overline{001}_2$$
\begin{array} {|r|r|}\hline 0. & 0 & 0 & 1 & 1& 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & \cdots\\ \hline \oplus\: 0. & 0 & 0 & 1 & 0 & 0 & 1 & 0 & 0 & 1 & 0 & 0 & 1 & \cdots \\ \hline =0. & 0 & 0 & 0 & 1 & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \cdots \\ \hline \end{array} $$\implies 0.\overline{0011}_2 \oplus 0.\overline{001}_2 = 0.\overline{000101111010}_2 = \frac{6}{65}.$$
I want to find the exact value of the "sum", $X$, or at least some more info about it.
My partial progress:
- I know the "sum" converges: the $k$th bit in the result is uniquely determined by the first $2^k$ terms, with all terms after $2^k$ only affecting the next bits. This means that for a given $\epsilon > 0$, we can choose $N = 2^{-\log_2(\epsilon)} = \frac{1}{\epsilon}$. This proves the convergence of the partial sums and thus the convergence of the entire sum.
- Numerical calculations show that $X \approx 1.539581$, however getting more digits is quite difficult. It takes $\mathcal{O}(2^n)$ time to calculate first $n$ binary digits. I am quite confident in the digits $1.10001010001000100000000_2$. Here's the Python program I used, using the
binary_fractionspackage from pip:
from fractions import Fraction
from binary_fractions import Binary
N = 1000
res = Binary("0")
for i in range(1,N+1):
res ^= Binary(Fraction(1,i))
print(res)
- While I see no way to make the calculation have smaller time complexity, it can still be sped up more because XOR is commutative and associative, which is why I am planning on writing a multithreaded / GPU based version of this code which could split the workload on multiple threads and combine back together. However this is simply an effort to speed up the numerical computation instead of getting the closed form result (well, if there is one).
- The problem can also be alternatively restated in trying to determine whether there is an even or an odd number of 1s in the binary representation of each fraction at some $k$th bit. If it is even, the resulting number would have a $0$ at the $k$th bit and $1$ otherwise.
- Using the above alternative statement the problem can be generalized for base $b$ fractions by replacing XOR with addition mod $b$, but I have not investigated that (yet?).
So, my question is: has there been any research/literature on something like this? Is there a simple formula I am missing? I conjecture that it is irrational because there does not seem to be some periodic part but I do not know how to prove it.
EDIT 5/11/2024 My current progress includes these discoveries:
- You actually need $2^{k-1}$ terms to determine the $k$th bit of $X$. All terms whose index is between $2^{k-1}$ and $2^k$ have their $k$th bit set to 1, and since there are $2^k - 2^{k-1} = 2^{k-1}$ terms in that interval, which is an even number, their total XOR becomes 0. So really, only the first $2^{k-1}$ matter.
- An explicit formula for XOR of two fractions looks like this: if $$\frac{1}{A} = \sum_{k=1}^{\infty} a_k 2^{-k}\text{ and }\frac{1}{B} = \sum_{k=1}^{\infty} b_k 2^{-k}$$ where $a_k, b_k \in \{0,1\}$ are the bits of $1/A$ and $1/B$ respectively, $$\frac{1}{A} \oplus \frac{1}{B} = \sum_{k=1}^{\infty} (a_k + b_k - 2a_k b_k) 2^{-k} = \sum_{k=1}^{\infty} (a_k - b_k)^2 2^{-k} = \sum_{k=1}^{\infty} |a_k - b_k| 2^{-k}.$$
- My C++ code for computing the value of $X$ can be found here: https://github.com/artemetra/binaryfrac. The current best value I have is $X \approx 0.10001010001000100000000000100000111100010000101100_2 \approx 1.539581306497932$. I am pretty certain in these digits.
- With that being said, the main overarching problem here is then finding the patterns between the binary representations of reciprocals, which I haven't been able to tame much except from some very narrow edge cases (such as powers of 2 and terms around those).