{
  "schemaVersion": 1,
  "slug": "mean-calculator",
  "category": "math",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "aa1324e73cd17af727d142457e36cc557a0aa8ac50bd8e267661bb40b8ad1cec",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/mean-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": "x̄ = Σx ÷ n; G = e^(Σ ln(x) ÷ n); H = n ÷ Σ(1 ÷ x)",
    "vars": [
      [
        "x̄",
        "arithmetic mean"
      ],
      [
        "G",
        "geometric mean"
      ],
      [
        "H",
        "harmonic mean"
      ],
      [
        "x",
        "entered values"
      ],
      [
        "n",
        "value count"
      ]
    ],
    "note": "Parses up to 10,000 finite values separated by commas, semicolons or whitespace; empty items are rejected. Geometric mean is undefined for nonpositive values; harmonic mean is undefined when reciprocal sum is zero or undefined."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const parseList=s=>{const t=String(s).trim(),num='[+-]?(?:\\\\d+(?:\\\\.\\\\d*)?|\\\\.\\\\d+)(?:[eE][+-]?\\\\d+)?',sep='(?:\\\\s*[,;]\\\\s*|\\\\s+)';if(!t||t.length>20000||!new RegExp('^\\\\s*'+num+'(?:'+sep+num+')*\\\\s*$').test(t))return null;const a=t.match(new RegExp(num,'g')).map(Number);return a.length<=10000&&a.every(Number.isFinite)?a:null;};const xs=parseList(values);if(!xs)return{mean:null,geometricMean:null,harmonicMean:null,sum:null,count:0,__error:'inputError'};const sum=xs.reduce((a,b)=>a+b,0);if(!Number.isFinite(sum))return{mean:null,geometricMean:null,harmonicMean:null,sum:null,count:0,__error:'inputError'};const mean=sum/xs.length,gm=xs.every(n=>n>0)?Math.exp(xs.reduce((a,b)=>a+Math.log(b),0)/xs.length):null,reciprocal=xs.some(n=>n===0)?null:xs.reduce((a,b)=>a+1/b,0),hm=reciprocal===null||reciprocal===0||!Number.isFinite(reciprocal)?null:xs.length/reciprocal;if((meanType==='geometric'&&gm===null)||(meanType==='harmonic'&&hm===null))return{mean:null,geometricMean:null,harmonicMean:null,sum:null,count:0,__error:'meanTypeError'};return{mean,geometricMean:gm,harmonicMean:hm,sum,count:xs.length};",
    "inputs": [
      {
        "name": "meanType",
        "type": "select",
        "default": "arithmetic",
        "options": [
          {
            "value": "arithmetic"
          },
          {
            "value": "geometric"
          },
          {
            "value": "harmonic"
          }
        ]
      },
      {
        "name": "values",
        "type": "text",
        "default": "4, 8, 15, 16, 23, 42",
        "step": 1
      }
    ],
    "outputs": [
      {
        "name": "mean",
        "precision": 4,
        "unit": ""
      },
      {
        "name": "geometricMean",
        "precision": 4,
        "unit": "",
        "optional": true
      },
      {
        "name": "harmonicMean",
        "precision": 4,
        "unit": "",
        "optional": true
      },
      {
        "name": "sum",
        "precision": 4,
        "unit": ""
      },
      {
        "name": "count",
        "precision": 0,
        "unit": ""
      }
    ],
    "interpret": null
  }
}
