# Check it yourself: Three bodies

Don't take our word for it. Each result here comes with its files and a check guide, and each guide says which checks you can rerun yourself. Some results rest on logs from programs that are not part of this book, or on files available on request; the guide says which. Where your run matches ours, you checked that part rather than trusted it. If something breaks, confuses you or does not match, you are welcome to tell us. We fix mistakes in the open and credit the person who found them. Why a recipe and not our program: https://gocheckyourself.org/how-to-check/

You do not have to trust our results or our programs. This page tells you, step by step, how to check the published files with tools you already have. The full written recipe is the chapter 'Check it yourself: fifteen periodic three-body orbits, and sixteen more' in https://gocheckyourself.org/text/three-body-experts.txt.

Steps 1 to 6, 9 have the command for Windows PowerShell and for macOS or Linux (bash), the output you should see, and a plain sentence on what a match means and what it does not. Steps 7 to 8 have no copy-paste script yet: each names the recipe to write yourself and the output to expect. If your output is different, the step has failed; do not skip it.

You need: a command line, and Python 3.8 or later (python on Windows, python3 on macOS or Linux) for the steps that run a script. Windows PowerShell 5.1 or later (pwsh also works). Scripts are short; read them before you run them.

## What is known not to work today

- Check 10 (the Lean file) needs Lean (elan) and takes a few seconds once Lean is installed; not run here.
- Checks 2, 5, 6, 7, 8 and 9 are written out in the chapter in words and formulas, without a copy-paste script here. Exact fractions and 8x8 matrices of very long numbers are needed; the book says Check 5 takes about half a minute and under 500 MB in Python. Our own re-run of all of checks 1 to 9 took about 18 seconds.
- The existence and Morse-index computations behind the files are too large to ship and are not rechecked by any step.
- Download size: about 50 MB (the gzip blocks for two orbits).

## Step 1: Make an empty working folder and say where the files are.

Windows PowerShell:

```powershell
$ProgressPreference = "SilentlyContinue"
$BASE = "https://gocheckyourself.org/data/files/three-body"
New-Item -ItemType Directory -Force check-three-body | Out-Null
Set-Location check-three-body
```

macOS or Linux (bash):

```bash
BASE="https://gocheckyourself.org/data/files/three-body"
mkdir -p check-three-body && cd check-three-body
```

You should see:

```
No output.
```

What a match shows, and what it does not: Nothing; this just makes a folder.

Cost: instant.

## Step 2: Download the list of fingerprints (SHA-256) that the book publishes for its files.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/three-body/certificates/SHA256SUMS.txt  f40c4a8af03458df65b8a224cfc6f7aa779b775356e5b0c1412314a35168f491

Windows PowerShell:

```powershell
New-Item -ItemType Directory -Force certificates | Out-Null
Invoke-WebRequest -UseBasicParsing -UserAgent "Mozilla/5.0" "$BASE/certificates/SHA256SUMS.txt" -OutFile certificates/SHA256SUMS.txt
```

macOS or Linux (bash):

```bash
mkdir -p certificates
curl -fsSL "$BASE/certificates/SHA256SUMS.txt" -o certificates/SHA256SUMS.txt
```

You should see:

```
No output. The file certificates/SHA256SUMS.txt exists. Each line is 64 hex digits, a space, an optional star, and a file path.
```

What a match shows, and what it does not: The list comes from the same site as the files, so by itself it just catches damaged or swapped files, not a site that lies in both places. Compare the list's own SHA-256 (see inputs) with a copy you trust, such as one a friend keeps, or one kept anywhere other than this site.

Cost: instant.

## Step 3: Download every file named in the list, keeping the folder layout the list expects.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/three-body/certificates/SHA256SUMS.txt  f40c4a8af03458df65b8a224cfc6f7aa779b775356e5b0c1412314a35168f491

Windows PowerShell:

```powershell
Get-Content certificates/SHA256SUMS.txt | Where-Object { $_.Trim() } | ForEach-Object {
  $rel = ($_ -replace '^[0-9a-fA-F]{64} [ *]','') -replace '^\./',''
  New-Item -ItemType Directory -Force (Split-Path -Parent (Join-Path $PWD $rel)) | Out-Null
  try { Invoke-WebRequest -UseBasicParsing -UserAgent "Mozilla/5.0" "$BASE/$rel" -OutFile $rel } catch { "NOT FOUND: $rel" }
}
```

macOS or Linux (bash):

```bash
while read -r h p; do
  p="${p#\*}"; p="${p#./}"; [ -z "$p" ] && continue
  mkdir -p "$(dirname "$p")"
  curl -fsSL "$BASE/$p" -o "$p" || echo "NOT FOUND: $p"
done < certificates/SHA256SUMS.txt
```

You should see:

```
One file per list line (199 lines). No output means every download worked.
```

What a match shows, and what it does not: A missing file can come back as the site's home page (status 200) instead of a not-found. The next step catches that, because the page's hash will not match.

Cost: seconds to a minute.

## Step 4: Compare the SHA-256 fingerprint of every downloaded file with the published list.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/three-body/certificates/SHA256SUMS.txt  f40c4a8af03458df65b8a224cfc6f7aa779b775356e5b0c1412314a35168f491

Windows PowerShell:

```powershell
$ok = 0; $bad = 0
Get-Content certificates/SHA256SUMS.txt | Where-Object { $_.Trim() } | ForEach-Object {
  $h = $_.Substring(0,64).ToLower()
  $rel = ($_ -replace '^[0-9a-fA-F]{64} [ *]','') -replace '^\./',''
  $f = Get-FileHash -Algorithm SHA256 -LiteralPath $rel -ErrorAction SilentlyContinue
  if ($f -and $f.Hash.ToLower() -eq $h) { $ok++ } else { $bad++; "NOT OK: $rel" }
}
"$ok OK, $bad not OK"
```

macOS or Linux (bash):

```bash
# Linux: sha256sum.  macOS: use "shasum -a 256 -c" instead of "sha256sum -c".
if command -v sha256sum >/dev/null; then C="sha256sum -c"; else C="shasum -a 256 -c"; fi
$C certificates/SHA256SUMS.txt 2>&1 | grep -v ": OK$" ; echo "$($C certificates/SHA256SUMS.txt 2>/dev/null | grep -c ": OK$") OK"
```

You should see:

```
PowerShell prints a line "199 OK, 0 not OK". bash prints every line that is not OK, then "199 OK".
```

What a match shows, and what it does not: A match shows that your files are exactly the files the list names. What the files say is tested by the other steps of this recipe. In the check guide's words, existence, the Morse indices and the other stability verdicts are stated here and are not recomputed by these checks. 

Cost: seconds.

## Step 5: Check 3 route 1: the two yin-yang II orbits are linearly stable, from the saved 2x2 interval matrices, in exact fractions.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/three-body/certificates/yin-yang-II-3a/transported-reversible.json  97e962dcfd96d4cb8568d7d2c6b6e50fc56703b997e37c0b39ec469e034bfa39

Windows PowerShell:

```powershell
@'
# Three bodies, check 3, route 1 (exact interval arithmetic, no differential equation).
# Usage: python threebody_check3_yinyang_route1.py <book-folder>      (the folder that holds certificates/)
import sys, json, os
from fractions import Fraction as F

def add(a, b): return (a[0] + b[0], a[1] + b[1])
def sub(a, b): return (a[0] - b[1], a[1] - b[0])
def mul(a, b):
    p = [a[0] * b[0], a[0] * b[1], a[1] * b[0], a[1] * b[1]]
    return (min(p), max(p))

for name in ("yin-yang-II-3a", "yin-yang-II-3b"):
    f = os.path.join(sys.argv[1], "certificates", name, "transported-reversible.json")
    d = json.load(open(f))
    c = [[(F(x[0]), F(x[1])) for x in row] for row in d["cosine_matrix_exact"]]
    t = add(c[0][0], c[1][1])                                   # trace
    det = sub(mul(c[0][0], c[1][1]), mul(c[0][1], c[1][0]))     # determinant
    disc = sub(mul(t, t), (4 * det[0], 4 * det[1]))             # t^2 - 4d
    one_minus_t_plus_d = add(sub((F(1), F(1)), t), det)
    one_plus_t_plus_d = add(add((F(1), F(1)), t), det)
    ok = (disc[0] > 0 and one_minus_t_plus_d[0] > 0 and one_plus_t_plus_d[0] > 0 and t[0] > -2 and t[1] < 2)
    ev = sorted((F(x[0]), F(x[1])) for x in d["result"]["cosine_eigenvalues_exact"])
    inside = all(-1 < e[0] and e[1] < 1 for e in ev) and ev[0][1] < ev[1][0]
    mid = [float((e[0] + e[1]) / 2) for e in ev]
    print(name, "route 1 passes:", ok and inside, "| cosines about %.4f and 1 - %.3g" % (mid[0], 1 - mid[1]))
'@ | Set-Content -Encoding utf8 threebody_check3_yinyang_route1.py
python threebody_check3_yinyang_route1.py .
```

macOS or Linux (bash):

```bash
cat > threebody_check3_yinyang_route1.py <<'EOF'
# Three bodies, check 3, route 1 (exact interval arithmetic, no differential equation).
# Usage: python threebody_check3_yinyang_route1.py <book-folder>      (the folder that holds certificates/)
import sys, json, os
from fractions import Fraction as F

def add(a, b): return (a[0] + b[0], a[1] + b[1])
def sub(a, b): return (a[0] - b[1], a[1] - b[0])
def mul(a, b):
    p = [a[0] * b[0], a[0] * b[1], a[1] * b[0], a[1] * b[1]]
    return (min(p), max(p))

for name in ("yin-yang-II-3a", "yin-yang-II-3b"):
    f = os.path.join(sys.argv[1], "certificates", name, "transported-reversible.json")
    d = json.load(open(f))
    c = [[(F(x[0]), F(x[1])) for x in row] for row in d["cosine_matrix_exact"]]
    t = add(c[0][0], c[1][1])                                   # trace
    det = sub(mul(c[0][0], c[1][1]), mul(c[0][1], c[1][0]))     # determinant
    disc = sub(mul(t, t), (4 * det[0], 4 * det[1]))             # t^2 - 4d
    one_minus_t_plus_d = add(sub((F(1), F(1)), t), det)
    one_plus_t_plus_d = add(add((F(1), F(1)), t), det)
    ok = (disc[0] > 0 and one_minus_t_plus_d[0] > 0 and one_plus_t_plus_d[0] > 0 and t[0] > -2 and t[1] < 2)
    ev = sorted((F(x[0]), F(x[1])) for x in d["result"]["cosine_eigenvalues_exact"])
    inside = all(-1 < e[0] and e[1] < 1 for e in ev) and ev[0][1] < ev[1][0]
    mid = [float((e[0] + e[1]) / 2) for e in ev]
    print(name, "route 1 passes:", ok and inside, "| cosines about %.4f and 1 - %.3g" % (mid[0], 1 - mid[1]))
EOF
python3 threebody_check3_yinyang_route1.py .
```

You should see:

```
yin-yang-II-3a route 1 passes: True | cosines about -0.0322 and 1 - 2.3e-09
yin-yang-II-3b route 1 passes: True | cosines about -0.0322 and 1 - 2.3e-09
```

What a match shows, and what it does not: It shows the stored matrices satisfy the stability conditions. It does not show the matrices are the right ones (that rests on the large computation that made them) and it is just barely stable (within 2.31e-9 of 1).

Cost: instant.

## Step 6: Check 4 (the twist part): for moth I the twist determinant lies entirely below zero.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/three-body/certificates/moth-I/torsion-set-005/bounds-DIAGNOSTIC.json  c08ab8f186da30eac47a3d44cad7483d4658ed10c50364440ddfb01a37be759a

Windows PowerShell:

```powershell
@'
# Three bodies, check 4, the twist: the real part of complex_determinant must lie entirely below zero.
# Usage: python threebody_check4_moth_twist.py <book-folder>
import sys, json, os
from fractions import Fraction as F
folder = os.path.join(sys.argv[1], "certificates", "moth-I")
for sub in sorted(os.listdir(folder)):
    nodes = json.load(open(os.path.join(folder, sub, "nodes.json")))
    if nodes.get("selected_nodes") == list(range(8)) and not nodes.get("fallback_old_wires"):
        diag = json.load(open(os.path.join(folder, sub, "bounds-DIAGNOSTIC.json")))
        lo, hi = [F(int(e["m"])) * F(2) ** e["e"] for e in diag["complex_determinant"]["re"]]
        print(sub, "nodes 0 to 7, no fallback; twist in [%.8f, %.8f]; entirely below zero: %s" % (float(lo), float(hi), hi < 0))
'@ | Set-Content -Encoding utf8 threebody_check4_moth_twist.py
python threebody_check4_moth_twist.py .
```

macOS or Linux (bash):

```bash
cat > threebody_check4_moth_twist.py <<'EOF'
# Three bodies, check 4, the twist: the real part of complex_determinant must lie entirely below zero.
# Usage: python threebody_check4_moth_twist.py <book-folder>
import sys, json, os
from fractions import Fraction as F
folder = os.path.join(sys.argv[1], "certificates", "moth-I")
for sub in sorted(os.listdir(folder)):
    nodes = json.load(open(os.path.join(folder, sub, "nodes.json")))
    if nodes.get("selected_nodes") == list(range(8)) and not nodes.get("fallback_old_wires"):
        diag = json.load(open(os.path.join(folder, sub, "bounds-DIAGNOSTIC.json")))
        lo, hi = [F(int(e["m"])) * F(2) ** e["e"] for e in diag["complex_determinant"]["re"]]
        print(sub, "nodes 0 to 7, no fallback; twist in [%.8f, %.8f]; entirely below zero: %s" % (float(lo), float(hi), hi < 0))
EOF
python3 threebody_check4_moth_twist.py .
```

You should see:

```
torsion-set-005 nodes 0 to 7, no fallback; twist in [-1230.08884821, -1230.08833806]; entirely below zero: True
```

What a match shows, and what it does not: This is one of the finite conditions for the KAM statement for moth I. The conclusion also needs the four premises in the chapter's Status section; this step shows none of them.

Cost: instant.

## Step 7: Checks 2, 5, 6, 7, 8, 9: boxes against the 2013 table, linear verdicts of the ten published-list orbits, the two Krawczyk inclusions, the six figure-eight-power orbits, distinctness of the 30 orbits, Morse summaries.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/three-body/certificates/existence/boxes.json  fa11352dff74d7f173706f0b8af00b289dfaa83ddcc8ac2ad8ac64d52452413e

Commands (same on both platforms; not run by us unless stated):

```
No copy-paste script yet. Write it yourself from the written recipe:
Chapter headings 'Check 2' to 'Check 9'. Python's fractions module gives exact interval arithmetic.
```

You should see:

```
Check 2: 16 boxes well formed, 15 rows agree with the 2013 table. Check 5: 3 stable, 4 unstable, 3 NOT SHOWN. Check 6: strict inclusion, norms about 1.28e-18 and 2.02e-15. Check 7: all six boxes pass, equal-phase choreography excluded for 5 of 6. Check 8: exactly two overlapping Q pairs, 30 distinct orbits in 32 boxes. Check 9: 16 of 16 consistent.
```

What a match shows, and what it does not: They recheck the final exact arithmetic, not the large computations behind the files.

Cost: Check 5 about half a minute and under 500 MB in plain Python; the rest seconds.

## Step 8: Check 10: build the one Lean file.

Commands (same on both platforms; not run by us unless stated):

```
No copy-paste script yet. Write it yourself from the written recipe:
In the unpacked lean folder (https://gocheckyourself.org/data/files/three-body/downloads/three-body-lean.zip), with Lean installed through elan: lake build.
```

You should see:

```
Seven lines saying each theorem does not depend on any axioms, then 'Build completed successfully'.
```

What a match shows, and what it does not: Lean checks the conditional implication and exact endpoint arithmetic; no orbit result.

Cost: a few seconds once Lean is installed.

## Step 9: See for yourself that a one-byte change is caught: change one byte in a copy of certificates/moth-I/torsion-set-005/nodes.json (https://gocheckyourself.org/data/files/three-body/certificates/moth-I/torsion-set-005/nodes.json) and look at the fingerprint.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/three-body/certificates/moth-I/torsion-set-005/nodes.json  dafbc03cb4a6ea46451c25f8c06317c29c3769730b058c005a55a89f7ae0931d

Windows PowerShell:

```powershell
python -c "b=bytearray(open('certificates/moth-I/torsion-set-005/nodes.json','rb').read()); b[0]^=1; open('tampered.copy','wb').write(b)"
"published : dafbc03cb4a6ea46451c25f8c06317c29c3769730b058c005a55a89f7ae0931d"
"your copy : " + (Get-FileHash -Algorithm SHA256 tampered.copy).Hash.ToLower()
```

macOS or Linux (bash):

```bash
python3 -c "b=bytearray(open('certificates/moth-I/torsion-set-005/nodes.json','rb').read()); b[0]^=1; open('tampered.copy','wb').write(b)"
echo "published : dafbc03cb4a6ea46451c25f8c06317c29c3769730b058c005a55a89f7ae0931d"
echo "your copy : $( (sha256sum tampered.copy 2>/dev/null || shasum -a 256 tampered.copy) | cut -c1-64 )"
```

You should see:

```
Two different 64-digit values; the 'published' value ends 7ae0931d and your copy's value is different.
```

What a match shows, and what it does not: It shows the fingerprint step would notice that change. It says nothing about the file you did not change.

Cost: instant.

