{
  "openapi": "3.1.1",
  "info": {
    "title": "N-Body \u0026 Three-Body Orbit Simulator API",
    "version": "1.0.0",
    "summary": "Three-body periodic orbits and your own planar n-body systems, with an energy-drift report.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://prooflinenbody.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Three-body periodic orbits and your own planar n-body systems, with an energy-drift report.",
        "description": "Simulate point masses under Newtonian gravity in a plane: published three-body periodic orbits (figure-eight, butterflies, moths, yin-yang and more from Šuvakov \u0026 Dmitrašinović 2013 and the 10-digit refinements of Li \u0026 Liao 2017), Lagrange’s triangle, the chaotic Pythagorean problem, or up to 12 bodies of your own. Choose an adaptive Dormand–Prince RK45 or a symplectic Verlet or Yoshida integrator and get the orbit plot, the energy, momentum and angular-momentum drift, the closest approach and how far a periodic orbit is from its start after each full period. Part of the Proofline math notebook.\n\nMethodology:\n- Each body feels a = Σ G·mⱼ·(rⱼ − rᵢ)/(|rⱼ − rᵢ|² + ε²)^{3/2} from all others (pairwise, O(n²)); positions and velocities form one state vector.\n- RK45 is the numerical engine’s Dormand–Prince 5(4) with adaptive steps (relative tolerance as set, absolute tolerance 100× smaller). Velocity Verlet (kick–drift–kick) and Yoshida’s fourth-order composition of three Verlet steps (weights 1/(2 − 2^{1/3}) and −2^{1/3}/(2 − 2^{1/3})) are symplectic: their energy error stays bounded instead of drifting, as long as the step resolves the closest approaches.\n- Conservation checks: total energy E = Σ ½mv² − Σ G·mᵢmⱼ/r, momentum and angular momentum are compared with their initial values at every output point. For periodic presets the step is aligned with the period and the phase-space distance |state(k·T) − state(0)| is reported for each whole period.\n- Verified: the Chenciner–Montgomery figure-eight returns to within 1e-7 after one period; the 10-digit Li–Liao orbits close to about 1e-8; the 5-digit Šuvakov–Dmitrašinović values close to about 1e-3, as their precision allows; Lagrange’s triangle rotates rigidly; and in the Pythagorean problem the lightest body (m = 3) escapes while the other two form a binary, as Szebehely and Peters found.\n\nA teaching and exploration tool: planar point masses only (no collisions, no relativity, no tides). Chaotic systems amplify every rounding error, so long runs show one possible future, not the future.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "proofline_nbody",
        "x-owner-app": "proofline",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProoflineNbodyInput"
              },
              "examples": {
                "example1": {
                  "summary": "Figure-eight choreography, one period",
                  "value": {
                    "preset": "figure-eight"
                  }
                },
                "example2": {
                  "summary": "Butterfly family, 10-digit initial conditions (closes to 1e-9)",
                  "value": {
                    "preset": "butterfly-refined"
                  }
                },
                "example3": {
                  "summary": "Moth I with the Yoshida symplectic integrator",
                  "value": {
                    "preset": "moth-1",
                    "method": "yoshida4",
                    "step": 0.0002
                  }
                },
                "example4": {
                  "summary": "Pythagorean problem: chaos, then an escape",
                  "value": {
                    "preset": "pythagorean",
                    "duration": 70
                  }
                },
                "example5": {
                  "summary": "Your own system: a star with two planets",
                  "value": {
                    "preset": "custom",
                    "bodies": "Star 1 0 0 0 0\nInner 0.001 1 0 0 1\nOuter 0.0005 2.5 0 0 0.632455532",
                    "duration": 50
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProoflineNbodyResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "ProoflineNbodyInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "preset": {
            "title": "Initial conditions",
            "type": "string",
            "enum": [
              "custom",
              "figure-eight",
              "butterfly-1",
              "butterfly-2",
              "bumblebee",
              "moth-1",
              "moth-2",
              "butterfly-3",
              "moth-3",
              "goggles",
              "butterfly-4",
              "dragonfly",
              "yarn",
              "yin-yang-1a",
              "yin-yang-1b",
              "yin-yang-2a",
              "yin-yang-2b",
              "figure-eight-refined",
              "butterfly-refined",
              "moth-refined",
              "goggles-refined",
              "dragonfly-refined",
              "yin-yang-refined",
              "lagrange",
              "pythagorean"
            ],
            "default": "figure-eight"
          },
          "bodies": {
            "title": "Bodies (custom: one per line)",
            "description": "One body per line: an optional name, then mass, x, y, vx and vy (G = 1 units unless you change G). At most 12 bodies. Used when “My own bodies” is selected.",
            "type": "string",
            "maxLength": 4000,
            "default": ""
          },
          "duration": {
            "title": "Duration (time units)",
            "description": "Empty: one period for the periodic presets, 70 for the Pythagorean problem, 10 for your own bodies.",
            "type": "number",
            "minimum": 0
          },
          "method": {
            "title": "Integrator",
            "type": "string",
            "enum": [
              "rk45",
              "yoshida4",
              "verlet"
            ],
            "default": "rk45"
          },
          "tolerance": {
            "title": "Tolerance (RK45)",
            "description": "Relative error per step of the adaptive method.",
            "type": "number",
            "minimum": 1e-14,
            "maximum": 0.001,
            "default": 1e-11
          },
          "step": {
            "title": "Step size (fixed-step methods)",
            "description": "Empty: the period (or the duration) divided by 20,000.",
            "type": "number",
            "minimum": 0
          },
          "G": {
            "title": "Gravitational constant G",
            "type": "number",
            "minimum": 0,
            "default": 1
          },
          "softening": {
            "title": "Softening length",
            "description": "Plummer softening ε: the force uses r² + ε², which tames close encounters but changes the physics slightly.",
            "type": "number",
            "minimum": 0,
            "default": 0
          },
          "outputPoints": {
            "title": "Output points",
            "type": "integer",
            "minimum": 11,
            "maximum": 4001,
            "default": 801
          }
        },
        "required": []
      },
      "ProoflineNbodyResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "preset",
              "presetName",
              "source",
              "bodies",
              "G",
              "softening",
              "method",
              "duration",
              "step",
              "steps",
              "forceEvaluations",
              "rejectedSteps",
              "completed",
              "energy0",
              "energyDriftMax",
              "energyDriftFinal",
              "momentumDrift",
              "angularMomentum0",
              "angularMomentumDrift",
              "closestApproach",
              "period",
              "returnDistances",
              "final",
              "samples"
            ],
            "properties": {
              "preset": {
                "type": "string"
              },
              "presetName": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "source": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "bodies": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "name",
                    "m",
                    "x",
                    "y",
                    "vx",
                    "vy"
                  ],
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "m": {
                      "type": "number"
                    },
                    "x": {
                      "type": "number"
                    },
                    "y": {
                      "type": "number"
                    },
                    "vx": {
                      "type": "number"
                    },
                    "vy": {
                      "type": "number"
                    }
                  }
                }
              },
              "G": {
                "type": "number"
              },
              "softening": {
                "type": "number"
              },
              "method": {
                "type": "string",
                "enum": [
                  "yoshida4",
                  "verlet",
                  "rk45"
                ]
              },
              "duration": {
                "type": "number"
              },
              "step": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "steps": {
                "type": "integer"
              },
              "forceEvaluations": {
                "type": "integer"
              },
              "rejectedSteps": {
                "type": "integer"
              },
              "completed": {
                "type": "boolean"
              },
              "energy0": {
                "type": "number"
              },
              "energyDriftMax": {
                "type": "number"
              },
              "energyDriftFinal": {
                "type": "number"
              },
              "momentumDrift": {
                "type": "number"
              },
              "angularMomentum0": {
                "type": "number"
              },
              "angularMomentumDrift": {
                "type": "number"
              },
              "closestApproach": {
                "type": "number"
              },
              "period": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "returnDistances": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "periods",
                    "time",
                    "distance"
                  ],
                  "properties": {
                    "periods": {
                      "type": "integer"
                    },
                    "time": {
                      "type": "number"
                    },
                    "distance": {
                      "type": "number"
                    }
                  }
                }
              },
              "final": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "name",
                    "x",
                    "y",
                    "vx",
                    "vy"
                  ],
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "x": {
                      "type": "number"
                    },
                    "y": {
                      "type": "number"
                    },
                    "vx": {
                      "type": "number"
                    },
                    "vy": {
                      "type": "number"
                    }
                  }
                }
              },
              "samples": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "t",
                  "xy",
                  "energyError"
                ],
                "properties": {
                  "t": {
                    "type": "array",
                    "items": {
                      "type": "number"
                    }
                  },
                  "xy": {
                    "type": "array",
                    "items": {
                      "type": "array",
                      "items": {
                        "type": [
                          "number",
                          "null"
                        ]
                      }
                    }
                  },
                  "energyError": {
                    "type": "array",
                    "items": {
                      "type": "number"
                    }
                  }
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}