Reading a verdict#
| You get | It means | Do |
|---|---|---|
proven: true, checked: true | The kernel checked a proof of every goal. | Done. Keep the broken variant as a test. |
stuck: 'sat' at @start | The law is false in the start state. | Fix the start state or the law, or add .pre if those params are impossible. |
proven: true, checked: true with assumes | Proven with a helper law the prover found (below); it holds in every state a run reaches from the start. | Paste the helper from found next to your law. If your code steps the rule from states it is handed, prove with {from: 'any'}. |
stuck: 'sat' at @step | A step can take a state where the laws hold to one where this law fails, and the prover's own search found neither a helper that proves it nor a run that breaks it. That state may be one no run reaches. | Run search for longer runs. A run that comes back is a real bug. No run: the law needs a helper law the search didn't find; state it next to this one in the same call. |
stuck: 'unknown' | The prover ran out of budget; why says which limit. | Split the law into laws about fewer conditions, or use fewer steps. |
proven: true, checked: false | The kernel rejected the prover's proof. | A bug in gdp-wired: report it with the rule. Never ship on it. |
Never weaken the law that matters to make it pass, and never widen .assume to hide a
bug: an assumption is a claim about every request your code will ever see. “The search found nothing” is not a
proof.
When the law needs a helper#
Some laws are true but can't be proven alone: a step from a state no run ever reaches would break them, so the
proof needs a second law that rules those states out. Writing that helper is the hard part of a proof by hand.
gdp-wired looks for it itself. When the prover alone stops and no run breaks the law, proveRule and
proveSteps search for the missing law (lemmas first, then invariants), prove it together with yours,
and hand it back as source to paste.
A connection pool: nothing is released that was not acquired. True, but not provable alone.
import {nat, oneOf, proveRule, rule, when} from 'gdp-wired'
const pool = rule('pool')
.params({size: nat})
.inputs({op: oneOf('acquire', 'release')})
.state({inUse: 0, acquired: 0, released: 0})
.flags(({op, size, inUse}) => ({
got: op.is('acquire').and(inUse.lt(size)),
back: op.is('release').and(inUse.gt(0)),
}))
.step(({inUse, acquired, released, got, back}) => ({
inUse: when(got, inUse.plus(1), when(back, inUse.minus(1), inUse)),
acquired: when(got, acquired.plus(1), acquired),
released: when(back, released.plus(1), released),
}))
const law = pool.law('nothing is released that was not acquired',
({released, acquired}) => released.atMost(acquired))
proveRule(pool, [law], {search: false})
// {proven: false, goal: 'nothing is released that was not acquired @step', stuck: 'sat'}
proveRule(pool, [law])
// {proven: true, checked: true,
// assumes: {states: 'reachable', laws: ['inUse + released <= acquired']},
// found: {laws: [{text: 'inUse + released <= acquired',
// source: "r.law('inUse + released <= acquired', ({inUse, acquired, released}) =>
// inUse.plus(released).atMost(acquired))"}]}}
The prover found the law nobody wrote (whatever is in use plus whatever came back never exceeds what was handed out), proved both, and the kernel checked the proof. The output is from gdp-wired 0.51.0, where the search took under two seconds.
- Paste what it found.
foundholds each helper as ther.law(...)call that states it, and lemmas about recurrences and lists the same way. Keep the helper with your law: the proof needs both. - Read
assumes. A helper it finds holds in the states a run reaches from the start, and the verdict says so. If your code steps the rule from a state it is handed (a stored one, another service's), prove with{from: 'any'}and requireproven && checked && !assumes: then the search never adds a helper, and the pool above is refused, rightly, until you state one that holds from every state. - Set the allowance. The search gets 10 s by default;
{search: {ms}}changes it, and{search: false}runs the prover alone. A false law still comes back with the run that breaks it: drop theinUse.gt(0)check on release and the same call returnsrun: {params: {size: 2}, trace: [{op: 1}]}, one release (choice 1) from the start. - Call the parts directly.
inferLaws(rule, laws)fromgdp-wired/inferfinds invariants (bounds, sums and differences, parities, laws about every key of a map);discover(rule, laws, stepLaws)fromgdp-wired/discoverfinds the lemmas a recurrence or a list's folds need.