{
  "schemaVersion": 1,
  "slug": "number-sequence-calculator",
  "category": "math",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "5a4d753fb5ba4165f83a447a3cd2cb1a70c19da45ff88a83c6b9a1495a832c35",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/number-sequence-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "arith: a_k = a₁+(k−1)d, S = k(2a₁+(k−1)d)/2; geom: a_k = a₁r^(k−1), S = a₁(r^k−1)/(r−1)",
    "vars": [
      [
        "a_k",
        "k-th term"
      ],
      [
        "S",
        "sum of first k terms"
      ],
      [
        "a₁",
        "first term"
      ],
      [
        "d",
        "common difference"
      ],
      [
        "r",
        "common ratio"
      ],
      [
        "k",
        "number of terms"
      ]
    ],
    "note": "For geometric r = 1, S = a₁×k; next term = a_k+d (arithmetic) or a_k×r (geometric); mean = S/k; non-finite results are flagged as too large."
  },
  "externalEvidence": {
    "reviewedAt": "2026-10-12",
    "sources": [
      {
        "name": "Wolfram MathWorld — Arithmetic series",
        "url": "https://mathworld.wolfram.com/ArithmeticSeries.html"
      },
      {
        "name": "Wolfram MathWorld — Finite geometric series",
        "url": "https://mathworld.wolfram.com/FiniteGeometricSeries.html"
      }
    ],
    "referenceRole": "definition",
    "implementationHash": "5a4d753fb5ba4165f83a447a3cd2cb1a70c19da45ff88a83c6b9a1495a832c35",
    "basis": "arith: a_k = a₁+(k−1)d, S = k(2a₁+(k−1)d)/2; geom: a_k = a₁r^(k−1), S = a₁(r^k−1)/(r−1)",
    "limitations": "The references explain definitions and methods; any extra preset must be checked against the assumptions on this page."
  },
  "contract": {
    "compute": "const k = Math.max(Math.floor(n), 1); let nth, sum; if(type === 'geo'){ nth = first*Math.pow(difference, k-1); sum = difference === 1 ? first*k : first*(Math.pow(difference,k)-1)/(difference-1); } else { nth = first + (k-1)*difference; sum = k*(2*first + (k-1)*difference)/2; } const next = type === 'geo' ? nth*difference : nth+difference; const mean = k ? sum/k : 0; const big = (v) => Number.isFinite(v) ? v : 'Result too large'; return { nthTerm: big(nth), sum: big(sum), nextTerm: big(next), mean: big(mean) };",
    "inputs": [
      {
        "name": "first",
        "type": "number",
        "default": 3,
        "min": -1000000000,
        "max": 1000000000,
        "step": 0.01
      },
      {
        "name": "difference",
        "type": "number",
        "default": 4,
        "min": -1000000,
        "max": 1000000,
        "step": 0.01
      },
      {
        "name": "n",
        "type": "number",
        "default": 10,
        "min": 1,
        "max": 10000,
        "step": 1
      },
      {
        "name": "type",
        "type": "select",
        "default": "arith",
        "options": [
          {
            "value": "arith"
          },
          {
            "value": "geo"
          }
        ]
      }
    ],
    "outputs": [
      {
        "name": "nthTerm",
        "precision": 4,
        "unit": ""
      },
      {
        "name": "sum",
        "precision": 4,
        "unit": ""
      },
      {
        "name": "nextTerm",
        "precision": 4,
        "unit": ""
      },
      {
        "name": "mean",
        "precision": 4,
        "unit": ""
      }
    ],
    "interpret": null
  }
}
