{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.calculatorx.com/schemas/engineering.tolerance.monte_carlo.input.json",
  "title": "1-D Tolerance Analysis Workspace — input",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "tolerances": {
      "type": "array",
      "minItems": 1,
      "description": "Canonical stack components. y = Σ c·(nominal + ε).",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [],
        "properties": {
          "name": {
            "type": "string"
          },
          "nominal": {
            "type": "number",
            "description": "Nominal dimension (default 0 = error-only stack)."
          },
          "nom": {
            "type": "number",
            "description": "Alias of nominal."
          },
          "half_tolerance": {
            "type": "number",
            "description": "± tolerance magnitude (half-width)."
          },
          "tolerance": {
            "type": "number",
            "description": "Alias of half_tolerance."
          },
          "tol": {
            "type": "number",
            "description": "Legacy alias of half_tolerance."
          },
          "coefficient": {
            "type": "number",
            "description": "Stack sense / sensitivity (default +1). Use -1 to subtract."
          },
          "sense": {
            "description": "Alias of coefficient: +/− or ±1",
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              }
            ]
          },
          "direction": {
            "description": "Alias of coefficient",
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              }
            ]
          },
          "distribution": {
            "type": "string",
            "enum": [
              "normal",
              "uniform",
              "triangular"
            ],
            "description": "Error distribution (default normal). k_sigma applies to normal only."
          },
          "mean_shift": {
            "type": "number",
            "description": "Process mean shift from nominal (default 0)."
          },
          "shift": {
            "type": "number",
            "description": "Alias of mean_shift."
          },
          "process_shift": {
            "type": "number",
            "description": "Alias of mean_shift."
          },
          "tol_plus": {
            "type": "number",
            "minimum": 0,
            "description": "Upper half-tolerance (+). Use with tol_minus for asymmetric."
          },
          "tol_minus": {
            "type": "number",
            "minimum": 0,
            "description": "Lower half-tolerance (−)."
          }
        },
        "anyOf": [
          {
            "required": [
              "half_tolerance"
            ]
          },
          {
            "required": [
              "tol_plus"
            ]
          },
          {
            "required": [
              "tol_minus"
            ]
          },
          {
            "required": [
              "tolerance"
            ]
          },
          {
            "required": [
              "tol"
            ]
          }
        ],
        "description": "REST accepts aliases. Prefer half_tolerance or both tol_plus+tol_minus."
      }
    },
    "tol": {
      "type": "array",
      "items": {
        "type": "number"
      },
      "description": "Legacy half-tolerance list (nominal=0, coefficient=+1)."
    },
    "tol1": {
      "type": "number",
      "description": "Web/legacy first ± half-tolerance."
    },
    "tol2": {
      "type": "number"
    },
    "tol3": {
      "type": "number"
    },
    "tol4": {
      "type": "number"
    },
    "tol5": {
      "type": "number"
    },
    "tol6": {
      "type": "number"
    },
    "tol7": {
      "type": "number"
    },
    "tol8": {
      "type": "number"
    },
    "N": {
      "type": "integer",
      "minimum": 100,
      "maximum": 100000,
      "description": "Monte Carlo iterations (default 5000)."
    },
    "seed": {
      "type": "integer",
      "minimum": 0,
      "description": "PRNG seed (mulberry32)."
    },
    "k_sigma": {
      "type": "number",
      "exclusiveMinimum": 0,
      "description": "For normal: half_tolerance = k_sigma · σ (default 3)."
    },
    "LSL": {
      "type": "number",
      "description": "Lower specification limit (optional)."
    },
    "USL": {
      "type": "number",
      "description": "Upper specification limit (optional)."
    },
    "lsl": {
      "type": "number",
      "description": "Alias of LSL."
    },
    "usl": {
      "type": "number",
      "description": "Alias of USL."
    },
    "unit": {
      "type": "string",
      "description": "Optional display unit (mm, in, …)."
    },
    "correlations": {
      "type": "array",
      "description": "Optional pairwise correlations: [{a,b,rho}] or legacy [{i,j,rho}]. Agent schema accepts name pairs only.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "a": {
            "description": "First component name or index",
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "integer"
              }
            ]
          },
          "b": {
            "description": "Second component name or index",
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "integer"
              }
            ]
          },
          "i": {
            "description": "Alias of a (0-based index or name)",
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "integer"
              }
            ]
          },
          "j": {
            "description": "Alias of b",
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "integer"
              }
            ]
          },
          "rho": {
            "type": "number",
            "minimum": -1,
            "maximum": 1
          }
        },
        "oneOf": [
          {
            "required": [
              "a",
              "b",
              "rho"
            ]
          },
          {
            "required": [
              "i",
              "j",
              "rho"
            ]
          }
        ]
      }
    },
    "sensitivity_method": {
      "type": "string",
      "enum": [
        "spearman",
        "pearson",
        "sobol",
        "shapley"
      ],
      "description": "Sensitivity method (default spearman). sobol = exact first-order for independent linear stacks; shapley = variance attribution (supports correlation)."
    },
    "sobol_N": {
      "type": "integer",
      "minimum": 128,
      "maximum": 4096,
      "description": "Optional Saltelli MC cross-check size when sensitivity_method=sobol."
    },
    "shapley_N": {
      "type": "integer",
      "minimum": 200,
      "maximum": 20000,
      "description": "Optional permutation count when sensitivity_method=shapley and d>12 (exact for d≤12)."
    }
  },
  "anyOf": [
    {
      "required": [
        "tolerances"
      ]
    },
    {
      "required": [
        "tol"
      ]
    },
    {
      "required": [
        "tol1"
      ]
    }
  ],
  "description": "1-D Tolerance Analysis Workspace — dimensional Monte Carlo with asymmetric ±tol, correlations (normal or NORTA), Spearman/Pearson/Sobol/Shapley sensitivity, σ convergence, LSL/USL yield, simulated capability, fingerprint, and snapshots. (calculation_version 1.12.0)"
}
