{
  "schemaVersion": 1,
  "slug": "prime-checker-calculator",
  "category": "math",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "5ed7462aec2bbbe9d8a18b31e7a2c48ff70893d972f90d2627f528e5397069f3",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/prime-checker-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": "τ = Σ_{k=1}^{⌊√n⌋} [k|n](2 − [k² = n]); n ∈ ℙ ⇔ τ = 2",
    "vars": [
      [
        "n",
        "Integer to test"
      ],
      [
        "k",
        "Trial divisor"
      ],
      [
        "⌊√n⌋",
        "Integer trial bound"
      ],
      [
        "[P]",
        "Iverson bracket: 1 if P holds, else 0"
      ],
      [
        "k|n",
        "k divides n"
      ],
      [
        "τ",
        "Number of divisors"
      ],
      [
        "ℙ",
        "Set of prime numbers"
      ]
    ],
    "note": "An integer greater than 1 is prime exactly when it has two positive divisors; the result states this directly."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "if(!Number.isInteger(n))return{divisors:null,primeFactors:null,squareRoot:null,largestFactorBelowRoot:null,isPrime:null,__error:'inputError'}; const num=n; if(num===0)return {divisors:null,primeFactors:null,squareRoot:0,largestFactorBelowRoot:null,isPrime:'Not prime'}; let count=0,firstFactor=0; for(let k=1;k<=Math.sqrt(num);k++){if(num%k===0){count+=(k*k===num)?1:2;if(k>1&&!firstFactor)firstFactor=k;}} let pf=0,rem=num,d=2; while(d*d<=rem){while(rem%d===0){pf++;rem/=d;}d++;}if(rem>1)pf++;return {divisors:count,primeFactors:pf,squareRoot:Math.sqrt(num),largestFactorBelowRoot:firstFactor||null,isPrime:num>1&&count===2?'Prime':'Not prime'};",
    "inputs": [
      {
        "name": "n",
        "type": "number",
        "default": 97,
        "min": 0,
        "max": 1000000000,
        "step": 1,
        "requiredValue": true
      }
    ],
    "outputs": [
      {
        "name": "isPrime",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "divisors",
        "precision": 0,
        "unit": "",
        "optional": true,
        "trimTrailingZeros": true
      },
      {
        "name": "primeFactors",
        "precision": 0,
        "unit": "",
        "optional": true,
        "trimTrailingZeros": true
      },
      {
        "name": "squareRoot",
        "precision": 4,
        "unit": "",
        "trimTrailingZeros": true
      },
      {
        "name": "largestFactorBelowRoot",
        "precision": 0,
        "unit": "",
        "optional": true,
        "trimTrailingZeros": true
      }
    ],
    "interpret": [
      {
        "max": 2.5,
        "key": "prime"
      },
      {
        "max": 3.5,
        "key": "squareOfPrime"
      },
      {
        "max": 1000000000,
        "key": "composite"
      }
    ]
  }
}
