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