back to index

Goldbach Conjecture

Verifying the Goldbach Conjecture by brute force for every even number up to 1 billion.


Goldbach's conjecture is easy to state and so far impossible to prove: every even integer greater than 2 is the sum of two primes. 4 = 2 + 2. 100 = 3 + 97. 1,000,000,000 = 3 + 999,999,997. It has been open since 1742. This project points a computer at it and records that no counterexample turns up.

The verifier was written from scratch over a long weekend in late November 2025. The plan was to start at a cap of a million and raise it as far as a laptop would carry it. The final run stops at one billion.

The whole thing is two short Python files. The first, goldbach_check.py, builds a sieve of Eratosthenes as a bytearray and then walks every even number n from 4 to the cap, looking for any prime p ≤ n/2 such that n - p is also prime. It stops at the first one it finds. If it ever fails to find one, it prints the counterexample and bails out. The sieve is the trick: once primality lookup is fast, the rest is a tight loop.


for n in range(4, max_n + 1, 2):
    found = False
    for p in primes:
        if p > n // 2:
            break
        if prime_set[n - p]:
            found = True
            break
    if not found:
        # counterexample — this never fires
        return False

At 1,000,000 the verifier finishes in about 0.224 seconds and prints the first ten decompositions as a sanity check. The second file, generate_thru_n.py, reuses the same sieve, but instead of stopping at a yes or no answer it writes out every decomposition it finds to a text file. That is the one that goes to 1 billion. It took 470 seconds, just under eight minutes, and produced a 12.38 GB text file that VS Code refused to open. The screenshot in the repo is VS Code declining the file size while the progress log scrolls past in the terminal.

No counterexamples, which is the expected outcome: the conjecture has been computationally verified well past 4×10^18 by people with actual compute budgets. This is a verification, not a proof, and verification is not proof in number theory. The conjecture is still open. What the run confirms, on one machine, is that the first billion even integers all behave. Goldbach wrote about the problem in 1742 in a letter to Euler, and nobody has closed it since. This does not close it either.

Python rather than something faster, because the code was written in one sitting with no compiler to fight. The sieve is the hot path, and bytearray makes it cheap enough that the bottleneck for the 1B run is mostly writing the output file to disk. Pushing past 1B would mean skipping the decompositions on disk and probably reaching for Rust with parallelized segmented sieving. The repo is here, and the code is short enough to be its own spec.