{
  "name": "Compiler optimization",
  "version": "1.0.0",
  "area": {
    "name": "Compiler optimization",
    "slug": "compiler",
    "group": "Programs & systems",
    "kind": "compiler",
    "summary": "A rewrite is correct when source and target agree under the exact language semantics and observable behavior.",
    "definitions": [
      {
        "term": "Semantic equivalence",
        "definition": "The same observable result for every input in the declared domain."
      },
      {
        "term": "Modular arithmetic",
        "definition": "Arithmetic wraps modulo 2ʷ for width w."
      },
      {
        "term": "Strength reduction",
        "definition": "Replacing an operation with another expression whose performance must be evaluated separately."
      }
    ],
    "methodology": [
      "Enumerate every value at the chosen bit width.",
      "Evaluate the source expression modulo 2ʷ.",
      "Evaluate the replacement under the same semantics.",
      "Compare outputs, including wraparound inputs."
    ],
    "complexity": "Unary width-w equivalence by enumeration checks 2ʷ inputs. This is practical for small widths, not a general large-program optimizer.",
    "common_error": "Correctness is not a speedup claim; duplicating an expression with side effects can be invalid.",
    "next_question": "Add expression DAGs, observable-state semantics, and checked equivalence certificates.",
    "references": [
      "https://softwarefoundations.cis.upenn.edu/plf-current/Smallstep.html"
    ]
  },
  "records": [
    {
      "id": "KL-FCS-011",
      "version": "1.0.0",
      "domain": "Compiler optimization",
      "kind": "compiler",
      "title": "Strength reduction under modular arithmetic",
      "problem": "Check the rewrite x × 2 → x + x for every unsigned four-bit x.",
      "specification": {
        "width": 4,
        "source": "x * 2",
        "semantics": "Pure expressions on four-bit values, with both operators modulo 16 and no observable side effects."
      },
      "claim": {
        "equivalent": true
      },
      "witness": {
        "replacement": "x + x"
      },
      "verification_scope": "Complete bit-vector equivalence · 16 inputs",
      "explanation": "For each possible input, the original and replacement expressions yield the same four-bit result, including values that wrap.",
      "limitations": "This example does not establish a rewrite for language undefined behavior, side effects, overflow flags, other widths, or floating-point arithmetic. No speedup is claimed.",
      "verification_status": "mechanically-checked",
      "review_status": "awaiting-independent-review",
      "provenance": {
        "origin": "Original Kenton Labs reference instance, authored with Codex assistance on 2026-10-11.",
        "external_dataset": null,
        "model_run": null
      },
      "references": [
        "https://softwarefoundations.cis.upenn.edu/plf-current/Smallstep.html"
      ],
      "license_status": "not-yet-selected",
      "dataset": {
        "family": "compiler",
        "task": "Check the rewrite x × 2 → x + x for every unsigned four-bit x.",
        "input_encoding": "Structured JSON; field meanings are stated in the specification.",
        "coverage": "Complete bit-vector equivalence · 16 inputs",
        "acceptance": [
          "Enumerate every value at the chosen bit width.",
          "Evaluate the source expression modulo 2ʷ.",
          "Evaluate the replacement under the same semantics.",
          "Compare outputs, including wraparound inputs."
        ],
        "generation": "Deterministic finite fixture; full enumeration or witness replay as stated.",
        "split_policy": "Reference corpus for exposition and reproduction; no train/test evaluation split is claimed."
      },
      "lesson": {
        "motivation": "A rewrite is correct when source and target agree under the exact language semantics and observable behavior.",
        "definitions": [
          {
            "term": "Semantic equivalence",
            "definition": "The same observable result for every input in the declared domain."
          },
          {
            "term": "Modular arithmetic",
            "definition": "Arithmetic wraps modulo 2ʷ for width w."
          },
          {
            "term": "Strength reduction",
            "definition": "Replacing an operation with another expression whose performance must be evaluated separately."
          }
        ],
        "reasoning": [
          "Enumerate every value at the chosen bit width.",
          "Evaluate the source expression modulo 2ʷ.",
          "Evaluate the replacement under the same semantics.",
          "Compare outputs, including wraparound inputs."
        ],
        "worked_example": "For each possible input, the original and replacement expressions yield the same four-bit result, including values that wrap.",
        "complexity": "Unary width-w equivalence by enumeration checks 2ʷ inputs. This is practical for small widths, not a general large-program optimizer.",
        "common_error": "Correctness is not a speedup claim; duplicating an expression with side effects can be invalid.",
        "further_work": "Add expression DAGs, observable-state semantics, and checked equivalence certificates."
      },
      "related_ids": [
        "KL-FCS-026",
        "KL-FCS-027"
      ]
    },
    {
      "id": "KL-FCS-026",
      "version": "1.0.0",
      "domain": "Compiler optimization",
      "kind": "compiler",
      "title": "Eliminate an eight-bit neutral addition",
      "problem": "Check a pure unsigned modular rewrite at every input.",
      "specification": {
        "width": 8,
        "source": "x + 0",
        "semantics": "Pure unsigned 8-bit arithmetic modulo 256, with no side effects."
      },
      "claim": {
        "equivalent": true
      },
      "witness": {
        "replacement": "x"
      },
      "verification_scope": "Complete equivalence · 256 inputs",
      "explanation": "The checker evaluates both expressions at every representable value. Overflow wraps identically in the two expressions.",
      "limitations": "The result does not transfer automatically to signed-overflow undefined behavior or effectful expressions.",
      "verification_status": "mechanically-checked",
      "review_status": "awaiting-independent-review",
      "provenance": {
        "origin": "Original Kenton Labs reference instance, authored with Codex assistance on 2026-10-11.",
        "external_dataset": null,
        "model_run": null
      },
      "references": [
        "https://softwarefoundations.cis.upenn.edu/plf-current/Smallstep.html"
      ],
      "license_status": "not-yet-selected",
      "dataset": {
        "family": "compiler",
        "task": "Check a pure unsigned modular rewrite at every input.",
        "input_encoding": "Structured JSON; field meanings are stated in the specification.",
        "coverage": "Complete equivalence · 256 inputs",
        "acceptance": [
          "Enumerate every value at the chosen bit width.",
          "Evaluate the source expression modulo 2ʷ.",
          "Evaluate the replacement under the same semantics.",
          "Compare outputs, including wraparound inputs."
        ],
        "generation": "Deterministic finite fixture; full enumeration or witness replay as stated.",
        "split_policy": "Reference corpus for exposition and reproduction; no train/test evaluation split is claimed."
      },
      "lesson": {
        "motivation": "A rewrite is correct when source and target agree under the exact language semantics and observable behavior.",
        "definitions": [
          {
            "term": "Semantic equivalence",
            "definition": "The same observable result for every input in the declared domain."
          },
          {
            "term": "Modular arithmetic",
            "definition": "Arithmetic wraps modulo 2ʷ for width w."
          },
          {
            "term": "Strength reduction",
            "definition": "Replacing an operation with another expression whose performance must be evaluated separately."
          }
        ],
        "reasoning": [
          "Enumerate every value at the chosen bit width.",
          "Evaluate the source expression modulo 2ʷ.",
          "Evaluate the replacement under the same semantics.",
          "Compare outputs, including wraparound inputs."
        ],
        "worked_example": "The checker evaluates both expressions at every representable value. Overflow wraps identically in the two expressions.",
        "complexity": "Unary width-w equivalence by enumeration checks 2ʷ inputs. This is practical for small widths, not a general large-program optimizer.",
        "common_error": "Correctness is not a speedup claim; duplicating an expression with side effects can be invalid.",
        "further_work": "Add expression DAGs, observable-state semantics, and checked equivalence certificates."
      },
      "related_ids": [
        "KL-FCS-011",
        "KL-FCS-027"
      ]
    },
    {
      "id": "KL-FCS-027",
      "version": "1.0.0",
      "domain": "Compiler optimization",
      "kind": "compiler",
      "title": "Triple a six-bit value by addition",
      "problem": "Check a pure unsigned modular rewrite at every input.",
      "specification": {
        "width": 6,
        "source": "x * 3",
        "semantics": "Pure unsigned 6-bit arithmetic modulo 64, with no side effects."
      },
      "claim": {
        "equivalent": true
      },
      "witness": {
        "replacement": "(x + x) + x"
      },
      "verification_scope": "Complete equivalence · 64 inputs",
      "explanation": "The checker evaluates both expressions at every representable value. Overflow wraps identically in the two expressions.",
      "limitations": "The result does not transfer automatically to signed-overflow undefined behavior or effectful expressions.",
      "verification_status": "mechanically-checked",
      "review_status": "awaiting-independent-review",
      "provenance": {
        "origin": "Original Kenton Labs reference instance, authored with Codex assistance on 2026-10-11.",
        "external_dataset": null,
        "model_run": null
      },
      "references": [
        "https://softwarefoundations.cis.upenn.edu/plf-current/Smallstep.html"
      ],
      "license_status": "not-yet-selected",
      "dataset": {
        "family": "compiler",
        "task": "Check a pure unsigned modular rewrite at every input.",
        "input_encoding": "Structured JSON; field meanings are stated in the specification.",
        "coverage": "Complete equivalence · 64 inputs",
        "acceptance": [
          "Enumerate every value at the chosen bit width.",
          "Evaluate the source expression modulo 2ʷ.",
          "Evaluate the replacement under the same semantics.",
          "Compare outputs, including wraparound inputs."
        ],
        "generation": "Deterministic finite fixture; full enumeration or witness replay as stated.",
        "split_policy": "Reference corpus for exposition and reproduction; no train/test evaluation split is claimed."
      },
      "lesson": {
        "motivation": "A rewrite is correct when source and target agree under the exact language semantics and observable behavior.",
        "definitions": [
          {
            "term": "Semantic equivalence",
            "definition": "The same observable result for every input in the declared domain."
          },
          {
            "term": "Modular arithmetic",
            "definition": "Arithmetic wraps modulo 2ʷ for width w."
          },
          {
            "term": "Strength reduction",
            "definition": "Replacing an operation with another expression whose performance must be evaluated separately."
          }
        ],
        "reasoning": [
          "Enumerate every value at the chosen bit width.",
          "Evaluate the source expression modulo 2ʷ.",
          "Evaluate the replacement under the same semantics.",
          "Compare outputs, including wraparound inputs."
        ],
        "worked_example": "The checker evaluates both expressions at every representable value. Overflow wraps identically in the two expressions.",
        "complexity": "Unary width-w equivalence by enumeration checks 2ʷ inputs. This is practical for small widths, not a general large-program optimizer.",
        "common_error": "Correctness is not a speedup claim; duplicating an expression with side effects can be invalid.",
        "further_work": "Add expression DAGs, observable-state semantics, and checked equivalence certificates."
      },
      "related_ids": [
        "KL-FCS-011",
        "KL-FCS-026"
      ]
    }
  ],
  "verification": [
    {
      "id": "KL-FCS-011",
      "status": "mechanically-checked",
      "check_units": 16,
      "scope": "Complete bit-vector equivalence · 16 inputs",
      "review_status": "awaiting-independent-review"
    },
    {
      "id": "KL-FCS-026",
      "status": "mechanically-checked",
      "check_units": 256,
      "scope": "Complete equivalence · 256 inputs",
      "review_status": "awaiting-independent-review"
    },
    {
      "id": "KL-FCS-027",
      "status": "mechanically-checked",
      "check_units": 64,
      "scope": "Complete equivalence · 64 inputs",
      "review_status": "awaiting-independent-review"
    }
  ]
}
