{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Refined Math task v1",
  "description": "A complete task for a registered runtime, with data, settings, optional bounded customer-program instructions and output presentation metadata.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "format",
    "schemaVersion",
    "adapterId",
    "payload"
  ],
  "properties": {
    "format": {
      "const": "refined.math.task"
    },
    "schemaVersion": {
      "const": 1
    },
    "adapterId": {
      "enum": [
        "math-model",
        "finite-count",
        "symbolic",
        "maxsat",
        "qap",
        "golomb",
        "functions",
        "matrix-factors",
        "semiprime",
        "integer-factorization",
        "nfs-polynomials",
        "max-cut",
        "partition",
        "set-cover",
        "coloring",
        "knapsack",
        "bin-packing",
        "subset-sum",
        "costas",
        "ramsey",
        "hadamard",
        "mixed-integer",
        "preference",
        "jssp",
        "bratu",
        "scalar-bvp",
        "adaptive-allen-cahn",
        "spectral-pde",
        "periodic-orbits",
        "customer-program",
        "customer-wasm"
      ]
    },
    "title": {
      "type": "string",
      "maxLength": 120
    },
    "id": {
      "type": "string",
      "maxLength": 256
    },
    "savedAt": {
      "type": "string"
    },
    "payload": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "model": {
          "$ref": "model.schema.json"
        },
        "input": {
          "type": "object"
        },
        "symbolic": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "operation",
            "expression",
            "variable"
          ],
          "properties": {
            "operation": {
              "enum": [
                "simplify",
                "expand",
                "differentiate",
                "solve",
                "factor",
                "integrate",
                "integrate_definite",
                "limit",
                "series"
              ]
            },
            "expression": {
              "type": "string",
              "minLength": 1,
              "maxLength": 4096
            },
            "variable": {
              "type": "string",
              "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"
            },
            "lower": {
              "type": "string",
              "minLength": 1,
              "maxLength": 4096
            },
            "upper": {
              "type": "string",
              "minLength": 1,
              "maxLength": 4096
            },
            "point": {
              "type": "string",
              "minLength": 1,
              "maxLength": 4096
            },
            "order": {
              "type": "integer",
              "minimum": 1,
              "maximum": 16
            },
            "direction": {
              "enum": [
                "both",
                "left",
                "right"
              ],
              "default": "both"
            }
          },
          "allOf": [
            {
              "if": {
                "properties": {
                  "operation": {
                    "const": "integrate_definite"
                  }
                }
              },
              "then": {
                "required": [
                  "lower",
                  "upper"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operation": {
                    "const": "limit"
                  }
                }
              },
              "then": {
                "required": [
                  "point"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operation": {
                    "const": "series"
                  }
                }
              },
              "then": {
                "required": [
                  "point",
                  "order"
                ]
              }
            },
            {
              "if": {
                "required": [
                  "lower"
                ]
              },
              "then": {
                "properties": {
                  "operation": {
                    "const": "integrate_definite"
                  }
                }
              }
            },
            {
              "if": {
                "required": [
                  "upper"
                ]
              },
              "then": {
                "properties": {
                  "operation": {
                    "const": "integrate_definite"
                  }
                }
              }
            },
            {
              "if": {
                "required": [
                  "point"
                ]
              },
              "then": {
                "properties": {
                  "operation": {
                    "enum": [
                      "limit",
                      "series"
                    ]
                  }
                }
              }
            },
            {
              "if": {
                "required": [
                  "order"
                ]
              },
              "then": {
                "properties": {
                  "operation": {
                    "const": "series"
                  }
                }
              }
            },
            {
              "if": {
                "required": [
                  "direction"
                ]
              },
              "then": {
                "properties": {
                  "operation": {
                    "const": "limit"
                  }
                }
              }
            }
          ]
        }
      },
      "oneOf": [
        {
          "required": [
            "model"
          ]
        },
        {
          "required": [
            "input"
          ]
        },
        {
          "required": [
            "symbolic"
          ]
        }
      ]
    },
    "options": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "seed": {
          "type": "integer",
          "minimum": 0,
          "maximum": 4294967295
        },
        "timeLimitMs": {
          "type": "integer",
          "minimum": 100,
          "maximum": 30000
        },
        "maxCandidateStates": {
          "type": "integer",
          "minimum": 16,
          "maximum": 100000
        },
        "maxEvaluations": {
          "type": "integer",
          "minimum": 16,
          "maximum": 1000000
        },
        "maxWorkUnits": {
          "type": "integer",
          "minimum": 1,
          "maximum": 200000000
        },
        "maxEnumeratedStates": {
          "type": "integer",
          "minimum": 1,
          "maximum": 2000000
        },
        "engine": {
          "$ref": "engine-settings.schema.json"
        }
      }
    },
    "lineage": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "definition",
        "data"
      ],
      "properties": {
        "definition": {
          "$ref": "definition.schema.json#/$defs/reference"
        },
        "data": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "id",
            "digest"
          ],
          "properties": {
            "id": {
              "type": "string",
              "pattern": "^[A-Za-z0-9][A-Za-z0-9_.-]{0,95}$"
            },
            "digest": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            },
            "title": {
              "type": "string",
              "maxLength": 120
            }
          }
        }
      }
    },
    "presentation": {
      "$ref": "outputs.schema.json"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "adapterId": {
            "enum": [
              "math-model",
              "finite-count"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "payload": {
            "required": [
              "model"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "adapterId": {
            "const": "symbolic"
          }
        }
      },
      "then": {
        "properties": {
          "payload": {
            "required": [
              "symbolic"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "adapterId": {
            "enum": [
              "maxsat",
              "qap",
              "golomb",
              "functions",
              "matrix-factors",
              "max-cut",
              "partition",
              "set-cover",
              "coloring",
              "knapsack",
              "bin-packing",
              "subset-sum",
              "costas",
              "ramsey",
              "hadamard",
              "mixed-integer",
              "preference",
              "jssp",
              "bratu",
              "scalar-bvp",
              "adaptive-allen-cahn",
              "spectral-pde",
              "periodic-orbits"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "payload": {
            "required": [
              "input"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "adapterId": {
            "enum": [
              "finite-count",
              "symbolic"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "options": {
            "not": {
              "required": [
                "engine"
              ]
            }
          }
        }
      }
    },
    {
      "$comment": "engine-capabilities-v3",
      "if": {
        "properties": {
          "adapterId": {
            "enum": [
              "math-model"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "options": {
            "properties": {
              "engine": {
                "properties": {
                  "overrides": {
                    "properties": {
                      "kickStrength": {
                        "maximum": 32
                      },
                      "guidanceWidth": {
                        "maximum": 12
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "$comment": "engine-capabilities-v3",
      "if": {
        "properties": {
          "adapterId": {
            "enum": [
              "customer-program"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "options": {
            "properties": {
              "engine": {
                "properties": {
                  "overrides": {
                    "properties": {
                      "kickStrength": {
                        "maximum": 16
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "$comment": "engine-capabilities-v3",
      "if": {
        "properties": {
          "adapterId": {
            "enum": [
              "maxsat",
              "qap",
              "golomb",
              "functions",
              "semiprime",
              "max-cut",
              "partition",
              "set-cover",
              "coloring",
              "subset-sum",
              "costas",
              "mixed-integer",
              "preference",
              "customer-wasm"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "options": {
            "properties": {
              "engine": {
                "properties": {
                  "overrides": {
                    "properties": {
                      "adaptiveAcceptanceEnabled": {
                        "const": false
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "$comment": "engine-capabilities-v3",
      "if": {
        "properties": {
          "adapterId": {
            "enum": [
              "maxsat",
              "golomb",
              "matrix-factors",
              "semiprime",
              "integer-factorization",
              "nfs-polynomials",
              "max-cut",
              "partition",
              "set-cover",
              "coloring",
              "knapsack",
              "bin-packing",
              "subset-sum",
              "ramsey",
              "hadamard",
              "bratu",
              "scalar-bvp",
              "adaptive-allen-cahn",
              "spectral-pde",
              "periodic-orbits",
              "customer-program",
              "customer-wasm"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "options": {
            "properties": {
              "engine": {
                "properties": {
                  "overrides": {
                    "properties": {
                      "acceleratorEnabled": {
                        "const": false
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "$comment": "engine-capabilities-v3",
      "if": {
        "properties": {
          "adapterId": {
            "enum": [
              "maxsat",
              "qap",
              "golomb",
              "functions",
              "matrix-factors",
              "semiprime",
              "integer-factorization",
              "nfs-polynomials",
              "max-cut",
              "partition",
              "set-cover",
              "coloring",
              "knapsack",
              "bin-packing",
              "subset-sum",
              "costas",
              "ramsey",
              "hadamard",
              "mixed-integer",
              "preference",
              "jssp",
              "bratu",
              "scalar-bvp",
              "adaptive-allen-cahn",
              "spectral-pde",
              "periodic-orbits",
              "customer-program",
              "customer-wasm"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "options": {
            "properties": {
              "engine": {
                "properties": {
                  "overrides": {
                    "properties": {
                      "acceleratorLocalSearchEnabled": {
                        "const": false
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "$comment": "engine-capabilities-v3",
      "if": {
        "properties": {
          "adapterId": {
            "enum": [
              "maxsat",
              "qap",
              "golomb",
              "functions",
              "semiprime",
              "integer-factorization",
              "nfs-polynomials",
              "max-cut",
              "partition",
              "set-cover",
              "coloring",
              "knapsack",
              "bin-packing",
              "subset-sum",
              "costas",
              "ramsey",
              "hadamard",
              "mixed-integer",
              "preference",
              "bratu",
              "scalar-bvp",
              "adaptive-allen-cahn",
              "spectral-pde",
              "periodic-orbits",
              "customer-program"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "options": {
            "properties": {
              "engine": {
                "properties": {
                  "overrides": {
                    "properties": {
                      "exactRepairEnabled": {
                        "const": false
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "$comment": "engine-capabilities-v3",
      "if": {
        "properties": {
          "adapterId": {
            "enum": [
              "maxsat",
              "golomb",
              "semiprime",
              "max-cut",
              "partition",
              "set-cover",
              "coloring",
              "knapsack",
              "bin-packing",
              "subset-sum",
              "costas",
              "ramsey",
              "hadamard",
              "preference",
              "customer-program"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "options": {
            "properties": {
              "engine": {
                "properties": {
                  "overrides": {
                    "properties": {
                      "recombinationCandidateLimit": {
                        "const": 0
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  ]
}
