gdp-wired 0.53.2 → 0.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -323,8 +323,10 @@ All of these are proven automatically, and each proof is also a Lean theorem:
323
323
  on rules read from code as on written ones; `proveTwoRuns` proves the law of the two runs side by side as one rule, a
324
324
  refutation the two runs (`research/regulated/`).
325
325
 
326
- When a law is false, the GPU search finds a real run that breaks it. When a law needs an invariant nobody wrote,
327
- `inferLaws` finds one on the CPU (and the GPU synthesizer, at scale, in `research/synth/`) and the kernel proves it.
326
+ When a law is false, the prover or GPU search finds a real run that breaks it, and `minimizeRun(rule, law, run)`
327
+ ([`docs/minimize.md`](docs/minimize.md)) shrinks a refuting run on the original rule until no single request can be
328
+ removed. When a law needs an invariant nobody wrote, `proveRule` proposes checked covering sums for item-against-total
329
+ laws and `inferLaws` finds invariants on the CPU (and the GPU synthesizer, at scale, in `research/synth/`) and the kernel proves it.
328
330
 
329
331
  **What it leaves to Lean or Bend.** Two things, and neither is a gap the next feature closes: proofs the prover would
330
332
  have to invent (induction over a recursive structure whose proof needs a lemma nobody stated and `discover` doesn't find, and arithmetic with
@@ -634,7 +636,7 @@ Proving and checking: a law over 64 steps proves in about 5 s, and Lean checks i
634
636
  | `kernel/` | The trusted kernel and the untrusted prover, with soundness fuzz (`kernel.test.ts`, `history.test.ts`) |
635
637
  | `lean-kernel/` | The kernel's Lean twin, its soundness proofs, and the exported trees |
636
638
  | `examples/` | The builders at work: `domains/` (187 rules across 21 domains, each with laws and broken variants), `harness.ts` (the triple check), `readme.ts`, `guide.ts` (the guide's code), `groups.ts` (two groups decided at every pair), `budget.ts`, `gdp.ts` (gdp-ts's example, its checks proven), `exists.ts` (laws with "there exists"), `datatypes.ts` (records and variants), `lemmas.ts` (recurrences and their lemmas), `invoices.ts` (lists a request carries), `folds.ts` (folds over trees), `trees.ts` (trees and lists of lists in the state), `composition.ts`, `sets.ts`, `quantifiers.ts`, `functions.ts`, `arith.ts` (division and remainder by a constant, integers in rules and datatypes), `lists.ts`, `sizes.ts`, `liveness.ts`, `steps.ts` (laws over up to 64 steps), and `jev-fabric/` (a Bend project's 59 proven laws, ported) |
637
- | `docs/` | [ARCHITECTURE.md](docs/ARCHITECTURE.md) (the trust boundaries and what guards each), [FRONTENDS.md](docs/FRONTENDS.md) (how a language's reader plugs in), [interchange.md](docs/interchange.md) (certificates as JSON, for checkers in other languages), the comparison with Bend and Lean |
639
+ | `docs/` | [ARCHITECTURE.md](docs/ARCHITECTURE.md) (the trust boundaries and what guards each), [FRONTENDS.md](docs/FRONTENDS.md) (how a language's reader plugs in), [minimize.md](docs/minimize.md) (shrinking refuting runs with `minimizeRun`), [interchange.md](docs/interchange.md) (certificates as JSON, for checkers in other languages), the comparison with Bend and Lean |
638
640
  | `compare/` | The same three rules in gdp-wired, Bend and plain Lean, checked and measured |
639
641
  | `research/` | Everything around the library ([`research/README.md`](research/README.md)): the GPU searches (`search/`, `hw/`, `modal-gpu/`), invariant and rank synthesis (`synth/`), relational laws and guard synthesis (`next/`), bit-vector laws (`sat/`), the enumeration and benchmarks (`enum/`, `gpu/`, `perf/`), the first Lean checker (`lean/`) and the first prototype, the audit path (`audit/`) |
640
642
  | `supercomputer/` | Everything above as jobs on boat (a warm pool), Modal and RunPod: `suite.json` is the regression suite (`modal/` links here until every lane has merged the rename) |
@@ -646,7 +648,8 @@ The npm package is built from `core/`, `kernel/` and `lean-kernel/` alone; nothi
646
648
 
647
649
  ## Running
648
650
 
649
- The npm package is the library: the builders (`gdp-wired`), the runtimes (`gdp-wired/machine`), composition
651
+ The npm package is the library: the builders (`gdp-wired`), the runtimes (`gdp-wired/machine`), refutation run
652
+ minimization (`gdp-wired/minimize`, also exported from `gdp-wired` and every frontend subpath), composition
650
653
  (`gdp-wired/compose`), XState machines as charts (`gdp-wired/xstate`), rules read from the code (`gdp-wired/extract`, with
651
654
  `typescript` installed), Effect services (`gdp-wired/effect`, with `typescript` and `effect`), lemmas nobody stated (`gdp-wired/discover`), invariant
652
655
  inference (`gdp-wired/infer`), the
@@ -5,7 +5,8 @@ type Closure = ReturnType<typeof proveSetFast>;
5
5
  type Drop = {
6
6
  name: string;
7
7
  goal: string;
8
- stuck: 'sat';
8
+ stuck?: 'sat';
9
+ reason?: string;
9
10
  };
10
11
  export type SeedGhosts = Pick<Ghosted, 'vars' | 'maps'>;
11
12
  export type SeedResult = {
@@ -21,5 +22,7 @@ export type SeedResult = {
21
22
  dropped: Drop[];
22
23
  reason: string;
23
24
  };
24
- export declare function proveCandidateSeeds(machine: Machine, publicLaws: Law[], candidates: Law[], witnesses?: Record<string, SomeWitness>, ghosts?: SeedGhosts): SeedResult;
25
+ export declare function proveCandidateSeeds(machine: Machine, publicLaws: Law[], candidates: Law[], witnesses?: Record<string, SomeWitness>, ghosts?: SeedGhosts, policy?: {
26
+ dropUndecided?: boolean;
27
+ }): SeedResult;
25
28
  export {};
@@ -5,7 +5,9 @@ import { checkGhostedLaws, ghostedMachine, ghostedOk, someOfGhostsOk, substC } f
5
5
  import { retainFrom } from "./proof-output.js";
6
6
  // The caller imposes the deadline. Only the complete checked family is evidence.
7
7
  // In particular neither a witness nor a ghost definition is a caller assumption.
8
- export function proveCandidateSeeds(machine, publicLaws, candidates, witnesses = {}, ghosts = { vars: {}, maps: {} }) {
8
+ export function proveCandidateSeeds(machine, publicLaws, candidates, witnesses = {}, ghosts = { vars: {}, maps: {} },
9
+ // (dropUndecided: a candidate neither proven nor refuted is dropped like a refuted one, not the whole attempt ended)
10
+ policy = {}) {
9
11
  const refuse = (reason) => ({ status: 'inconclusive', kept: [], dropped: [], reason });
10
12
  if (Object.keys(machine.counts ?? {}).length)
11
13
  return refuse('count-bearing machine requires counted candidate admission');
@@ -68,9 +70,9 @@ export function proveCandidateSeeds(machine, publicLaws, candidates, witnesses =
68
70
  for (let i = 0; i < kept.length; i++) {
69
71
  const decision = decideLaw(working, family, plainPublic.length + i) ?? proveLaw(working, family, plainPublic.length + i);
70
72
  if (!decision.proven) {
71
- if (decision.stuck !== 'sat')
73
+ if (decision.stuck !== 'sat' && !policy.dropUndecided)
72
74
  return { status: 'inconclusive', kept, dropped, reason: `undecided candidate: ${kept[i].name}: ${decision.stuck}${'why' in decision && decision.why ? `: ${decision.why}` : ''}` };
73
- dropped.push({ name: kept[i].name, goal: decision.goal, stuck: 'sat' });
75
+ dropped.push({ name: kept[i].name, goal: decision.goal, ...(decision.stuck === 'sat' ? { stuck: 'sat' } : { reason: 'undecided' }) });
74
76
  kept = kept.filter((_, j) => j !== i);
75
77
  removed = true;
76
78
  break;
@@ -0,0 +1,14 @@
1
+ import { type C, type E, type Law, type Machine } from './machine.js';
2
+ export type CoveringShape = {
3
+ key: string;
4
+ map: string;
5
+ term: E;
6
+ total: E;
7
+ unless: C[];
8
+ plain: boolean;
9
+ };
10
+ export declare function coveringShapes(m: Machine, law: Law): CoveringShape[];
11
+ export declare function companions(m: Machine, shape: CoveringShape, most?: number): string[];
12
+ export type DeclareSum = (map: string, at: (key: E) => E, plain: boolean) => string | undefined;
13
+ export declare function coveringSeeds(m: Machine, law: Law, declare: DeclareSum): Law[];
14
+ export declare function cellSeeds(m: Machine, law: Law, most?: number): Law[];
@@ -0,0 +1,269 @@
1
+ const text = (u) => JSON.stringify(u);
2
+ const one = { op: 'const', value: 1 }, zero = { op: 'const', value: 0 };
3
+ const plus = (a, b) => ({ op: 'add', a, b });
4
+ // The law's body as clauses (a conjunction of disjunctions of literals), or undefined past `most` clauses or at a
5
+ // quantifier or a flag (no law of this shape reads one).
6
+ function clauses(c, neg, most) {
7
+ switch (c.op) {
8
+ case 'not': return clauses(c.x, !neg, most);
9
+ case 'and':
10
+ case 'or': {
11
+ const parts = c.xs.map(x => clauses(x, neg, most));
12
+ if (parts.some(p => !p))
13
+ return undefined;
14
+ if ((c.op === 'and') !== neg) {
15
+ const out = parts.flat();
16
+ return out.length > most ? undefined : out;
17
+ }
18
+ let out = [[]];
19
+ for (const p of parts) {
20
+ out = out.flatMap(a => p.map(b => [...a, ...b]));
21
+ if (out.length > most)
22
+ return undefined;
23
+ }
24
+ return out;
25
+ }
26
+ case '<':
27
+ case '<=':
28
+ case '=': return [[{ c, neg }]];
29
+ case 'flag':
30
+ case 'all': return undefined;
31
+ }
32
+ }
33
+ function reads(t, key, r = { vars: new Set(), maps: new Set(), keyed: true, shaped: true }) {
34
+ switch (t.op) {
35
+ case 'var':
36
+ r.vars.add(t.name);
37
+ break;
38
+ case 'const': break;
39
+ case 'get':
40
+ r.maps.add(t.map);
41
+ if (!(t.key.op === 'var' && t.key.name === key)) {
42
+ r.keyed = false;
43
+ reads(t.key, key, r);
44
+ }
45
+ break;
46
+ case 'mul':
47
+ reads(t.a, key, r);
48
+ break;
49
+ case 'add':
50
+ case 'sub':
51
+ case 'min':
52
+ case 'max':
53
+ case 'prod':
54
+ reads(t.a, key, r);
55
+ reads(t.b, key, r);
56
+ break;
57
+ case 'if':
58
+ reads(t.c, key, r);
59
+ reads(t.then, key, r);
60
+ reads(t.else, key, r);
61
+ break;
62
+ case 'tup':
63
+ case 'proj':
64
+ r.shaped = false;
65
+ break;
66
+ case '<':
67
+ case '<=':
68
+ case '=':
69
+ reads(t.a, key, r);
70
+ reads(t.b, key, r);
71
+ break;
72
+ case 'and':
73
+ case 'or':
74
+ for (const x of t.xs)
75
+ reads(x, key, r);
76
+ break;
77
+ case 'not':
78
+ reads(t.x, key, r);
79
+ break;
80
+ case 'flag':
81
+ case 'all':
82
+ r.shaped = false;
83
+ break;
84
+ }
85
+ return r;
86
+ }
87
+ // A literal as lo ≤ hi, where it is one (¬(a < b) is b ≤ a; a < b over naturals is a + 1 ≤ b, kept for a constant a;
88
+ // ¬(X = 0) and ¬(0 = X) are 1 ≤ X).
89
+ function atMost(l) {
90
+ const c = l.c;
91
+ if (c.op === '<=' && !l.neg)
92
+ return { lo: c.a, hi: c.b };
93
+ if (c.op === '<' && l.neg)
94
+ return { lo: c.b, hi: c.a };
95
+ if (c.op === '<' && !l.neg && c.a.op === 'const')
96
+ return { lo: { op: 'const', value: c.a.value + 1 }, hi: c.b };
97
+ if (c.op === '<=' && l.neg && c.b.op === 'const')
98
+ return { lo: { op: 'const', value: c.b.value + 1 }, hi: c.a };
99
+ if (c.op === '=' && l.neg) {
100
+ if (c.a.op === 'const' && c.a.value === 0)
101
+ return { lo: one, hi: c.b };
102
+ if (c.b.op === 'const' && c.b.value === 0)
103
+ return { lo: one, hi: c.a };
104
+ }
105
+ return undefined;
106
+ }
107
+ const litC = (l) => (l.neg ? { op: 'not', x: l.c } : l.c);
108
+ const notLit = (l) => (l.neg ? l.c : { op: 'not', x: l.c });
109
+ // The clauses of the law that have the shape, each read as guard, weight and total.
110
+ export function coveringShapes(m, law) {
111
+ const key = law.forall;
112
+ if (!key || law.keys?.length || law.some?.length || law.ex || law.finite !== undefined || law.witness)
113
+ return [];
114
+ if (m.history || Object.keys(m.counts ?? {}).length || !m.maps)
115
+ return [];
116
+ const cs = clauses(law.holds, false, 16);
117
+ if (!cs)
118
+ return [];
119
+ const stateMap = (name) => Object.hasOwn(m.maps, name) && !(m.inputMaps ?? []).includes(name) && !Object.hasOwn(m.fns ?? {}, name);
120
+ const scalar = (name) => Object.hasOwn(m.state, name) && !Object.hasOwn(m.sums ?? {}, name);
121
+ // A term of the cells at the key alone (what a sum's term may read); a term of the state and params, with a state
122
+ // variable (a total).
123
+ const cellTerm = (t) => { const r = reads(t, key); return r.shaped && r.keyed && r.maps.size > 0 && r.vars.size === 0 && [...r.maps].every(stateMap); };
124
+ const free = (t) => { const r = reads(t, key); return r.shaped && !r.vars.has(key) && r.maps.size === 0; };
125
+ const total = (t) => free(t) && [...reads(t, key).vars].some(scalar);
126
+ const out = [];
127
+ for (const clause of cs) {
128
+ const guard = [], unless = [];
129
+ let weight, tot, ok = true;
130
+ for (const l of clause) {
131
+ if (cellTerm(l.c)) {
132
+ guard.push(notLit(l));
133
+ continue;
134
+ }
135
+ const le = atMost(l);
136
+ if (le && total(le.hi) && !weight && !tot && cellTerm(le.lo)) {
137
+ weight = le.lo;
138
+ tot = le.hi;
139
+ continue;
140
+ }
141
+ // (a member implies a positive count: 1 ≤ X; two of them in one clause, 1 ≤ X or 1 ≤ Y, are covered by X + Y)
142
+ if (le && total(le.hi) && le.lo.op === 'const' && le.lo.value === 1 && (!weight || text(weight) === text(one))) {
143
+ weight = one;
144
+ tot = tot ? plus(tot, le.hi) : le.hi;
145
+ continue;
146
+ }
147
+ if (free(l.c)) {
148
+ unless.push(litC(l));
149
+ continue;
150
+ }
151
+ ok = false;
152
+ break;
153
+ }
154
+ if (!ok || !weight || !tot)
155
+ continue;
156
+ // (a count needs a guard to count by: with none, 1 ≤ X is no law about the cells)
157
+ if (weight === one && !guard.length)
158
+ continue;
159
+ const term = guard.length ? { op: 'if', c: guard.length === 1 ? guard[0] : { op: 'and', xs: guard }, then: weight, else: zero } : weight;
160
+ const maps = [...reads(term, key).maps].sort();
161
+ out.push({ key, map: maps[0], term, total: tot, unless, plain: !guard.length && weight.op === 'get' });
162
+ }
163
+ return out;
164
+ }
165
+ // The other maps a total is charged for: a state map of naturals starting at 0 whose cell the step adds to or takes
166
+ // from a state variable of the total (read as a value, not only as a condition), and that the shape's own term doesn't
167
+ // read. At most `most`, in the machine's order.
168
+ export function companions(m, shape, most = 2) {
169
+ const mine = reads(shape.term, shape.key).maps, vars = [...reads(shape.total, shape.key).vars].filter(n => Object.hasOwn(m.state, n));
170
+ const valued = new Set();
171
+ const values = (e) => {
172
+ switch (e.op) {
173
+ case 'get':
174
+ valued.add(e.map);
175
+ break;
176
+ case 'mul':
177
+ values(e.a);
178
+ break;
179
+ case 'add':
180
+ case 'sub':
181
+ case 'min':
182
+ case 'max':
183
+ case 'prod':
184
+ values(e.a);
185
+ values(e.b);
186
+ break;
187
+ case 'if':
188
+ values(e.then);
189
+ values(e.else);
190
+ break;
191
+ case 'var':
192
+ case 'const':
193
+ case 'tup':
194
+ case 'proj': break;
195
+ }
196
+ };
197
+ for (const n of vars) {
198
+ const u = m.step.state?.[n];
199
+ if (u)
200
+ values(u);
201
+ }
202
+ return Object.keys(m.maps ?? {}).filter(map => valued.has(map) && !mine.has(map) && m.maps[map] === 0 && !!m.step.maps?.[map] &&
203
+ !(m.inputMaps ?? []).includes(map)).slice(0, most);
204
+ }
205
+ export function coveringSeeds(m, law, declare) {
206
+ const out = [], seen = new Set();
207
+ const subst = (t, from, to) => JSON.parse(text(t), (_k, v) => (v && v.op === 'var' && v.name === from ? to : v));
208
+ let stem = 'covering';
209
+ while (text([m, law]).includes(`${stem} `))
210
+ stem += '$';
211
+ for (const shape of coveringShapes(m, law)) {
212
+ const own = declare(shape.map, k => subst(shape.term, shape.key, k), shape.plain);
213
+ if (!own)
214
+ continue;
215
+ const others = companions(m, shape).flatMap(map => { const s = declare(map, k => ({ op: 'get', map, key: k }), true); return s ? [s] : []; });
216
+ const sets = [[]];
217
+ for (const o of others)
218
+ sets.push(...sets.map(s => [...s, o]));
219
+ for (const set of sets.sort((a, b) => b.length - a.length)) {
220
+ const left = set.reduce((acc, s) => plus(acc, { op: 'var', name: s }), { op: 'var', name: own });
221
+ for (const op of ['=', '<=']) {
222
+ const tie = { op, a: left, b: shape.total };
223
+ const holds = shape.unless.length ? { op: 'or', xs: [...shape.unless, tie] } : tie;
224
+ if (seen.has(text(holds)))
225
+ continue;
226
+ seen.add(text(holds));
227
+ out.push({ name: `${stem} ${out.length}: ${[own, ...set].join(' + ')} ${op === '=' ? '=' : '≤'} its total`, holds });
228
+ }
229
+ }
230
+ }
231
+ return out;
232
+ }
233
+ // The cell facts a covering sum leans on: the sum moves only as the step says while the cells it filters by keep to
234
+ // the states the rule reaches (a counted row is never idle again), which no helper over the sum states. For the maps
235
+ // the shapes' terms read and the maps written at the same key (a row's other columns): every pair of values, of two
236
+ // of those maps, that the syntax compares a cell with, as "no key holds both". Most are false and a short run or the
237
+ // candidate check drops them; the rest are what the sums' step goals read at the written key.
238
+ export function cellSeeds(m, law, most = 160) {
239
+ const shapes = coveringShapes(m, law);
240
+ if (!shapes.length)
241
+ return [];
242
+ const guards = new Set(shapes.flatMap(s => [...reads(s.term, s.key).maps]));
243
+ const written = (map) => { const w = m.step.maps?.[map]; return !w ? undefined : 'each' in w ? 'each' : text(w.key); };
244
+ const rows = new Set([...guards].map(written).filter(k => k !== undefined));
245
+ const maps = Object.keys(m.maps ?? {}).filter(map => !(m.inputMaps ?? []).includes(map) && (guards.has(map) || rows.has(written(map) ?? ''))).slice(0, 8);
246
+ const values = new Map(maps.map(map => [map, new Set([m.maps[map]])]));
247
+ JSON.parse(text([m.step, m.assume, law.holds]), (_k, v) => {
248
+ if (v && v.op === '=')
249
+ for (const [a, b] of [[v.a, v.b], [v.b, v.a]])
250
+ if (a?.op === 'get' && b?.op === 'const' && values.has(a.map))
251
+ values.get(a.map).add(b.value);
252
+ return v;
253
+ });
254
+ let stem = 'covering';
255
+ while (text([m, law]).includes(`${stem} `))
256
+ stem += '$';
257
+ const key = `${stem}$cell`, out = [];
258
+ const is = (map, value) => ({ op: '=', a: { op: 'get', map, key: { op: 'var', name: key } }, b: { op: 'const', value } });
259
+ const lits = maps.flatMap(map => { const vs = [...values.get(map)].sort((a, b) => a - b); return vs.length <= 4 ? vs.map(value => ({ map, value })) : []; });
260
+ for (let i = 0; i < lits.length; i++)
261
+ for (let j = i + 1; j < lits.length; j++) {
262
+ const a = lits[i], b = lits[j];
263
+ if (a.map === b.map || out.length >= most)
264
+ continue;
265
+ out.push({ name: `${stem} cell ${out.length}: no key has ${a.map} = ${a.value} and ${b.map} = ${b.value}`, forall: key,
266
+ holds: { op: 'or', xs: [{ op: 'not', x: is(a.map, a.value) }, { op: 'not', x: is(b.map, b.value) }] } });
267
+ }
268
+ return out;
269
+ }
@@ -1174,3 +1174,4 @@ export declare class RoseFold<P extends Obj = {}, I extends Obj = {}, S extends
1174
1174
  }): Agreement;
1175
1175
  }
1176
1176
  export { Chart, chart, type StateNode, type Transition } from './chart.js';
1177
+ export { minimizeRun, minimizeRunDetailed, type MinimizeOptions, type Minimized, type RunRequest, type RunTrace } from './minimize.js';
package/dist/core/dsl.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { retainFrom, retainCounted, retainAggregate, publishProof, withPublicRule, retainStepProof, publishStepProof, retainLiveProof, publishLiveProof } from "./proof-output.js";
2
2
  import { searchAggregate } from "./aggregate-search.js";
3
+ import { cellSeeds, coveringSeeds } from "./covering.js";
3
4
  import { searchNow as countedSearchNow } from "./wall.js";
4
5
  // Typed builders for machines, decisions and loops: names are declared once and come back as typed values, so a
5
6
  // misspelled name, a law that reads a request, or a step that sets an undeclared variable is a TypeScript error, and
@@ -25,6 +26,7 @@ import { binder, copyVariable, encodeBinders, generatedVariable, guardReserved,
25
26
  import { candidates, cone, searchCounted } from "./counts.js";
26
27
  import { proveCandidateSeeds } from "./candidate-seeds.js";
27
28
  import { orderedPairSeed } from "./ordered-pair-seeds.js";
29
+ import { filterUnguardedSeeds, proposeUnguardedSeeds } from "./unguard-seeds.js";
28
30
  import { tryLockstepScalars } from "./lockstep.js";
29
31
  import { proveCountedCandidateSeeds } from "./counted-candidate-seeds.js";
30
32
  import { stepSeedFamilies, tryStepSeed } from "./step-seeds.js";
@@ -957,6 +959,8 @@ function sumOver(map, at, plain) {
957
959
  sumDecls.set(id, { key, term });
958
960
  return new Term(generatedVariable(id), scope?.vars[id]);
959
961
  }
962
+ // A sum over every key of a term given at a key (core/covering.ts's candidates), under sumOver's names: its variable.
963
+ const sumOfTerm = (map, at, plain) => sumOver(map, key => new Term(at(key.e)), plain).e.name;
960
964
  // The sums a set of terms reads (by name), declared.
961
965
  export const sumsIn = (ts, more = []) => {
962
966
  if (!sumDecls.size)
@@ -3622,6 +3626,50 @@ function proveRuleWall(r, laws, opts, captureMachine) {
3622
3626
  const result = ms === undefined ? run() : withWall(searchWall(ms), run);
3623
3627
  return retainFrom(translationVerdict(r, laws, result), [result]);
3624
3628
  }
3629
+ // The covering candidates of a law (core/covering.ts), tried as candidate seeds: each a law over sums the rule gains
3630
+ // (withSumsOf), one a short run breaks left out, the rest dropped or kept by proveCandidateSeeds, whose kept family the
3631
+ // kernel checks with the law. Undefined unless that is a checked proof: the search then goes on as if never asked.
3632
+ function tryCovering(r, law, ms, originalRule = r) {
3633
+ return withStageWall(countedSearchNow() + ms, () => {
3634
+ const base = r.machine;
3635
+ let kinds;
3636
+ const declare = (map, at, plain) => {
3637
+ try {
3638
+ const name = sumOfTerm(map, at, plain);
3639
+ if (!Object.hasOwn(base.sums ?? {}, name)) {
3640
+ const k = kinds ?? (kinds = r.kindLaws());
3641
+ const cand = { ...base, sums: { ...base.sums, ...sumsIn([], [name]) } };
3642
+ const { goals } = sumMachine(cand, undefined, k);
3643
+ if (goals.length && refusedSumCover(cand, k))
3644
+ return undefined;
3645
+ }
3646
+ return name;
3647
+ }
3648
+ catch (e) {
3649
+ if (e instanceof WallExpired || e instanceof WatchdogExpired)
3650
+ throw e;
3651
+ return undefined;
3652
+ }
3653
+ };
3654
+ const seeds = coveringSeeds(base, law, declare);
3655
+ if (!seeds.length)
3656
+ return undefined;
3657
+ const summed = r.withSumsOf(seeds), machine = summed.machine;
3658
+ if (refusedSumCover(machine, withKinds(summed, [law])))
3659
+ return undefined;
3660
+ const alive = seeds.filter(s => !refuteByRuns(summed, [s], [], refuteBudget, originalRule)?.run);
3661
+ if (!alive.length)
3662
+ return undefined;
3663
+ let seeded = proveCandidateSeeds(machine, withKinds(summed, [law]), alive);
3664
+ // (the sums alone first; then with the cell facts they lean on, each one a short run breaks left out)
3665
+ if (seeded.status !== 'checked')
3666
+ seeded = proveCandidateSeeds(machine, withKinds(summed, [law]), [...cellSeeds(base, law).filter(s => !refuteByRuns(summed, [s], [], refuteBudget, originalRule)?.run), ...alive], undefined, undefined, { dropUndecided: true });
3667
+ if (seeded.status !== 'checked')
3668
+ return undefined;
3669
+ const found = seeded.kept.map(l => ({ text: l.name, law: l }));
3670
+ return retainFrom({ ...verdictOf(seeded.closure), found: { laws: found }, ...withAssumes(found) }, [seeded.closure], { kind: 'inference', original: machine, laws: [law] });
3671
+ }, () => undefined);
3672
+ }
3625
3673
  function proveRuleIn(r, laws, opts, captureMachine) {
3626
3674
  const originalRule = r;
3627
3675
  r = r.withSumsOf(laws, opts.candidateSeeds?.laws ?? []);
@@ -3699,6 +3747,14 @@ function proveRuleIn(r, laws, opts, captureMachine) {
3699
3747
  opts = { ...opts, search: { ...search, ms: Math.max(0, seedMs - (countedSearchNow() - start)) } };
3700
3748
  }
3701
3749
  }
3750
+ // A law that an aggregate total covers every item (core/covering.ts): the sums that tie the total to the items, as
3751
+ // candidates, within half of the search's time (25 s at most). Kept only as a checked proof of the law.
3752
+ if (opts.search !== false && opts.from !== 'any' && !opts.candidateSeeds && laws.length === 1 && laws[0].forall &&
3753
+ search?.work === undefined && !completeWorkProfile.enabled && seedMs > 0 && Number.isFinite(seedMs)) {
3754
+ const covered = tryCovering(r, laws[0], Math.min(seedMs / 2, 25_000), originalRule);
3755
+ if (covered)
3756
+ return covered;
3757
+ }
3702
3758
  if (refuted)
3703
3759
  return searched(r, laws, [], refutedVerdict(refuted), opts, originalRule);
3704
3760
  if (r === originalRule && !opts.candidateSeeds && opts.from !== 'any' && opts.search !== false &&
@@ -3734,7 +3790,7 @@ function proveRuleIn(r, laws, opts, captureMachine) {
3734
3790
  : { proven: false, checked: false, stuck: 'unknown' };
3735
3791
  if (out)
3736
3792
  retainFrom(v, [out]);
3737
- return searched(r, laws, [], v, opts, originalRule);
3793
+ return searched(r, laws, [], v, opts, originalRule, r === originalRule ? captureMachine : undefined);
3738
3794
  }
3739
3795
  export function proveSteps(r, laws, stepLaws, opts = {}) {
3740
3796
  return watchdogVerdict(opts.watchdogMs, () => workVerdict(opts, plan => proveStepsWall(r, laws, stepLaws, plan)));
@@ -3842,9 +3898,11 @@ function stepGhosts(m, stepLaws) {
3842
3898
  // recurrences or carried lists (the rule made again with them), then invariants over what it then is. The verdict is the
3843
3899
  // prover's on the laws with what was found; when nothing is found, the prover's own (with why).
3844
3900
  let searchOriginalRule;
3845
- function searched(r, laws, stepLaws, v, opts, original = r) {
3846
- const prev = searchOriginalRule;
3901
+ let searchCaptureMachine;
3902
+ function searched(r, laws, stepLaws, v, opts, original = r, capture) {
3903
+ const prev = searchOriginalRule, prevCap = searchCaptureMachine;
3847
3904
  searchOriginalRule = original;
3905
+ searchCaptureMachine = capture;
3848
3906
  try {
3849
3907
  return searchedIn(r, laws, stepLaws, v, opts);
3850
3908
  }
@@ -3861,6 +3919,7 @@ function searched(r, laws, stepLaws, v, opts, original = r) {
3861
3919
  }
3862
3920
  finally {
3863
3921
  searchOriginalRule = prev;
3922
+ searchCaptureMachine = prevCap;
3864
3923
  }
3865
3924
  }
3866
3925
  function searchedIn(r, laws, stepLaws, v, opts) {
@@ -3970,6 +4029,31 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
3970
4029
  // (each found invariant proven from init: none where the step laws hold from any state)
3971
4030
  if (any)
3972
4031
  return { ...v, why: [v.why, 'no invariant searched for: {from: \'any\'}'].filter(Boolean).join('; ') };
4032
+ // Unguarded per-key multi-map accounting seeds (core/unguard-seeds.ts): lift guard-decoupled
4033
+ // conjuncts from latched ∀-laws, sample-filter, and check with the ordinary kernel.
4034
+ if (!stepLaws.length && !laws.some(l => l.some?.length) && Object.keys(rule.machine.maps ?? {}).length && (explicitWork !== undefined || until - clock() - tail >= 500)) {
4035
+ const fm = !lemmas && rule === r && searchCaptureMachine ? searchCaptureMachine : rule.machine;
4036
+ const raw = laws.flatMap(l => proposeUnguardedSeeds(fm, l));
4037
+ if (raw.length) {
4038
+ const draws = { params: (rand, bound) => rule.randomParams(rand, bound), input: (rand, bound, ps) => rule.randomInput(rand, bound, ps) };
4039
+ const cands = filterUnguardedSeeds(fm, raw, draws);
4040
+ const kinds = rule.kindLaws();
4041
+ for (const h of cands) {
4042
+ const rem = until - clock() - tail;
4043
+ if (explicitWork === undefined && rem < 500)
4044
+ break;
4045
+ const share = Math.min(12_000, rem / 3);
4046
+ const allLaws = [...kinds, h, ...laws];
4047
+ const out = explicitWork === undefined
4048
+ ? counted(fullRate, () => withStageDeadline(clock() + share, () => proveLaws(fm, allLaws), () => undefined), true)
4049
+ : withStageWork(remainingStageWork(explicitWork, 4), () => proveLaws(fm, allLaws), () => undefined);
4050
+ if (out?.proven && out.checked) {
4051
+ const found = [{ law: h, text: h.name }];
4052
+ return retainFrom({ proven: true, checked: true, found: { laws: found, ...(lemmas ? { lemmas } : {}) }, assumes: reachableBy(found) }, [out], { kind: 'inference', original: fm, laws });
4053
+ }
4054
+ }
4055
+ }
4056
+ }
3973
4057
  let fresh = [];
3974
4058
  if (Object.keys(rule.machine.maps ?? {}).length && until - clock() - tail > 1000) {
3975
4059
  const fm = rule.machine, share = (until - clock() - tail) / 10;
@@ -4576,3 +4660,5 @@ export class RoseFold {
4576
4660
  }
4577
4661
  // Statecharts (core/chart.ts): states nested and in parallel regions, compiled to a rule.
4578
4662
  export { Chart, chart } from "./chart.js";
4663
+ // Minimal refuting runs (core/minimize.ts): a run that breaks a law, cut down until no single request can go.
4664
+ export { minimizeRun, minimizeRunDetailed } from "./minimize.js";
@@ -5,7 +5,7 @@ import { type Source } from './extract-read.js';
5
5
  import { type ExtractOptions, type Extraction } from './extract.js';
6
6
  import { type ScheduleRule } from './effect-schedule.js';
7
7
  import { type Prim } from './effect-prims.js';
8
- export { proveRule, proveSteps } from './dsl.js';
8
+ export { minimizeRun, minimizeRunDetailed, proveRule, proveSteps } from './dsl.js';
9
9
  export { jitterRun, replaySchedule, scheduleConforms, stepper } from './effect-schedule.js';
10
10
  export { primitiveConforms, primitiveLaws, primitiveRule } from './effect-prims.js';
11
11
  type Mod = Record<string, any>;
@@ -29,7 +29,7 @@ import { Parts, readSchedule, replaySchedule, scheduleConforms, scheduleRule } f
29
29
  import { asRule, lift } from "./system.js";
30
30
  import { attachSource, inheritSource } from "./source-check.js";
31
31
  import { rewritePrims } from "./effect-prims.js";
32
- export { proveRule, proveSteps } from "./dsl.js";
32
+ export { minimizeRun, minimizeRunDetailed, proveRule, proveSteps } from "./dsl.js";
33
33
  export { jitterRun, replaySchedule, scheduleConforms, stepper } from "./effect-schedule.js";
34
34
  export { primitiveConforms, primitiveLaws, primitiveRule } from "./effect-prims.js";
35
35
  const REFS = new Set(['Ref', 'SynchronizedRef', 'SubscriptionRef', 'TxRef', 'TRef']), MAKES = ['make', 'makeUnsafe', 'unsafeMake'];
@@ -5,7 +5,7 @@ import type { Sorts } from './extract-print.js';
5
5
  import { type GoRead } from './extract-go.js';
6
6
  import { type GoCheckOptions, type GoEvidence, type GoLeaf } from './extract-go-check.js';
7
7
  import { type CRead } from './c/reader.js';
8
- export { proveRule, proveSteps } from './dsl.js';
8
+ export { minimizeRun, minimizeRunDetailed, proveRule, proveSteps } from './dsl.js';
9
9
  export type COptions = {
10
10
  entry?: string;
11
11
  methods?: string[];
@@ -30,7 +30,7 @@ import { buildCheck, builtEvidence, compileLimit, stubbed } from "./extract-step
30
30
  import { goNames, readGo, unsignedDomains } from "./extract-go.js";
31
31
  import { speak } from "./extract-go-check.js";
32
32
  import { clangDump, constantsOf, flagsFor, node, readC } from "./c/reader.js";
33
- export { proveRule, proveSteps } from "./dsl.js";
33
+ export { minimizeRun, minimizeRunDetailed, proveRule, proveSteps } from "./dsl.js";
34
34
  // (C++ that includes little, embedded code's without the standard library: its whole dump is small, read whole; else
35
35
  // only the class's, its headers' being hundreds of MB)
36
36
  const smallTUs = new Map();
@@ -1,7 +1,7 @@
1
1
  import { type Extraction } from './extract.js';
2
2
  import { type FileURL } from './extract-read.js';
3
3
  import { type SModule, type StepOptions, type StepRead } from './extract-step.js';
4
- export { proveRule, proveSteps } from './dsl.js';
4
+ export { minimizeRun, minimizeRunDetailed, proveRule, proveSteps } from './dsl.js';
5
5
  export type ExOptions = StepOptions & {
6
6
  elixir?: string;
7
7
  };
@@ -1,6 +1,6 @@
1
1
  import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
2
2
  import { asset, extractStep, node } from "./extract-step.js";
3
- export { proveRule, proveSteps } from "./dsl.js";
3
+ export { minimizeRun, minimizeRunDetailed, proveRule, proveSteps } from "./dsl.js";
4
4
  const here = (f) => asset(`ex/${f}`);
5
5
  export function readElixir(file, module, elixir = 'elixir') {
6
6
  const cp = node('node:child_process'), path = node('node:path');
@@ -3,7 +3,7 @@ import { type Arg, type Model, type FileURL } from './extract-read.js';
3
3
  import { type Extraction, type Name } from './extract.js';
4
4
  import { type Answer } from './extract-step.js';
5
5
  import { type GoCheckOptions, type GoLeaf } from './extract-go-check.js';
6
- export { proveRule, proveSteps } from './dsl.js';
6
+ export { minimizeRun, minimizeRunDetailed, proveRule, proveSteps } from './dsl.js';
7
7
  export type TT = {
8
8
  k: string;
9
9
  go?: string;
@@ -40,7 +40,7 @@ import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
40
40
  import { fromModel } from "./extract.js";
41
41
  import { asset, Stepper, iteTerm, mapWritesOf, phiP, rangeLaws, rangeOf, varTerm } from "./extract-step.js";
42
42
  import { checkGo } from "./extract-go-check.js";
43
- export { proveRule, proveSteps } from "./dsl.js";
43
+ export { minimizeRun, minimizeRunDetailed, proveRule, proveSteps } from "./dsl.js";
44
44
  const refuse = (x, what) => { throw new Refusal(typeof x === 'string' ? x : x.p || '?', what); };
45
45
  // --- the lowering: Go's JSON into the step IR, what the types decide decided here ------------------------------------
46
46
  class Go {
@@ -1,7 +1,7 @@
1
1
  import { type Extraction } from './extract.js';
2
2
  import { type FileURL } from './extract-read.js';
3
3
  import { type SModule, type StepOptions, type StepRead } from './extract-step.js';
4
- export { proveRule, proveSteps } from './dsl.js';
4
+ export { minimizeRun, minimizeRunDetailed, proveRule, proveSteps } from './dsl.js';
5
5
  export type JvmOptions = StepOptions & {
6
6
  root?: string;
7
7
  classpath?: string[];
@@ -1,6 +1,6 @@
1
1
  import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
2
2
  import { asset, compileLimit, entryNames, extractStep, node } from "./extract-step.js";
3
- export { proveRule, proveSteps } from "./dsl.js";
3
+ export { minimizeRun, minimizeRunDetailed, proveRule, proveSteps } from "./dsl.js";
4
4
  const here = (f) => asset(`jvm/${f}`);
5
5
  const TOOLS = ['Jvm.java', 'JavaReader.java', 'Harness.java', 'Rt.java'];
6
6
  // (a JVM's stack trace: its exception's line first)
@@ -1,7 +1,7 @@
1
1
  import { type Extraction } from './extract.js';
2
2
  import { type FileURL } from './extract-read.js';
3
3
  import { type SModule, type StepOptions, type StepRead } from './extract-step.js';
4
- export { proveRule, proveSteps } from './dsl.js';
4
+ export { minimizeRun, minimizeRunDetailed, proveRule, proveSteps } from './dsl.js';
5
5
  export type PyOptions = StepOptions & {
6
6
  root?: string;
7
7
  python?: string;
@@ -1,6 +1,6 @@
1
1
  import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
2
2
  import { asset, entryNames, extractStep, node } from "./extract-step.js";
3
- export { proveRule, proveSteps } from "./dsl.js";
3
+ export { minimizeRun, minimizeRunDetailed, proveRule, proveSteps } from "./dsl.js";
4
4
  const here = (f) => asset(`py/${f}`);
5
5
  // The module as the reader lowers it (the names given and the module's functions).
6
6
  export function readPython(file, names, opts = {}) {