gdp-wired 0.26.0 → 0.28.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/dist/core/accel.d.ts +24 -0
- package/dist/core/accel.js +557 -207
- package/dist/core/bmc.d.ts +4 -1
- package/dist/core/bmc.js +18 -15
- package/dist/core/cycles.d.ts +2 -0
- package/dist/core/cycles.js +1 -1
- package/dist/core/cyclic.js +17 -10
- package/dist/core/data.d.ts +1 -0
- package/dist/core/data.js +73 -18
- package/dist/core/discover.js +64 -25
- package/dist/core/dsl.js +108 -18
- package/dist/core/extract-check.d.ts +52 -2
- package/dist/core/extract-check.js +155 -104
- package/dist/core/extract-read.d.ts +25 -0
- package/dist/core/extract-read.js +55 -14
- package/dist/core/extract-shapes.js +94 -18
- package/dist/core/extract-xstate.js +16 -3
- package/dist/core/extract.d.ts +1 -0
- package/dist/core/extract.js +16 -8
- package/dist/core/fresh.d.ts +9 -0
- package/dist/core/fresh.js +91 -0
- package/dist/core/infer.d.ts +1 -0
- package/dist/core/infer.js +64 -46
- package/dist/core/live.d.ts +15 -0
- package/dist/core/live.js +317 -0
- package/dist/core/machine.js +0 -1
- package/dist/core/nonterm.d.ts +3 -1
- package/dist/core/nonterm.js +103 -25
- package/dist/core/solver.d.ts +21 -0
- package/dist/core/solver.js +8 -0
- package/dist/core/translate.js +69 -19
- package/dist/kernel/cdcl.js +212 -78
- package/dist/kernel/kernel.d.ts +17 -1
- package/dist/kernel/kernel.js +158 -2
- package/dist/kernel/prove.d.ts +30 -4
- package/dist/kernel/prove.js +119 -25
- package/dist/kernel/reader.d.ts +74 -5
- package/dist/kernel/reader.js +531 -75
- package/dist/kernel/simplex.d.ts +26 -1
- package/dist/kernel/simplex.js +148 -14
- package/dist/lean-kernel/emit.d.ts +15 -3
- package/dist/lean-kernel/emit.js +144 -12
- package/dist/lean-kernel/library.js +1 -1
- package/package.json +2 -2
package/dist/kernel/cdcl.js
CHANGED
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
// sides; one the path decides follows the parent that agrees; a leaf's derivation is found again among the rows at
|
|
18
18
|
// its tree path (a longer path than its clause's), and where a row isn't there, the rows at the tree path are solved
|
|
19
19
|
// afresh.
|
|
20
|
-
import { env, refuteFast, solve, work } from "../core/solver.js";
|
|
20
|
+
import { costs, env, refuteFast, solve, work } from "../core/solver.js";
|
|
21
21
|
import { checkRefutation } from "../core/check.js";
|
|
22
|
-
import { atomOf, canon, canonFlip,
|
|
23
|
-
import {
|
|
22
|
+
import { atomOf, canon, canonFlip, isMonomial, leafConstraints } from "./kernel.js";
|
|
23
|
+
import { cellPair, late, leafRowsOf, logged, nearOf, openAt, pairedKeys, queryHook, rowsAt, unitAtoms } from "./prove.js";
|
|
24
24
|
import { Reader, namesOf } from "./reader.js";
|
|
25
25
|
import { Simplex } from "./simplex.js";
|
|
26
26
|
// A derivation's own inputs: the rows it reads, in order, and the steps renumbered to them.
|
|
@@ -61,7 +61,8 @@ export const cdclStats = { on: false, runs: 0, proven: 0, conflicts: 0, decision
|
|
|
61
61
|
// any value: the trail's atoms, the naturals, the term columns' definitions), as core/infer.ts's join reads it.
|
|
62
62
|
export const REFUTED = 'refuted, not unfolded';
|
|
63
63
|
export function growCdcl(goal, root, budget, opts = {}) {
|
|
64
|
-
|
|
64
|
+
const go = () => cdclSession(goal, root, opts).run(budget, opts.wall);
|
|
65
|
+
return queryHook.on && !queryHook.depth ? logged(opts.model ? 'model' : 'cdcl', goal, go) : go();
|
|
65
66
|
}
|
|
66
67
|
// A search kept from one run to the next (core/bmc.ts's deeper goals): its atoms, their activities and phases, its learned
|
|
67
68
|
// clauses and the simplex's tableau. Between runs the caller may add hypotheses to the goal (goal.hyps grows; none is
|
|
@@ -85,22 +86,57 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
85
86
|
// (with opts.core: each leaf's hypotheses, by node; the hypothesis each row at this node came from)
|
|
86
87
|
const leafHyps = new Map(), wantCore = !!(opts.core && opts.model);
|
|
87
88
|
const hypsOf = (rs) => {
|
|
88
|
-
|
|
89
|
-
for (let i = 0; i < goal.hyps.length; i++)
|
|
90
|
-
for (const r of reader.facts(i).rows)
|
|
91
|
-
at.set(r, i);
|
|
92
|
-
return [...new Set(rs.flatMap(r => { const i = at.get(r); return i === undefined ? [] : [i]; }))];
|
|
89
|
+
return reader.hypsOf(rs);
|
|
93
90
|
};
|
|
94
91
|
let inc = 1;
|
|
95
92
|
// An atom as a variable: the stored form is the one whose canonical text is the variable's name (the smaller).
|
|
96
93
|
const ensure = (lin) => {
|
|
97
94
|
const key = keyOf(lin);
|
|
98
95
|
if (!vars.has(key)) {
|
|
99
|
-
const flip = key !== canon(lin), stored = flip ? atomOf(lin, false).lin : lin;
|
|
100
|
-
vars.set(key, { lin: stored, terms:
|
|
96
|
+
const flip = key !== canon(lin), stored = flip ? atomOf(lin, false).lin : lin, terms = Object.entries(stored).filter(([x0]) => x0 !== '1');
|
|
97
|
+
vars.set(key, { name: key, lin: stored, terms, col: terms.some(([x0]) => x0.startsWith('⟦')), level: -1, at: -1, act: 0, phase: !flip });
|
|
101
98
|
}
|
|
102
99
|
return key;
|
|
103
100
|
};
|
|
101
|
+
// Each candidate form's variable (none for a constant form), and the node it was last met at (the candidates told
|
|
102
|
+
// apart by form, as a set of forms would).
|
|
103
|
+
const recs = new WeakMap();
|
|
104
|
+
const recOf = (lin) => { let r = recs.get(lin); if (!r)
|
|
105
|
+
recs.set(lin, (r = { x: namesOf(lin).length > 0 ? vars.get(ensure(lin)) : undefined, seen: 0 })); return r; };
|
|
106
|
+
let candGen = 0, colsOn = 0, pairsChanged = 0;
|
|
107
|
+
// prove.ts's openCells at the trail, from the reader's live cells: each pair of one map whose keys' difference the
|
|
108
|
+
// trail leaves open (that atom, or its flip where the trail decides it one way); made again only where the live cells
|
|
109
|
+
// or the decisions about pairs have changed.
|
|
110
|
+
let cellsAt = [-1, -1], cellsOpen = [];
|
|
111
|
+
const truthOf = (lin) => { const x = recOf(lin).x; return x?.val === undefined ? undefined : x.name === canon(lin) ? x.val : !x.val; };
|
|
112
|
+
const openCellsLive = () => {
|
|
113
|
+
if (cellsAt[0] === reader.cellsChanged && cellsAt[1] === pairsChanged)
|
|
114
|
+
return cellsOpen;
|
|
115
|
+
const out = [];
|
|
116
|
+
for (const names of reader.cells.values()) {
|
|
117
|
+
const ns = [...names];
|
|
118
|
+
for (let i = 0; i < ns.length; i++)
|
|
119
|
+
for (let j = i + 1; j < ns.length; j++) {
|
|
120
|
+
const pair = cellPair(ns[i], ns[j]);
|
|
121
|
+
if (pairedKeys.skip && Object.keys(pair.d).some(isMonomial))
|
|
122
|
+
continue;
|
|
123
|
+
for (const lin of [pair.d, pair.neg]) {
|
|
124
|
+
const x = recOf(lin).x;
|
|
125
|
+
if (x)
|
|
126
|
+
x.pair = true;
|
|
127
|
+
}
|
|
128
|
+
const a = truthOf(pair.d), b = truthOf(pair.neg);
|
|
129
|
+
if (a === undefined)
|
|
130
|
+
out.push(pair.d);
|
|
131
|
+
else if (a === true && b === undefined)
|
|
132
|
+
out.push(pair.neg);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
cellsAt = [reader.cellsChanged, pairsChanged];
|
|
136
|
+
return (cellsOpen = out);
|
|
137
|
+
};
|
|
138
|
+
const listRecs = new WeakMap();
|
|
139
|
+
const bx = new Simplex(true, true), bxIn = new Set(), toAssert = new Set(), toRetract = new Set();
|
|
104
140
|
// The root's own decisions are level 0, with no reason: they stay in every clause (the tree starts below them).
|
|
105
141
|
const rootNames = new Set(), stamps = [];
|
|
106
142
|
let stampN = 0;
|
|
@@ -112,6 +148,8 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
112
148
|
stamps[x.at] = ++stampN;
|
|
113
149
|
trail.push(name);
|
|
114
150
|
rootNames.add(name);
|
|
151
|
+
if (x.col)
|
|
152
|
+
colsOn++;
|
|
115
153
|
}
|
|
116
154
|
const reader = new Reader(goal, {
|
|
117
155
|
get: name => vars.get(name), stamp: at => stamps[at], size: () => trail.length,
|
|
@@ -135,6 +173,10 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
135
173
|
else
|
|
136
174
|
x.reason = reason;
|
|
137
175
|
trail.push(name);
|
|
176
|
+
if (x.col)
|
|
177
|
+
colsOn++;
|
|
178
|
+
if (x.pair)
|
|
179
|
+
pairsChanged++;
|
|
138
180
|
reader.touch(name);
|
|
139
181
|
};
|
|
140
182
|
const undoTo = (l) => {
|
|
@@ -144,6 +186,10 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
144
186
|
delete x.val;
|
|
145
187
|
x.level = -1;
|
|
146
188
|
delete x.reason;
|
|
189
|
+
if (x.col)
|
|
190
|
+
colsOn--;
|
|
191
|
+
if (x.pair)
|
|
192
|
+
pairsChanged++;
|
|
147
193
|
reader.touch(name);
|
|
148
194
|
}
|
|
149
195
|
levels.length = l;
|
|
@@ -261,15 +307,32 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
261
307
|
// With a model wanted: each open atom's phase (no term column's) set to its value at the simplex's point, which meets
|
|
262
308
|
// every row read (over the rationals), so a decision tends to stay feasible (runs/unsat/bmc-only-phase: 320 of
|
|
263
309
|
// CHC-COMP's 475 unsat tasks, 280 without; each atom decided at once at the point instead, 271).
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
310
|
+
// (set where it is read: for the atom decided, at the node it is decided; an atom met open at a node and decided at a
|
|
311
|
+
// later one where the simplex didn't run keeps the phase it last had)
|
|
312
|
+
const phaseAtPoint = (x, lp) => {
|
|
313
|
+
if (x.val !== undefined || x.col)
|
|
314
|
+
return;
|
|
315
|
+
// (lp.holds(x.lin), its columns kept per tableau)
|
|
316
|
+
if (x.sx !== lp) {
|
|
317
|
+
x.sx = lp;
|
|
318
|
+
x.sj = x.terms.map(([x0]) => lp.indexOf(x0));
|
|
319
|
+
}
|
|
320
|
+
let v = x.lin['1'] ?? 0, known = true;
|
|
321
|
+
for (let q = 0; q < x.sj.length && known; q++) {
|
|
322
|
+
const j = x.sj[q];
|
|
323
|
+
if (j === undefined)
|
|
324
|
+
known = false;
|
|
325
|
+
else
|
|
326
|
+
v += x.terms[q][1] * lp.value(j);
|
|
327
|
+
}
|
|
328
|
+
if (!known) {
|
|
269
329
|
const at = lp.holds(x.lin);
|
|
270
330
|
if (at !== undefined)
|
|
271
331
|
x.phase = at;
|
|
332
|
+
x.sx = undefined;
|
|
333
|
+
return;
|
|
272
334
|
}
|
|
335
|
+
x.phase = v <= 1e-7 * Math.max(1, Math.abs(v));
|
|
273
336
|
};
|
|
274
337
|
let restartAt = 32, nRestart = 0, sinceRestart = 0;
|
|
275
338
|
const stuck = (kind, why, extra = {}) => ({ stuck: kind, path: pathOf(), why, ...extra });
|
|
@@ -289,11 +352,11 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
289
352
|
}
|
|
290
353
|
else
|
|
291
354
|
assumed = undefined;
|
|
292
|
-
return search();
|
|
355
|
+
return queryHook.on && !queryHook.depth ? logged(opts.model ? 'model' : 'cdcl', goal, search) : search();
|
|
293
356
|
};
|
|
294
357
|
const search = () => {
|
|
295
358
|
for (;;) {
|
|
296
|
-
if (++budget.nodes > 200_000 ||
|
|
359
|
+
if (++budget.nodes > 200_000 || late(until) || (wall !== undefined && performance.now() > wall))
|
|
297
360
|
return stuck('unknown', budget.nodes > 200_000 ? 'nodes' : 'time');
|
|
298
361
|
let conflict;
|
|
299
362
|
const ci = propagate();
|
|
@@ -309,84 +372,126 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
309
372
|
else {
|
|
310
373
|
reader.begin();
|
|
311
374
|
st.nodes++;
|
|
312
|
-
|
|
375
|
+
// The rows, kept from the node before (reader.ts's sync); the forms that came and went: the single-variable
|
|
376
|
+
// ones' bounds now (for bound propagation, `bx`), the simplex's when it next runs (`toAssert`, `toRetract`: a
|
|
377
|
+
// form in and out between its runs never reaches it).
|
|
378
|
+
const rowsR = t(() => (reader.sync(), reader.live), ms => { st.rowsMs += ms; });
|
|
313
379
|
const full = rowsR;
|
|
380
|
+
const single = (id) => reader.form(full[reader.slotOf(id)].lin).names.length === 1;
|
|
381
|
+
for (const id of reader.left) {
|
|
382
|
+
if (bxIn.delete(id))
|
|
383
|
+
bx.retract(id);
|
|
384
|
+
if (sx && !toAssert.delete(id))
|
|
385
|
+
toRetract.add(id);
|
|
386
|
+
}
|
|
387
|
+
for (const id of reader.entered) {
|
|
388
|
+
if (single(id)) {
|
|
389
|
+
bxIn.add(id);
|
|
390
|
+
bx.assert(id, full[reader.slotOf(id)].lin);
|
|
391
|
+
}
|
|
392
|
+
if (sx && !toRetract.delete(id))
|
|
393
|
+
toAssert.add(id);
|
|
394
|
+
}
|
|
314
395
|
if (verify) {
|
|
315
396
|
const mine = new Set(rowsR.map(r => canon(r.lin))), theirs = new Set(leafConstraints(goal, pathOf()).map(r => canon(r.lin)));
|
|
316
397
|
if (mine.size !== theirs.size || [...mine].some(x => !theirs.has(x)))
|
|
317
398
|
throw new Error(`reader.ts's rows differ from kernel.ts's at a node of ${goal.name}`);
|
|
318
399
|
}
|
|
319
400
|
work.n += 1 + full.length;
|
|
401
|
+
costs.cdclNodes++;
|
|
402
|
+
costs.cdclRows += full.length;
|
|
320
403
|
// (the elimination below reads term columns' rows only once the trail has an atom about one, as growPlain does)
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
404
|
+
const columns = colsOn > 0;
|
|
405
|
+
// (the rows read by the elimination, made when it runs, in kernel.ts's order: elimination's choices, and the
|
|
406
|
+
// bounded one's give-up, follow the order it is given)
|
|
407
|
+
let kidx, idx, rows;
|
|
408
|
+
const korder = () => (kidx ??= reader.rows().map(r => reader.slotOf(reader.form(r.lin).id)));
|
|
409
|
+
const plain = () => {
|
|
410
|
+
if (rows)
|
|
411
|
+
return rows;
|
|
412
|
+
idx = korder().filter(i => columns || !reader.readsColumn(full[i].lin));
|
|
413
|
+
return (rows = idx.map(i => full[i]));
|
|
414
|
+
};
|
|
415
|
+
const at = (i) => (i < plain().length ? idx[i] : full.length + i - plain().length);
|
|
330
416
|
// The candidates, in growPlain's order: the units, the conclusion's open atoms, the hypotheses' near it, the
|
|
331
417
|
// rest, pairs of cells.
|
|
332
418
|
const cands = t(() => {
|
|
333
|
-
|
|
419
|
+
// (each list's forms' variables kept with the list, the same array while it stands)
|
|
420
|
+
const g = ++candGen, keep = [];
|
|
421
|
+
const take = (lins) => {
|
|
422
|
+
let rs = listRecs.get(lins);
|
|
423
|
+
if (!rs)
|
|
424
|
+
listRecs.set(lins, (rs = lins.map(recOf)));
|
|
425
|
+
costs.scan += rs.length;
|
|
426
|
+
for (const r of rs) {
|
|
427
|
+
if (r.seen === g)
|
|
428
|
+
continue;
|
|
429
|
+
r.seen = g;
|
|
430
|
+
if (r.x && r.x.val === undefined)
|
|
431
|
+
keep.push(r.x);
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
take(unitAtoms(goal));
|
|
334
435
|
if (last >= 0)
|
|
335
|
-
reader.
|
|
436
|
+
take(reader.openList(last));
|
|
336
437
|
for (let i = 0; i < last; i++)
|
|
337
438
|
if (near[i])
|
|
338
|
-
reader.
|
|
439
|
+
take(reader.openList(i));
|
|
339
440
|
for (let i = 0; i < last; i++)
|
|
340
441
|
if (!near[i])
|
|
341
|
-
reader.
|
|
342
|
-
if (
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
const seen = new Set();
|
|
346
|
-
return out.filter(lin => !seen.has(lin) && (seen.add(lin), namesOf(lin).length > 0) && !decidedLin(lin));
|
|
442
|
+
take(reader.openList(i));
|
|
443
|
+
if (reader.hasCells())
|
|
444
|
+
take(openCellsLive());
|
|
445
|
+
return keep;
|
|
347
446
|
}, ms => { st.orderMs += ms; });
|
|
348
447
|
const open = cands.length > 0;
|
|
349
448
|
// Bound propagation: an open atom its variables' bounds (the single-variable rows) decide.
|
|
350
449
|
const tb = timing ? performance.now() : 0;
|
|
351
450
|
if (open) {
|
|
352
|
-
const lo = new Map(), hi = new Map();
|
|
353
|
-
full.forEach((r, i) => {
|
|
354
|
-
const ks = namesOf(r.lin);
|
|
355
|
-
if (ks.length !== 1)
|
|
356
|
-
return;
|
|
357
|
-
const x0 = ks[0], c = r.lin[x0], k0 = r.lin['1'] ?? 0;
|
|
358
|
-
if (c > 0) {
|
|
359
|
-
const b = Math.floor(-k0 / c);
|
|
360
|
-
if (b < (hi.get(x0)?.[0] ?? Infinity))
|
|
361
|
-
hi.set(x0, [b, i]);
|
|
362
|
-
}
|
|
363
|
-
else if (c < 0) {
|
|
364
|
-
const b = Math.ceil(k0 / -c);
|
|
365
|
-
if (b > (lo.get(x0)?.[0] ?? -Infinity))
|
|
366
|
-
lo.set(x0, [b, i]);
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
451
|
let forced = 0;
|
|
370
|
-
for (const
|
|
371
|
-
const name =
|
|
372
|
-
if (x.val !== undefined ||
|
|
452
|
+
for (const x of cands) {
|
|
453
|
+
const name = x.name;
|
|
454
|
+
if (x.val !== undefined || x.col)
|
|
373
455
|
continue; // (a term column's rows read differently once its choice is decided)
|
|
456
|
+
// (unforced at the bounds it last read, which haven't changed since: unforced still)
|
|
457
|
+
// (no bound has changed since; or a name without any; or no bound it reads has)
|
|
458
|
+
if (x.bver === bx.changes)
|
|
459
|
+
continue;
|
|
460
|
+
if (!x.bj) {
|
|
461
|
+
if (x.bjAt === bx.vars)
|
|
462
|
+
continue;
|
|
463
|
+
x.bjAt = bx.vars;
|
|
464
|
+
const bj = x.terms.map(([x0]) => bx.indexOf(x0));
|
|
465
|
+
if (bj.some(j => j === undefined))
|
|
466
|
+
continue;
|
|
467
|
+
x.bj = bj;
|
|
468
|
+
}
|
|
469
|
+
const bj = x.bj;
|
|
470
|
+
let sig = 0;
|
|
471
|
+
for (const j of bj)
|
|
472
|
+
sig += bx.version(j);
|
|
473
|
+
if (x.bsig === sig) {
|
|
474
|
+
x.bver = bx.changes;
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
374
477
|
const side = (val) => {
|
|
375
478
|
let sum = x.lin['1'] ?? 0;
|
|
376
479
|
const used = [];
|
|
377
|
-
for (
|
|
378
|
-
const
|
|
379
|
-
if (!b)
|
|
480
|
+
for (let q = 0; q < bj.length; q++) {
|
|
481
|
+
const c = x.terms[q][1], j = bj[q], up = (c > 0) === val, b = up ? bx.high(j) : bx.low(j);
|
|
482
|
+
if (!Number.isFinite(b))
|
|
380
483
|
return undefined;
|
|
381
|
-
sum += c * b
|
|
382
|
-
used.push(
|
|
484
|
+
sum += c * b;
|
|
485
|
+
used.push(reader.slotOf(up ? bx.highWhy(j) : bx.lowWhy(j)));
|
|
383
486
|
}
|
|
384
487
|
return (val ? sum <= 0 : sum >= 1) ? used : undefined;
|
|
385
488
|
};
|
|
489
|
+
let hit = false;
|
|
386
490
|
for (const val of [true, false]) {
|
|
387
491
|
const used = side(val);
|
|
388
492
|
if (!used)
|
|
389
493
|
continue;
|
|
494
|
+
hit = true;
|
|
390
495
|
const w = new Set();
|
|
391
496
|
for (const i of used)
|
|
392
497
|
for (const n of rowsR[i].w)
|
|
@@ -397,6 +502,8 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
397
502
|
forced++;
|
|
398
503
|
break;
|
|
399
504
|
}
|
|
505
|
+
x.bsig = hit ? undefined : sig;
|
|
506
|
+
x.bver = hit ? undefined : bx.changes;
|
|
400
507
|
}
|
|
401
508
|
if (timing)
|
|
402
509
|
st.boundMs += performance.now() - tb;
|
|
@@ -413,14 +520,30 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
413
520
|
if (sx) {
|
|
414
521
|
const t0 = timing ? performance.now() : 0;
|
|
415
522
|
// (a tableau that has gathered many more forms than a node reads is begun again: every pivot updates them all)
|
|
416
|
-
|
|
523
|
+
const over = sx.size > 4 * full.length + 500 || sx.nnz > lpFill * full.length;
|
|
524
|
+
if (over) {
|
|
417
525
|
sx = new Simplex();
|
|
418
526
|
st.lpRebuilds++;
|
|
419
527
|
}
|
|
528
|
+
// (a tableau begun has the rows asserted in kernel.ts's order, which its variables', so Bland's rule, follow)
|
|
529
|
+
if (over || !sx.vars)
|
|
530
|
+
for (const r of reader.rows())
|
|
531
|
+
sx.assert(reader.form(r.lin).id, r.lin);
|
|
532
|
+
else {
|
|
533
|
+
for (const id of toRetract)
|
|
534
|
+
sx.retract(id);
|
|
535
|
+
for (const id of toAssert)
|
|
536
|
+
sx.assert(id, full[reader.slotOf(id)].lin);
|
|
537
|
+
}
|
|
538
|
+
toAssert.clear();
|
|
539
|
+
toRetract.clear();
|
|
420
540
|
const p0 = sx.pivots;
|
|
421
|
-
let lp = sx.
|
|
541
|
+
let lp = sx.settle();
|
|
422
542
|
if (lp.kind === 'sat')
|
|
423
543
|
lp = sx.check();
|
|
544
|
+
if (lp.kind === 'conflict')
|
|
545
|
+
lp = { kind: 'conflict', rows: lp.rows.map(id => reader.slotOf(id)) };
|
|
546
|
+
costs.pivots += sx.pivots - p0;
|
|
424
547
|
if (timing) {
|
|
425
548
|
st.lpMs += performance.now() - t0;
|
|
426
549
|
st.pivots += sx.pivots - p0;
|
|
@@ -443,6 +566,7 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
443
566
|
return;
|
|
444
567
|
}
|
|
445
568
|
st.fmCalls++;
|
|
569
|
+
const rows = plain();
|
|
446
570
|
if (open && rows.length > 60) {
|
|
447
571
|
const fast = refuteFast(rows);
|
|
448
572
|
if (fast?.kind === 'refuted')
|
|
@@ -454,25 +578,24 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
454
578
|
steps = verdict.steps.map(s => (s.kind === 'input' ? { ...s, index: at(s.index) } : s));
|
|
455
579
|
}
|
|
456
580
|
if (!steps && open && !columns && full.length > rows.length) {
|
|
457
|
-
const fast = refuteFast(full);
|
|
581
|
+
const k = korder(), fast = refuteFast(k.map(i => full[i]));
|
|
458
582
|
if (fast?.kind === 'refuted')
|
|
459
|
-
steps = fast.steps;
|
|
583
|
+
steps = fast.steps.map(s => (s.kind === 'input' ? { ...s, index: k[s.index] } : s));
|
|
460
584
|
}
|
|
461
585
|
}, ms => { st.solveMs += ms; });
|
|
462
586
|
if (steps)
|
|
463
587
|
conflict = leafAt(rowsR, steps);
|
|
464
588
|
else {
|
|
465
|
-
if (opts.model && lpSat && sx && open)
|
|
466
|
-
phaseAtPoint(cands, sx);
|
|
467
589
|
// A decision: the open atom of highest activity (the first candidate among equals).
|
|
468
|
-
let pick, best = -1;
|
|
469
|
-
for (const
|
|
470
|
-
const name = ensure(lin), x = vars.get(name);
|
|
590
|
+
let pick, best = -1, px;
|
|
591
|
+
for (const x of cands)
|
|
471
592
|
if (x.val === undefined && x.act > best) {
|
|
472
593
|
best = x.act;
|
|
473
|
-
pick = name;
|
|
594
|
+
pick = x.name;
|
|
595
|
+
px = x;
|
|
474
596
|
}
|
|
475
|
-
|
|
597
|
+
if (opts.model && lpSat && sx && open && px)
|
|
598
|
+
phaseAtPoint(px, sx);
|
|
476
599
|
if (!pick && verdict?.kind === 'unknown') {
|
|
477
600
|
for (const [x0, value] of Object.entries(verdict.point ?? {})) {
|
|
478
601
|
if (Math.abs(value - Math.round(value)) < 1e-9 || isMonomial(x0))
|
|
@@ -605,12 +728,22 @@ function unfold(goal, nodes, top, root, maxLeaves, until) {
|
|
|
605
728
|
pop();
|
|
606
729
|
return no && { split: n.on, yes, no };
|
|
607
730
|
}
|
|
608
|
-
if (++leaves > maxLeaves ||
|
|
731
|
+
if (++leaves > maxLeaves || late(until)) {
|
|
609
732
|
cdclStats.unfoldWhy = leaves > maxLeaves ? 'leaves' : 'time';
|
|
610
733
|
return undefined;
|
|
611
734
|
}
|
|
612
735
|
reader.begin();
|
|
613
|
-
const rows = reader.leafRows();
|
|
736
|
+
const src = [], rows = reader.leafRows(src);
|
|
737
|
+
costs.unfoldRows += rows.length;
|
|
738
|
+
// (the rows the leaf's derivation reads kept with it: prove.ts's leafRowsOf)
|
|
739
|
+
const noted = (leaf) => {
|
|
740
|
+
const t = { leaf }, at = new Map();
|
|
741
|
+
for (const st of leaf)
|
|
742
|
+
if (st.kind === 'input' && st.index < rows.length)
|
|
743
|
+
at.set(st.index, { lin: rows[st.index].lin, src: src[st.index] });
|
|
744
|
+
leafRowsOf.set(t, { n: rows.length, at });
|
|
745
|
+
return t;
|
|
746
|
+
};
|
|
614
747
|
if (verify) {
|
|
615
748
|
const path = new Map(stack.map(x => [x.name, { lin: x.lin, holds: x.holds }])), kr = leafConstraints(goal, path);
|
|
616
749
|
if (kr.length !== rows.length || kr.some((r, j) => canon(r.lin) !== canon(rows[j].lin))) {
|
|
@@ -633,16 +766,17 @@ function unfold(goal, nodes, top, root, maxLeaves, until) {
|
|
|
633
766
|
steps.push({ ...s, index: j });
|
|
634
767
|
}
|
|
635
768
|
if (steps.length === n.steps.length && checkRefutation(rows, steps))
|
|
636
|
-
return
|
|
769
|
+
return noted(steps);
|
|
637
770
|
// (a row a longer path reads otherwise: a hypothesis false outright there, a choice decided)
|
|
638
771
|
cdclStats.resolved2++;
|
|
639
772
|
work.n += 1 + rows.length;
|
|
773
|
+
costs.unfoldRows += rows.length;
|
|
640
774
|
const fast = rows.length > 60 ? refuteFast(rows) : undefined;
|
|
641
775
|
if (fast?.kind === 'refuted')
|
|
642
|
-
return
|
|
776
|
+
return noted(fast.steps);
|
|
643
777
|
const out = solve(rows);
|
|
644
778
|
if (out.kind === 'refuted')
|
|
645
|
-
return
|
|
779
|
+
return noted(out.steps);
|
|
646
780
|
cdclStats.unfoldWhy = 'refute';
|
|
647
781
|
return undefined;
|
|
648
782
|
};
|
package/dist/kernel/kernel.d.ts
CHANGED
|
@@ -99,7 +99,23 @@ export type Recur = {
|
|
|
99
99
|
tree: Tree;
|
|
100
100
|
};
|
|
101
101
|
export declare function recurGoal(l: Loop, r: Pick<Recur, 'set' | 'wit'>): Goal;
|
|
102
|
-
export declare function checkRecur(l: Loop, r: Recur): boolean;
|
|
102
|
+
export declare function checkRecur(l: Loop, r: Recur | RecurCases): boolean;
|
|
103
|
+
export type RecurCases = Omit<Recur, 'tree'> & {
|
|
104
|
+
cover: Tree;
|
|
105
|
+
cases: {
|
|
106
|
+
pins: [string, number][];
|
|
107
|
+
cond: C;
|
|
108
|
+
tree: Tree;
|
|
109
|
+
}[];
|
|
110
|
+
};
|
|
111
|
+
export declare const foldPinned: (c: C, pins: [string, number][]) => C;
|
|
112
|
+
export declare const pinC: (pins: [string, number][]) => C;
|
|
113
|
+
export declare const coverGoal: (r: {
|
|
114
|
+
set: C;
|
|
115
|
+
cases: Pick<RecurCases["cases"][number], "pins" | "cond">[];
|
|
116
|
+
}) => Goal;
|
|
117
|
+
export declare function caseGoals(l: Loop, r: Pick<Recur, 'set' | 'wit'>, cases: Pick<RecurCases['cases'][number], 'pins' | 'cond'>[]): Goal[];
|
|
118
|
+
export declare function checkRecurCases(l: Loop, r: RecurCases): boolean;
|
|
103
119
|
export declare function progressObligations(m: Machine, laws: Law[], instances: Instances, p: {
|
|
104
120
|
name: string;
|
|
105
121
|
when: C;
|