gdp-wired 0.22.0 → 0.24.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 +27 -2
- package/dist/core/bmc.d.ts +49 -0
- package/dist/core/bmc.js +509 -0
- package/dist/core/check.d.ts +1 -1
- package/dist/core/check.js +19 -6
- package/dist/core/cycles.d.ts +38 -0
- package/dist/core/cycles.js +531 -43
- package/dist/core/data.d.ts +25 -1
- package/dist/core/data.js +984 -215
- package/dist/core/discover.js +8 -3
- package/dist/core/dsl.d.ts +17 -3
- package/dist/core/dsl.js +81 -15
- package/dist/core/extract-check.d.ts +77 -0
- package/dist/core/extract-check.js +785 -0
- package/dist/core/extract-ir.d.ts +139 -0
- package/dist/core/extract-ir.js +198 -0
- package/dist/core/extract-print.d.ts +30 -0
- package/dist/core/extract-print.js +426 -0
- package/dist/core/extract-read.d.ts +298 -0
- package/dist/core/extract-read.js +1298 -0
- package/dist/core/extract-shapes.d.ts +13 -0
- package/dist/core/extract-shapes.js +993 -0
- package/dist/core/extract-xstate.d.ts +34 -0
- package/dist/core/extract-xstate.js +320 -0
- package/dist/core/extract.d.ts +31 -0
- package/dist/core/extract.js +249 -0
- package/dist/core/infer.js +518 -5
- package/dist/core/kind.d.ts +30 -0
- package/dist/core/kind.js +81 -0
- package/dist/core/nonterm.d.ts +34 -0
- package/dist/core/nonterm.js +610 -0
- package/dist/core/q.d.ts +17 -0
- package/dist/core/q.js +52 -0
- package/dist/core/rationals.d.ts +112 -0
- package/dist/core/rationals.js +281 -0
- package/dist/core/relation.d.ts +28 -0
- package/dist/core/relation.js +483 -0
- package/dist/core/solver.d.ts +5 -2
- package/dist/core/solver.js +65 -20
- package/dist/core/transfer.d.ts +3 -3
- package/dist/core/transfer.js +69 -42
- package/dist/core/xstate.d.ts +6 -0
- package/dist/core/xstate.js +70 -12
- package/dist/kernel/cdcl.d.ts +13 -0
- package/dist/kernel/cdcl.js +307 -236
- package/dist/kernel/kernel.d.ts +106 -0
- package/dist/kernel/kernel.js +342 -0
- package/dist/kernel/prove.js +14 -3
- package/dist/kernel/qprove.d.ts +18 -0
- package/dist/kernel/qprove.js +157 -0
- package/dist/kernel/reader.d.ts +14 -0
- package/dist/kernel/reader.js +102 -14
- package/dist/kernel/simplex.d.ts +4 -0
- package/dist/kernel/simplex.js +38 -11
- package/dist/lean-kernel/emit.d.ts +46 -1
- package/dist/lean-kernel/emit.js +125 -16
- package/dist/lean-kernel/library.js +4 -1
- package/dist/lean-kernel/qlean.d.ts +26 -0
- package/dist/lean-kernel/qlean.js +105 -0
- package/package.json +16 -3
package/dist/kernel/cdcl.js
CHANGED
|
@@ -39,14 +39,36 @@ function localize(rows, steps) {
|
|
|
39
39
|
});
|
|
40
40
|
return { inputs, steps: out };
|
|
41
41
|
}
|
|
42
|
+
// An atom's variable: the smaller of its canonical text and its flip's (remembered per form).
|
|
43
|
+
const keyMemo = new WeakMap();
|
|
44
|
+
const keyOf = (lin) => {
|
|
45
|
+
let key = keyMemo.get(lin);
|
|
46
|
+
if (key === undefined) {
|
|
47
|
+
const a = canon(lin), b = canonFlip(lin);
|
|
48
|
+
keyMemo.set(lin, (key = b < a ? b : a));
|
|
49
|
+
}
|
|
50
|
+
return key;
|
|
51
|
+
};
|
|
42
52
|
// GDP_CDCL_LP=0: each node solved by elimination alone (no simplex); GDP_CDCL_FILL (8): the simplex's tableau begun
|
|
43
53
|
// again past this many entries a row the node reads (research/step's comparisons).
|
|
44
54
|
const env = globalThis.process?.env ?? {};
|
|
45
55
|
const lpFill = Number(env.GDP_CDCL_FILL ?? 8), useLp = env.GDP_CDCL_LP !== '0', verify = env.GDP_CDCL_VERIFY === '1';
|
|
46
56
|
// Counters research/step reads (times only while `on`).
|
|
47
57
|
export const cdclStats = { on: false, runs: 0, proven: 0, conflicts: 0, decisions: 0, solveMs: 0, rowsMs: 0, coreMs: 0, unfoldMs: 0, leaves: 0, resolved: 0, coreSize: 0, pathSize: 0, lpMisses: 0, resolved2: 0, unfoldWhy: '', orderMs: 0, boundMs: 0, openMisses: 0, lpMs: 0, lpUnknown: 0, fmCalls: 0, pivots: 0, lpRebuilds: 0, lpRows: 0, lpNnz: 0, lpVars: 0, lpLoad: 0, nodes: 0, boundRounds: 0 };
|
|
58
|
+
// `opts.model`: only whether the goal has a model is wanted (core/bmc.ts): a refutation isn't unfolded into a tree, its
|
|
59
|
+
// outcome `unknown` with `why` REFUTED; each decision's phase is the simplex's point's (phaseAtPoint); past `opts.wall` (wall time) the search stops as past its budget.
|
|
60
|
+
export const REFUTED = 'refuted, not unfolded';
|
|
48
61
|
export function growCdcl(goal, root, budget, opts = {}) {
|
|
49
|
-
|
|
62
|
+
return cdclSession(goal, root, opts).run(budget, opts.wall);
|
|
63
|
+
}
|
|
64
|
+
// A search kept from one run to the next (core/bmc.ts's deeper goals): its atoms, their activities and phases, its learned
|
|
65
|
+
// clauses and the simplex's tableau. Between runs the caller may add hypotheses to the goal (goal.hyps grows; none is
|
|
66
|
+
// taken away), so every clause learned stays a consequence of the goal. A run may assume an atom (`assume`, decided
|
|
67
|
+
// first, at level 1): where the search learns it false the run ends refuted (REFUTED), as where nothing is assumed and
|
|
68
|
+
// the goal is refuted. Each run's own budget: nodes, `until` on the counted clock, `wall`.
|
|
69
|
+
export function cdclSession(goal, root, opts = {}) {
|
|
70
|
+
let until = Infinity, budget = { nodes: 0 }, wall, assumed;
|
|
71
|
+
const st = cdclStats, timing = st.on;
|
|
50
72
|
const t = (f, add) => { if (!timing)
|
|
51
73
|
return f(); const t0 = performance.now(); try {
|
|
52
74
|
return f();
|
|
@@ -61,9 +83,9 @@ export function growCdcl(goal, root, budget, opts = {}) {
|
|
|
61
83
|
let inc = 1;
|
|
62
84
|
// An atom as a variable: the stored form is the one whose canonical text is the variable's name (the smaller).
|
|
63
85
|
const ensure = (lin) => {
|
|
64
|
-
const
|
|
86
|
+
const key = keyOf(lin);
|
|
65
87
|
if (!vars.has(key)) {
|
|
66
|
-
const stored = flip ? atomOf(lin, false).lin : lin;
|
|
88
|
+
const flip = key !== canon(lin), stored = flip ? atomOf(lin, false).lin : lin;
|
|
67
89
|
vars.set(key, { lin: stored, terms: Object.entries(stored).filter(([x0]) => x0 !== '1'), level: -1, at: -1, act: 0, phase: !flip });
|
|
68
90
|
}
|
|
69
91
|
return key;
|
|
@@ -84,8 +106,9 @@ export function growCdcl(goal, root, budget, opts = {}) {
|
|
|
84
106
|
get: name => vars.get(name), stamp: at => stamps[at], size: () => trail.length,
|
|
85
107
|
lin: at => { const name = trail[at], x = vars.get(name); return { name, lin: x.lin, holds: x.val }; },
|
|
86
108
|
});
|
|
87
|
-
|
|
88
|
-
const
|
|
109
|
+
let last = goal.hyps.length - 1;
|
|
110
|
+
const near = nearOf(goal);
|
|
111
|
+
const decidedLin = (lin) => vars.get(keyOf(lin))?.val !== undefined;
|
|
89
112
|
const fixed = trail.length;
|
|
90
113
|
const level = () => levels.length;
|
|
91
114
|
const pathOf = () => new Map(trail.map(name => { const x = vars.get(name); return [name, { lin: x.lin, holds: x.val }]; }));
|
|
@@ -101,14 +124,16 @@ export function growCdcl(goal, root, budget, opts = {}) {
|
|
|
101
124
|
else
|
|
102
125
|
x.reason = reason;
|
|
103
126
|
trail.push(name);
|
|
127
|
+
reader.touch(name);
|
|
104
128
|
};
|
|
105
129
|
const undoTo = (l) => {
|
|
106
130
|
const keep = levels[l] ?? trail.length;
|
|
107
131
|
while (trail.length > Math.max(keep, fixed)) {
|
|
108
|
-
const x = vars.get(
|
|
132
|
+
const name = trail.pop(), x = vars.get(name);
|
|
109
133
|
delete x.val;
|
|
110
134
|
x.level = -1;
|
|
111
135
|
delete x.reason;
|
|
136
|
+
reader.touch(name);
|
|
112
137
|
}
|
|
113
138
|
levels.length = l;
|
|
114
139
|
};
|
|
@@ -220,255 +245,301 @@ export function growCdcl(goal, root, budget, opts = {}) {
|
|
|
220
245
|
}, ms => { st.coreMs += ms; });
|
|
221
246
|
const luby = (i) => { let n = 1; while ((1 << n) - 1 < i + 1)
|
|
222
247
|
n++; return (1 << n) - 1 === i + 1 ? 1 << (n - 1) : luby(i + 1 - (1 << (n - 1))); };
|
|
248
|
+
// With a model wanted: each open atom's phase (no term column's) set to its value at the simplex's point, which meets
|
|
249
|
+
// every row read (over the rationals), so a decision tends to stay feasible (runs/unsat/bmc-only-phase: 320 of
|
|
250
|
+
// CHC-COMP's 475 unsat tasks, 280 without; each atom decided at once at the point instead, 271).
|
|
251
|
+
const phaseAtPoint = (cands, lp) => {
|
|
252
|
+
for (const lin of cands) {
|
|
253
|
+
const x = vars.get(ensure(lin));
|
|
254
|
+
if (x.val !== undefined || x.terms.some(([key]) => key.startsWith('⟦')))
|
|
255
|
+
continue;
|
|
256
|
+
const at = lp.holds(x.lin);
|
|
257
|
+
if (at !== undefined)
|
|
258
|
+
x.phase = at;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
223
261
|
let restartAt = 32, nRestart = 0, sinceRestart = 0;
|
|
224
262
|
const stuck = (kind, why, extra = {}) => ({ stuck: kind, path: pathOf(), why, ...extra });
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
263
|
+
const run = (b, w, assume) => {
|
|
264
|
+
budget = b;
|
|
265
|
+
until = b.until ?? Infinity;
|
|
266
|
+
wall = w;
|
|
267
|
+
last = goal.hyps.length - 1;
|
|
268
|
+
restartAt = 32;
|
|
269
|
+
nRestart = 0;
|
|
270
|
+
sinceRestart = 0;
|
|
271
|
+
undoTo(0);
|
|
272
|
+
qhead = Math.min(qhead, trail.length); // (a run before this one may have left decisions)
|
|
273
|
+
if (assume) {
|
|
274
|
+
const name = ensure(assume);
|
|
275
|
+
assumed = [name, name === canon(assume)];
|
|
276
|
+
}
|
|
277
|
+
else
|
|
278
|
+
assumed = undefined;
|
|
279
|
+
return search();
|
|
280
|
+
};
|
|
281
|
+
const search = () => {
|
|
282
|
+
for (;;) {
|
|
283
|
+
if (++budget.nodes > 200_000 || clock() > until || (wall !== undefined && performance.now() > wall))
|
|
284
|
+
return stuck('unknown', budget.nodes > 200_000 ? 'nodes' : 'time');
|
|
285
|
+
let conflict;
|
|
286
|
+
const ci = propagate();
|
|
287
|
+
if (ci !== undefined)
|
|
288
|
+
conflict = clauses[ci];
|
|
289
|
+
else if (assumed && vars.get(assumed[0]).val === !assumed[1])
|
|
290
|
+
return { stuck: 'unknown', path: new Map(), why: REFUTED };
|
|
291
|
+
else if (assumed && vars.get(assumed[0]).val === undefined) {
|
|
292
|
+
levels.push(trail.length);
|
|
293
|
+
assign(assumed[0], assumed[1]);
|
|
294
|
+
continue;
|
|
241
295
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
296
|
+
else {
|
|
297
|
+
reader.begin();
|
|
298
|
+
st.nodes++;
|
|
299
|
+
const rowsR = t(() => reader.rows(), ms => { st.rowsMs += ms; });
|
|
300
|
+
const full = rowsR;
|
|
301
|
+
if (verify) {
|
|
302
|
+
const mine = new Set(rowsR.map(r => canon(r.lin))), theirs = new Set(leafConstraints(goal, pathOf()).map(r => canon(r.lin)));
|
|
303
|
+
if (mine.size !== theirs.size || [...mine].some(x => !theirs.has(x)))
|
|
304
|
+
throw new Error(`reader.ts's rows differ from kernel.ts's at a node of ${goal.name}`);
|
|
305
|
+
}
|
|
306
|
+
work.n += 1 + full.length;
|
|
307
|
+
// (the elimination below reads term columns' rows only once the trail has an atom about one, as growPlain does)
|
|
308
|
+
let columns = false;
|
|
309
|
+
for (let i = 0; i < trail.length && !columns; i++)
|
|
310
|
+
for (const key in vars.get(trail[i]).lin)
|
|
311
|
+
if (key.startsWith('⟦')) {
|
|
312
|
+
columns = true;
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
const idx = columns ? undefined : full.flatMap((r, i) => (namesOf(r.lin).some(key => key.startsWith('⟦')) ? [] : [i]));
|
|
316
|
+
const rows = idx ? idx.map(i => full[i]) : full, at = (i) => (!idx ? i : i < rows.length ? idx[i] : full.length + i - rows.length);
|
|
317
|
+
// The candidates, in growPlain's order: the units, the conclusion's open atoms, the hypotheses' near it, the
|
|
318
|
+
// rest, pairs of cells.
|
|
319
|
+
const cands = t(() => {
|
|
320
|
+
const out = [...unitAtoms(goal)];
|
|
321
|
+
if (last >= 0)
|
|
322
|
+
reader.open(last, out);
|
|
323
|
+
for (let i = 0; i < last; i++)
|
|
324
|
+
if (near[i])
|
|
325
|
+
reader.open(i, out);
|
|
326
|
+
for (let i = 0; i < last; i++)
|
|
327
|
+
if (!near[i])
|
|
328
|
+
reader.open(i, out);
|
|
329
|
+
if (rows.some(r => namesOf(r.lin).some(isCell)))
|
|
330
|
+
for (const x of openCells(rows, pathOf()))
|
|
331
|
+
out.push(x);
|
|
332
|
+
const seen = new Set();
|
|
333
|
+
return out.filter(lin => !seen.has(lin) && (seen.add(lin), namesOf(lin).length > 0) && !decidedLin(lin));
|
|
334
|
+
}, ms => { st.orderMs += ms; });
|
|
335
|
+
const open = cands.length > 0;
|
|
336
|
+
// Bound propagation: an open atom its variables' bounds (the single-variable rows) decide.
|
|
337
|
+
const tb = timing ? performance.now() : 0;
|
|
338
|
+
if (open) {
|
|
339
|
+
const lo = new Map(), hi = new Map();
|
|
340
|
+
full.forEach((r, i) => {
|
|
341
|
+
const ks = namesOf(r.lin);
|
|
342
|
+
if (ks.length !== 1)
|
|
343
|
+
return;
|
|
344
|
+
const x0 = ks[0], c = r.lin[x0], k0 = r.lin['1'] ?? 0;
|
|
345
|
+
if (c > 0) {
|
|
346
|
+
const b = Math.floor(-k0 / c);
|
|
347
|
+
if (b < (hi.get(x0)?.[0] ?? Infinity))
|
|
348
|
+
hi.set(x0, [b, i]);
|
|
349
|
+
}
|
|
350
|
+
else if (c < 0) {
|
|
351
|
+
const b = Math.ceil(k0 / -c);
|
|
352
|
+
if (b > (lo.get(x0)?.[0] ?? -Infinity))
|
|
353
|
+
lo.set(x0, [b, i]);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
let forced = 0;
|
|
357
|
+
for (const lin of cands) {
|
|
358
|
+
const name = ensure(lin), x = vars.get(name);
|
|
359
|
+
if (x.val !== undefined || namesOf(x.lin).some(key => key.startsWith('⟦')))
|
|
360
|
+
continue; // (a term column's rows read differently once its choice is decided)
|
|
361
|
+
const side = (val) => {
|
|
362
|
+
let sum = x.lin['1'] ?? 0;
|
|
363
|
+
const used = [];
|
|
364
|
+
for (const [x0, c] of x.terms) {
|
|
365
|
+
const b = (c > 0) === val ? hi.get(x0) : lo.get(x0);
|
|
366
|
+
if (!b)
|
|
367
|
+
return undefined;
|
|
368
|
+
sum += c * b[0];
|
|
369
|
+
used.push(b[1]);
|
|
370
|
+
}
|
|
371
|
+
return (val ? sum <= 0 : sum >= 1) ? used : undefined;
|
|
372
|
+
};
|
|
373
|
+
for (const val of [true, false]) {
|
|
374
|
+
const used = side(val);
|
|
375
|
+
if (!used)
|
|
376
|
+
continue;
|
|
377
|
+
const w = new Set();
|
|
378
|
+
for (const i of used)
|
|
379
|
+
for (const n of rowsR[i].w)
|
|
380
|
+
w.add(n);
|
|
381
|
+
clauses.push({ lits: new Map([[name, !val]]), node: -1 });
|
|
382
|
+
pending.set(clauses.length - 1, { w, used: used.map(i => full[i].lin), name, val });
|
|
383
|
+
assign(name, val, clauses.length - 1);
|
|
384
|
+
forced++;
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
285
387
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
388
|
+
if (timing)
|
|
389
|
+
st.boundMs += performance.now() - tb;
|
|
390
|
+
if (forced) {
|
|
391
|
+
st.boundRounds++;
|
|
392
|
+
continue;
|
|
290
393
|
}
|
|
291
|
-
}
|
|
292
|
-
let
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
return undefined;
|
|
304
|
-
sum += c * b[0];
|
|
305
|
-
used.push(b[1]);
|
|
394
|
+
}
|
|
395
|
+
let steps, lpSat = false;
|
|
396
|
+
let verdict;
|
|
397
|
+
t(() => {
|
|
398
|
+
// The simplex first (warm from the node before): a conflict's rows, refuted exactly, are the leaf. With a case
|
|
399
|
+
// still open, a node it finds feasible is split; with none, the exact elimination below decides it (integers).
|
|
400
|
+
if (sx) {
|
|
401
|
+
const t0 = timing ? performance.now() : 0;
|
|
402
|
+
// (a tableau that has gathered many more forms than a node reads is begun again: every pivot updates them all)
|
|
403
|
+
if (sx.size > 4 * full.length + 500 || sx.nnz > lpFill * full.length) {
|
|
404
|
+
sx = new Simplex();
|
|
405
|
+
st.lpRebuilds++;
|
|
306
406
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
if (
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
407
|
+
const p0 = sx.pivots;
|
|
408
|
+
let lp = sx.load(full);
|
|
409
|
+
if (lp.kind === 'sat')
|
|
410
|
+
lp = sx.check();
|
|
411
|
+
if (timing) {
|
|
412
|
+
st.lpMs += performance.now() - t0;
|
|
413
|
+
st.pivots += sx.pivots - p0;
|
|
414
|
+
st.lpRows = sx.size;
|
|
415
|
+
st.lpNnz = sx.nnz;
|
|
416
|
+
st.lpVars = sx.vars;
|
|
417
|
+
st.lpLoad = full.length;
|
|
418
|
+
if (lp.kind === 'unknown')
|
|
419
|
+
st.lpUnknown++;
|
|
420
|
+
}
|
|
421
|
+
if (lp.kind === 'conflict') {
|
|
422
|
+
const support = lp.rows.sort((x, y) => x - y), out = solve(support.map(i => full[i]));
|
|
423
|
+
if (out.kind === 'refuted')
|
|
424
|
+
steps = out.steps.map(s => (s.kind === 'input' ? { ...s, index: support[s.index] } : s));
|
|
425
|
+
else
|
|
426
|
+
st.lpMisses++;
|
|
427
|
+
}
|
|
428
|
+
lpSat = lp.kind === 'sat';
|
|
429
|
+
if (steps || (open && lp.kind === 'sat'))
|
|
430
|
+
return;
|
|
322
431
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
continue;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
let steps;
|
|
332
|
-
let verdict;
|
|
333
|
-
t(() => {
|
|
334
|
-
// The simplex first (warm from the node before): a conflict's rows, refuted exactly, are the leaf. With a case
|
|
335
|
-
// still open, a node it finds feasible is split; with none, the exact elimination below decides it (integers).
|
|
336
|
-
if (sx) {
|
|
337
|
-
const t0 = timing ? performance.now() : 0;
|
|
338
|
-
// (a tableau that has gathered many more forms than a node reads is begun again: every pivot updates them all)
|
|
339
|
-
if (sx.size > 4 * full.length + 500 || sx.nnz > lpFill * full.length) {
|
|
340
|
-
sx = new Simplex();
|
|
341
|
-
st.lpRebuilds++;
|
|
432
|
+
st.fmCalls++;
|
|
433
|
+
if (open && rows.length > 60) {
|
|
434
|
+
const fast = refuteFast(rows);
|
|
435
|
+
if (fast?.kind === 'refuted')
|
|
436
|
+
steps = fast.steps.map(s => (s.kind === 'input' ? { ...s, index: at(s.index) } : s));
|
|
342
437
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
if (timing) {
|
|
348
|
-
st.lpMs += performance.now() - t0;
|
|
349
|
-
st.pivots += sx.pivots - p0;
|
|
350
|
-
st.lpRows = sx.size;
|
|
351
|
-
st.lpNnz = sx.nnz;
|
|
352
|
-
st.lpVars = sx.vars;
|
|
353
|
-
st.lpLoad = full.length;
|
|
354
|
-
if (lp.kind === 'unknown')
|
|
355
|
-
st.lpUnknown++;
|
|
438
|
+
if (!steps) {
|
|
439
|
+
verdict = open && rows.length > 60 ? solve(rows, 2 * rows.length) : solve(rows);
|
|
440
|
+
if (verdict.kind === 'refuted')
|
|
441
|
+
steps = verdict.steps.map(s => (s.kind === 'input' ? { ...s, index: at(s.index) } : s));
|
|
356
442
|
}
|
|
357
|
-
if (
|
|
358
|
-
const
|
|
359
|
-
if (
|
|
360
|
-
steps =
|
|
361
|
-
else
|
|
362
|
-
st.lpMisses++;
|
|
443
|
+
if (!steps && open && !columns && full.length > rows.length) {
|
|
444
|
+
const fast = refuteFast(full);
|
|
445
|
+
if (fast?.kind === 'refuted')
|
|
446
|
+
steps = fast.steps;
|
|
363
447
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
if (!steps && open && !columns && full.length > rows.length) {
|
|
379
|
-
const fast = refuteFast(full);
|
|
380
|
-
if (fast?.kind === 'refuted')
|
|
381
|
-
steps = fast.steps;
|
|
382
|
-
}
|
|
383
|
-
}, ms => { st.solveMs += ms; });
|
|
384
|
-
if (steps)
|
|
385
|
-
conflict = leafAt(rowsR, steps);
|
|
386
|
-
else {
|
|
387
|
-
// A decision: the open atom of highest activity (the first candidate among equals).
|
|
388
|
-
let pick, best = -1;
|
|
389
|
-
for (const lin of cands) {
|
|
390
|
-
const name = ensure(lin), x = vars.get(name);
|
|
391
|
-
if (x.val === undefined && x.act > best) {
|
|
392
|
-
best = x.act;
|
|
393
|
-
pick = name;
|
|
448
|
+
}, ms => { st.solveMs += ms; });
|
|
449
|
+
if (steps)
|
|
450
|
+
conflict = leafAt(rowsR, steps);
|
|
451
|
+
else {
|
|
452
|
+
if (opts.model && lpSat && sx && open)
|
|
453
|
+
phaseAtPoint(cands, sx);
|
|
454
|
+
// A decision: the open atom of highest activity (the first candidate among equals).
|
|
455
|
+
let pick, best = -1;
|
|
456
|
+
for (const lin of cands) {
|
|
457
|
+
const name = ensure(lin), x = vars.get(name);
|
|
458
|
+
if (x.val === undefined && x.act > best) {
|
|
459
|
+
best = x.act;
|
|
460
|
+
pick = name;
|
|
461
|
+
}
|
|
394
462
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
463
|
+
if (!pick && verdict?.kind === 'unknown') {
|
|
464
|
+
for (const [x0, value] of Object.entries(verdict.point ?? {})) {
|
|
465
|
+
if (Math.abs(value - Math.round(value)) < 1e-9 || isMonomial(x0))
|
|
466
|
+
continue;
|
|
467
|
+
const c = Math.floor(value), lin = c === 0 ? { [x0]: 1 } : { [x0]: 1, 1: -c };
|
|
468
|
+
if (!decidedLin(lin)) {
|
|
469
|
+
pick = ensure(lin);
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
404
472
|
}
|
|
405
473
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
474
|
+
// Nothing open by this reading: the kernel's own reading of the trail (prove.ts's) has the last word.
|
|
475
|
+
if (!pick) {
|
|
476
|
+
const p = pathOf(), more = openAt(goal, p, rowsAt(goal, p)).find(lin => Object.keys(lin).some(key => key !== '1') && !decidedLin(lin));
|
|
477
|
+
if (more) {
|
|
478
|
+
st.openMisses++;
|
|
479
|
+
pick = ensure(more);
|
|
480
|
+
}
|
|
413
481
|
}
|
|
482
|
+
if (!pick)
|
|
483
|
+
return verdict?.kind === 'sat' ? stuck('sat', 'a model', { witness: verdict.witness }) : stuck('unknown', 'no split');
|
|
484
|
+
levels.push(trail.length);
|
|
485
|
+
st.decisions++;
|
|
486
|
+
assign(pick, vars.get(pick).phase);
|
|
487
|
+
continue;
|
|
414
488
|
}
|
|
415
|
-
if (!pick)
|
|
416
|
-
return verdict?.kind === 'sat' ? stuck('sat', 'a model', { witness: verdict.witness }) : stuck('unknown', 'no split');
|
|
417
|
-
levels.push(trail.length);
|
|
418
|
-
st.decisions++;
|
|
419
|
-
assign(pick, vars.get(pick).phase);
|
|
420
|
-
continue;
|
|
421
489
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
490
|
+
// Conflict analysis.
|
|
491
|
+
st.conflicts++;
|
|
492
|
+
sinceRestart++;
|
|
493
|
+
let c = conflict;
|
|
494
|
+
for (;;) {
|
|
495
|
+
if (!c.lits.size) {
|
|
496
|
+
if (opts.model)
|
|
497
|
+
return { stuck: 'unknown', path: new Map(), why: REFUTED };
|
|
498
|
+
const tree = t(() => unfold(goal, nodes, c.node, root, opts.maxLeaves ?? 20_000, until), ms => { st.unfoldMs += ms; });
|
|
499
|
+
if (!tree)
|
|
500
|
+
return stuck('unknown', 'unfold');
|
|
501
|
+
st.proven++;
|
|
502
|
+
return { tree, nodes: budget.nodes };
|
|
503
|
+
}
|
|
504
|
+
const top = Math.max(...[...c.lits.keys()].map(name => vars.get(name).level));
|
|
505
|
+
if (top < level()) {
|
|
506
|
+
undoTo(top);
|
|
507
|
+
qhead = trail.length;
|
|
508
|
+
}
|
|
509
|
+
const here = [...c.lits.keys()].filter(name => vars.get(name).level === top);
|
|
510
|
+
if (top === 0) {
|
|
511
|
+
c = resolveOn(c, here.reduce((a, b) => (vars.get(a).at > vars.get(b).at ? a : b)));
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
if (here.length === 1)
|
|
515
|
+
break;
|
|
516
|
+
const latest = here.reduce((a, b) => (vars.get(a).at > vars.get(b).at ? a : b));
|
|
517
|
+
if (vars.get(latest).reason === undefined)
|
|
518
|
+
break;
|
|
519
|
+
c = resolveOn(c, latest);
|
|
434
520
|
}
|
|
435
521
|
const top = Math.max(...[...c.lits.keys()].map(name => vars.get(name).level));
|
|
436
|
-
if (top < level()) {
|
|
437
|
-
undoTo(top);
|
|
438
|
-
qhead = trail.length;
|
|
439
|
-
}
|
|
440
522
|
const here = [...c.lits.keys()].filter(name => vars.get(name).level === top);
|
|
441
|
-
|
|
442
|
-
|
|
523
|
+
bump(c.lits);
|
|
524
|
+
const learned = addClause(c.lits, c.node);
|
|
525
|
+
if (here.length !== 1) {
|
|
526
|
+
undoTo(Math.max(0, top - 1));
|
|
527
|
+
qhead = Math.min(qhead, trail.length);
|
|
443
528
|
continue;
|
|
444
529
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
const learned = addClause(c.lits, c.node);
|
|
456
|
-
if (here.length !== 1) {
|
|
457
|
-
undoTo(Math.max(0, top - 1));
|
|
458
|
-
qhead = Math.min(qhead, trail.length);
|
|
459
|
-
continue;
|
|
460
|
-
}
|
|
461
|
-
const uip = here[0];
|
|
462
|
-
undoTo(Math.max(0, ...[...c.lits.keys()].filter(name => name !== uip).map(name => vars.get(name).level)));
|
|
463
|
-
qhead = trail.length;
|
|
464
|
-
assign(uip, !c.lits.get(uip), learned);
|
|
465
|
-
if (sinceRestart >= restartAt) {
|
|
466
|
-
sinceRestart = 0;
|
|
467
|
-
restartAt = 32 * luby(++nRestart);
|
|
468
|
-
undoTo(0);
|
|
469
|
-
qhead = Math.min(qhead, trail.length);
|
|
530
|
+
const uip = here[0];
|
|
531
|
+
undoTo(Math.max(0, ...[...c.lits.keys()].filter(name => name !== uip).map(name => vars.get(name).level)));
|
|
532
|
+
qhead = trail.length;
|
|
533
|
+
assign(uip, !c.lits.get(uip), learned);
|
|
534
|
+
if (sinceRestart >= restartAt) {
|
|
535
|
+
sinceRestart = 0;
|
|
536
|
+
restartAt = 32 * luby(++nRestart);
|
|
537
|
+
undoTo(0);
|
|
538
|
+
qhead = Math.min(qhead, trail.length);
|
|
539
|
+
}
|
|
470
540
|
}
|
|
471
|
-
}
|
|
541
|
+
};
|
|
542
|
+
return { run };
|
|
472
543
|
}
|
|
473
544
|
// The DAG as a kernel tree below `root`, walked depth first with a reader of its own (the tree's path is a stack, as
|
|
474
545
|
// the search's trail is): each leaf's derivation found again among the rows at its tree path, in kernel.ts's order (the
|
|
@@ -477,11 +548,11 @@ export function growCdcl(goal, root, budget, opts = {}) {
|
|
|
477
548
|
function unfold(goal, nodes, top, root, maxLeaves, until) {
|
|
478
549
|
const stack = [], on = new Map(), stamps = [];
|
|
479
550
|
let stampN = 0, leaves = 0;
|
|
480
|
-
const
|
|
481
|
-
const
|
|
551
|
+
const reader = new Reader(goal, { get: name => on.get(name), stamp: at => stamps[at], size: () => stack.length, lin: at => stack[at] });
|
|
552
|
+
const push = (name, lin, holds) => { on.set(name, { val: holds, at: stack.length }); stamps[stack.length] = ++stampN; stack.push({ name, lin, holds }); reader.touch(name); };
|
|
553
|
+
const pop = () => { const name = stack.pop().name; on.delete(name); reader.touch(name); };
|
|
482
554
|
for (const [key, a] of root)
|
|
483
555
|
push(key, a.lin, a.holds);
|
|
484
|
-
const reader = new Reader(goal, { get: name => on.get(name), stamp: at => stamps[at], size: () => stack.length, lin: at => stack[at] });
|
|
485
556
|
const go = (i) => {
|
|
486
557
|
const n = nodes[i];
|
|
487
558
|
if ('res' in n) {
|