
<div class="callout callout-note"><p>The prover is one piece of the Vary toolchain. This page covers how proof results feed the editor, the compiler, CI, and mutation testing.</p></div>

## At a glance

| Feature | Command or setting | What it gives you |
|---|---|---|
| Proof cache | Automatic | Results are cached per function by content hash. Editing a function re-proves it and the functions that depend on its contract, and nothing else |
| Editor | Save a file | Proves in the background. Refuted shows as an error with an example input, undecided as a warning. Budgets are short |
| Check rules | `vary check` | `VCC005` flags a loop in a function with an `out` or `post` contract that has no `invariant`, and `VCC006` flags a `lemma` that nothing calls |
| CI baseline | `--write-baseline proofs.json`, `--baseline proofs.json` | Records what is proven and fails a run when any of it regresses |
| Vacuous and trivial contracts | Automatic, `--no-triviality` | An `in` block no input satisfies makes the function `vacuous` and nothing in it proven; a proven clause that holds without the body is marked `trivial` |
| Replay | `vary prove --replay` | Runs the compiled function on solver-chosen inputs and observes every proven clause on the runtime result; a disagreement is `replay-mismatch` |
| Check removal | `elide_proven_contracts = true` under `[compiler]` | Removes the run-time `out`, `post` and loop checks of fully proven functions |
| Mutation | `vary prove --mutants`, `vary mutate --with-proofs` | Proof results kill mutants without running tests |
| Reports | `vary prove --json` | A versioned machine-readable report |
| Lean | `--export-lean`, `--external-proofs` | A hand-off for goals SMT cannot settle |

## CI baselines

Record what is proven once, and let CI fail when anything in the record stops being proven:

```bash
vary prove --write-baseline proofs.json
vary prove --baseline proofs.json
```

A proven obligation in the baseline that is no longer proven fails the run, whatever it became.

## Contracts that cannot hide

A proof is only as good as the contract it proves. Two questions are asked beside every proof so a wrong contract cannot pass as a right one.

| Verdict | What it means | What you do |
|---|---|---|
| `vacuous` | No input satisfies the `in` block (with the class invariants). Every obligation of the function is `vacuous` and none counts as proven. The note names the clauses that conflict | Fix the `in` block |
| `trivial` | A proven `out` or `post` clause holds without the function body: a tautology such as `r == r`, or a clause the `in` block already implies. The verdict stays `proven` | Decide whether the clause is meant to carry intent; if so, strengthen it |

`trivial` is advice and never fails a run. `--no-triviality` switches the question off. `vary check` rule `VCC002` catches the shapes that need no solver.

## Replay against the compiled program

A proof says what the source means. The compiled program is what runs. `--replay` checks that they agree:

```bash
vary prove --replay src/
```

For every function with a proven `out` or `post` clause, the solver picks a few inputs that satisfy the `in` block, the compiled function runs on them through the test runner, and each proven clause is observed on the runtime result. A clause that fails is reported as `replay-mismatch` with the input, the run fails, and the cause is a compiler or encoding bug by definition. Clauses that use `old(...)` are not replayed and the report says how many were skipped. The replay is cached with the proof, so an unchanged function is not run again.

## Removing checks that are proven

Contracts run as checks in production unless you tell the compiler otherwise. When a function's contracts are all proven, those checks can never fail, so they can go. Set `elide_proven_contracts = true` under `[compiler]` in `vary.toml`.

| What is removed | When |
|---|---|
| `out`, `post` and loop checks | The function is fully proven |
| `in` checks on underscore-private functions | Every call site is proven |
| `in` checks on public functions | `elide_public_preconditions` is set. Callers outside the file are then unchecked, so enable it only when you accept that |

The setting is part of the artifact identity, so a cached build never mixes checked and unchecked code.

## Proofs and mutation testing

Mutation testing asks whether your checks notice a change. Proofs make that question cheaper and sharper.

| Command | What it does |
|---|---|
| `vary mutate --with-proofs` | A mutant that the prover refutes is counted as killed without running any test, which speeds up slow suites. The report gains a proof section: which functions are fully proven and how many of their mutants the proof kills or lets through |
| `vary prove --mutants` | Mutates each proven function and proves the mutants. A mutant whose contract obligations all still hold means the contract is too weak to notice that change |

A mutant that survives a proof is a better signal than one that survives a test suite: it means the contract itself has a gap, not just the tests.

## Reports and what a proof relied on

`vary prove --json` writes a versioned report. Each obligation lists `assumes`: the callee contracts and the builtin axioms (`builtin:sorted`, `builtin:sum`, and so on) that the proof used. Opaque calls appear as `opaque:NAME`. This is the trusted base of a result, made visible. A clause that holds without the body carries `"trivial": true`, the summary counts `vacuous` obligations and `trivial_clauses`, and a replayed function carries a `replay` block with the inputs run and every mismatch.

## Lean export

When SMT cannot settle a goal, hand it to a proof assistant:

```bash
vary prove --export-lean proofs/ --function gcd
vary prove --external-proofs proofs/
```

The first command writes a Lean 4 file. A recursive function with a `decreases` measure becomes a Lean `def` with `termination_by`, so theorems about it can be proven. You write the proof. The second command accepts `<function>.lean` files that Lean checks and reports the goals as proven-external.

Vary guards the hand-off. The theorem statements and function definitions in the file must be exactly the exported ones, a stale proof is rejected, and a file that uses `sorry` or declares extra axioms is rejected. Only the `decreasing_by` proof and helper theorems are yours.
