gdp-wired 0.24.0 → 0.26.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 +44 -0
- package/dist/core/accel.js +955 -0
- package/dist/core/bmc.d.ts +8 -0
- package/dist/core/bmc.js +263 -97
- package/dist/core/cycles.d.ts +2 -3
- package/dist/core/cycles.js +409 -174
- package/dist/core/cyclic.d.ts +4 -1
- package/dist/core/cyclic.js +86 -64
- package/dist/core/data.d.ts +9 -1
- package/dist/core/data.js +872 -168
- package/dist/core/discover.js +2 -3
- package/dist/core/dsl.d.ts +3 -2
- package/dist/core/dsl.js +21 -18
- package/dist/core/exists.js +7 -14
- package/dist/core/extract-check.d.ts +3 -2
- package/dist/core/extract-check.js +137 -50
- package/dist/core/extract-print.d.ts +1 -0
- package/dist/core/extract-print.js +26 -3
- package/dist/core/extract-read.d.ts +85 -4
- package/dist/core/extract-read.js +295 -34
- package/dist/core/extract-shapes.d.ts +14 -0
- package/dist/core/extract-shapes.js +608 -78
- package/dist/core/extract-xstate.d.ts +5 -1
- package/dist/core/extract-xstate.js +618 -184
- package/dist/core/extract.js +73 -27
- package/dist/core/infer.d.ts +1 -0
- package/dist/core/infer.js +364 -40
- package/dist/core/machine.d.ts +6 -0
- package/dist/core/machine.js +35 -3
- package/dist/core/nonterm.d.ts +9 -2
- package/dist/core/nonterm.js +173 -9
- 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 +95 -39
- package/dist/core/solver.d.ts +12 -0
- package/dist/core/solver.js +76 -30
- package/dist/core/transfer.js +23 -14
- package/dist/core/translate.d.ts +1 -1
- package/dist/core/translate.js +22 -49
- package/dist/core/xstate.d.ts +6 -1
- package/dist/core/xstate.js +336 -55
- package/dist/kernel/cdcl.d.ts +5 -0
- package/dist/kernel/cdcl.js +44 -8
- package/dist/kernel/prove.d.ts +6 -1
- package/dist/kernel/prove.js +101 -85
- package/dist/kernel/reader.d.ts +1 -0
- package/dist/kernel/reader.js +4 -3
- package/dist/kernel/simplex.d.ts +1 -1
- package/dist/kernel/simplex.js +13 -1
- package/package.json +3 -2
package/dist/kernel/cdcl.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
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 { env, refuteFast, solve, work } from "../core/solver.js";
|
|
21
21
|
import { checkRefutation } from "../core/check.js";
|
|
22
22
|
import { atomOf, canon, canonFlip, isCell, isMonomial, leafConstraints } from "./kernel.js";
|
|
23
23
|
import { clock, nearOf, openAt, openCells, rowsAt, unitAtoms } from "./prove.js";
|
|
@@ -51,12 +51,14 @@ 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 };
|
|
58
57
|
// `opts.model`: only whether the goal has a model is wanted (core/bmc.ts): a refutation isn't unfolded into a tree, its
|
|
59
58
|
// 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.
|
|
59
|
+
// `opts.core`, with `model`: a refutation's outcome also names the hypotheses its leaves read (`core`, their indices in
|
|
60
|
+
// goal.hyps): those alone have no model (each leaf's rows are those hypotheses' facts at its decisions, or rows true of
|
|
61
|
+
// any value: the trail's atoms, the naturals, the term columns' definitions), as core/infer.ts's join reads it.
|
|
60
62
|
export const REFUTED = 'refuted, not unfolded';
|
|
61
63
|
export function growCdcl(goal, root, budget, opts = {}) {
|
|
62
64
|
return cdclSession(goal, root, opts).run(budget, opts.wall);
|
|
@@ -80,6 +82,15 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
80
82
|
const vars = new Map(), trail = [], levels = [];
|
|
81
83
|
let sx = useLp ? new Simplex() : undefined;
|
|
82
84
|
const nodes = [], clauses = [], occ = new Map();
|
|
85
|
+
// (with opts.core: each leaf's hypotheses, by node; the hypothesis each row at this node came from)
|
|
86
|
+
const leafHyps = new Map(), wantCore = !!(opts.core && opts.model);
|
|
87
|
+
const hypsOf = (rs) => {
|
|
88
|
+
const at = new Map();
|
|
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]; }))];
|
|
93
|
+
};
|
|
83
94
|
let inc = 1;
|
|
84
95
|
// An atom as a variable: the stored form is the one whose canonical text is the variable's name (the smaller).
|
|
85
96
|
const ensure = (lin) => {
|
|
@@ -206,8 +217,10 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
206
217
|
};
|
|
207
218
|
// A leaf: the decisions of a reason (the root's are every leaf's, below which the tree starts: not literals of its
|
|
208
219
|
// clause) and a derivation over the rows it reads.
|
|
209
|
-
const leafNode = (w, inputs, steps, extra) => {
|
|
220
|
+
const leafNode = (w, inputs, steps, extra, hyps) => {
|
|
210
221
|
nodes.push({ inputs, steps });
|
|
222
|
+
if (hyps)
|
|
223
|
+
leafHyps.set(nodes.length - 1, hyps);
|
|
211
224
|
st.leaves++;
|
|
212
225
|
const lits = new Map();
|
|
213
226
|
for (const name of w)
|
|
@@ -227,7 +240,7 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
227
240
|
w.add(name);
|
|
228
241
|
st.pathSize += trail.length - fixed;
|
|
229
242
|
const local = localize(rows, steps);
|
|
230
|
-
return leafNode(w, local.inputs, local.steps);
|
|
243
|
+
return leafNode(w, local.inputs, local.steps, undefined, wantCore ? hypsOf(steps.flatMap(s => (s.kind === 'input' ? [rows[s.index]] : []))) : undefined);
|
|
231
244
|
}, ms => { st.coreMs += ms; });
|
|
232
245
|
// Bound propagation's reasons, made when conflict analysis reads them: the atom's bounds (single-variable rows at the
|
|
233
246
|
// trail then) and its other side refute each other, a leaf at the bounds' reasons with that side decided.
|
|
@@ -239,7 +252,7 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
239
252
|
const s = solve(local);
|
|
240
253
|
if (s.kind !== 'refuted')
|
|
241
254
|
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]);
|
|
255
|
+
const loc = localize(local, s.steps), made = leafNode(b.w, loc.inputs, loc.steps, [b.name, !b.val], b.hyps);
|
|
243
256
|
c.lits = made.lits;
|
|
244
257
|
c.node = made.node;
|
|
245
258
|
}, ms => { st.coreMs += ms; });
|
|
@@ -379,7 +392,7 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
379
392
|
for (const n of rowsR[i].w)
|
|
380
393
|
w.add(n);
|
|
381
394
|
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 });
|
|
395
|
+
pending.set(clauses.length - 1, { w, used: used.map(i => full[i].lin), name, val, ...(wantCore ? { hyps: hypsOf(used.map(i => rowsR[i])) } : {}) });
|
|
383
396
|
assign(name, val, clauses.length - 1);
|
|
384
397
|
forced++;
|
|
385
398
|
break;
|
|
@@ -493,8 +506,31 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
493
506
|
let c = conflict;
|
|
494
507
|
for (;;) {
|
|
495
508
|
if (!c.lits.size) {
|
|
496
|
-
if (opts.model)
|
|
497
|
-
|
|
509
|
+
if (opts.model) {
|
|
510
|
+
if (!wantCore)
|
|
511
|
+
return { stuck: 'unknown', path: new Map(), why: REFUTED };
|
|
512
|
+
// the hypotheses the leaves below the empty clause read (a clause never made into a node, a bound's not yet
|
|
513
|
+
// materialized, leaves the core unknown)
|
|
514
|
+
const core = new Set(), seen = new Set(), todo = [c.node];
|
|
515
|
+
let whole = true;
|
|
516
|
+
while (todo.length) {
|
|
517
|
+
const i = todo.pop();
|
|
518
|
+
if (i < 0) {
|
|
519
|
+
whole = false;
|
|
520
|
+
break;
|
|
521
|
+
}
|
|
522
|
+
if (seen.has(i))
|
|
523
|
+
continue;
|
|
524
|
+
seen.add(i);
|
|
525
|
+
const nd = nodes[i];
|
|
526
|
+
if ('res' in nd)
|
|
527
|
+
todo.push(...nd.res);
|
|
528
|
+
else
|
|
529
|
+
for (const h of leafHyps.get(i) ?? [])
|
|
530
|
+
core.add(h);
|
|
531
|
+
}
|
|
532
|
+
return { stuck: 'unknown', path: new Map(), why: REFUTED, ...(whole ? { core: [...core].sort((a, b) => a - b) } : {}) };
|
|
533
|
+
}
|
|
498
534
|
const tree = t(() => unfold(goal, nodes, c.node, root, opts.maxLeaves ?? 20_000, until), ms => { st.unfoldMs += ms; });
|
|
499
535
|
if (!tree)
|
|
500
536
|
return stuck('unknown', 'unfold');
|
package/dist/kernel/prove.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
@@ -8,6 +8,7 @@ export declare const pairedKeys: {
|
|
|
8
8
|
export declare function openCells(rows: {
|
|
9
9
|
lin: Lin;
|
|
10
10
|
}[], path: Path): Lin[];
|
|
11
|
+
export declare function parseKey(text: string): Lin;
|
|
11
12
|
export declare const profile: {
|
|
12
13
|
on: boolean;
|
|
13
14
|
goals: {
|
|
@@ -52,6 +53,10 @@ export declare function grow(goal: Goal, path?: Path, budget?: {
|
|
|
52
53
|
until?: number;
|
|
53
54
|
units?: boolean;
|
|
54
55
|
}): Outcome;
|
|
56
|
+
export declare function withTrees<T>(f: () => T): T;
|
|
57
|
+
export declare const realModels: {
|
|
58
|
+
on: boolean;
|
|
59
|
+
};
|
|
55
60
|
export declare function rowsAt(goal: Goal, path: Path): ReturnType<typeof leafConstraintsReusing>;
|
|
56
61
|
export declare function widen(part: Goal, whole: Goal, tree: Tree, opaque?: Record<string, E>, pp?: Path, wp?: Path): Tree | undefined;
|
|
57
62
|
export declare function nearOf(goal: Goal): boolean[];
|
package/dist/kernel/prove.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
// An untrusted prover for the kernel: grows a split tree until every leaf's constraints are refuted by solve(), splitting
|
|
2
|
+
// on whatever atom the hypotheses leave open (an if's condition, a min's or ∸'s comparison, a disjunction's atoms, two
|
|
3
|
+
// reads of one map at keys not yet known equal or apart). Its trees go to kernel.check; nothing it says is trusted.
|
|
4
|
+
// What keeps it fast (research/perf/prover-bench.ts and prover-stress.ts measure each):
|
|
5
|
+
// - the conclusion's atoms are split first: a case it never reads is often one no refutation needs;
|
|
6
|
+
// - a node with a case still to split asks only "refuted or not": its Farkas rows first (solver.ts refuteFast), then
|
|
7
|
+
// a bounded elimination; the full one, which a satisfiable system needs to the last variable, only at the leaves;
|
|
8
|
+
// - a refutation of a split's yes side that never reads the split refutes its parent (lift), and the no side is skipped;
|
|
9
|
+
// - a hypothesis' rows and open atoms, and every term inside them, are reused from an earlier path that decided the
|
|
10
|
+
// same atoms they read (kernel.ts's reusing), so a new decision reads again only what it touches.
|
|
11
|
+
import { walkOnce } from "../core/machine.js";
|
|
12
|
+
import { add, env, k, refuteFast, scale, solve, sub, v, work } from "../core/solver.js";
|
|
2
13
|
import { checkRefutation } from "../core/check.js";
|
|
3
14
|
import { allowNode, allowTranslated, certCyclic, certOn, certSearch, closingInsts, crossCyclic, cyclicOn, cycLog, hasQuantified, loopNodes, machineNodes, proveCyclic, reqTS, searchedStepNodes, skMachine, timedKind, withWitness, translatedProof, uncovered, uncoveredWhy } from "../core/cyclic.js";
|
|
4
15
|
import { proveSome, someLaws } from "../core/exists.js";
|
|
@@ -88,11 +99,13 @@ export function openCells(rows, path) {
|
|
|
88
99
|
const names = [...new Set(rows.flatMap(r => Object.keys(r.lin)))].filter(isCell);
|
|
89
100
|
const out = [];
|
|
90
101
|
const keyText = (n) => n.slice(n.indexOf('[') + 1, -1);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
102
|
+
// (each name's map and key read once: the pairs are quadratic in the names)
|
|
103
|
+
const maps = names.map(n => n.slice(0, n.indexOf('['))), keys = names.map(n => parseKey(keyText(n)));
|
|
104
|
+
for (let i = 0; i < names.length; i++)
|
|
105
|
+
for (let j = i + 1; j < names.length; j++) {
|
|
106
|
+
if (maps[i] !== maps[j])
|
|
94
107
|
continue;
|
|
95
|
-
const d = sub(
|
|
108
|
+
const d = sub(keys[i], keys[j]);
|
|
96
109
|
if (pairedKeys.skip && Object.keys(d).some(isMonomial))
|
|
97
110
|
continue;
|
|
98
111
|
const dec = (lin) => path.get(canon(lin))?.holds ?? (path.has(canonFlip(lin)) ? !path.get(canonFlip(lin)).holds : undefined);
|
|
@@ -140,7 +153,8 @@ const quotient = (d) => {
|
|
|
140
153
|
};
|
|
141
154
|
// The cells' key differences split at their quotient's equality, by canonical text: their quotient.
|
|
142
155
|
const cellDiffs = new Map();
|
|
143
|
-
|
|
156
|
+
// A key's canonical text read back as its linear form.
|
|
157
|
+
export function parseKey(text) {
|
|
144
158
|
const out = {};
|
|
145
159
|
let depth = 0, start = 0;
|
|
146
160
|
for (let i = 0; i <= text.length; i++) {
|
|
@@ -186,7 +200,7 @@ const solveP = (rows, maxRows) => {
|
|
|
186
200
|
// PROVE_DUMP: a hook research/perf/prof sets to read each root goal.
|
|
187
201
|
export let proveDump;
|
|
188
202
|
export const setProveDump = (f) => { proveDump = f; };
|
|
189
|
-
const proveTrace = !!
|
|
203
|
+
const proveTrace = !!env.PROVE_TRACE;
|
|
190
204
|
// `why`, when the budget ran out: which limit, at what size, and what usually helps.
|
|
191
205
|
// Set while core/cyclic.ts grows its goals.
|
|
192
206
|
export const cellProducts = { on: false };
|
|
@@ -249,6 +263,39 @@ export function grow(goal, path = new Map(), budget = { nodes: 0, until: clock()
|
|
|
249
263
|
console.error(`[grow] ${goal.name}: ${goal.hyps.length} hyps, ${budget.nodes} nodes, ${Math.round(performance.now() - t)} ms, ${'tree' in out ? 'proven' : `${out.stuck}${out.why ? ` (${out.why})` : ''}`}`);
|
|
250
264
|
return out;
|
|
251
265
|
}
|
|
266
|
+
// (a root goal grown before within `withTrees`: its tree again; a tree is the kernel's to check wherever it goes)
|
|
267
|
+
const key = treeCache.on && !path.size && !budget.nodes ? treeKey(goal) : undefined, had = key === undefined ? undefined : treeCache.trees.get(key);
|
|
268
|
+
if (had)
|
|
269
|
+
return { tree: had, nodes: 0 };
|
|
270
|
+
if (key !== undefined) {
|
|
271
|
+
const out = growKept(goal, path, budget);
|
|
272
|
+
if ('tree' in out)
|
|
273
|
+
treeCache.keep(key, out.tree);
|
|
274
|
+
return out;
|
|
275
|
+
}
|
|
276
|
+
return growKept(goal, path, budget);
|
|
277
|
+
}
|
|
278
|
+
// Trees of root goals kept by their hypotheses (and the search's modes) while `withTrees` runs: core/infer.ts proves each
|
|
279
|
+
// law of a set alone (proveLaw) and then the set as a whole (proveRule), the same goals twice. At most 2,000 trees, and
|
|
280
|
+
// goals of at most 4 MB written out.
|
|
281
|
+
const treeCache = { on: 0, trees: new Map(), keep(key, tree) { if (this.trees.size >= 2000)
|
|
282
|
+
this.trees.clear(); this.trees.set(key, tree); } };
|
|
283
|
+
const treeKey = (goal) => { const text = JSON.stringify(goal.hyps); return text.length > 4_000_000 ? undefined : `${cellProducts.on ? 1 : 0}${unitsNow ? 1 : 0}${text}`; };
|
|
284
|
+
// GDP_TREES=0: no tree kept (each goal grown every time it is asked).
|
|
285
|
+
const keepTrees = env.GDP_TREES !== '0';
|
|
286
|
+
export function withTrees(f) {
|
|
287
|
+
if (!keepTrees)
|
|
288
|
+
return f();
|
|
289
|
+
treeCache.on++;
|
|
290
|
+
try {
|
|
291
|
+
return f();
|
|
292
|
+
}
|
|
293
|
+
finally {
|
|
294
|
+
if (--treeCache.on === 0)
|
|
295
|
+
treeCache.trees.clear();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function growKept(goal, path, budget) {
|
|
252
299
|
if (!profile.on || path.size || budget.nodes)
|
|
253
300
|
return growRoot(goal, path, budget);
|
|
254
301
|
const t = performance.now(), s0 = profile.solves, m0 = profile.solveMs, r0 = profile.rowsMs, n0 = profile.nodes;
|
|
@@ -258,8 +305,7 @@ export function grow(goal, path = new Map(), budget = { nodes: 0, until: clock()
|
|
|
258
305
|
}
|
|
259
306
|
// The share of a root goal's budget the CDCL search gets (GDP_CDCL_SHARE; 0 turns it off), and the quick search's nodes
|
|
260
307
|
// before it (GDP_QUICK_CAP; 64 where the CDCL search isn't tried, as before it): research/step's comparisons.
|
|
261
|
-
const
|
|
262
|
-
const cdclShare = Number(proveEnv.GDP_CDCL_SHARE ?? 0.75), quickCap = Number(proveEnv.GDP_QUICK_CAP ?? 16);
|
|
308
|
+
const cdclShare = Number(env.GDP_CDCL_SHARE ?? 0.75), quickCap = Number(env.GDP_QUICK_CAP ?? 16);
|
|
263
309
|
function growRoot(goal, path, budget) {
|
|
264
310
|
// Past a few cases, CDCL over the atoms (kernel/cdcl.ts), with most of the budget: a linear goal's refutation there
|
|
265
311
|
// is a resolution of short clauses, which the tree search would find again in every case that reaches one. Unknown
|
|
@@ -286,7 +332,10 @@ function growRoot(goal, path, budget) {
|
|
|
286
332
|
if (cdcl) {
|
|
287
333
|
const now = clock(), end = withinDeadline(budget.until ?? Infinity);
|
|
288
334
|
const out = growCdcl(goal, path, { nodes: 0, until: end === Infinity ? end : now + cdclShare * (end - now) });
|
|
289
|
-
|
|
335
|
+
// (with `realModels.on`, a model whose products don't multiply out is no model: the CDCL search reads a product as
|
|
336
|
+
// a name of its own, where the plain search below multiplies rows; a goal whose products only its cases bring,
|
|
337
|
+
// core/nonterm.ts's x' := x·y)
|
|
338
|
+
if ('tree' in out || (out.stuck === 'sat' && !(realModels.on && fakeProducts(out.witness))))
|
|
290
339
|
return out;
|
|
291
340
|
}
|
|
292
341
|
const open = new Set(root.flatMap(r => Object.keys(r.lin)).filter(n => n.startsWith('⟦') && columnTerm(n)?.op === 'if')).size;
|
|
@@ -299,6 +348,8 @@ function growRoot(goal, path, budget) {
|
|
|
299
348
|
}
|
|
300
349
|
return growPlain(goal, path, budget);
|
|
301
350
|
}
|
|
351
|
+
export const realModels = { on: false };
|
|
352
|
+
const fakeProducts = (w) => !!w && Object.keys(w).some(key => isMonomial(key) && (w[key] ?? 0) !== factorsOf(key).reduce((acc, f) => acc * (w[f] ?? 0), 1));
|
|
302
353
|
function growPlain(goal, path, budget) {
|
|
303
354
|
if (budget.cap !== undefined && budget.nodes >= budget.cap)
|
|
304
355
|
return { stuck: 'unknown', path, why: 'cap' };
|
|
@@ -716,12 +767,19 @@ export function widen(part, whole, tree, opaque = {}, pp = new Map(), wp = pp) {
|
|
|
716
767
|
}
|
|
717
768
|
// Whether each hypothesis reads only names the goal's conclusion (its last hypothesis) reads.
|
|
718
769
|
const nearSeen = new WeakMap();
|
|
719
|
-
|
|
770
|
+
// (the names a term reads, its shared parts walked once: a witness read at each of its uses is one object)
|
|
771
|
+
const namesOf = (t) => {
|
|
772
|
+
const out = new Set();
|
|
773
|
+
walkOnce(t, o => { for (const [key, v] of Object.entries(o))
|
|
774
|
+
if ((key === 'name' || key === 'map') && typeof v === 'string')
|
|
775
|
+
out.add(v); });
|
|
776
|
+
return out;
|
|
777
|
+
};
|
|
720
778
|
export function nearOf(goal) {
|
|
721
779
|
let out = nearSeen.get(goal);
|
|
722
780
|
if (!out) {
|
|
723
781
|
const theirs = new Set(namesOf(goal.hyps.at(-1)));
|
|
724
|
-
nearSeen.set(goal, (out = goal.hyps.map(h => namesOf(h).every(n => theirs.has(n)))));
|
|
782
|
+
nearSeen.set(goal, (out = goal.hyps.map(h => [...namesOf(h)].every(n => theirs.has(n)))));
|
|
725
783
|
}
|
|
726
784
|
return out;
|
|
727
785
|
}
|
|
@@ -729,7 +787,7 @@ export function nearOf(goal) {
|
|
|
729
787
|
// `?f = 1` holds, `k < len` where it is given). Split at the top, its forced side refutes at once; split late, under
|
|
730
788
|
// every other case, it is split again in each.
|
|
731
789
|
// GDP_UNITS=0 leaves them in the goal's order (for comparing).
|
|
732
|
-
const unitFirst =
|
|
790
|
+
const unitFirst = env.GDP_UNITS !== '0';
|
|
733
791
|
let unitsNow = true;
|
|
734
792
|
// The units growPlain splits first, where it does (kernel/cdcl.ts reads them too).
|
|
735
793
|
export const unitAtoms = (goal) => (unitFirst && unitsNow ? unitsOf(goal) : []);
|
|
@@ -947,25 +1005,28 @@ function fractional(point, path) {
|
|
|
947
1005
|
return undefined;
|
|
948
1006
|
}
|
|
949
1007
|
// The keys a proof assumes the every-key laws at: every key the step and the laws read, and the fresh key of the goal.
|
|
1008
|
+
// Each map read of a term (inE) or a condition (inC) given to f, outermost first, a quantified flag's body included.
|
|
1009
|
+
const eachRead = (f) => {
|
|
1010
|
+
const inE = (e) => { if (e.op === 'get') {
|
|
1011
|
+
f(e);
|
|
1012
|
+
inE(e.key);
|
|
1013
|
+
}
|
|
1014
|
+
else if (e.op === 'if')
|
|
1015
|
+
(inC(e.c), inE(e.then), inE(e.else));
|
|
1016
|
+
else if (e.op === 'mul')
|
|
1017
|
+
inE(e.a);
|
|
1018
|
+
else if ('a' in e)
|
|
1019
|
+
(inE(e.a), inE(e.b)); };
|
|
1020
|
+
const inC = (c) => (c.op === 'flag' ? undefined : c.op === 'all' ? inC(c.c) : c.op === 'not' ? inC(c.x) : c.op === 'and' || c.op === 'or' ? c.xs.forEach(inC) : (inE(c.a), inE(c.b)));
|
|
1021
|
+
return { inE, inC };
|
|
1022
|
+
};
|
|
950
1023
|
// A key bound by a quantified flag or a write at every key isn't one: those reads are at every key already.
|
|
951
1024
|
function readKeys(m, laws) {
|
|
952
1025
|
const out = new Map();
|
|
953
1026
|
const bound = new Set([...Object.values(m.step.flags ?? {}).flatMap(c => (c.op === 'all' ? boundOf(c) : [])), ...Object.values(m.step.maps ?? {}).flatMap(w => ('each' in w ? [w.each] : []))]);
|
|
954
1027
|
const free = (e) => !JSON.stringify(e).match(/"name":"([^"]+)"/g)?.some(n => bound.has(n.slice(8, -1)));
|
|
955
|
-
const inE = (e
|
|
956
|
-
|
|
957
|
-
if (free(e.key))
|
|
958
|
-
out.set(JSON.stringify(e.key), e.key);
|
|
959
|
-
inE(e.key);
|
|
960
|
-
}
|
|
961
|
-
else if (e.op === 'if')
|
|
962
|
-
(inC(e.c), inE(e.then), inE(e.else));
|
|
963
|
-
else if (e.op === 'mul')
|
|
964
|
-
inE(e.a);
|
|
965
|
-
else if ('a' in e)
|
|
966
|
-
(inE(e.a), inE(e.b));
|
|
967
|
-
};
|
|
968
|
-
const inC = (c) => (c.op === 'flag' ? undefined : c.op === 'all' ? inC(c.c) : c.op === 'not' ? inC(c.x) : c.op === 'and' || c.op === 'or' ? c.xs.forEach(inC) : (inE(c.a), inE(c.b)));
|
|
1028
|
+
const { inE, inC } = eachRead(e => { if (free(e.key))
|
|
1029
|
+
out.set(JSON.stringify(e.key), e.key); });
|
|
969
1030
|
Object.values(m.step.state ?? {}).forEach(inE);
|
|
970
1031
|
Object.values(m.step.flags ?? {}).forEach(inC);
|
|
971
1032
|
for (const w of Object.values(m.step.maps ?? {})) {
|
|
@@ -993,20 +1054,7 @@ function keysInlined(m, keys) {
|
|
|
993
1054
|
const shifts = (m) => Object.values(m.step.maps ?? {}).some(w => 'each' in w && !plainKey(w.value, w.each));
|
|
994
1055
|
// The keys some goals read a map at.
|
|
995
1056
|
function mapKeys(goals) {
|
|
996
|
-
const out = new Map();
|
|
997
|
-
const inE = (e) => {
|
|
998
|
-
if (e.op === 'get') {
|
|
999
|
-
out.set(JSON.stringify(e.key), e.key);
|
|
1000
|
-
inE(e.key);
|
|
1001
|
-
}
|
|
1002
|
-
else if (e.op === 'if')
|
|
1003
|
-
(inC(e.c), inE(e.then), inE(e.else));
|
|
1004
|
-
else if (e.op === 'mul')
|
|
1005
|
-
inE(e.a);
|
|
1006
|
-
else if ('a' in e)
|
|
1007
|
-
(inE(e.a), inE(e.b));
|
|
1008
|
-
};
|
|
1009
|
-
const inC = (c) => (c.op === 'flag' ? undefined : c.op === 'all' ? inC(c.c) : c.op === 'not' ? inC(c.x) : c.op === 'and' || c.op === 'or' ? c.xs.forEach(inC) : (inE(c.a), inE(c.b)));
|
|
1057
|
+
const out = new Map(), { inC } = eachRead(e => { out.set(JSON.stringify(e.key), e.key); });
|
|
1010
1058
|
for (const g of goals)
|
|
1011
1059
|
g.hyps.forEach(inC);
|
|
1012
1060
|
return [...out.values()];
|
|
@@ -1051,21 +1099,8 @@ const related = (keys, focus, n) => {
|
|
|
1051
1099
|
const tuples = (keys, n) => (n === 0 ? [] : n === 1 ? keys : keys.flatMap(a => { const rest = tuples(keys, n - 1); return Array.from({ length: rest.length / (n - 1) }, (_, t) => [a, ...rest.slice(t * (n - 1), (t + 1) * (n - 1))]).flat(); }));
|
|
1052
1100
|
// The keys some goals read a function at.
|
|
1053
1101
|
function fnKeys(m, goals) {
|
|
1054
|
-
const fns = Object.keys(m.fns ?? {}), out = new Map()
|
|
1055
|
-
|
|
1056
|
-
if (e.op === 'get') {
|
|
1057
|
-
if (fns.includes(e.map))
|
|
1058
|
-
out.set(JSON.stringify(e.key), e.key);
|
|
1059
|
-
inE(e.key);
|
|
1060
|
-
}
|
|
1061
|
-
else if (e.op === 'if')
|
|
1062
|
-
(inC(e.c), inE(e.then), inE(e.else));
|
|
1063
|
-
else if (e.op === 'mul')
|
|
1064
|
-
inE(e.a);
|
|
1065
|
-
else if ('a' in e)
|
|
1066
|
-
(inE(e.a), inE(e.b));
|
|
1067
|
-
};
|
|
1068
|
-
const inC = (c) => (c.op === 'flag' ? undefined : c.op === 'all' ? inC(c.c) : c.op === 'not' ? inC(c.x) : c.op === 'and' || c.op === 'or' ? c.xs.forEach(inC) : (inE(c.a), inE(c.b)));
|
|
1102
|
+
const fns = Object.keys(m.fns ?? {}), out = new Map(), { inC } = eachRead(e => { if (fns.includes(e.map))
|
|
1103
|
+
out.set(JSON.stringify(e.key), e.key); });
|
|
1069
1104
|
for (const g of goals)
|
|
1070
1105
|
g.hyps.forEach(inC);
|
|
1071
1106
|
return [...out.values()];
|
|
@@ -1192,24 +1227,13 @@ function instancesFor(m, laws, build, opts = {}) {
|
|
|
1192
1227
|
// Untrusted: fewer instances still make a checked proof, and where they don't prove a goal the full set is tried.
|
|
1193
1228
|
const triggers = (body, key) => {
|
|
1194
1229
|
const out = [], mentions = (e) => JSON.stringify(e).includes(`"name":${JSON.stringify(key)}`);
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
out.push({ map: e.map, at: e.key });
|
|
1198
|
-
inE(e.key);
|
|
1199
|
-
}
|
|
1200
|
-
else if (e.op === 'if')
|
|
1201
|
-
(inC(e.c), inE(e.then), inE(e.else));
|
|
1202
|
-
else if (e.op === 'mul')
|
|
1203
|
-
inE(e.a);
|
|
1204
|
-
else if ('a' in e)
|
|
1205
|
-
(inE(e.a), inE(e.b)); };
|
|
1206
|
-
const inC = (c) => (c.op === 'flag' ? undefined : c.op === 'all' ? inC(c.c) : c.op === 'not' ? inC(c.x) : c.op === 'and' || c.op === 'or' ? c.xs.forEach(inC) : (inE(c.a), inE(c.b)));
|
|
1207
|
-
inC(body);
|
|
1230
|
+
eachRead(e => { if (mentions(e.key))
|
|
1231
|
+
out.push({ map: e.map, at: e.key }); }).inC(body);
|
|
1208
1232
|
return out;
|
|
1209
1233
|
};
|
|
1210
1234
|
const substKey = (e, key, by) => JSON.parse(JSON.stringify(e).replaceAll(`{"op":"var","name":${JSON.stringify(key)}}`, JSON.stringify(by)));
|
|
1211
1235
|
// GDP_TRIGGER=0 keeps every instance (for comparing).
|
|
1212
|
-
const triggerOn =
|
|
1236
|
+
const triggerOn = env.GDP_TRIGGER !== '0';
|
|
1213
1237
|
function triggered(m, laws, inst, build, focus = []) {
|
|
1214
1238
|
if (!triggerOn)
|
|
1215
1239
|
return inst;
|
|
@@ -1233,17 +1257,7 @@ function triggered(m, laws, inst, build, focus = []) {
|
|
|
1233
1257
|
const out = Object.fromEntries(Object.entries(inst).map(([n, ks]) => [n, bodies.has(n) ? tuplesOf(n, ks).filter(kept).flat() : ks]));
|
|
1234
1258
|
for (let round = 0; round < 8; round++) {
|
|
1235
1259
|
const reads = new Set();
|
|
1236
|
-
const
|
|
1237
|
-
reads.add(`${e.map}|${JSON.stringify(e.key)}`);
|
|
1238
|
-
inE(e.key);
|
|
1239
|
-
}
|
|
1240
|
-
else if (e.op === 'if')
|
|
1241
|
-
(inC(e.c), inE(e.then), inE(e.else));
|
|
1242
|
-
else if (e.op === 'mul')
|
|
1243
|
-
inE(e.a);
|
|
1244
|
-
else if ('a' in e)
|
|
1245
|
-
(inE(e.a), inE(e.b)); };
|
|
1246
|
-
const inC = (c) => (c.op === 'flag' ? undefined : c.op === 'all' ? inC(c.c) : c.op === 'not' ? inC(c.x) : c.op === 'and' || c.op === 'or' ? c.xs.forEach(inC) : (inE(c.a), inE(c.b)));
|
|
1260
|
+
const { inC } = eachRead(e => { reads.add(`${e.map}|${JSON.stringify(e.key)}`); });
|
|
1247
1261
|
for (const g of build(out))
|
|
1248
1262
|
g.hyps.forEach(inC);
|
|
1249
1263
|
let grew = false;
|
|
@@ -1516,7 +1530,7 @@ function proveThinned(m, laws, instances) {
|
|
|
1516
1530
|
if (!('tree' in out) && laws.some(l => instances[l.name] !== fulls[l.name]))
|
|
1517
1531
|
return proveWith(m, laws, fulls);
|
|
1518
1532
|
if (!('tree' in out))
|
|
1519
|
-
return
|
|
1533
|
+
return stuckAt(goal, out, nodes, leaves);
|
|
1520
1534
|
trees[goal.name] = out.tree;
|
|
1521
1535
|
nodes += out.nodes;
|
|
1522
1536
|
leaves += countLeaves(out.tree);
|
|
@@ -1524,6 +1538,8 @@ function proveThinned(m, laws, instances) {
|
|
|
1524
1538
|
const proof = { instances, trees };
|
|
1525
1539
|
return { proven: true, nodes, leaves, checked: !usualCheck.on || checkLaws(m, laws, proof), proof };
|
|
1526
1540
|
}
|
|
1541
|
+
// A goal left unproven, the search's report so far.
|
|
1542
|
+
const stuckAt = (goal, out, nodes, leaves) => ({ proven: false, nodes, leaves, failed: { goal: goal.name, stuck: out.stuck, ...(out.witness ? { witness: out.witness } : {}), ...(out.why ? { why: out.why } : {}) }, checked: false });
|
|
1527
1543
|
// Every goal of the laws with these instances.
|
|
1528
1544
|
function proveWith(m, laws, instances) {
|
|
1529
1545
|
const trees = {};
|
|
@@ -1531,7 +1547,7 @@ function proveWith(m, laws, instances) {
|
|
|
1531
1547
|
for (const goal of obligations(m, laws, instances)) {
|
|
1532
1548
|
const out = grow(goal);
|
|
1533
1549
|
if (!('tree' in out))
|
|
1534
|
-
return
|
|
1550
|
+
return stuckAt(goal, out, nodes, leaves);
|
|
1535
1551
|
trees[goal.name] = out.tree;
|
|
1536
1552
|
nodes += out.nodes;
|
|
1537
1553
|
leaves += countLeaves(out.tree);
|
|
@@ -1596,7 +1612,7 @@ function proveStepLawsAsGiven(m, laws, stepLaws, base) {
|
|
|
1596
1612
|
}
|
|
1597
1613
|
}
|
|
1598
1614
|
if (!('tree' in out))
|
|
1599
|
-
return
|
|
1615
|
+
return stuckAt(goal, out, nodes, leaves);
|
|
1600
1616
|
if (minimal.on) {
|
|
1601
1617
|
const had = perStep[sl.name] ?? instances, built = stepLawObligations(m, laws, had, sl).find(g => g.name === goal.name);
|
|
1602
1618
|
if (built) {
|
|
@@ -1678,7 +1694,7 @@ export function proveProgress(m, laws, p) {
|
|
|
1678
1694
|
for (const goal of progressObligations(m, ls, instances, p)) {
|
|
1679
1695
|
const out = grow(goal);
|
|
1680
1696
|
if (!('tree' in out))
|
|
1681
|
-
return
|
|
1697
|
+
return stuckAt(goal, out, nodes, leaves);
|
|
1682
1698
|
trees[goal.name] = out.tree;
|
|
1683
1699
|
nodes += out.nodes;
|
|
1684
1700
|
leaves += countLeaves(out.tree);
|
package/dist/kernel/reader.d.ts
CHANGED
package/dist/kernel/reader.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { add, k, scale, sub, v } from "../core/solver.js";
|
|
1
|
+
import { add, env, k, scale, sub, v } from "../core/solver.js";
|
|
2
2
|
import { atomOf, canon, canonFlip, columnTerm, factorsOf, isCell, termColumn } from "./kernel.js";
|
|
3
3
|
export const none = new Set();
|
|
4
4
|
export const join = (a, b) => {
|
|
@@ -13,7 +13,8 @@ export const join = (a, b) => {
|
|
|
13
13
|
};
|
|
14
14
|
const R0 = { w: none, pos: -1, fin: true };
|
|
15
15
|
const both = (a, b) => ({ w: join(a.w, b.w), pos: Math.max(a.pos, b.pos), fin: a.fin && b.fin });
|
|
16
|
-
|
|
16
|
+
// The kernel's product of two linear forms (kernel.ts's `times`): each monomial its factors sorted, joined by '*'.
|
|
17
|
+
export function times(a, b) {
|
|
17
18
|
const out = [];
|
|
18
19
|
for (const [p, cp] of Object.entries(a))
|
|
19
20
|
for (const [q, cq] of Object.entries(b)) {
|
|
@@ -37,7 +38,7 @@ function same(site, owner, a, b, c, make) {
|
|
|
37
38
|
return out;
|
|
38
39
|
}
|
|
39
40
|
// GDP_READER_CLEAN=0: values with an open read found again at every node, as before (for comparing).
|
|
40
|
-
const keepClean =
|
|
41
|
+
const keepClean = env.GDP_READER_CLEAN !== '0';
|
|
41
42
|
export class Reader {
|
|
42
43
|
goal;
|
|
43
44
|
trail;
|
package/dist/kernel/simplex.d.ts
CHANGED
package/dist/kernel/simplex.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
+
// Untrusted: an incremental simplex over the rows a search reads at its nodes (each row lin <= 0), in floating point,
|
|
2
|
+
// as an SMT solver's arithmetic does it (Dutertre and de Moura's general form). A row of one variable is a bound on
|
|
3
|
+
// it; any other row is a bound on a slack, one per linear form up to a factor (each slack a basic variable of the
|
|
4
|
+
// tableau, its form over the nonbasic ones). `load` makes a node's rows the bounds (the tableau and the basis are kept
|
|
5
|
+
// from the node before, so a node that differs a little from the last costs a few pivots, not an elimination);
|
|
6
|
+
// `check` pivots until every basic variable is within its bounds (Bland's rule) or a row can't be: its explanation,
|
|
7
|
+
// the rows whose bounds it reads, is a rational refutation's support. Floating point only picks the rows: the caller
|
|
8
|
+
// refutes them exactly (core/solver.ts) and the kernel checks that; a verdict the floats misjudge costs a fallback.
|
|
9
|
+
// Bounds are rounded to integers (every variable is a natural, every form an integer combination): what a cut of the
|
|
10
|
+
// row by its coefficients' divisor gives, which the exact elimination makes as well. Over the rationals (`integral`
|
|
11
|
+
// false) nothing is rounded, and a strict row's bound is moved in by a hair (1e-7, relative): the floats only pick a
|
|
12
|
+
// conflict's rows, which the exact elimination then refutes, strictness and all, or doesn't.
|
|
13
|
+
import { gcd } from "../core/solver.js";
|
|
1
14
|
const eps = 1e-9;
|
|
2
15
|
// A bound's tolerance: relative past 1 (values drift by a few ulps a pivot).
|
|
3
16
|
const tol = (b) => 1e-7 * Math.max(1, Math.abs(b));
|
|
4
|
-
const gcd = (a, b) => (b === 0 ? Math.abs(a) : gcd(b, a % b));
|
|
5
17
|
const formMemo = new WeakMap();
|
|
6
18
|
function formOf(lin) {
|
|
7
19
|
let out = formMemo.get(lin);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gdp-wired",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.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",
|
|
@@ -135,6 +135,7 @@
|
|
|
135
135
|
"oxlint": "1.88.0",
|
|
136
136
|
"oxlint-tsgolint": "7.0.2004",
|
|
137
137
|
"typescript": "5.9.3",
|
|
138
|
-
"xstate": "5.33.2"
|
|
138
|
+
"xstate": "5.33.2",
|
|
139
|
+
"xstate4": "npm:xstate@4.38.3"
|
|
139
140
|
}
|
|
140
141
|
}
|