{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.calculatorx.com/schemas/math.sequences/1.0.3/output.json",
  "title": "Integer sequences — success output",
  "type": "object",
  "additionalProperties": false,
  "$defs": {
    "resultBranch0Result": {
      "type": "object",
      "properties": {
        "mode": {
          "const": "arithmetic"
        },
        "n": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000
        },
        "a": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "d": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "term": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "value": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "sum": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "exact": {
          "type": "string",
          "pattern": "^-?\\d+$"
        },
        "formula": {
          "const": "a_n = a + (n−1)d,  S_n = n/2 · (2a + (n−1)d)"
        },
        "algorithm": {
          "const": "closed_form"
        },
        "max_n": {
          "const": 1000
        },
        "numeric_domain": {
          "const": "integer"
        },
        "exactness": {
          "const": "exact"
        },
        "numeric_backend": {
          "const": "bigint"
        }
      },
      "required": [
        "mode",
        "n",
        "a",
        "d",
        "term",
        "value",
        "sum",
        "exact",
        "formula",
        "algorithm",
        "max_n",
        "numeric_domain",
        "exactness",
        "numeric_backend"
      ],
      "additionalProperties": false
    },
    "resultBranch1Result": {
      "type": "object",
      "properties": {
        "mode": {
          "const": "geometric"
        },
        "n": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000
        },
        "a": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "r": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "term": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "value": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "sum": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "exact": {
          "type": "string",
          "pattern": "^-?\\d+$"
        },
        "formula": {
          "const": "a_n = a r^{n−1},  S_n = a(r^n − 1)/(r − 1)"
        },
        "algorithm": {
          "const": "closed_form"
        },
        "max_n": {
          "const": 1000
        },
        "numeric_domain": {
          "const": "integer"
        },
        "exactness": {
          "const": "exact"
        },
        "numeric_backend": {
          "const": "bigint"
        }
      },
      "required": [
        "mode",
        "n",
        "a",
        "r",
        "term",
        "value",
        "sum",
        "exact",
        "formula",
        "algorithm",
        "max_n",
        "numeric_domain",
        "exactness",
        "numeric_backend"
      ],
      "additionalProperties": false
    },
    "resultBranch2Result": {
      "type": "object",
      "properties": {
        "mode": {
          "const": "fibonacci"
        },
        "n": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000
        },
        "term": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "value": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "sum": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "exact": {
          "type": "string",
          "pattern": "^-?\\d+$"
        },
        "prev": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "convention": {
          "const": "F_0=0, F_1=1"
        },
        "formula": {
          "const": "F_n = F_{n-1} + F_{n-2}"
        },
        "algorithm": {
          "const": "iterative_recurrence"
        },
        "max_n": {
          "const": 1000
        },
        "numeric_domain": {
          "const": "integer"
        },
        "exactness": {
          "const": "exact"
        },
        "numeric_backend": {
          "const": "bigint"
        }
      },
      "required": [
        "mode",
        "n",
        "term",
        "value",
        "sum",
        "exact",
        "prev",
        "convention",
        "formula",
        "algorithm",
        "max_n",
        "numeric_domain",
        "exactness",
        "numeric_backend"
      ],
      "additionalProperties": false
    },
    "resultBranch3Result": {
      "type": "object",
      "properties": {
        "mode": {
          "const": "linear_recurrence"
        },
        "n": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000
        },
        "p": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "q": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "a0": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "a1": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "term": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "value": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "string",
              "pattern": "^-?\\d+$"
            }
          ]
        },
        "exact": {
          "type": "string",
          "pattern": "^-?\\d+$"
        },
        "formula": {
          "const": "u_n = p·u_{n-1} + q·u_{n-2}"
        },
        "algorithm": {
          "const": "iterative_recurrence"
        },
        "max_n": {
          "const": 1000
        },
        "numeric_domain": {
          "const": "integer"
        },
        "exactness": {
          "const": "exact"
        },
        "numeric_backend": {
          "const": "bigint"
        }
      },
      "required": [
        "mode",
        "n",
        "p",
        "q",
        "a0",
        "a1",
        "term",
        "value",
        "exact",
        "formula",
        "algorithm",
        "max_n",
        "numeric_domain",
        "exactness",
        "numeric_backend"
      ],
      "additionalProperties": false
    },
    "calcResult": {
      "oneOf": [
        {
          "$ref": "#/$defs/resultBranch0Result"
        },
        {
          "$ref": "#/$defs/resultBranch1Result"
        },
        {
          "$ref": "#/$defs/resultBranch2Result"
        },
        {
          "$ref": "#/$defs/resultBranch3Result"
        }
      ]
    }
  },
  "required": [
    "status",
    "capability_id",
    "engine",
    "inputs",
    "result",
    "result_detail",
    "calculation_version",
    "verification",
    "review"
  ],
  "properties": {
    "id": {
      "type": "string",
      "description": "Requested tool id"
    },
    "status": {
      "const": "success"
    },
    "capability_id": {
      "const": "math.sequences"
    },
    "tool": {
      "type": "string",
      "description": "Requested tool id"
    },
    "engine": {
      "type": "string"
    },
    "inputs": {
      "description": "Normalized calculation inputs (aliases resolved to canonical form)",
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "mode": {
              "const": "arithmetic"
            },
            "n": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            },
            "a": {
              "type": "string",
              "pattern": "^-?\\d+$",
              "maxLength": 49
            },
            "d": {
              "type": "string",
              "pattern": "^-?\\d+$",
              "maxLength": 49
            }
          },
          "required": [
            "mode",
            "n",
            "a",
            "d"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "mode": {
              "const": "geometric"
            },
            "n": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            },
            "a": {
              "type": "string",
              "pattern": "^-?\\d+$",
              "maxLength": 49
            },
            "r": {
              "type": "string",
              "pattern": "^-?\\d+$",
              "maxLength": 49
            }
          },
          "required": [
            "mode",
            "n",
            "a",
            "r"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "mode": {
              "const": "fibonacci"
            },
            "n": {
              "type": "integer",
              "minimum": 0,
              "maximum": 1000
            }
          },
          "required": [
            "mode",
            "n"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "mode": {
              "const": "linear_recurrence"
            },
            "n": {
              "type": "integer",
              "minimum": 0,
              "maximum": 1000
            },
            "p": {
              "type": "string",
              "pattern": "^-?\\d+$",
              "maxLength": 49
            },
            "q": {
              "type": "string",
              "pattern": "^-?\\d+$",
              "maxLength": 49
            },
            "a0": {
              "type": "string",
              "pattern": "^-?\\d+$",
              "maxLength": 49
            },
            "a1": {
              "type": "string",
              "pattern": "^-?\\d+$",
              "maxLength": 49
            }
          },
          "required": [
            "mode",
            "n",
            "p",
            "q",
            "a0",
            "a1"
          ],
          "additionalProperties": false
        }
      ]
    },
    "result": {
      "$ref": "#/$defs/calcResult"
    },
    "result_detail": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "value",
        "unit",
        "formatted"
      ],
      "properties": {
        "value": {
          "$ref": "#/$defs/calcResult"
        },
        "unit": {
          "type": [
            "string",
            "null"
          ]
        },
        "formatted": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "formula": {
      "anyOf": [
        {
          "type": "null"
        },
        {
          "type": "string"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string"
            },
            "expression": {
              "type": "string"
            },
            "label": {
              "type": "string"
            }
          }
        }
      ]
    },
    "assumptions": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "warnings": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "code"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "severity": {
            "type": "string"
          },
          "detail": {
            "type": "string"
          },
          "suggestion": {
            "type": "string"
          }
        }
      }
    },
    "verification": {
      "type": "object",
      "additionalProperties": false,
      "description": "Computational verification under CVP. Review-policy tiers live on `review`, not here.",
      "required": [
        "cvp"
      ],
      "properties": {
        "cvp": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "status",
            "protocol",
            "profile",
            "verified_scope",
            "verification_revision",
            "evidence_digest"
          ],
          "properties": {
            "status": {
              "type": "string",
              "description": "CVP verification status (e.g. VERIFIED)"
            },
            "protocol": {
              "type": "string",
              "description": "CVP protocol id, e.g. 1.0.0-proposed"
            },
            "profile": {
              "type": "string"
            },
            "verified_scope": {
              "type": "string"
            },
            "verification_revision": {
              "type": [
                "string",
                "null"
              ]
            },
            "evidence_digest": {
              "type": [
                "string",
                "null"
              ]
            },
            "production": {
              "type": [
                "string",
                "null"
              ],
              "description": "Production freshness, e.g. CURRENT"
            },
            "evidence": {
              "type": "string",
              "format": "uri"
            }
          }
        }
      }
    },
    "review": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tier",
        "engine_tested",
        "expert_reviewed",
        "source_checked",
        "reviewed_by",
        "reviewer_role",
        "last_reviewed"
      ],
      "properties": {
        "tier": {
          "type": "string",
          "enum": [
            "candidate",
            "engine_tested",
            "internally_reviewed",
            "expert_verified"
          ]
        },
        "engine_tested": {
          "type": "boolean"
        },
        "expert_reviewed": {
          "type": "boolean"
        },
        "internally_reviewed": {
          "type": "boolean"
        },
        "review_kind": {
          "type": [
            "string",
            "null"
          ]
        },
        "source_checked": {
          "type": "boolean"
        },
        "reviewed_by": {
          "type": [
            "string",
            "null"
          ]
        },
        "reviewer_role": {
          "type": [
            "string",
            "null"
          ]
        },
        "last_reviewed": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "tier": {
                "const": "expert_verified"
              }
            },
            "required": [
              "tier"
            ]
          },
          "then": {
            "properties": {
              "engine_tested": {
                "const": true
              },
              "expert_reviewed": {
                "const": true
              },
              "source_checked": {
                "const": true
              },
              "reviewed_by": {
                "type": "string",
                "minLength": 1
              },
              "reviewer_role": {
                "type": "string",
                "minLength": 1
              },
              "last_reviewed": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "tier": {
                "const": "internally_reviewed"
              }
            },
            "required": [
              "tier"
            ]
          },
          "then": {
            "properties": {
              "engine_tested": {
                "const": true
              },
              "internally_reviewed": {
                "const": true
              },
              "source_checked": {
                "const": true
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "tier": {
                "const": "engine_tested"
              }
            },
            "required": [
              "tier"
            ]
          },
          "then": {
            "properties": {
              "engine_tested": {
                "const": true
              }
            }
          }
        }
      ]
    },
    "calculation_version": {
      "type": "string",
      "const": "1.0.3"
    },
    "api_version": {
      "type": "string"
    },
    "api_contract_version": {
      "type": "string"
    },
    "spec_version": {
      "type": "string"
    },
    "page": {
      "type": [
        "string",
        "null"
      ],
      "description": "Canonical calculator page URL"
    },
    "links": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schema_input": {
          "type": "string",
          "format": "uri"
        },
        "schema_output": {
          "type": "string",
          "format": "uri"
        },
        "evidence": {
          "type": "string",
          "format": "uri"
        },
        "openapi": {
          "type": "string",
          "format": "uri"
        },
        "capabilities": {
          "type": "string",
          "format": "uri"
        },
        "mcp": {
          "type": "string",
          "format": "uri"
        }
      }
    }
  }
}
