gdp-wired 0.24.0 → 0.25.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 +44 -0
- package/dist/core/accel.js +720 -0
- package/dist/core/cycles.js +428 -97
- package/dist/core/data.d.ts +8 -0
- package/dist/core/data.js +828 -95
- package/dist/core/infer.d.ts +1 -0
- package/dist/core/infer.js +298 -28
- package/dist/core/nonterm.d.ts +4 -1
- package/dist/core/nonterm.js +98 -2
- package/dist/core/relation.js +75 -3
- package/dist/core/transfer.js +1 -1
- package/dist/kernel/cdcl.d.ts +5 -0
- package/dist/kernel/cdcl.js +43 -6
- package/dist/kernel/prove.js +6 -4
- package/package.json +1 -1
package/dist/core/relation.js
CHANGED
|
@@ -111,21 +111,90 @@ function assert(c, p, positive, n) {
|
|
|
111
111
|
// The body's value of a state variable on a path: its ifs decided or split, a truncated difference at the top kept
|
|
112
112
|
// whole (an integer's part, if it is one).
|
|
113
113
|
// An if and the ifs of its else branches, one after another (a long chain of rules is no deeper a recursion).
|
|
114
|
+
// (A condition the pins decide alone, pc = 3 and t = 1 on a path that pins both, is read at them first: a chain of a
|
|
115
|
+
// rule per case, for every path, is then a walk, not a split of each case.)
|
|
114
116
|
function chain(e, p, n, leaf) {
|
|
115
117
|
const out = [];
|
|
116
118
|
let cur = e, ps = [p];
|
|
117
119
|
while (cur.op === 'if' && ps.length) {
|
|
118
|
-
const c = cur.c, then = cur.then;
|
|
119
|
-
for (const q of ps)
|
|
120
|
+
const c = cur.c, then = cur.then, next = [];
|
|
121
|
+
for (const q of ps) {
|
|
122
|
+
const t = truthAt(c, q.pins);
|
|
123
|
+
if (t === true) {
|
|
124
|
+
out.push(...leaf(then, q, n));
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (t === false) {
|
|
128
|
+
next.push(q);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
120
131
|
for (const r of assert(c, q, true, n))
|
|
121
132
|
out.push(...leaf(then, r, n));
|
|
122
|
-
|
|
133
|
+
next.push(...assert(c, q, false, n));
|
|
134
|
+
}
|
|
135
|
+
ps = next;
|
|
123
136
|
cur = cur.else;
|
|
124
137
|
}
|
|
125
138
|
for (const q of ps)
|
|
126
139
|
out.push(...leaf(cur, q, n));
|
|
127
140
|
return out;
|
|
128
141
|
}
|
|
142
|
+
// A term's value, and a condition's truth, where the pins decide them (undefined where a name isn't pinned).
|
|
143
|
+
function valueAt(e, pins) {
|
|
144
|
+
switch (e.op) {
|
|
145
|
+
case 'var': return pins[e.name];
|
|
146
|
+
case 'const': return e.value;
|
|
147
|
+
case 'mul': {
|
|
148
|
+
const a = valueAt(e.a, pins);
|
|
149
|
+
return a === undefined ? undefined : e.k * a;
|
|
150
|
+
}
|
|
151
|
+
case 'if': {
|
|
152
|
+
const c = truthAt(e.c, pins);
|
|
153
|
+
return c === undefined ? undefined : valueAt(c ? e.then : e.else, pins);
|
|
154
|
+
}
|
|
155
|
+
case 'add':
|
|
156
|
+
case 'sub':
|
|
157
|
+
case 'min':
|
|
158
|
+
case 'max':
|
|
159
|
+
case 'prod': {
|
|
160
|
+
const a = valueAt(e.a, pins), b = a === undefined ? undefined : valueAt(e.b, pins);
|
|
161
|
+
if (a === undefined || b === undefined)
|
|
162
|
+
return undefined;
|
|
163
|
+
return e.op === 'add' ? a + b : e.op === 'sub' ? Math.max(0, a - b) : e.op === 'min' ? Math.min(a, b) : e.op === 'max' ? Math.max(a, b) : a * b;
|
|
164
|
+
}
|
|
165
|
+
case 'get': return undefined;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function truthAt(c, pins) {
|
|
169
|
+
switch (c.op) {
|
|
170
|
+
case '<':
|
|
171
|
+
case '<=':
|
|
172
|
+
case '=': {
|
|
173
|
+
const a = valueAt(c.a, pins), b = a === undefined ? undefined : valueAt(c.b, pins);
|
|
174
|
+
if (a === undefined || b === undefined)
|
|
175
|
+
return undefined;
|
|
176
|
+
return c.op === '<' ? a < b : c.op === '<=' ? a <= b : a === b;
|
|
177
|
+
}
|
|
178
|
+
case 'and':
|
|
179
|
+
case 'or': {
|
|
180
|
+
let open = false;
|
|
181
|
+
for (const x of c.xs) {
|
|
182
|
+
const t = truthAt(x, pins);
|
|
183
|
+
if (t === undefined)
|
|
184
|
+
open = true;
|
|
185
|
+
else if (t === (c.op === 'or'))
|
|
186
|
+
return t;
|
|
187
|
+
}
|
|
188
|
+
return open ? undefined : c.op === 'and';
|
|
189
|
+
}
|
|
190
|
+
case 'not': {
|
|
191
|
+
const t = truthAt(c.x, pins);
|
|
192
|
+
return t === undefined ? undefined : !t;
|
|
193
|
+
}
|
|
194
|
+
case 'flag':
|
|
195
|
+
case 'all': return undefined;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
129
198
|
function valueOf(e, p, n) {
|
|
130
199
|
if (e.op === 'if')
|
|
131
200
|
return chain(e, p, n, valueOf);
|
|
@@ -351,6 +420,9 @@ const norm = (x) => { const g = x.reduce(bgcd, 0n); return g > 1n ? x.map(y => y
|
|
|
351
420
|
const dot = (a, b) => a.reduce((s, x, i) => s + x * b[i], 0n);
|
|
352
421
|
export function generators(rows, names, nats = [], cap = 600, until = Infinity) {
|
|
353
422
|
const n = names.length, at = new Map(names.map((x, i) => [x, i]));
|
|
423
|
+
// (a row over a name not given has no place: no generators, rather than its coefficient dropped)
|
|
424
|
+
if (rows.some(r => Object.keys(r).some(x => x !== '1' && !at.has(x))))
|
|
425
|
+
return undefined;
|
|
354
426
|
const hs = [...rows.map(r => { const h = Array.from({ length: n + 1 }, () => 0n); for (const [x, c] of Object.entries(r)) {
|
|
355
427
|
if (x === '1')
|
|
356
428
|
h[n] = BigInt(c);
|
package/dist/core/transfer.js
CHANGED
|
@@ -331,7 +331,7 @@ export function proveThrough(l, plan, opts, until) {
|
|
|
331
331
|
// (through the bridges and unfolded: half the time left, the other half through the unfolding alone, the functions
|
|
332
332
|
// as written)
|
|
333
333
|
const again = b.unfolded && bridged.size > 0;
|
|
334
|
-
const r = searchIn(b.lstar, opts, again ? clock() + (until - clock()) / 2 : until, { p: b.p, fs, base: [], level: 0 });
|
|
334
|
+
const r = searchIn(b.lstar, opts, again ? clock() + (until - clock()) / 2 : until, { p: b.p, fs, base: [], level: 0, merge: true });
|
|
335
335
|
tried += r.verdict.tried;
|
|
336
336
|
if (!r.out && again && clock() < until) {
|
|
337
337
|
bridged = new Map();
|
package/dist/kernel/cdcl.d.ts
CHANGED
|
@@ -34,6 +34,9 @@ export declare const cdclStats: {
|
|
|
34
34
|
boundRounds: number;
|
|
35
35
|
};
|
|
36
36
|
export declare const REFUTED = "refuted, not unfolded";
|
|
37
|
+
export type Refuted = Outcome & {
|
|
38
|
+
core?: number[];
|
|
39
|
+
};
|
|
37
40
|
export declare function growCdcl(goal: Goal, root: Path, budget: {
|
|
38
41
|
nodes: number;
|
|
39
42
|
until?: number;
|
|
@@ -41,10 +44,12 @@ export declare function growCdcl(goal: Goal, root: Path, budget: {
|
|
|
41
44
|
maxLeaves?: number;
|
|
42
45
|
model?: boolean;
|
|
43
46
|
wall?: number;
|
|
47
|
+
core?: boolean;
|
|
44
48
|
}): Outcome;
|
|
45
49
|
export declare function cdclSession(goal: Goal, root: Path, opts?: {
|
|
46
50
|
maxLeaves?: number;
|
|
47
51
|
model?: boolean;
|
|
52
|
+
core?: boolean;
|
|
48
53
|
}): {
|
|
49
54
|
run: (b: {
|
|
50
55
|
nodes: number;
|
package/dist/kernel/cdcl.js
CHANGED
|
@@ -57,6 +57,9 @@ const lpFill = Number(env.GDP_CDCL_FILL ?? 8), useLp = env.GDP_CDCL_LP !== '0',
|
|
|
57
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
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
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
|
+
// `opts.core`, with `model`: a refutation's outcome also names the hypotheses its leaves read (`core`, their indices in
|
|
61
|
+
// goal.hyps): those alone have no model (each leaf's rows are those hypotheses' facts at its decisions, or rows true of
|
|
62
|
+
// any value: the trail's atoms, the naturals, the term columns' definitions), as core/infer.ts's join reads it.
|
|
60
63
|
export const REFUTED = 'refuted, not unfolded';
|
|
61
64
|
export function growCdcl(goal, root, budget, opts = {}) {
|
|
62
65
|
return cdclSession(goal, root, opts).run(budget, opts.wall);
|
|
@@ -80,6 +83,15 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
80
83
|
const vars = new Map(), trail = [], levels = [];
|
|
81
84
|
let sx = useLp ? new Simplex() : undefined;
|
|
82
85
|
const nodes = [], clauses = [], occ = new Map();
|
|
86
|
+
// (with opts.core: each leaf's hypotheses, by node; the hypothesis each row at this node came from)
|
|
87
|
+
const leafHyps = new Map(), wantCore = !!(opts.core && opts.model);
|
|
88
|
+
const hypsOf = (rs) => {
|
|
89
|
+
const at = new Map();
|
|
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]; }))];
|
|
94
|
+
};
|
|
83
95
|
let inc = 1;
|
|
84
96
|
// An atom as a variable: the stored form is the one whose canonical text is the variable's name (the smaller).
|
|
85
97
|
const ensure = (lin) => {
|
|
@@ -206,8 +218,10 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
206
218
|
};
|
|
207
219
|
// A leaf: the decisions of a reason (the root's are every leaf's, below which the tree starts: not literals of its
|
|
208
220
|
// clause) and a derivation over the rows it reads.
|
|
209
|
-
const leafNode = (w, inputs, steps, extra) => {
|
|
221
|
+
const leafNode = (w, inputs, steps, extra, hyps) => {
|
|
210
222
|
nodes.push({ inputs, steps });
|
|
223
|
+
if (hyps)
|
|
224
|
+
leafHyps.set(nodes.length - 1, hyps);
|
|
211
225
|
st.leaves++;
|
|
212
226
|
const lits = new Map();
|
|
213
227
|
for (const name of w)
|
|
@@ -227,7 +241,7 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
227
241
|
w.add(name);
|
|
228
242
|
st.pathSize += trail.length - fixed;
|
|
229
243
|
const local = localize(rows, steps);
|
|
230
|
-
return leafNode(w, local.inputs, local.steps);
|
|
244
|
+
return leafNode(w, local.inputs, local.steps, undefined, wantCore ? hypsOf(steps.flatMap(s => (s.kind === 'input' ? [rows[s.index]] : []))) : undefined);
|
|
231
245
|
}, ms => { st.coreMs += ms; });
|
|
232
246
|
// Bound propagation's reasons, made when conflict analysis reads them: the atom's bounds (single-variable rows at the
|
|
233
247
|
// trail then) and its other side refute each other, a leaf at the bounds' reasons with that side decided.
|
|
@@ -239,7 +253,7 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
239
253
|
const s = solve(local);
|
|
240
254
|
if (s.kind !== 'refuted')
|
|
241
255
|
throw new Error('a bound propagation its bounds do not refute');
|
|
242
|
-
const loc = localize(local, s.steps), made = leafNode(b.w, loc.inputs, loc.steps, [b.name, !b.val]);
|
|
256
|
+
const loc = localize(local, s.steps), made = leafNode(b.w, loc.inputs, loc.steps, [b.name, !b.val], b.hyps);
|
|
243
257
|
c.lits = made.lits;
|
|
244
258
|
c.node = made.node;
|
|
245
259
|
}, ms => { st.coreMs += ms; });
|
|
@@ -379,7 +393,7 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
379
393
|
for (const n of rowsR[i].w)
|
|
380
394
|
w.add(n);
|
|
381
395
|
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 });
|
|
396
|
+
pending.set(clauses.length - 1, { w, used: used.map(i => full[i].lin), name, val, ...(wantCore ? { hyps: hypsOf(used.map(i => rowsR[i])) } : {}) });
|
|
383
397
|
assign(name, val, clauses.length - 1);
|
|
384
398
|
forced++;
|
|
385
399
|
break;
|
|
@@ -493,8 +507,31 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
493
507
|
let c = conflict;
|
|
494
508
|
for (;;) {
|
|
495
509
|
if (!c.lits.size) {
|
|
496
|
-
if (opts.model)
|
|
497
|
-
|
|
510
|
+
if (opts.model) {
|
|
511
|
+
if (!wantCore)
|
|
512
|
+
return { stuck: 'unknown', path: new Map(), why: REFUTED };
|
|
513
|
+
// the hypotheses the leaves below the empty clause read (a clause never made into a node, a bound's not yet
|
|
514
|
+
// materialized, leaves the core unknown)
|
|
515
|
+
const core = new Set(), seen = new Set(), todo = [c.node];
|
|
516
|
+
let whole = true;
|
|
517
|
+
while (todo.length) {
|
|
518
|
+
const i = todo.pop();
|
|
519
|
+
if (i < 0) {
|
|
520
|
+
whole = false;
|
|
521
|
+
break;
|
|
522
|
+
}
|
|
523
|
+
if (seen.has(i))
|
|
524
|
+
continue;
|
|
525
|
+
seen.add(i);
|
|
526
|
+
const nd = nodes[i];
|
|
527
|
+
if ('res' in nd)
|
|
528
|
+
todo.push(...nd.res);
|
|
529
|
+
else
|
|
530
|
+
for (const h of leafHyps.get(i) ?? [])
|
|
531
|
+
core.add(h);
|
|
532
|
+
}
|
|
533
|
+
return { stuck: 'unknown', path: new Map(), why: REFUTED, ...(whole ? { core: [...core].sort((a, b) => a - b) } : {}) };
|
|
534
|
+
}
|
|
498
535
|
const tree = t(() => unfold(goal, nodes, c.node, root, opts.maxLeaves ?? 20_000, until), ms => { st.unfoldMs += ms; });
|
|
499
536
|
if (!tree)
|
|
500
537
|
return stuck('unknown', 'unfold');
|
package/dist/kernel/prove.js
CHANGED
|
@@ -88,11 +88,13 @@ export function openCells(rows, path) {
|
|
|
88
88
|
const names = [...new Set(rows.flatMap(r => Object.keys(r.lin)))].filter(isCell);
|
|
89
89
|
const out = [];
|
|
90
90
|
const keyText = (n) => n.slice(n.indexOf('[') + 1, -1);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
// (each name's map and key read once: the pairs are quadratic in the names)
|
|
92
|
+
const maps = names.map(n => n.slice(0, n.indexOf('['))), keys = names.map(n => parse(keyText(n)));
|
|
93
|
+
for (let i = 0; i < names.length; i++)
|
|
94
|
+
for (let j = i + 1; j < names.length; j++) {
|
|
95
|
+
if (maps[i] !== maps[j])
|
|
94
96
|
continue;
|
|
95
|
-
const d = sub(
|
|
97
|
+
const d = sub(keys[i], keys[j]);
|
|
96
98
|
if (pairedKeys.skip && Object.keys(d).some(isMonomial))
|
|
97
99
|
continue;
|
|
98
100
|
const dec = (lin) => path.get(canon(lin))?.holds ?? (path.has(canonFlip(lin)) ? !path.get(canonFlip(lin)).holds : undefined);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gdp-wired",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "An automatic prover for stateful rules (budgets, caps, windows, workflows, policies): laws proven with no proof to write, checked again in Lean, counterexamples found on the GPU, the rule shipped as code",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"verification",
|