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/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 { 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.
|
|
@@ -51,7 +51,6 @@ const keyOf = (lin) => {
|
|
|
51
51
|
};
|
|
52
52
|
// GDP_CDCL_LP=0: each node solved by elimination alone (no simplex); GDP_CDCL_FILL (8): the simplex's tableau begun
|
|
53
53
|
// again past this many entries a row the node reads (research/step's comparisons).
|
|
54
|
-
const env = globalThis.process?.env ?? {};
|
|
55
54
|
const lpFill = Number(env.GDP_CDCL_FILL ?? 8), useLp = env.GDP_CDCL_LP !== '0', verify = env.GDP_CDCL_VERIFY === '1';
|
|
56
55
|
// Counters research/step reads (times only while `on`).
|
|
57
56
|
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 };
|
|
@@ -62,7 +61,8 @@ export const cdclStats = { on: false, runs: 0, proven: 0, conflicts: 0, decision
|
|
|
62
61
|
// any value: the trail's atoms, the naturals, the term columns' definitions), as core/infer.ts's join reads it.
|
|
63
62
|
export const REFUTED = 'refuted, not unfolded';
|
|
64
63
|
export function growCdcl(goal, root, budget, opts = {}) {
|
|
65
|
-
|
|
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();
|
|
66
66
|
}
|
|
67
67
|
// A search kept from one run to the next (core/bmc.ts's deeper goals): its atoms, their activities and phases, its learned
|
|
68
68
|
// clauses and the simplex's tableau. Between runs the caller may add hypotheses to the goal (goal.hyps grows; none is
|
|
@@ -86,22 +86,57 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
86
86
|
// (with opts.core: each leaf's hypotheses, by node; the hypothesis each row at this node came from)
|
|
87
87
|
const leafHyps = new Map(), wantCore = !!(opts.core && opts.model);
|
|
88
88
|
const hypsOf = (rs) => {
|
|
89
|
-
|
|
90
|
-
for (let i = 0; i < goal.hyps.length; i++)
|
|
91
|
-
for (const r of reader.facts(i).rows)
|
|
92
|
-
at.set(r, i);
|
|
93
|
-
return [...new Set(rs.flatMap(r => { const i = at.get(r); return i === undefined ? [] : [i]; }))];
|
|
89
|
+
return reader.hypsOf(rs);
|
|
94
90
|
};
|
|
95
91
|
let inc = 1;
|
|
96
92
|
// An atom as a variable: the stored form is the one whose canonical text is the variable's name (the smaller).
|
|
97
93
|
const ensure = (lin) => {
|
|
98
94
|
const key = keyOf(lin);
|
|
99
95
|
if (!vars.has(key)) {
|
|
100
|
-
const flip = key !== canon(lin), stored = flip ? atomOf(lin, false).lin : lin;
|
|
101
|
-
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 });
|
|
102
98
|
}
|
|
103
99
|
return key;
|
|
104
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();
|
|
105
140
|
// The root's own decisions are level 0, with no reason: they stay in every clause (the tree starts below them).
|
|
106
141
|
const rootNames = new Set(), stamps = [];
|
|
107
142
|
let stampN = 0;
|
|
@@ -113,6 +148,8 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
113
148
|
stamps[x.at] = ++stampN;
|
|
114
149
|
trail.push(name);
|
|
115
150
|
rootNames.add(name);
|
|
151
|
+
if (x.col)
|
|
152
|
+
colsOn++;
|
|
116
153
|
}
|
|
117
154
|
const reader = new Reader(goal, {
|
|
118
155
|
get: name => vars.get(name), stamp: at => stamps[at], size: () => trail.length,
|
|
@@ -136,6 +173,10 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
136
173
|
else
|
|
137
174
|
x.reason = reason;
|
|
138
175
|
trail.push(name);
|
|
176
|
+
if (x.col)
|
|
177
|
+
colsOn++;
|
|
178
|
+
if (x.pair)
|
|
179
|
+
pairsChanged++;
|
|
139
180
|
reader.touch(name);
|
|
140
181
|
};
|
|
141
182
|
const undoTo = (l) => {
|
|
@@ -145,6 +186,10 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
145
186
|
delete x.val;
|
|
146
187
|
x.level = -1;
|
|
147
188
|
delete x.reason;
|
|
189
|
+
if (x.col)
|
|
190
|
+
colsOn--;
|
|
191
|
+
if (x.pair)
|
|
192
|
+
pairsChanged++;
|
|
148
193
|
reader.touch(name);
|
|
149
194
|
}
|
|
150
195
|
levels.length = l;
|
|
@@ -262,15 +307,32 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
262
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
|
|
263
308
|
// every row read (over the rationals), so a decision tends to stay feasible (runs/unsat/bmc-only-phase: 320 of
|
|
264
309
|
// CHC-COMP's 475 unsat tasks, 280 without; each atom decided at once at the point instead, 271).
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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) {
|
|
270
329
|
const at = lp.holds(x.lin);
|
|
271
330
|
if (at !== undefined)
|
|
272
331
|
x.phase = at;
|
|
332
|
+
x.sx = undefined;
|
|
333
|
+
return;
|
|
273
334
|
}
|
|
335
|
+
x.phase = v <= 1e-7 * Math.max(1, Math.abs(v));
|
|
274
336
|
};
|
|
275
337
|
let restartAt = 32, nRestart = 0, sinceRestart = 0;
|
|
276
338
|
const stuck = (kind, why, extra = {}) => ({ stuck: kind, path: pathOf(), why, ...extra });
|
|
@@ -290,11 +352,11 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
290
352
|
}
|
|
291
353
|
else
|
|
292
354
|
assumed = undefined;
|
|
293
|
-
return search();
|
|
355
|
+
return queryHook.on && !queryHook.depth ? logged(opts.model ? 'model' : 'cdcl', goal, search) : search();
|
|
294
356
|
};
|
|
295
357
|
const search = () => {
|
|
296
358
|
for (;;) {
|
|
297
|
-
if (++budget.nodes > 200_000 ||
|
|
359
|
+
if (++budget.nodes > 200_000 || late(until) || (wall !== undefined && performance.now() > wall))
|
|
298
360
|
return stuck('unknown', budget.nodes > 200_000 ? 'nodes' : 'time');
|
|
299
361
|
let conflict;
|
|
300
362
|
const ci = propagate();
|
|
@@ -310,84 +372,126 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
310
372
|
else {
|
|
311
373
|
reader.begin();
|
|
312
374
|
st.nodes++;
|
|
313
|
-
|
|
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; });
|
|
314
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
|
+
}
|
|
315
395
|
if (verify) {
|
|
316
396
|
const mine = new Set(rowsR.map(r => canon(r.lin))), theirs = new Set(leafConstraints(goal, pathOf()).map(r => canon(r.lin)));
|
|
317
397
|
if (mine.size !== theirs.size || [...mine].some(x => !theirs.has(x)))
|
|
318
398
|
throw new Error(`reader.ts's rows differ from kernel.ts's at a node of ${goal.name}`);
|
|
319
399
|
}
|
|
320
400
|
work.n += 1 + full.length;
|
|
401
|
+
costs.cdclNodes++;
|
|
402
|
+
costs.cdclRows += full.length;
|
|
321
403
|
// (the elimination below reads term columns' rows only once the trail has an atom about one, as growPlain does)
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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);
|
|
331
416
|
// The candidates, in growPlain's order: the units, the conclusion's open atoms, the hypotheses' near it, the
|
|
332
417
|
// rest, pairs of cells.
|
|
333
418
|
const cands = t(() => {
|
|
334
|
-
|
|
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));
|
|
335
435
|
if (last >= 0)
|
|
336
|
-
reader.
|
|
436
|
+
take(reader.openList(last));
|
|
337
437
|
for (let i = 0; i < last; i++)
|
|
338
438
|
if (near[i])
|
|
339
|
-
reader.
|
|
439
|
+
take(reader.openList(i));
|
|
340
440
|
for (let i = 0; i < last; i++)
|
|
341
441
|
if (!near[i])
|
|
342
|
-
reader.
|
|
343
|
-
if (
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
const seen = new Set();
|
|
347
|
-
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;
|
|
348
446
|
}, ms => { st.orderMs += ms; });
|
|
349
447
|
const open = cands.length > 0;
|
|
350
448
|
// Bound propagation: an open atom its variables' bounds (the single-variable rows) decide.
|
|
351
449
|
const tb = timing ? performance.now() : 0;
|
|
352
450
|
if (open) {
|
|
353
|
-
const lo = new Map(), hi = new Map();
|
|
354
|
-
full.forEach((r, i) => {
|
|
355
|
-
const ks = namesOf(r.lin);
|
|
356
|
-
if (ks.length !== 1)
|
|
357
|
-
return;
|
|
358
|
-
const x0 = ks[0], c = r.lin[x0], k0 = r.lin['1'] ?? 0;
|
|
359
|
-
if (c > 0) {
|
|
360
|
-
const b = Math.floor(-k0 / c);
|
|
361
|
-
if (b < (hi.get(x0)?.[0] ?? Infinity))
|
|
362
|
-
hi.set(x0, [b, i]);
|
|
363
|
-
}
|
|
364
|
-
else if (c < 0) {
|
|
365
|
-
const b = Math.ceil(k0 / -c);
|
|
366
|
-
if (b > (lo.get(x0)?.[0] ?? -Infinity))
|
|
367
|
-
lo.set(x0, [b, i]);
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
451
|
let forced = 0;
|
|
371
|
-
for (const
|
|
372
|
-
const name =
|
|
373
|
-
if (x.val !== undefined ||
|
|
452
|
+
for (const x of cands) {
|
|
453
|
+
const name = x.name;
|
|
454
|
+
if (x.val !== undefined || x.col)
|
|
374
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
|
+
}
|
|
375
477
|
const side = (val) => {
|
|
376
478
|
let sum = x.lin['1'] ?? 0;
|
|
377
479
|
const used = [];
|
|
378
|
-
for (
|
|
379
|
-
const
|
|
380
|
-
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))
|
|
381
483
|
return undefined;
|
|
382
|
-
sum += c * b
|
|
383
|
-
used.push(
|
|
484
|
+
sum += c * b;
|
|
485
|
+
used.push(reader.slotOf(up ? bx.highWhy(j) : bx.lowWhy(j)));
|
|
384
486
|
}
|
|
385
487
|
return (val ? sum <= 0 : sum >= 1) ? used : undefined;
|
|
386
488
|
};
|
|
489
|
+
let hit = false;
|
|
387
490
|
for (const val of [true, false]) {
|
|
388
491
|
const used = side(val);
|
|
389
492
|
if (!used)
|
|
390
493
|
continue;
|
|
494
|
+
hit = true;
|
|
391
495
|
const w = new Set();
|
|
392
496
|
for (const i of used)
|
|
393
497
|
for (const n of rowsR[i].w)
|
|
@@ -398,6 +502,8 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
398
502
|
forced++;
|
|
399
503
|
break;
|
|
400
504
|
}
|
|
505
|
+
x.bsig = hit ? undefined : sig;
|
|
506
|
+
x.bver = hit ? undefined : bx.changes;
|
|
401
507
|
}
|
|
402
508
|
if (timing)
|
|
403
509
|
st.boundMs += performance.now() - tb;
|
|
@@ -414,14 +520,30 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
414
520
|
if (sx) {
|
|
415
521
|
const t0 = timing ? performance.now() : 0;
|
|
416
522
|
// (a tableau that has gathered many more forms than a node reads is begun again: every pivot updates them all)
|
|
417
|
-
|
|
523
|
+
const over = sx.size > 4 * full.length + 500 || sx.nnz > lpFill * full.length;
|
|
524
|
+
if (over) {
|
|
418
525
|
sx = new Simplex();
|
|
419
526
|
st.lpRebuilds++;
|
|
420
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();
|
|
421
540
|
const p0 = sx.pivots;
|
|
422
|
-
let lp = sx.
|
|
541
|
+
let lp = sx.settle();
|
|
423
542
|
if (lp.kind === 'sat')
|
|
424
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;
|
|
425
547
|
if (timing) {
|
|
426
548
|
st.lpMs += performance.now() - t0;
|
|
427
549
|
st.pivots += sx.pivots - p0;
|
|
@@ -444,6 +566,7 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
444
566
|
return;
|
|
445
567
|
}
|
|
446
568
|
st.fmCalls++;
|
|
569
|
+
const rows = plain();
|
|
447
570
|
if (open && rows.length > 60) {
|
|
448
571
|
const fast = refuteFast(rows);
|
|
449
572
|
if (fast?.kind === 'refuted')
|
|
@@ -455,25 +578,24 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
455
578
|
steps = verdict.steps.map(s => (s.kind === 'input' ? { ...s, index: at(s.index) } : s));
|
|
456
579
|
}
|
|
457
580
|
if (!steps && open && !columns && full.length > rows.length) {
|
|
458
|
-
const fast = refuteFast(full);
|
|
581
|
+
const k = korder(), fast = refuteFast(k.map(i => full[i]));
|
|
459
582
|
if (fast?.kind === 'refuted')
|
|
460
|
-
steps = fast.steps;
|
|
583
|
+
steps = fast.steps.map(s => (s.kind === 'input' ? { ...s, index: k[s.index] } : s));
|
|
461
584
|
}
|
|
462
585
|
}, ms => { st.solveMs += ms; });
|
|
463
586
|
if (steps)
|
|
464
587
|
conflict = leafAt(rowsR, steps);
|
|
465
588
|
else {
|
|
466
|
-
if (opts.model && lpSat && sx && open)
|
|
467
|
-
phaseAtPoint(cands, sx);
|
|
468
589
|
// A decision: the open atom of highest activity (the first candidate among equals).
|
|
469
|
-
let pick, best = -1;
|
|
470
|
-
for (const
|
|
471
|
-
const name = ensure(lin), x = vars.get(name);
|
|
590
|
+
let pick, best = -1, px;
|
|
591
|
+
for (const x of cands)
|
|
472
592
|
if (x.val === undefined && x.act > best) {
|
|
473
593
|
best = x.act;
|
|
474
|
-
pick = name;
|
|
594
|
+
pick = x.name;
|
|
595
|
+
px = x;
|
|
475
596
|
}
|
|
476
|
-
|
|
597
|
+
if (opts.model && lpSat && sx && open && px)
|
|
598
|
+
phaseAtPoint(px, sx);
|
|
477
599
|
if (!pick && verdict?.kind === 'unknown') {
|
|
478
600
|
for (const [x0, value] of Object.entries(verdict.point ?? {})) {
|
|
479
601
|
if (Math.abs(value - Math.round(value)) < 1e-9 || isMonomial(x0))
|
|
@@ -606,12 +728,22 @@ function unfold(goal, nodes, top, root, maxLeaves, until) {
|
|
|
606
728
|
pop();
|
|
607
729
|
return no && { split: n.on, yes, no };
|
|
608
730
|
}
|
|
609
|
-
if (++leaves > maxLeaves ||
|
|
731
|
+
if (++leaves > maxLeaves || late(until)) {
|
|
610
732
|
cdclStats.unfoldWhy = leaves > maxLeaves ? 'leaves' : 'time';
|
|
611
733
|
return undefined;
|
|
612
734
|
}
|
|
613
735
|
reader.begin();
|
|
614
|
-
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
|
+
};
|
|
615
747
|
if (verify) {
|
|
616
748
|
const path = new Map(stack.map(x => [x.name, { lin: x.lin, holds: x.holds }])), kr = leafConstraints(goal, path);
|
|
617
749
|
if (kr.length !== rows.length || kr.some((r, j) => canon(r.lin) !== canon(rows[j].lin))) {
|
|
@@ -634,16 +766,17 @@ function unfold(goal, nodes, top, root, maxLeaves, until) {
|
|
|
634
766
|
steps.push({ ...s, index: j });
|
|
635
767
|
}
|
|
636
768
|
if (steps.length === n.steps.length && checkRefutation(rows, steps))
|
|
637
|
-
return
|
|
769
|
+
return noted(steps);
|
|
638
770
|
// (a row a longer path reads otherwise: a hypothesis false outright there, a choice decided)
|
|
639
771
|
cdclStats.resolved2++;
|
|
640
772
|
work.n += 1 + rows.length;
|
|
773
|
+
costs.unfoldRows += rows.length;
|
|
641
774
|
const fast = rows.length > 60 ? refuteFast(rows) : undefined;
|
|
642
775
|
if (fast?.kind === 'refuted')
|
|
643
|
-
return
|
|
776
|
+
return noted(fast.steps);
|
|
644
777
|
const out = solve(rows);
|
|
645
778
|
if (out.kind === 'refuted')
|
|
646
|
-
return
|
|
779
|
+
return noted(out.steps);
|
|
647
780
|
cdclStats.unfoldWhy = 'refute';
|
|
648
781
|
return undefined;
|
|
649
782
|
};
|
package/dist/kernel/prove.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type C, type E, type Law, type Machine } from '../core/machine.js';
|
|
2
2
|
import { type Lin } from '../core/solver.js';
|
|
3
3
|
import type { Cyclic } from './cyclic.js';
|
|
4
4
|
import { type Goal, type Instances, type Liveness, type Loop, type Path, type StepLaw, type Tree, leafConstraintsReusing } from './kernel.js';
|
|
5
5
|
export declare const pairedKeys: {
|
|
6
6
|
skip: boolean;
|
|
7
7
|
};
|
|
8
|
-
export declare
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export declare const cellPair: (a: string, b: string) => {
|
|
9
|
+
d: Lin;
|
|
10
|
+
neg: Lin;
|
|
11
|
+
q0?: Lin;
|
|
12
|
+
q1?: Lin;
|
|
13
|
+
};
|
|
14
|
+
export declare function parseKey(text: string): Lin;
|
|
11
15
|
export declare const profile: {
|
|
12
16
|
on: boolean;
|
|
13
17
|
goals: {
|
|
@@ -44,7 +48,10 @@ export type Outcome = {
|
|
|
44
48
|
why?: string;
|
|
45
49
|
};
|
|
46
50
|
export declare const clock: () => number;
|
|
47
|
-
export declare function counted<T>(perMs: number, f: () => T): T;
|
|
51
|
+
export declare function counted<T>(perMs: number, f: () => T, full?: boolean): T;
|
|
52
|
+
export declare const fullRate = 250;
|
|
53
|
+
export declare const fullWork: () => number;
|
|
54
|
+
export declare const late: (until: number) => boolean;
|
|
48
55
|
export declare const withinDeadline: (until: number) => number;
|
|
49
56
|
export declare function withDeadline<T>(until: number, f: () => T): T;
|
|
50
57
|
export declare function grow(goal: Goal, path?: Path, budget?: {
|
|
@@ -52,6 +59,22 @@ export declare function grow(goal: Goal, path?: Path, budget?: {
|
|
|
52
59
|
until?: number;
|
|
53
60
|
units?: boolean;
|
|
54
61
|
}): Outcome;
|
|
62
|
+
export declare function withTrees<T>(f: () => T): T;
|
|
63
|
+
export declare const queryHook: {
|
|
64
|
+
on?: (q: {
|
|
65
|
+
kind: string;
|
|
66
|
+
goal: Goal;
|
|
67
|
+
ms: number;
|
|
68
|
+
work: number;
|
|
69
|
+
out: Outcome;
|
|
70
|
+
depth: number;
|
|
71
|
+
}) => void;
|
|
72
|
+
depth: number;
|
|
73
|
+
};
|
|
74
|
+
export declare function logged(kind: string, goal: Goal, f: () => Outcome): Outcome;
|
|
75
|
+
export declare const realModels: {
|
|
76
|
+
on: boolean;
|
|
77
|
+
};
|
|
55
78
|
export declare function rowsAt(goal: Goal, path: Path): ReturnType<typeof leafConstraintsReusing>;
|
|
56
79
|
export declare function widen(part: Goal, whole: Goal, tree: Tree, opaque?: Record<string, E>, pp?: Path, wp?: Path): Tree | undefined;
|
|
57
80
|
export declare function nearOf(goal: Goal): boolean[];
|
|
@@ -62,6 +85,14 @@ export declare function openAt(goal: Goal, path: Path, rows: {
|
|
|
62
85
|
export declare const minimal: {
|
|
63
86
|
on: boolean;
|
|
64
87
|
};
|
|
88
|
+
export type LeafRows = {
|
|
89
|
+
n: number;
|
|
90
|
+
at: Map<number, {
|
|
91
|
+
lin: Lin;
|
|
92
|
+
src: number | [string, string];
|
|
93
|
+
}>;
|
|
94
|
+
};
|
|
95
|
+
export declare const leafRowsOf: WeakMap<object, LeafRows>;
|
|
65
96
|
export declare function usedHyps(goal: Goal, tree: Tree, path?: Path, out?: Set<number>): Set<number>;
|
|
66
97
|
export type Report = {
|
|
67
98
|
proven: boolean;
|