gdp-wired 0.25.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 +1 -1
- package/dist/core/accel.js +336 -101
- 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 +35 -131
- package/dist/core/cyclic.d.ts +4 -1
- package/dist/core/cyclic.js +86 -64
- package/dist/core/data.d.ts +1 -1
- package/dist/core/data.js +89 -118
- 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.js +72 -18
- package/dist/core/machine.d.ts +6 -0
- package/dist/core/machine.js +35 -3
- package/dist/core/nonterm.d.ts +5 -1
- package/dist/core/nonterm.js +109 -41
- 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 +12 -0
- package/dist/core/solver.js +76 -30
- package/dist/core/transfer.js +22 -13
- 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.js +1 -2
- package/dist/kernel/prove.d.ts +6 -1
- package/dist/kernel/prove.js +96 -82
- 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/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";
|
|
@@ -89,7 +100,7 @@ export function openCells(rows, path) {
|
|
|
89
100
|
const out = [];
|
|
90
101
|
const keyText = (n) => n.slice(n.indexOf('[') + 1, -1);
|
|
91
102
|
// (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 =>
|
|
103
|
+
const maps = names.map(n => n.slice(0, n.indexOf('['))), keys = names.map(n => parseKey(keyText(n)));
|
|
93
104
|
for (let i = 0; i < names.length; i++)
|
|
94
105
|
for (let j = i + 1; j < names.length; j++) {
|
|
95
106
|
if (maps[i] !== maps[j])
|
|
@@ -142,7 +153,8 @@ const quotient = (d) => {
|
|
|
142
153
|
};
|
|
143
154
|
// The cells' key differences split at their quotient's equality, by canonical text: their quotient.
|
|
144
155
|
const cellDiffs = new Map();
|
|
145
|
-
|
|
156
|
+
// A key's canonical text read back as its linear form.
|
|
157
|
+
export function parseKey(text) {
|
|
146
158
|
const out = {};
|
|
147
159
|
let depth = 0, start = 0;
|
|
148
160
|
for (let i = 0; i <= text.length; i++) {
|
|
@@ -188,7 +200,7 @@ const solveP = (rows, maxRows) => {
|
|
|
188
200
|
// PROVE_DUMP: a hook research/perf/prof sets to read each root goal.
|
|
189
201
|
export let proveDump;
|
|
190
202
|
export const setProveDump = (f) => { proveDump = f; };
|
|
191
|
-
const proveTrace = !!
|
|
203
|
+
const proveTrace = !!env.PROVE_TRACE;
|
|
192
204
|
// `why`, when the budget ran out: which limit, at what size, and what usually helps.
|
|
193
205
|
// Set while core/cyclic.ts grows its goals.
|
|
194
206
|
export const cellProducts = { on: false };
|
|
@@ -251,6 +263,39 @@ export function grow(goal, path = new Map(), budget = { nodes: 0, until: clock()
|
|
|
251
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})` : ''}`}`);
|
|
252
264
|
return out;
|
|
253
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) {
|
|
254
299
|
if (!profile.on || path.size || budget.nodes)
|
|
255
300
|
return growRoot(goal, path, budget);
|
|
256
301
|
const t = performance.now(), s0 = profile.solves, m0 = profile.solveMs, r0 = profile.rowsMs, n0 = profile.nodes;
|
|
@@ -260,8 +305,7 @@ export function grow(goal, path = new Map(), budget = { nodes: 0, until: clock()
|
|
|
260
305
|
}
|
|
261
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
|
|
262
307
|
// before it (GDP_QUICK_CAP; 64 where the CDCL search isn't tried, as before it): research/step's comparisons.
|
|
263
|
-
const
|
|
264
|
-
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);
|
|
265
309
|
function growRoot(goal, path, budget) {
|
|
266
310
|
// Past a few cases, CDCL over the atoms (kernel/cdcl.ts), with most of the budget: a linear goal's refutation there
|
|
267
311
|
// is a resolution of short clauses, which the tree search would find again in every case that reaches one. Unknown
|
|
@@ -288,7 +332,10 @@ function growRoot(goal, path, budget) {
|
|
|
288
332
|
if (cdcl) {
|
|
289
333
|
const now = clock(), end = withinDeadline(budget.until ?? Infinity);
|
|
290
334
|
const out = growCdcl(goal, path, { nodes: 0, until: end === Infinity ? end : now + cdclShare * (end - now) });
|
|
291
|
-
|
|
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))))
|
|
292
339
|
return out;
|
|
293
340
|
}
|
|
294
341
|
const open = new Set(root.flatMap(r => Object.keys(r.lin)).filter(n => n.startsWith('⟦') && columnTerm(n)?.op === 'if')).size;
|
|
@@ -301,6 +348,8 @@ function growRoot(goal, path, budget) {
|
|
|
301
348
|
}
|
|
302
349
|
return growPlain(goal, path, budget);
|
|
303
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));
|
|
304
353
|
function growPlain(goal, path, budget) {
|
|
305
354
|
if (budget.cap !== undefined && budget.nodes >= budget.cap)
|
|
306
355
|
return { stuck: 'unknown', path, why: 'cap' };
|
|
@@ -718,12 +767,19 @@ export function widen(part, whole, tree, opaque = {}, pp = new Map(), wp = pp) {
|
|
|
718
767
|
}
|
|
719
768
|
// Whether each hypothesis reads only names the goal's conclusion (its last hypothesis) reads.
|
|
720
769
|
const nearSeen = new WeakMap();
|
|
721
|
-
|
|
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
|
+
};
|
|
722
778
|
export function nearOf(goal) {
|
|
723
779
|
let out = nearSeen.get(goal);
|
|
724
780
|
if (!out) {
|
|
725
781
|
const theirs = new Set(namesOf(goal.hyps.at(-1)));
|
|
726
|
-
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)))));
|
|
727
783
|
}
|
|
728
784
|
return out;
|
|
729
785
|
}
|
|
@@ -731,7 +787,7 @@ export function nearOf(goal) {
|
|
|
731
787
|
// `?f = 1` holds, `k < len` where it is given). Split at the top, its forced side refutes at once; split late, under
|
|
732
788
|
// every other case, it is split again in each.
|
|
733
789
|
// GDP_UNITS=0 leaves them in the goal's order (for comparing).
|
|
734
|
-
const unitFirst =
|
|
790
|
+
const unitFirst = env.GDP_UNITS !== '0';
|
|
735
791
|
let unitsNow = true;
|
|
736
792
|
// The units growPlain splits first, where it does (kernel/cdcl.ts reads them too).
|
|
737
793
|
export const unitAtoms = (goal) => (unitFirst && unitsNow ? unitsOf(goal) : []);
|
|
@@ -949,25 +1005,28 @@ function fractional(point, path) {
|
|
|
949
1005
|
return undefined;
|
|
950
1006
|
}
|
|
951
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
|
+
};
|
|
952
1023
|
// A key bound by a quantified flag or a write at every key isn't one: those reads are at every key already.
|
|
953
1024
|
function readKeys(m, laws) {
|
|
954
1025
|
const out = new Map();
|
|
955
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] : []))]);
|
|
956
1027
|
const free = (e) => !JSON.stringify(e).match(/"name":"([^"]+)"/g)?.some(n => bound.has(n.slice(8, -1)));
|
|
957
|
-
const inE = (e
|
|
958
|
-
|
|
959
|
-
if (free(e.key))
|
|
960
|
-
out.set(JSON.stringify(e.key), e.key);
|
|
961
|
-
inE(e.key);
|
|
962
|
-
}
|
|
963
|
-
else if (e.op === 'if')
|
|
964
|
-
(inC(e.c), inE(e.then), inE(e.else));
|
|
965
|
-
else if (e.op === 'mul')
|
|
966
|
-
inE(e.a);
|
|
967
|
-
else if ('a' in e)
|
|
968
|
-
(inE(e.a), inE(e.b));
|
|
969
|
-
};
|
|
970
|
-
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); });
|
|
971
1030
|
Object.values(m.step.state ?? {}).forEach(inE);
|
|
972
1031
|
Object.values(m.step.flags ?? {}).forEach(inC);
|
|
973
1032
|
for (const w of Object.values(m.step.maps ?? {})) {
|
|
@@ -995,20 +1054,7 @@ function keysInlined(m, keys) {
|
|
|
995
1054
|
const shifts = (m) => Object.values(m.step.maps ?? {}).some(w => 'each' in w && !plainKey(w.value, w.each));
|
|
996
1055
|
// The keys some goals read a map at.
|
|
997
1056
|
function mapKeys(goals) {
|
|
998
|
-
const out = new Map();
|
|
999
|
-
const inE = (e) => {
|
|
1000
|
-
if (e.op === 'get') {
|
|
1001
|
-
out.set(JSON.stringify(e.key), e.key);
|
|
1002
|
-
inE(e.key);
|
|
1003
|
-
}
|
|
1004
|
-
else if (e.op === 'if')
|
|
1005
|
-
(inC(e.c), inE(e.then), inE(e.else));
|
|
1006
|
-
else if (e.op === 'mul')
|
|
1007
|
-
inE(e.a);
|
|
1008
|
-
else if ('a' in e)
|
|
1009
|
-
(inE(e.a), inE(e.b));
|
|
1010
|
-
};
|
|
1011
|
-
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); });
|
|
1012
1058
|
for (const g of goals)
|
|
1013
1059
|
g.hyps.forEach(inC);
|
|
1014
1060
|
return [...out.values()];
|
|
@@ -1053,21 +1099,8 @@ const related = (keys, focus, n) => {
|
|
|
1053
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(); }));
|
|
1054
1100
|
// The keys some goals read a function at.
|
|
1055
1101
|
function fnKeys(m, goals) {
|
|
1056
|
-
const fns = Object.keys(m.fns ?? {}), out = new Map()
|
|
1057
|
-
|
|
1058
|
-
if (e.op === 'get') {
|
|
1059
|
-
if (fns.includes(e.map))
|
|
1060
|
-
out.set(JSON.stringify(e.key), e.key);
|
|
1061
|
-
inE(e.key);
|
|
1062
|
-
}
|
|
1063
|
-
else if (e.op === 'if')
|
|
1064
|
-
(inC(e.c), inE(e.then), inE(e.else));
|
|
1065
|
-
else if (e.op === 'mul')
|
|
1066
|
-
inE(e.a);
|
|
1067
|
-
else if ('a' in e)
|
|
1068
|
-
(inE(e.a), inE(e.b));
|
|
1069
|
-
};
|
|
1070
|
-
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); });
|
|
1071
1104
|
for (const g of goals)
|
|
1072
1105
|
g.hyps.forEach(inC);
|
|
1073
1106
|
return [...out.values()];
|
|
@@ -1194,24 +1227,13 @@ function instancesFor(m, laws, build, opts = {}) {
|
|
|
1194
1227
|
// Untrusted: fewer instances still make a checked proof, and where they don't prove a goal the full set is tried.
|
|
1195
1228
|
const triggers = (body, key) => {
|
|
1196
1229
|
const out = [], mentions = (e) => JSON.stringify(e).includes(`"name":${JSON.stringify(key)}`);
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
out.push({ map: e.map, at: e.key });
|
|
1200
|
-
inE(e.key);
|
|
1201
|
-
}
|
|
1202
|
-
else if (e.op === 'if')
|
|
1203
|
-
(inC(e.c), inE(e.then), inE(e.else));
|
|
1204
|
-
else if (e.op === 'mul')
|
|
1205
|
-
inE(e.a);
|
|
1206
|
-
else if ('a' in e)
|
|
1207
|
-
(inE(e.a), inE(e.b)); };
|
|
1208
|
-
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)));
|
|
1209
|
-
inC(body);
|
|
1230
|
+
eachRead(e => { if (mentions(e.key))
|
|
1231
|
+
out.push({ map: e.map, at: e.key }); }).inC(body);
|
|
1210
1232
|
return out;
|
|
1211
1233
|
};
|
|
1212
1234
|
const substKey = (e, key, by) => JSON.parse(JSON.stringify(e).replaceAll(`{"op":"var","name":${JSON.stringify(key)}}`, JSON.stringify(by)));
|
|
1213
1235
|
// GDP_TRIGGER=0 keeps every instance (for comparing).
|
|
1214
|
-
const triggerOn =
|
|
1236
|
+
const triggerOn = env.GDP_TRIGGER !== '0';
|
|
1215
1237
|
function triggered(m, laws, inst, build, focus = []) {
|
|
1216
1238
|
if (!triggerOn)
|
|
1217
1239
|
return inst;
|
|
@@ -1235,17 +1257,7 @@ function triggered(m, laws, inst, build, focus = []) {
|
|
|
1235
1257
|
const out = Object.fromEntries(Object.entries(inst).map(([n, ks]) => [n, bodies.has(n) ? tuplesOf(n, ks).filter(kept).flat() : ks]));
|
|
1236
1258
|
for (let round = 0; round < 8; round++) {
|
|
1237
1259
|
const reads = new Set();
|
|
1238
|
-
const
|
|
1239
|
-
reads.add(`${e.map}|${JSON.stringify(e.key)}`);
|
|
1240
|
-
inE(e.key);
|
|
1241
|
-
}
|
|
1242
|
-
else if (e.op === 'if')
|
|
1243
|
-
(inC(e.c), inE(e.then), inE(e.else));
|
|
1244
|
-
else if (e.op === 'mul')
|
|
1245
|
-
inE(e.a);
|
|
1246
|
-
else if ('a' in e)
|
|
1247
|
-
(inE(e.a), inE(e.b)); };
|
|
1248
|
-
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)}`); });
|
|
1249
1261
|
for (const g of build(out))
|
|
1250
1262
|
g.hyps.forEach(inC);
|
|
1251
1263
|
let grew = false;
|
|
@@ -1518,7 +1530,7 @@ function proveThinned(m, laws, instances) {
|
|
|
1518
1530
|
if (!('tree' in out) && laws.some(l => instances[l.name] !== fulls[l.name]))
|
|
1519
1531
|
return proveWith(m, laws, fulls);
|
|
1520
1532
|
if (!('tree' in out))
|
|
1521
|
-
return
|
|
1533
|
+
return stuckAt(goal, out, nodes, leaves);
|
|
1522
1534
|
trees[goal.name] = out.tree;
|
|
1523
1535
|
nodes += out.nodes;
|
|
1524
1536
|
leaves += countLeaves(out.tree);
|
|
@@ -1526,6 +1538,8 @@ function proveThinned(m, laws, instances) {
|
|
|
1526
1538
|
const proof = { instances, trees };
|
|
1527
1539
|
return { proven: true, nodes, leaves, checked: !usualCheck.on || checkLaws(m, laws, proof), proof };
|
|
1528
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 });
|
|
1529
1543
|
// Every goal of the laws with these instances.
|
|
1530
1544
|
function proveWith(m, laws, instances) {
|
|
1531
1545
|
const trees = {};
|
|
@@ -1533,7 +1547,7 @@ function proveWith(m, laws, instances) {
|
|
|
1533
1547
|
for (const goal of obligations(m, laws, instances)) {
|
|
1534
1548
|
const out = grow(goal);
|
|
1535
1549
|
if (!('tree' in out))
|
|
1536
|
-
return
|
|
1550
|
+
return stuckAt(goal, out, nodes, leaves);
|
|
1537
1551
|
trees[goal.name] = out.tree;
|
|
1538
1552
|
nodes += out.nodes;
|
|
1539
1553
|
leaves += countLeaves(out.tree);
|
|
@@ -1598,7 +1612,7 @@ function proveStepLawsAsGiven(m, laws, stepLaws, base) {
|
|
|
1598
1612
|
}
|
|
1599
1613
|
}
|
|
1600
1614
|
if (!('tree' in out))
|
|
1601
|
-
return
|
|
1615
|
+
return stuckAt(goal, out, nodes, leaves);
|
|
1602
1616
|
if (minimal.on) {
|
|
1603
1617
|
const had = perStep[sl.name] ?? instances, built = stepLawObligations(m, laws, had, sl).find(g => g.name === goal.name);
|
|
1604
1618
|
if (built) {
|
|
@@ -1680,7 +1694,7 @@ export function proveProgress(m, laws, p) {
|
|
|
1680
1694
|
for (const goal of progressObligations(m, ls, instances, p)) {
|
|
1681
1695
|
const out = grow(goal);
|
|
1682
1696
|
if (!('tree' in out))
|
|
1683
|
-
return
|
|
1697
|
+
return stuckAt(goal, out, nodes, leaves);
|
|
1684
1698
|
trees[goal.name] = out.tree;
|
|
1685
1699
|
nodes += out.nodes;
|
|
1686
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
|
}
|