{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.calculatorx.com/schemas/math.special.output.json",
  "title": "Special functions — success output",
  "type": "object",
  "additionalProperties": false,
  "$defs": {
    "resultBranch0Result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "x",
        "value",
        "formula",
        "erf",
        "erfc"
      ],
      "properties": {
        "mode": {
          "const": "erf"
        },
        "x": {
          "type": "number"
        },
        "value": {
          "type": "number"
        },
        "formula": {
          "type": "string"
        },
        "erf": {
          "type": "number"
        },
        "erfc": {
          "type": "number"
        }
      }
    },
    "resultBranch1Result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "x",
        "value",
        "formula",
        "erf",
        "erfc"
      ],
      "properties": {
        "mode": {
          "const": "erfc"
        },
        "x": {
          "type": "number"
        },
        "value": {
          "type": "number"
        },
        "formula": {
          "type": "string"
        },
        "erf": {
          "type": "number"
        },
        "erfc": {
          "type": "number"
        }
      }
    },
    "resultBranch2Result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "x",
        "value",
        "formula",
        "gamma"
      ],
      "properties": {
        "mode": {
          "const": "gamma"
        },
        "x": {
          "type": "number"
        },
        "value": {
          "type": "number"
        },
        "formula": {
          "type": "string"
        },
        "gamma": {
          "type": "number"
        }
      }
    },
    "resultBranch3Result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "x",
        "value",
        "formula",
        "lgamma"
      ],
      "properties": {
        "mode": {
          "const": "lgamma"
        },
        "x": {
          "type": "number"
        },
        "value": {
          "type": "number"
        },
        "formula": {
          "type": "string"
        },
        "lgamma": {
          "type": "number"
        }
      }
    },
    "resultBranch4Result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "x",
        "value",
        "formula",
        "n",
        "algorithm"
      ],
      "properties": {
        "mode": {
          "const": "bessel_j"
        },
        "x": {
          "type": "number"
        },
        "value": {
          "type": "number"
        },
        "formula": {
          "type": "string"
        },
        "n": {
          "type": "integer",
          "minimum": 0,
          "maximum": 8
        },
        "algorithm": {
          "type": "string"
        }
      }
    },
    "resultBranch5Result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "x",
        "value",
        "formula",
        "n",
        "algorithm"
      ],
      "properties": {
        "mode": {
          "const": "bessel_y"
        },
        "x": {
          "type": "number"
        },
        "value": {
          "type": "number"
        },
        "formula": {
          "type": "string"
        },
        "n": {
          "type": "integer",
          "minimum": 0,
          "maximum": 8
        },
        "algorithm": {
          "type": "string"
        }
      }
    },
    "resultBranch6Result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "x",
        "value",
        "formula",
        "n",
        "algorithm"
      ],
      "properties": {
        "mode": {
          "const": "bessel_i"
        },
        "x": {
          "type": "number"
        },
        "value": {
          "type": "number"
        },
        "formula": {
          "type": "string"
        },
        "n": {
          "type": "integer",
          "minimum": 0,
          "maximum": 8
        },
        "algorithm": {
          "type": "string"
        }
      }
    },
    "resultBranch7Result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "x",
        "value",
        "formula",
        "n",
        "algorithm"
      ],
      "properties": {
        "mode": {
          "const": "bessel_k"
        },
        "x": {
          "type": "number"
        },
        "value": {
          "type": "number"
        },
        "formula": {
          "type": "string"
        },
        "n": {
          "type": "integer",
          "minimum": 0,
          "maximum": 8
        },
        "algorithm": {
          "type": "string"
        }
      }
    },
    "resultBranch8Result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "x",
        "value",
        "formula",
        "branch",
        "algorithm"
      ],
      "properties": {
        "mode": {
          "const": "lambert_w"
        },
        "x": {
          "type": "number"
        },
        "value": {
          "type": "number"
        },
        "formula": {
          "type": "string"
        },
        "branch": {
          "const": 0
        },
        "algorithm": {
          "type": "string"
        }
      }
    },
    "resultBranch9Result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "x",
        "value",
        "formula",
        "branch",
        "algorithm"
      ],
      "properties": {
        "mode": {
          "const": "lambert_wm1"
        },
        "x": {
          "type": "number"
        },
        "value": {
          "type": "number"
        },
        "formula": {
          "type": "string"
        },
        "branch": {
          "const": -1
        },
        "algorithm": {
          "type": "string"
        }
      }
    },
    "resultBranch10Result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "x",
        "value",
        "formula",
        "y",
        "algorithm"
      ],
      "properties": {
        "mode": {
          "const": "beta"
        },
        "x": {
          "type": "number"
        },
        "value": {
          "type": "number"
        },
        "formula": {
          "type": "string"
        },
        "y": {
          "type": "number"
        },
        "algorithm": {
          "type": "string"
        }
      }
    },
    "resultBranch11Result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "x",
        "value",
        "formula",
        "a",
        "b",
        "regularized",
        "algorithm"
      ],
      "properties": {
        "mode": {
          "const": "incomplete_beta"
        },
        "x": {
          "type": "number"
        },
        "value": {
          "type": "number"
        },
        "formula": {
          "type": "string"
        },
        "a": {
          "type": "number"
        },
        "b": {
          "type": "number"
        },
        "regularized": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "algorithm": {
          "type": "string"
        }
      }
    },
    "resultBranch12Result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "x",
        "value",
        "formula",
        "algorithm"
      ],
      "properties": {
        "mode": {
          "const": "sinc"
        },
        "x": {
          "type": "number"
        },
        "value": {
          "type": "number"
        },
        "formula": {
          "type": "string"
        },
        "algorithm": {
          "type": "string"
        }
      }
    },
    "resultBranch13Result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "x",
        "value",
        "formula",
        "algorithm"
      ],
      "properties": {
        "mode": {
          "const": "normalized_sinc"
        },
        "x": {
          "type": "number"
        },
        "value": {
          "type": "number"
        },
        "formula": {
          "type": "string"
        },
        "algorithm": {
          "type": "string"
        }
      }
    },
    "calcResult": {
      "oneOf": [
        {
          "$ref": "#/$defs/resultBranch0Result"
        },
        {
          "$ref": "#/$defs/resultBranch1Result"
        },
        {
          "$ref": "#/$defs/resultBranch2Result"
        },
        {
          "$ref": "#/$defs/resultBranch3Result"
        },
        {
          "$ref": "#/$defs/resultBranch4Result"
        },
        {
          "$ref": "#/$defs/resultBranch5Result"
        },
        {
          "$ref": "#/$defs/resultBranch6Result"
        },
        {
          "$ref": "#/$defs/resultBranch7Result"
        },
        {
          "$ref": "#/$defs/resultBranch8Result"
        },
        {
          "$ref": "#/$defs/resultBranch9Result"
        },
        {
          "$ref": "#/$defs/resultBranch10Result"
        },
        {
          "$ref": "#/$defs/resultBranch11Result"
        },
        {
          "$ref": "#/$defs/resultBranch12Result"
        },
        {
          "$ref": "#/$defs/resultBranch13Result"
        }
      ]
    }
  },
  "required": [
    "status",
    "capability_id",
    "engine",
    "inputs",
    "result",
    "result_detail",
    "calculation_version",
    "verification"
  ],
  "properties": {
    "id": {
      "type": "string",
      "description": "Requested tool id"
    },
    "status": {
      "const": "success"
    },
    "capability_id": {
      "const": "math.special"
    },
    "tool": {
      "type": "string",
      "description": "Requested tool id"
    },
    "engine": {
      "type": "string"
    },
    "inputs": {
      "type": "object",
      "description": "Normalized calculation inputs (aliases resolved)"
    },
    "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,
      "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"
          ]
        },
        "citation_kind": {
          "type": "string"
        },
        "expert_review": {
          "type": "string"
        },
        "domain_review": {
          "type": "string"
        },
        "calculation_version": {
          "type": "string"
        },
        "calc_tests": {
          "type": [
            "string",
            "null"
          ]
        },
        "tests_passed": {
          "type": [
            "integer",
            "null"
          ]
        },
        "tests_total": {
          "type": [
            "integer",
            "null"
          ]
        },
        "artifact_contract": {
          "type": [
            "string",
            "null"
          ]
        },
        "trust_peek": {
          "type": [
            "string",
            "null"
          ]
        },
        "verification_revision": {
          "type": "string"
        },
        "verified_scope": {
          "type": "string"
        },
        "evidence_digest": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      },
      "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.10.6"
    },
    "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"
        }
      }
    }
  }
}
