gdp-wired 0.24.0 → 0.26.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.
Files changed (52) hide show
  1. package/README.md +14 -9
  2. package/dist/core/accel.d.ts +44 -0
  3. package/dist/core/accel.js +955 -0
  4. package/dist/core/bmc.d.ts +8 -0
  5. package/dist/core/bmc.js +263 -97
  6. package/dist/core/cycles.d.ts +2 -3
  7. package/dist/core/cycles.js +409 -174
  8. package/dist/core/cyclic.d.ts +4 -1
  9. package/dist/core/cyclic.js +86 -64
  10. package/dist/core/data.d.ts +9 -1
  11. package/dist/core/data.js +872 -168
  12. package/dist/core/discover.js +2 -3
  13. package/dist/core/dsl.d.ts +3 -2
  14. package/dist/core/dsl.js +21 -18
  15. package/dist/core/exists.js +7 -14
  16. package/dist/core/extract-check.d.ts +3 -2
  17. package/dist/core/extract-check.js +137 -50
  18. package/dist/core/extract-print.d.ts +1 -0
  19. package/dist/core/extract-print.js +26 -3
  20. package/dist/core/extract-read.d.ts +85 -4
  21. package/dist/core/extract-read.js +295 -34
  22. package/dist/core/extract-shapes.d.ts +14 -0
  23. package/dist/core/extract-shapes.js +608 -78
  24. package/dist/core/extract-xstate.d.ts +5 -1
  25. package/dist/core/extract-xstate.js +618 -184
  26. package/dist/core/extract.js +73 -27
  27. package/dist/core/infer.d.ts +1 -0
  28. package/dist/core/infer.js +364 -40
  29. package/dist/core/machine.d.ts +6 -0
  30. package/dist/core/machine.js +35 -3
  31. package/dist/core/nonterm.d.ts +9 -2
  32. package/dist/core/nonterm.js +173 -9
  33. package/dist/core/q.d.ts +1 -0
  34. package/dist/core/q.js +2 -2
  35. package/dist/core/relation.d.ts +1 -0
  36. package/dist/core/relation.js +95 -39
  37. package/dist/core/solver.d.ts +12 -0
  38. package/dist/core/solver.js +76 -30
  39. package/dist/core/transfer.js +23 -14
  40. package/dist/core/translate.d.ts +1 -1
  41. package/dist/core/translate.js +22 -49
  42. package/dist/core/xstate.d.ts +6 -1
  43. package/dist/core/xstate.js +336 -55
  44. package/dist/kernel/cdcl.d.ts +5 -0
  45. package/dist/kernel/cdcl.js +44 -8
  46. package/dist/kernel/prove.d.ts +6 -1
  47. package/dist/kernel/prove.js +101 -85
  48. package/dist/kernel/reader.d.ts +1 -0
  49. package/dist/kernel/reader.js +4 -3
  50. package/dist/kernel/simplex.d.ts +1 -1
  51. package/dist/kernel/simplex.js +13 -1
  52. package/package.json +3 -2
@@ -23,6 +23,7 @@ export declare function fixed(hyps: C[]): {
23
23
  hyps: C[];
24
24
  fixed: Record<string, number>;
25
25
  } | undefined;
26
+ export declare function tidier(bools: Set<string>): (cs: C[]) => C[];
26
27
  export declare function relax(hyps: C[]): C[] | undefined;
27
28
  export declare function reduce(hyps: C[]): {
28
29
  hyps: C[];
@@ -47,3 +48,10 @@ export declare function forcedRun(m: Machine, laws: Law[], opts: {
47
48
  guesses?: number;
48
49
  }): BoundedRun | undefined;
49
50
  export declare function findBoundedRun(m: Machine, laws: Law[], opts: BmcOptions): BoundedRun | undefined;
51
+ export type BoundedSearch = {
52
+ run: (ms: number, wall?: number) => BoundedRun | 'over' | 'paused';
53
+ depth: () => number;
54
+ };
55
+ export declare function boundedSearch(m: Machine, laws: Law[], opts: Omit<BmcOptions, 'ms' | 'wall'> & {
56
+ forcedMs: number;
57
+ }): BoundedSearch | undefined;
package/dist/core/bmc.js CHANGED
@@ -26,7 +26,8 @@ import { stepLawObligations, substC, substE } from "../kernel/kernel.js";
26
26
  import { clock, counted } from "../kernel/prove.js";
27
27
  import { REFUTED, cdclSession, growCdcl } from "../kernel/cdcl.js";
28
28
  import { allowed } from "./watch.js";
29
- import { simpC, simpE } from "./nonterm.js";
29
+ import { isF as isFalse, isT as isTrue, simpC, simpE } from "./nonterm.js";
30
+ import { env, linOfE, plus, vars } from "./solver.js";
30
31
  // Machines whose runs the goals describe as they are: scalars only (no maps, history or carried maps), no quantified
31
32
  // flag, no function but division by a constant (whose facts fix its value); laws plain (no key, no "there exists").
32
33
  export function bmcFits(m, laws) {
@@ -49,8 +50,7 @@ export const bmcRate = 250;
49
50
  // A forced run's share of the budget, and its steps at most (a derivation checkDerivation replays step by step).
50
51
  const forcedShare = 0.3, forcedSteps = 1_000_000;
51
52
  // GDP_BMC_RELAX=0: no relaxed goal first; GDP_BMC_INC=0: each depth's goal a search of its own (for comparing).
52
- const env = globalThis.process?.env ?? {};
53
- const useRelax = env.GDP_BMC_RELAX !== '0', useInc = env.GDP_BMC_INC !== '0';
53
+ const useRelax = env.GDP_BMC_RELAX !== '0', useInc = env.GDP_BMC_INC !== '0', useTidy = env.GDP_BMC_TIDY !== '0';
54
54
  // The goal of depth k: a run of k steps from the start whose last state breaks a law.
55
55
  export function bmcGoal(m, laws, k) {
56
56
  const start = { op: 'and', xs: Object.entries(m.state).map(([n, e]) => ({ op: '=', a: { op: 'var', name: n }, b: e })) };
@@ -64,8 +64,6 @@ export function bmcGoal(m, laws, k) {
64
64
  // terms folded (core/nonterm.ts's simpC), until none is left; the names fixed, with their values (a model's part), or
65
65
  // undefined where a hypothesis folds to false (no model).
66
66
  const top = (c) => (c.op === 'and' ? c.xs.flatMap(top) : [c]);
67
- const isFalse = (c) => (c.op === '<' || c.op === '<=') && c.a.op === 'const' && c.b.op === 'const' && (c.op === '<' ? c.a.value >= c.b.value : c.a.value > c.b.value);
68
- const isTrue = (c) => c.op === '<=' && c.a.op === 'const' && c.b.op === 'const' && c.a.value <= c.b.value;
69
67
  export function fixed(hyps) {
70
68
  const values = {};
71
69
  let cs = hyps.flatMap(top);
@@ -133,6 +131,120 @@ const occurrences = (xs, out = new Map()) => {
133
131
  xs.forEach(go);
134
132
  return out;
135
133
  };
134
+ // The goal tidied, keeping its models (`tidy`): a comparison whose sides differ by a constant (x5 = 10 + x5, the CHC's
135
+ // pairs read on both sides) folded to its truth, and a yes/no copied through an if (b~1 = if y = 1 then 1 else 0, how a
136
+ // CHC Bool argument is written) read as the copy itself where y is a yes/no (0 or 1: an input the assumption bounds by 1,
137
+ // or a state value every step writes as one), so `reduce` puts it in. Each step's yes/no values are the inputs a
138
+ // hypothesis bounds by 1 and the names an equation gives a 0/1 value.
139
+ const diffConst = (a, b) => {
140
+ const l = linOfE(a), r = l && linOfE(b), d = r && plus(l, r, -1);
141
+ return d && !vars(d).length ? d['1'] ?? 0 : undefined;
142
+ };
143
+ const T0 = { op: '<=', a: { op: 'const', value: 0 }, b: { op: 'const', value: 0 } }, F0 = { op: '<', a: { op: 'const', value: 0 }, b: { op: 'const', value: 0 } };
144
+ export function tidier(bools) {
145
+ const memo = new WeakMap();
146
+ const isBool = (e) => (e.op === 'const' ? e.value === 0 || e.value === 1 : e.op === 'var' ? bools.has(e.name) : e.op === 'if' ? isBool(e.then) && isBool(e.else) : false);
147
+ const oneOf = (c) => (c.op === '=' && c.a.op === 'var' && bools.has(c.a.name) && c.b.op === 'const' && c.b.value === 1 ? c.a.name : c.op === '=' && c.b.op === 'var' && bools.has(c.b.name) && c.a.op === 'const' && c.a.value === 1 ? c.b.name : undefined);
148
+ const e1 = (e) => {
149
+ const hit = memo.get(e);
150
+ if (hit)
151
+ return hit;
152
+ let out = e;
153
+ switch (e.op) {
154
+ case 'add':
155
+ case 'sub':
156
+ case 'min':
157
+ case 'max':
158
+ case 'prod': {
159
+ const a = e1(e.a), b = e1(e.b);
160
+ if (a !== e.a || b !== e.b)
161
+ out = { ...e, a, b };
162
+ break;
163
+ }
164
+ case 'mul': {
165
+ const a = e1(e.a);
166
+ if (a !== e.a)
167
+ out = { ...e, a };
168
+ break;
169
+ }
170
+ case 'if': {
171
+ const c = c1(e.c), t = e1(e.then), f = e1(e.else), v = oneOf(c);
172
+ if (v !== undefined && t.op === 'const' && t.value === 1 && f.op === 'const' && f.value === 0)
173
+ out = { op: 'var', name: v };
174
+ else if (c.op === '<=' && c.a.op === 'const' && c.b.op === 'const')
175
+ out = c.a.value <= c.b.value ? t : f;
176
+ else if (c.op === '<' && c.a.op === 'const' && c.b.op === 'const')
177
+ out = c.a.value < c.b.value ? t : f;
178
+ else if (c !== e.c || t !== e.then || f !== e.else)
179
+ out = { op: 'if', c, then: t, else: f };
180
+ break;
181
+ }
182
+ case 'get': {
183
+ const key = e1(e.key);
184
+ if (key !== e.key)
185
+ out = { ...e, key };
186
+ break;
187
+ }
188
+ case 'var':
189
+ case 'const': break;
190
+ }
191
+ memo.set(e, out);
192
+ return out;
193
+ };
194
+ const c1 = (c) => {
195
+ const hit = memo.get(c);
196
+ if (hit)
197
+ return hit;
198
+ let out = c;
199
+ switch (c.op) {
200
+ case '<=':
201
+ case '<':
202
+ case '=': {
203
+ const a = e1(c.a), b = e1(c.b), d = diffConst(a, b);
204
+ if (d !== undefined)
205
+ out = (c.op === '<=' ? d <= 0 : c.op === '<' ? d < 0 : d === 0) ? T0 : F0;
206
+ else if (a !== c.a || b !== c.b)
207
+ out = { op: c.op, a, b };
208
+ break;
209
+ }
210
+ case 'and':
211
+ case 'or': {
212
+ const xs = c.xs.map(c1);
213
+ if (xs.some((x, i) => x !== c.xs[i]))
214
+ out = simpC({ op: c.op, xs });
215
+ break;
216
+ }
217
+ case 'not': {
218
+ const x = c1(c.x);
219
+ if (x !== c.x)
220
+ out = simpC({ op: 'not', x });
221
+ break;
222
+ }
223
+ case 'flag':
224
+ case 'all': break;
225
+ }
226
+ memo.set(c, out);
227
+ return out;
228
+ };
229
+ // Learns the yes/no names of some hypotheses (a bound by 1, an equation giving a 0/1 value), then tidies them.
230
+ return (cs) => {
231
+ for (const c of cs) {
232
+ if (c.op === '<=' && c.a.op === 'var' && c.b.op === 'const' && c.b.value <= 1)
233
+ bools.add(c.a.name);
234
+ if (c.op === '<' && c.a.op === 'var' && c.b.op === 'const' && c.b.value <= 2)
235
+ bools.add(c.a.name);
236
+ }
237
+ for (let again = true; again;) {
238
+ again = false;
239
+ for (const c of cs)
240
+ if (c.op === '=' && c.a.op === 'var' && !bools.has(c.a.name) && isBool(e1(c.b))) {
241
+ bools.add(c.a.name);
242
+ again = true;
243
+ }
244
+ }
245
+ return cs.map(c1);
246
+ };
247
+ }
136
248
  // The goal relaxed (above): each pair written normalized at a step (n = a ∸ b and n$neg = b ∸ a, its partner the name
137
249
  // with $neg before the step's ~j) as one equation of differences.
138
250
  const partnerOf = (n) => (n.includes('$neg') ? undefined : n.replace(/(~\d+)?$/, j => `$neg${j}`));
@@ -249,6 +361,10 @@ export function replay(m, laws, run) {
249
361
  // steps; the k-step goals fold to false without a case past depth 64) are its runs; a machine whose steps read their
250
362
  // requests stops within a few steps. The run, as a bounded run's.
251
363
  export function forcedRun(m, laws, opts) {
364
+ const out = forcedRunner(m, laws, opts)?.(opts.wall);
365
+ return typeof out === 'object' ? out : undefined;
366
+ }
367
+ function forcedRunner(m, laws, opts) {
252
368
  if (m.params.length || !laws.length || !bmcFits(m, laws))
253
369
  return undefined;
254
370
  // Each input bounded by the assumption (a top-level i < c or i <= c, c at most 64): its values; the others free.
@@ -309,38 +425,48 @@ export function forcedRun(m, laws, opts) {
309
425
  } };
310
426
  const broken = (st) => laws.find(l => !evalC(l.holds, {}, st, m))?.name;
311
427
  const requests = choices.map(ch => ({ ...Object.fromEntries(free.map(i => [i, 0])), ...ch }));
312
- let st = js.init({}), guesses = opts.guesses ?? 2;
428
+ let st = js.init({}), guesses = opts.guesses ?? 2, n = 0, over = false;
313
429
  const trace = [];
314
- for (let n = 0; n < opts.steps && (n % 256 || performance.now() < opts.wall); n++) {
315
- let next, request, forced = true;
316
- for (const [j, input] of requests.entries()) {
317
- if (at[j].some(([n, v]) => st.scalars[n] !== v))
318
- continue;
319
- const a = take(st, input);
320
- if (!a)
321
- continue;
322
- const law = broken(a);
323
- if (law !== undefined) {
324
- const { [ok]: _, ...before } = st.scalars;
325
- return { law, depth: n + 1, witness: { ...before, ...numbersOf(input) }, params: {}, trace: [...trace, input] };
430
+ return (wall) => {
431
+ if (over)
432
+ return 'over';
433
+ for (; n < opts.steps; n++) {
434
+ if (!(n % 256) && performance.now() >= wall)
435
+ return 'paused';
436
+ let next, request, forced = true;
437
+ for (const [j, input] of requests.entries()) {
438
+ if (at[j].some(([x, v]) => st.scalars[x] !== v))
439
+ continue;
440
+ const a = take(st, input);
441
+ if (!a)
442
+ continue;
443
+ const law = broken(a);
444
+ if (law !== undefined) {
445
+ const { [ok]: _, ...before } = st.scalars;
446
+ over = true;
447
+ return { law, depth: n + 1, witness: { ...before, ...numbersOf(input) }, params: {}, trace: [...trace, input] };
448
+ }
449
+ if (same(a, st))
450
+ continue;
451
+ if (reads[j])
452
+ forced = false;
453
+ if (!next) {
454
+ next = a;
455
+ request = input;
456
+ }
457
+ else if (!same(next, a))
458
+ forced = false;
326
459
  }
327
- if (same(a, st))
328
- continue;
329
- if (reads[j])
330
- forced = false;
331
- if (!next) {
332
- next = a;
333
- request = input;
460
+ if (!next || (!forced && --guesses < 0)) {
461
+ over = true;
462
+ return 'over';
334
463
  }
335
- else if (!same(next, a))
336
- forced = false;
464
+ trace.push(request);
465
+ st = next;
337
466
  }
338
- if (!next || (!forced && --guesses < 0))
339
- return undefined;
340
- trace.push(request);
341
- st = next;
342
- }
343
- return undefined;
467
+ over = true;
468
+ return 'over';
469
+ };
344
470
  }
345
471
  // The deeper goals as one growing goal, for one CDCL search kept from depth to depth (kernel/cdcl.ts's cdclSession):
346
472
  // each step's hypotheses written once, in names that stay (the state after step j as n~j, the j-th request as input@j),
@@ -356,7 +482,7 @@ function unrolled(m, laws) {
356
482
  const stateAt = (j) => Object.fromEntries(Object.keys(m.state).map(n => [n, j === 0 ? m.state[n] : v(`${n}~${j}`)]));
357
483
  const put = (c) => simpC(substC(c, { vars: sub, maps: {}, flags: {} }));
358
484
  let k = 0, dead = false;
359
- const session = cdclSession(goal, new Map(), { model: true });
485
+ const session = cdclSession(goal, new Map(), { model: true }), tidy = useTidy ? tidier(new Set()) : (cs) => cs;
360
486
  // The cone of influence: the state values the laws, the assumption or the precondition read, and those the updates of
361
487
  // these read, again until no more; the others' terms are left out at every step (no hypothesis reads them, and the
362
488
  // interpreter takes the run's own values).
@@ -377,7 +503,7 @@ function unrolled(m, laws) {
377
503
  const raw = [...(j === 1 && m.pre ? [m.pre] : []), ...(m.assume ? [substC(m.assume, at)] : []), ...[...live].map((n) => ({ op: '=', a: v(`${n}~${j}`), b: substE(m.step.state?.[n] ?? v(n), at) }))];
378
504
  let cs = (useRelax ? relax(raw) : undefined) ?? raw;
379
505
  for (;;) {
380
- cs = cs.map(put).flatMap(top);
506
+ cs = tidy(cs.map(put).flatMap(top)).flatMap(top);
381
507
  if (cs.some(isFalse))
382
508
  return undefined;
383
509
  cs = cs.filter(c => !isTrue(c));
@@ -433,77 +559,117 @@ function unrolled(m, laws) {
433
559
  goal.hyps.push({ op: 'or', xs: [{ op: '<=', a: K(1), b: v(`act@${k}`) }, query] });
434
560
  return { k, out: session.run(b, wall, { [`act@${k}`]: 1 }) };
435
561
  };
436
- return { next, defs };
562
+ // The same depth's query asked again (its search cut short by its budget), its hypotheses already in.
563
+ const again = (b, wall) => ({ k, out: dead ? 'impossible' : session.run(b, wall, { [`act@${k}`]: 1 }) });
564
+ return { next, again, defs };
437
565
  }
438
566
  export function findBoundedRun(m, laws, opts) {
567
+ // A forced run first, within forcedShare of the budget (as wall time: it is the compiled rule's, not the kernel's).
568
+ const now = performance.now(), end = Math.min(opts.wall ?? Infinity, now + opts.ms);
569
+ const out = boundedSearch(m, laws, { ...opts, forcedMs: forcedShare * (end - now) })?.run(opts.ms, opts.wall);
570
+ return typeof out === 'object' ? out : undefined;
571
+ }
572
+ export function boundedSearch(m, laws, opts) {
439
573
  if (!laws.length || !bmcFits(m, laws))
440
574
  return undefined;
441
575
  const last = Math.min(64, opts.depth ?? 64);
442
- // A forced run first, within forcedShare of the budget (as wall time: it is the compiled rule's, not the kernel's).
443
- const now = performance.now(), end = Math.min(opts.wall ?? Infinity, now + opts.ms);
444
- const forced = forcedRun(m, laws, { steps: forcedSteps, wall: now + forcedShare * (end - now) });
445
- if (forced)
446
- return forced;
447
- return counted(bmcRate, () => {
448
- const until = clock() + opts.ms;
449
- const inc = useInc && !(opts.from && opts.from > 1) && !Object.keys(m.fns ?? {}).length && !Object.keys(m.step.flags ?? {}).length ? unrolled(m, laws) : undefined;
450
- for (let k = opts.from ?? 1; k <= last && clock() < until && !(opts.wall !== undefined && performance.now() > opts.wall); k++) {
451
- const t0 = clock();
452
- if (inc) {
453
- const { out } = inc.next({ nodes: 0, until }, opts.wall);
454
- if (out === 'impossible') {
455
- opts.progress?.(k, 'refuted', Math.round(clock() - t0));
456
- return undefined;
576
+ const forced = forcedRunner(m, laws, { steps: forcedSteps });
577
+ let forcedLeft = forced === undefined ? 0 : opts.forcedMs, over = false, again = false;
578
+ let inc, made = false, k = opts.from ?? 1;
579
+ const run = (ms, wall) => {
580
+ if (over)
581
+ return 'over';
582
+ if (forced && forcedLeft > 0) {
583
+ const t0 = performance.now(), out = forced(Math.min(wall ?? Infinity, t0 + forcedLeft));
584
+ forcedLeft -= performance.now() - t0;
585
+ if (typeof out === 'object') {
586
+ over = true;
587
+ return out;
588
+ }
589
+ if (out === 'over')
590
+ forcedLeft = 0;
591
+ else if (wall !== undefined && performance.now() >= wall)
592
+ return 'paused';
593
+ }
594
+ return counted(bmcRate, () => {
595
+ const until = clock() + ms;
596
+ const late = () => clock() >= until || (wall !== undefined && performance.now() >= wall);
597
+ if (!made) {
598
+ made = true;
599
+ inc = useInc && !(opts.from && opts.from > 1) && !Object.keys(m.fns ?? {}).length && !Object.keys(m.step.flags ?? {}).length ? unrolled(m, laws) : undefined;
600
+ }
601
+ const done = (out) => { over = true; return out; };
602
+ for (; k <= last; k++) {
603
+ if (late())
604
+ return 'paused';
605
+ const t0 = clock();
606
+ if (inc) {
607
+ const { out } = again ? inc.again({ nodes: 0, until }, wall) : inc.next({ nodes: 0, until }, wall);
608
+ again = false;
609
+ if (out === 'impossible') {
610
+ opts.progress?.(k, 'refuted', Math.round(clock() - t0));
611
+ return done('over');
612
+ }
613
+ if (out === 'refuted' || 'tree' in out || out.why === REFUTED) {
614
+ opts.progress?.(k, 'refuted', Math.round(clock() - t0));
615
+ continue;
616
+ }
617
+ if (out.stuck !== 'sat' || !out.witness) {
618
+ opts.progress?.(k, 'unknown', Math.round(clock() - t0));
619
+ if (out.why === 'time' && late()) {
620
+ again = true;
621
+ return 'paused';
622
+ }
623
+ return done('over');
624
+ }
625
+ const run = runOf(m, putBack(m, out.witness, inc.defs), k), broken = replay(m, laws, run);
626
+ if (broken) {
627
+ opts.progress?.(k, 'sat', Math.round(clock() - t0));
628
+ return done({ law: broken.law, witness: broken.witness, depth: broken.steps, params: run.params, trace: run.trace.slice(0, broken.steps) });
629
+ }
630
+ // (a model the interpreter refuses: the goal itself asked at this depth, below)
631
+ }
632
+ let goal;
633
+ try {
634
+ goal = bmcGoal(m, laws, k);
635
+ }
636
+ catch {
637
+ return done('over');
457
638
  }
458
- if (out === 'refuted' || 'tree' in out || out.why === REFUTED) {
639
+ const f = fixed(goal.hyps);
640
+ if (!f) {
459
641
  opts.progress?.(k, 'refuted', Math.round(clock() - t0));
460
642
  continue;
461
643
  }
462
- if (out.stuck !== 'sat' || !out.witness) {
463
- opts.progress?.(k, 'unknown', Math.round(clock() - t0));
464
- return undefined;
644
+ // The goal asked (relaxed or as it is), reduced: refuted, or a run that breaks a law, or neither (undefined).
645
+ const ask = (hyps) => {
646
+ const r = reduce(hyps);
647
+ if (!r)
648
+ return 'refuted';
649
+ const out = growCdcl({ name: goal.name, hyps: r.hyps }, new Map(), { nodes: 0, until }, { model: true, ...(wall !== undefined ? { wall } : {}) });
650
+ if ('tree' in out || out.why === REFUTED)
651
+ return 'refuted';
652
+ if (out.stuck !== 'sat' || !out.witness)
653
+ return 'unknown';
654
+ const run = runOf(m, putBack(m, { ...out.witness, ...f.fixed }, r.defs), k), broken = replay(m, laws, run);
655
+ return broken ? { law: broken.law, witness: broken.witness, depth: broken.steps, params: run.params, trace: run.trace.slice(0, broken.steps) } : 'sat';
656
+ };
657
+ const relaxed = useRelax && !inc ? relax(f.hyps) : undefined;
658
+ let got = relaxed ? ask(relaxed) : 'sat';
659
+ if (got === 'sat')
660
+ got = ask(f.hyps);
661
+ // (out of its budget: this depth asked again next time; with a session, its query too, as it stands)
662
+ opts.progress?.(k, typeof got === 'string' ? got : 'sat', Math.round(clock() - t0));
663
+ if (got === 'unknown' && late()) {
664
+ again = !!inc;
665
+ return 'paused';
465
666
  }
466
- const run = runOf(m, putBack(m, out.witness, inc.defs), k), broken = replay(m, laws, run);
467
- if (broken) {
468
- opts.progress?.(k, 'sat', Math.round(clock() - t0));
469
- return { law: broken.law, witness: broken.witness, depth: broken.steps, params: run.params, trace: run.trace.slice(0, broken.steps) };
470
- }
471
- // (a model the interpreter refuses: the goal itself asked at this depth, below)
472
- }
473
- let goal;
474
- try {
475
- goal = bmcGoal(m, laws, k);
476
- }
477
- catch {
478
- return undefined;
479
- }
480
- const f = fixed(goal.hyps);
481
- if (!f) {
482
- opts.progress?.(k, 'refuted', Math.round(clock() - t0));
483
- continue;
667
+ if (got === 'refuted')
668
+ continue;
669
+ return done(typeof got === 'string' ? 'over' : got);
484
670
  }
485
- // The goal asked (relaxed or as it is), reduced: refuted, or a run that breaks a law, or neither (undefined).
486
- const ask = (hyps) => {
487
- const r = reduce(hyps);
488
- if (!r)
489
- return 'refuted';
490
- const out = growCdcl({ name: goal.name, hyps: r.hyps }, new Map(), { nodes: 0, until }, { model: true, ...(opts.wall !== undefined ? { wall: opts.wall } : {}) });
491
- if ('tree' in out || out.why === REFUTED)
492
- return 'refuted';
493
- if (out.stuck !== 'sat' || !out.witness)
494
- return 'unknown';
495
- const run = runOf(m, putBack(m, { ...out.witness, ...f.fixed }, r.defs), k), broken = replay(m, laws, run);
496
- return broken ? { law: broken.law, witness: broken.witness, depth: broken.steps, params: run.params, trace: run.trace.slice(0, broken.steps) } : 'sat';
497
- };
498
- const relaxed = useRelax && !inc ? relax(f.hyps) : undefined;
499
- let got = relaxed ? ask(relaxed) : 'sat';
500
- if (got === 'sat')
501
- got = ask(f.hyps);
502
- opts.progress?.(k, typeof got === 'string' ? got : 'sat', Math.round(clock() - t0));
503
- if (got === 'refuted')
504
- continue;
505
- return typeof got === 'string' ? undefined : got;
506
- }
507
- return undefined;
508
- });
671
+ return done('over');
672
+ });
673
+ };
674
+ return { run, depth: () => k };
509
675
  }
@@ -1,4 +1,5 @@
1
1
  import type { C, E, Law, Machine, Request } from './machine.js';
2
+ import { argsKey } from './machine.js';
2
3
  import type { Liveness, Loop, Tree } from '../kernel/kernel.js';
3
4
  import { type Cyclic, type Fact } from '../kernel/cyclic.js';
4
5
  import { type NodeSpec } from './cyclic.js';
@@ -34,8 +35,7 @@ export type CycleVerdict = {
34
35
  witness?: Record<string, number>;
35
36
  why?: string;
36
37
  };
37
- export declare const pairE: (a: E, b: E) => E;
38
- export declare const argsKey: (args: E[]) => E;
38
+ export { argsKey };
39
39
  export declare const linE: (coef: Record<string, number>, c: number) => E;
40
40
  export declare const showE: (e: E) => string;
41
41
  export declare const showC: (c: C) => string;
@@ -141,4 +141,3 @@ export declare function cycleLemmas(m: Machine, laws: Law[], stepLaws?: StepLaw[
141
141
  proof?: Cyclic;
142
142
  why?: string;
143
143
  };
144
- export {};