This notebook is used to generate data regarding the Goldbach conjecture: rows are of the form $N, a, b$ where $N$ is an even number, $a< b$ are prime and $N=a + b$.

First we write a Python function `goldbach` that takes `N` and returns all pairs of numbers $a, b$.


```python
import sympy as sym
import pandas as pd

def goldbach(N):
    """Returns all pairs of primes that sum to give N"""
    primes = list(sym.primerange(1, N))
    sums = []
    for i, p1 in enumerate(primes):
        for p2 in primes[i:]:
            if p1 + p2 == N:
                sums.append((p1, p2))
    return sums
```

Let us use the above function to create our data:


```python
maxN = 500
data = [[N, *pair] for N in range(4, maxN + 1) 
        for pair in goldbach(N) if N % 2 == 0 ]
```

Let us write our data to an excel file:


```python
df = pd.DataFrame(data, columns=["N","a", "b"])  # Create a data frame
df.to_excel("data/goldbach.xlsx")  # Write it to excel
```

21ab2614794ec6b3c5d7f47949eeb7dc96d9ec04
ipynb
Jupyter Notebook
nbs/A1-Appendix-creating-Goldbach-data.ipynb
dianetam523/Python-Mathematics-Handbook
04036b58dc82943c9ac577abe74c1a2b387e40ce
MIT
nbs/A1-Appendix-creating-Goldbach-data.ipynb
dianetam523/Python-Mathematics-Handbook
04036b58dc82943c9ac577abe74c1a2b387e40ce
MIT
nbs/A1-Appendix-creating-Goldbach-data.ipynb
dianetam523/Python-Mathematics-Handbook
04036b58dc82943c9ac577abe74c1a2b387e40ce
MIT
Qwen/Qwen-72B
1. YES
2. YES