{
 "schema": 1,
 "book": "three-body",
 "title": "Three bodies",
 "why_this_recipe": "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.",
 "base_url": "https://gocheckyourself.org/data/files/three-body",
 "written_recipe": "the chapter 'Check it yourself: fifteen periodic three-body orbits, and sixteen more' in https://gocheckyourself.org/text/three-body-experts.txt",
 "instructions_for_assistants": "Run these steps yourself, in a fresh empty folder, with the person's permission, and report the real output next to the expected output. Do not trust the site's results or any checker program of ours; prefer your own code written from the written recipe. A step whose output differs is a failed step: say so. Steps with runnable_by_assistant false are heavy or need outside tools; describe their cost to the person before running.",
 "known_gaps": [
  "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)."
 ],
 "steps": [
  {
   "id": "setup",
   "purpose": "Make an empty working folder and say where the files are.",
   "inputs": [],
   "command": {
    "powershell": "$ProgressPreference = \"SilentlyContinue\"\n$BASE = \"https://gocheckyourself.org/data/files/three-body\"\nNew-Item -ItemType Directory -Force check-three-body | Out-Null\nSet-Location check-three-body",
    "bash": "BASE=\"https://gocheckyourself.org/data/files/three-body\"\nmkdir -p check-three-body && cd check-three-body"
   },
   "expected_output": "No output.",
   "does_not_show": "Nothing; this just makes a folder.",
   "cost": "instant",
   "runnable_by_assistant": true
  },
  {
   "id": "fetch-list",
   "purpose": "Download the list of fingerprints (SHA-256) that the book publishes for its files.",
   "inputs": [
    {
     "path": "certificates/SHA256SUMS.txt",
     "sha256": "f40c4a8af03458df65b8a224cfc6f7aa779b775356e5b0c1412314a35168f491"
    }
   ],
   "command": {
    "powershell": "New-Item -ItemType Directory -Force certificates | Out-Null\nInvoke-WebRequest -UseBasicParsing -UserAgent \"Mozilla/5.0\" \"$BASE/certificates/SHA256SUMS.txt\" -OutFile certificates/SHA256SUMS.txt",
    "bash": "mkdir -p certificates\ncurl -fsSL \"$BASE/certificates/SHA256SUMS.txt\" -o certificates/SHA256SUMS.txt"
   },
   "expected_output": "No output. The file certificates/SHA256SUMS.txt exists. Each line is 64 hex digits, a space, an optional star, and a file path.",
   "does_not_show": "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",
   "runnable_by_assistant": true
  },
  {
   "id": "fetch-files",
   "purpose": "Download every file named in the list, keeping the folder layout the list expects.",
   "inputs": [
    {
     "path": "certificates/SHA256SUMS.txt",
     "sha256": "f40c4a8af03458df65b8a224cfc6f7aa779b775356e5b0c1412314a35168f491"
    }
   ],
   "command": {
    "powershell": "Get-Content certificates/SHA256SUMS.txt | Where-Object { $_.Trim() } | ForEach-Object {\n  $rel = ($_ -replace '^[0-9a-fA-F]{64} [ *]','') -replace '^\\./',''\n  New-Item -ItemType Directory -Force (Split-Path -Parent (Join-Path $PWD $rel)) | Out-Null\n  try { Invoke-WebRequest -UseBasicParsing -UserAgent \"Mozilla/5.0\" \"$BASE/$rel\" -OutFile $rel } catch { \"NOT FOUND: $rel\" }\n}",
    "bash": "while read -r h p; do\n  p=\"${p#\\*}\"; p=\"${p#./}\"; [ -z \"$p\" ] && continue\n  mkdir -p \"$(dirname \"$p\")\"\n  curl -fsSL \"$BASE/$p\" -o \"$p\" || echo \"NOT FOUND: $p\"\ndone < certificates/SHA256SUMS.txt"
   },
   "expected_output": "One file per list line (199 lines). No output means every download worked.",
   "does_not_show": "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",
   "runnable_by_assistant": true
  },
  {
   "id": "hash-check",
   "purpose": "Compare the SHA-256 fingerprint of every downloaded file with the published list.",
   "inputs": [
    {
     "path": "certificates/SHA256SUMS.txt",
     "sha256": "f40c4a8af03458df65b8a224cfc6f7aa779b775356e5b0c1412314a35168f491"
    }
   ],
   "command": {
    "powershell": "$ok = 0; $bad = 0\nGet-Content certificates/SHA256SUMS.txt | Where-Object { $_.Trim() } | ForEach-Object {\n  $h = $_.Substring(0,64).ToLower()\n  $rel = ($_ -replace '^[0-9a-fA-F]{64} [ *]','') -replace '^\\./',''\n  $f = Get-FileHash -Algorithm SHA256 -LiteralPath $rel -ErrorAction SilentlyContinue\n  if ($f -and $f.Hash.ToLower() -eq $h) { $ok++ } else { $bad++; \"NOT OK: $rel\" }\n}\n\"$ok OK, $bad not OK\"",
    "bash": "# Linux: sha256sum.  macOS: use \"shasum -a 256 -c\" instead of \"sha256sum -c\".\nif command -v sha256sum >/dev/null; then C=\"sha256sum -c\"; else C=\"shasum -a 256 -c\"; fi\n$C certificates/SHA256SUMS.txt 2>&1 | grep -v \": OK$\" ; echo \"$($C certificates/SHA256SUMS.txt 2>/dev/null | grep -c \": OK$\") OK\""
   },
   "expected_output": "PowerShell prints a line \"199 OK, 0 not OK\". bash prints every line that is not OK, then \"199 OK\".",
   "does_not_show": "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",
   "runnable_by_assistant": true
  },
  {
   "id": "check-3",
   "purpose": "Check 3 route 1: the two yin-yang II orbits are linearly stable, from the saved 2x2 interval matrices, in exact fractions.",
   "inputs": [
    {
     "path": "certificates/yin-yang-II-3a/transported-reversible.json",
     "sha256": "97e962dcfd96d4cb8568d7d2c6b6e50fc56703b997e37c0b39ec469e034bfa39"
    }
   ],
   "command": {
    "powershell": "@'\n# Three bodies, check 3, route 1 (exact interval arithmetic, no differential equation).\n# Usage: python threebody_check3_yinyang_route1.py <book-folder>      (the folder that holds certificates/)\nimport sys, json, os\nfrom fractions import Fraction as F\n\ndef add(a, b): return (a[0] + b[0], a[1] + b[1])\ndef sub(a, b): return (a[0] - b[1], a[1] - b[0])\ndef mul(a, b):\n    p = [a[0] * b[0], a[0] * b[1], a[1] * b[0], a[1] * b[1]]\n    return (min(p), max(p))\n\nfor name in (\"yin-yang-II-3a\", \"yin-yang-II-3b\"):\n    f = os.path.join(sys.argv[1], \"certificates\", name, \"transported-reversible.json\")\n    d = json.load(open(f))\n    c = [[(F(x[0]), F(x[1])) for x in row] for row in d[\"cosine_matrix_exact\"]]\n    t = add(c[0][0], c[1][1])                                   # trace\n    det = sub(mul(c[0][0], c[1][1]), mul(c[0][1], c[1][0]))     # determinant\n    disc = sub(mul(t, t), (4 * det[0], 4 * det[1]))             # t^2 - 4d\n    one_minus_t_plus_d = add(sub((F(1), F(1)), t), det)\n    one_plus_t_plus_d = add(add((F(1), F(1)), t), det)\n    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)\n    ev = sorted((F(x[0]), F(x[1])) for x in d[\"result\"][\"cosine_eigenvalues_exact\"])\n    inside = all(-1 < e[0] and e[1] < 1 for e in ev) and ev[0][1] < ev[1][0]\n    mid = [float((e[0] + e[1]) / 2) for e in ev]\n    print(name, \"route 1 passes:\", ok and inside, \"| cosines about %.4f and 1 - %.3g\" % (mid[0], 1 - mid[1]))\n'@ | Set-Content -Encoding utf8 threebody_check3_yinyang_route1.py\npython threebody_check3_yinyang_route1.py .",
    "bash": "cat > threebody_check3_yinyang_route1.py <<'EOF'\n# Three bodies, check 3, route 1 (exact interval arithmetic, no differential equation).\n# Usage: python threebody_check3_yinyang_route1.py <book-folder>      (the folder that holds certificates/)\nimport sys, json, os\nfrom fractions import Fraction as F\n\ndef add(a, b): return (a[0] + b[0], a[1] + b[1])\ndef sub(a, b): return (a[0] - b[1], a[1] - b[0])\ndef mul(a, b):\n    p = [a[0] * b[0], a[0] * b[1], a[1] * b[0], a[1] * b[1]]\n    return (min(p), max(p))\n\nfor name in (\"yin-yang-II-3a\", \"yin-yang-II-3b\"):\n    f = os.path.join(sys.argv[1], \"certificates\", name, \"transported-reversible.json\")\n    d = json.load(open(f))\n    c = [[(F(x[0]), F(x[1])) for x in row] for row in d[\"cosine_matrix_exact\"]]\n    t = add(c[0][0], c[1][1])                                   # trace\n    det = sub(mul(c[0][0], c[1][1]), mul(c[0][1], c[1][0]))     # determinant\n    disc = sub(mul(t, t), (4 * det[0], 4 * det[1]))             # t^2 - 4d\n    one_minus_t_plus_d = add(sub((F(1), F(1)), t), det)\n    one_plus_t_plus_d = add(add((F(1), F(1)), t), det)\n    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)\n    ev = sorted((F(x[0]), F(x[1])) for x in d[\"result\"][\"cosine_eigenvalues_exact\"])\n    inside = all(-1 < e[0] and e[1] < 1 for e in ev) and ev[0][1] < ev[1][0]\n    mid = [float((e[0] + e[1]) / 2) for e in ev]\n    print(name, \"route 1 passes:\", ok and inside, \"| cosines about %.4f and 1 - %.3g\" % (mid[0], 1 - mid[1]))\nEOF\npython3 threebody_check3_yinyang_route1.py ."
   },
   "expected_output": "yin-yang-II-3a route 1 passes: True | cosines about -0.0322 and 1 - 2.3e-09\nyin-yang-II-3b route 1 passes: True | cosines about -0.0322 and 1 - 2.3e-09",
   "does_not_show": "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",
   "runnable_by_assistant": true,
   "script_file": "threebody_check3_yinyang_route1.py"
  },
  {
   "id": "check-4",
   "purpose": "Check 4 (the twist part): for moth I the twist determinant lies entirely below zero.",
   "inputs": [
    {
     "path": "certificates/moth-I/torsion-set-005/bounds-DIAGNOSTIC.json",
     "sha256": "c08ab8f186da30eac47a3d44cad7483d4658ed10c50364440ddfb01a37be759a"
    }
   ],
   "command": {
    "powershell": "@'\n# Three bodies, check 4, the twist: the real part of complex_determinant must lie entirely below zero.\n# Usage: python threebody_check4_moth_twist.py <book-folder>\nimport sys, json, os\nfrom fractions import Fraction as F\nfolder = os.path.join(sys.argv[1], \"certificates\", \"moth-I\")\nfor sub in sorted(os.listdir(folder)):\n    nodes = json.load(open(os.path.join(folder, sub, \"nodes.json\")))\n    if nodes.get(\"selected_nodes\") == list(range(8)) and not nodes.get(\"fallback_old_wires\"):\n        diag = json.load(open(os.path.join(folder, sub, \"bounds-DIAGNOSTIC.json\")))\n        lo, hi = [F(int(e[\"m\"])) * F(2) ** e[\"e\"] for e in diag[\"complex_determinant\"][\"re\"]]\n        print(sub, \"nodes 0 to 7, no fallback; twist in [%.8f, %.8f]; entirely below zero: %s\" % (float(lo), float(hi), hi < 0))\n'@ | Set-Content -Encoding utf8 threebody_check4_moth_twist.py\npython threebody_check4_moth_twist.py .",
    "bash": "cat > threebody_check4_moth_twist.py <<'EOF'\n# Three bodies, check 4, the twist: the real part of complex_determinant must lie entirely below zero.\n# Usage: python threebody_check4_moth_twist.py <book-folder>\nimport sys, json, os\nfrom fractions import Fraction as F\nfolder = os.path.join(sys.argv[1], \"certificates\", \"moth-I\")\nfor sub in sorted(os.listdir(folder)):\n    nodes = json.load(open(os.path.join(folder, sub, \"nodes.json\")))\n    if nodes.get(\"selected_nodes\") == list(range(8)) and not nodes.get(\"fallback_old_wires\"):\n        diag = json.load(open(os.path.join(folder, sub, \"bounds-DIAGNOSTIC.json\")))\n        lo, hi = [F(int(e[\"m\"])) * F(2) ** e[\"e\"] for e in diag[\"complex_determinant\"][\"re\"]]\n        print(sub, \"nodes 0 to 7, no fallback; twist in [%.8f, %.8f]; entirely below zero: %s\" % (float(lo), float(hi), hi < 0))\nEOF\npython3 threebody_check4_moth_twist.py ."
   },
   "expected_output": "torsion-set-005 nodes 0 to 7, no fallback; twist in [-1230.08884821, -1230.08833806]; entirely below zero: True",
   "does_not_show": "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",
   "runnable_by_assistant": true,
   "script_file": "threebody_check4_moth_twist.py"
  },
  {
   "id": "checks-2-5-6-7-8-9",
   "purpose": "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.",
   "inputs": [
    {
     "path": "certificates/existence/boxes.json",
     "sha256": "fa11352dff74d7f173706f0b8af00b289dfaa83ddcc8ac2ad8ac64d52452413e"
    }
   ],
   "command": {
    "any": "No copy-paste script yet. Write it yourself from the written recipe\u003a\nChapter headings 'Check 2' to 'Check 9'. Python's fractions module gives exact interval arithmetic."
   },
   "expected_output": "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.",
   "does_not_show": "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",
   "runnable_by_assistant": false
  },
  {
   "id": "check-10-lean",
   "purpose": "Check 10: build the one Lean file.",
   "inputs": [],
   "command": {
    "any": "No copy-paste script yet. Write it yourself from the written recipe\u003a\nIn the unpacked lean folder (https://gocheckyourself.org/data/files/three-body/downloads/three-body-lean.zip), with Lean installed through elan: lake build."
   },
   "expected_output": "Seven lines saying each theorem does not depend on any axioms, then 'Build completed successfully'.",
   "does_not_show": "Lean checks the conditional implication and exact endpoint arithmetic; no orbit result.",
   "cost": "a few seconds once Lean is installed",
   "runnable_by_assistant": false
  },
  {
   "id": "one-byte-change",
   "purpose": "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.",
   "inputs": [
    {
     "path": "certificates/moth-I/torsion-set-005/nodes.json",
     "sha256": "dafbc03cb4a6ea46451c25f8c06317c29c3769730b058c005a55a89f7ae0931d",
     "local": "certificates/moth-I/torsion-set-005/nodes.json"
    }
   ],
   "command": {
    "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)\"\n\"published : dafbc03cb4a6ea46451c25f8c06317c29c3769730b058c005a55a89f7ae0931d\"\n\"your copy : \" + (Get-FileHash -Algorithm SHA256 tampered.copy).Hash.ToLower()",
    "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)\"\necho \"published : dafbc03cb4a6ea46451c25f8c06317c29c3769730b058c005a55a89f7ae0931d\"\necho \"your copy : $( (sha256sum tampered.copy 2>/dev/null || shasum -a 256 tampered.copy) | cut -c1-64 )\""
   },
   "expected_output": "Two different 64-digit values; the 'published' value ends 7ae0931d and your copy's value is different.",
   "does_not_show": "It shows the fingerprint step would notice that change. It says nothing about the file you did not change.",
   "cost": "instant",
   "runnable_by_assistant": true
  }
 ]
}