# Sum-loop obligations for n ≤ 10

KL-FCS-041 · Program verification · version 1.0.0

## Problem

Verify a loop that increments i and then adds i to total, starting from zero.

## Context

Connect preconditions, invariants, variants, and postconditions in a completely specified bounded program family.

## Definitions

- **Loop invariant**: A property maintained at every loop boundary.
- **Variant**: A value in a well-founded domain that strictly decreases while the loop runs.
- **Postcondition**: The property required when execution exits.

## Checked result

Postcondition holds: yes; Variant decreases: yes.

The invariant explains the partial sum at each boundary. The remaining iteration count strictly decreases, and the exit condition turns the invariant into the postcondition.

## Checker reasoning

1. Enumerate every admitted bound n.
2. Start with i=0 and total=0.
3. Check 2·total=i(i+1) and the decreasing variant n−i.
4. Replay the sample trace and require total=n(n+1)/2 at exit.

## Dataset construction

{
  "family": "program-verification",
  "task": "Verify a loop that increments i and then adds i to total, starting from zero.",
  "input_encoding": "Structured JSON; field meanings are stated in the specification.",
  "coverage": "Complete bounded program family · 11 inputs",
  "acceptance": [
    "Enumerate every admitted bound n.",
    "Start with i=0 and total=0.",
    "Check 2·total=i(i+1) and the decreasing variant n−i.",
    "Replay the sample trace and require total=n(n+1)/2 at exit."
  ],
  "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."
}

## Formal payload

```json
{
  "specification": {
    "program": "sum-first-n",
    "max_n": 10,
    "sample_n": 5,
    "precondition": "n ≥ 0; i=0; total=0",
    "invariant": "2*total = i*(i+1) and 0 ≤ i ≤ n",
    "variant": "n-i"
  },
  "claim": {
    "postcondition_holds": true,
    "variant_decreases": true
  },
  "witness": {
    "trace": [
      [
        0,
        0
      ],
      [
        1,
        1
      ],
      [
        2,
        3
      ],
      [
        3,
        6
      ],
      [
        4,
        10
      ],
      [
        5,
        15
      ]
    ]
  }
}
```

## Complexity

The family runs Σ n loop iterations for n=0…N, so total replay is O(N²).

## Limits

This replay checks n through the stated bound; it does not constitute an unrestricted deductive proof.

## Common error and further work

A postcondition on one execution is weaker than an invariant and a declared input domain.

Add inductive proof obligations and externally checked Hoare derivations.

## Verification

Complete bounded program family · 11 inputs. 11 checker units.
Replay with `python3 tools/verify.py`. Mechanical status: checked; human review
has not yet been recorded. Custom Python verification, not a proof-assistant
claim. Checker 1.0.0 and exact source hashes are in `verification.json`.

## Provenance and references

Original Kenton Labs reference instance, authored with Codex assistance on 2026-10-11.
No external dataset or model-generation experiment. Reuse-license selection
remains pending.

- [Conceptual reference](https://dafny.org/latest/OnlineTutorial/guide)
