gdp-wired 0.45.0 → 0.47.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 +61 -8
- package/dist/core/bitsets.d.ts +2 -0
- package/dist/core/bitsets.js +23 -0
- package/dist/core/bmc.js +6 -2
- package/dist/core/c/reader.d.ts +9 -1
- package/dist/core/c/reader.js +423 -31
- package/dist/core/calendar.d.ts +29 -0
- package/dist/core/calendar.js +82 -0
- package/dist/core/cli.d.ts +4 -0
- package/dist/core/cli.js +206 -40
- package/dist/core/compose.js +3 -1
- package/dist/core/counts.d.ts +4 -1
- package/dist/core/counts.js +314 -85
- package/dist/core/cycles.js +8 -1
- package/dist/core/cyclic.d.ts +1 -0
- package/dist/core/cyclic.js +13 -7
- package/dist/core/data-synth.d.ts +3 -0
- package/dist/core/data-synth.js +252 -0
- package/dist/core/data.d.ts +2 -1
- package/dist/core/data.js +223 -24
- package/dist/core/discover.js +3 -1
- package/dist/core/draft.d.ts +19 -0
- package/dist/core/draft.js +53 -0
- package/dist/core/dsl.d.ts +37 -3
- package/dist/core/dsl.js +167 -26
- package/dist/core/effect-schema.d.ts +90 -0
- package/dist/core/effect-schema.js +500 -0
- package/dist/core/effect.d.ts +4 -11
- package/dist/core/effect.js +3 -79
- package/dist/core/exists.d.ts +1 -0
- package/dist/core/exists.js +191 -16
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +169 -22
- package/dist/core/extract-check.d.ts +1 -0
- package/dist/core/extract-check.js +97 -6
- package/dist/core/extract-go-check.d.ts +1 -1
- package/dist/core/extract-go-check.js +26 -5
- package/dist/core/extract-go.d.ts +8 -0
- package/dist/core/extract-go.js +67 -6
- package/dist/core/extract-ir.d.ts +1 -0
- package/dist/core/extract-ir.js +15 -0
- package/dist/core/extract-jvm.d.ts +1 -1
- package/dist/core/extract-jvm.js +2 -0
- package/dist/core/extract-orm.d.ts +12 -0
- package/dist/core/extract-orm.js +244 -0
- package/dist/core/extract-print.js +20 -1
- package/dist/core/extract-py.d.ts +1 -0
- package/dist/core/extract-py.js +1 -1
- package/dist/core/extract-read.d.ts +26 -1
- package/dist/core/extract-read.js +14 -7
- package/dist/core/extract-rs.js +63 -15
- package/dist/core/extract-shapes.d.ts +1 -0
- package/dist/core/extract-shapes.js +84 -0
- package/dist/core/extract-sol.d.ts +10 -1
- package/dist/core/extract-sol.js +70 -22
- package/dist/core/extract-standalone.d.ts +3 -0
- package/dist/core/extract-standalone.js +221 -0
- package/dist/core/extract-step.d.ts +151 -1
- package/dist/core/extract-step.js +1232 -60
- package/dist/core/extract-swift.js +6 -2
- package/dist/core/extract.d.ts +9 -0
- package/dist/core/extract.js +77 -7
- package/dist/core/fiber-run.d.ts +5 -0
- package/dist/core/fiber-run.js +18 -0
- package/dist/core/infer.d.ts +4 -1
- package/dist/core/infer.js +918 -217
- package/dist/core/jvm/JavaReader.java +23 -6
- package/dist/core/jvm/Jvm.java +3 -0
- package/dist/core/jvm/KtReader.java +6 -5
- package/dist/core/laws.d.ts +10 -3
- package/dist/core/laws.js +226 -23
- package/dist/core/machine.d.ts +15 -1
- package/dist/core/machine.js +187 -15
- package/dist/core/nonterm.js +14 -1
- package/dist/core/orm/harness.js +61 -0
- package/dist/core/orm-fixtures/schema.prisma +5 -0
- package/dist/core/py/harness.py +183 -10
- package/dist/core/py/reader.py +234 -40
- package/dist/core/reader-fixtures/README.md +28 -0
- package/dist/core/reader-fixtures/c-693042.cpp +8 -0
- package/dist/core/reader-fixtures/go-685506.go +14 -0
- package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
- package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
- package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
- package/dist/core/reader-fixtures/swift-735726.swift +15 -0
- package/dist/core/reader-fixtures/swift-735990.swift +15 -0
- package/dist/core/reader-fixtures/swift-739158.swift +4 -0
- package/dist/core/reader-fixtures/swift-744834.swift +15 -0
- package/dist/core/reader-fixtures/swift-746946.swift +31 -0
- package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
- package/dist/core/relation.d.ts +1 -1
- package/dist/core/relation.js +29 -2
- package/dist/core/relational.js +4 -2
- package/dist/core/rs/Cargo.toml +1 -1
- package/dist/core/rs/src/main.rs +466 -11
- package/dist/core/sample-cache.d.ts +8 -0
- package/dist/core/sample-cache.js +46 -0
- package/dist/core/security.d.ts +38 -0
- package/dist/core/security.js +88 -0
- package/dist/core/sol/harness.py +57 -4
- package/dist/core/sol-concrete.d.ts +23 -0
- package/dist/core/sol-concrete.js +195 -0
- package/dist/core/solver.js +3 -1
- package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
- package/dist/core/system.js +1 -1
- package/dist/core/transfer.js +22 -9
- package/dist/core/translate.js +39 -10
- package/dist/core/watch.js +50 -5
- package/dist/interchange/format.js +11 -1
- package/dist/kernel/cdcl.d.ts +5 -0
- package/dist/kernel/cdcl.js +56 -9
- package/dist/kernel/epr.js +108 -26
- package/dist/kernel/kernel.d.ts +29 -1
- package/dist/kernel/kernel.js +325 -62
- package/dist/kernel/model-sequence.d.ts +3 -0
- package/dist/kernel/model-sequence.js +34 -0
- package/dist/kernel/prove.d.ts +10 -3
- package/dist/kernel/prove.js +332 -71
- package/dist/kernel/reader.d.ts +3 -0
- package/dist/kernel/reader.js +101 -14
- package/dist/kernel/share.d.ts +1 -0
- package/dist/kernel/share.js +27 -0
- package/dist/lean-kernel/emit.js +30 -37
- package/dist/lean-kernel/lean-terms.js +5 -0
- package/dist/lean-kernel/library.js +10 -10
- package/package.json +6 -1
package/dist/kernel/prove.js
CHANGED
|
@@ -8,14 +8,15 @@
|
|
|
8
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
9
|
// - a hypothesis' rows and open atoms, and every term inside them, are reused from an earlier path that decided the
|
|
10
10
|
// same atoms they read (kernel.ts's reusing), so a new decision reads again only what it touches.
|
|
11
|
-
import { evalC, evalE, walkOnce } from "../core/machine.js";
|
|
11
|
+
import { cpair, evalC, evalE, walkOnce } from "../core/machine.js";
|
|
12
12
|
import { add, costs, env, k, refuteFast, scale, solve, sub, v, work } from "../core/solver.js";
|
|
13
13
|
import { checkRefutation } from "../core/check.js";
|
|
14
14
|
import { allowNode, allowTranslated, certCyclic, certOn, certSearch, stepCertFloor, translateMs, closingInsts, crossCyclic, cyclicOn, cycLog, hasQuantified, loopNodes, machineNodes, proveCyclic, reqTS, searchedStepNodes, skMachine, timedKind, withWitness, translatedProof, uncovered, uncoveredWhy } from "../core/cyclic.js";
|
|
15
15
|
import { proveSome, someLaws } from "../core/exists.js";
|
|
16
16
|
import { REFUTED, growCdcl } from "./cdcl.js";
|
|
17
|
-
import { decide, pastEprCap, patternsOf } from "./epr.js";
|
|
18
|
-
import {
|
|
17
|
+
import { decide, eprMeter, pastEprCap, patternsOf, withEprCap } from "./epr.js";
|
|
18
|
+
import { projected, tupleParts } from "./kernel.js";
|
|
19
|
+
import { assumed, atomOf, boundOf, canon, canonFlip, cellParts, columnTerm, decided, factorsOf, isCell, isMonomial, stepZone, check, checkLaws, checkStepLaws, historyMachine, plainOf, substC, substE, leafConstraints, leafConstraintsReusing, reusing, linear, livenessHelpful, livenessParts, strongly, loopMachine, obligations, plainKey, progressObligations, stepLawObligations, trueC, truth, unreachable, witnessesOf, withProducts } from "./kernel.js";
|
|
19
20
|
// The atoms the path leaves open, in evaluation order: deciding any of them makes progress.
|
|
20
21
|
function openE(e, path, out) {
|
|
21
22
|
switch (e.op) {
|
|
@@ -24,6 +25,8 @@ function openE(e, path, out) {
|
|
|
24
25
|
case 'mul': return openE(e.a, path, out);
|
|
25
26
|
case 'prod': return (openE(e.a, path, out), openE(e.b, path, out));
|
|
26
27
|
case 'get': return openE(e.key, path, out);
|
|
28
|
+
case 'tup': return (openE(e.a, path, out), openE(e.b, path, out));
|
|
29
|
+
case 'proj': return openE(e.a.op === 'tup' ? (e.k === 0 ? e.a.a : e.a.b) : e.a, path, out);
|
|
27
30
|
case 'if': {
|
|
28
31
|
const t = truth(e.c, path);
|
|
29
32
|
if (t === undefined)
|
|
@@ -54,6 +57,9 @@ function openC(c, path, out) {
|
|
|
54
57
|
return openC(c.x, path, out);
|
|
55
58
|
if (c.op === 'and' || c.op === 'or')
|
|
56
59
|
return c.xs.forEach(y => openC(y, path, out));
|
|
60
|
+
// (two tuples equal: their parts' equalities, the kernel's reading)
|
|
61
|
+
if (c.op === '=' && c.a.op === 'tup' && c.b.op === 'tup')
|
|
62
|
+
return [c.a.a, c.a.b].forEach((x, i) => openC({ op: '=', a: x, b: i ? c.b.b : c.b.a }, path, out));
|
|
57
63
|
const a = linear(c.a, path), b = linear(c.b, path), own = [];
|
|
58
64
|
if (a && b) {
|
|
59
65
|
const d = sub(a, b);
|
|
@@ -87,6 +93,10 @@ function openH(c, path, out, positive = true) {
|
|
|
87
93
|
}
|
|
88
94
|
if (c.op === 'flag' || c.op === 'all')
|
|
89
95
|
return;
|
|
96
|
+
if (c.op === '=' && c.a.op === 'tup' && c.b.op === 'tup') {
|
|
97
|
+
const parts = [{ op: '=', a: c.a.a, b: c.b.a }, { op: '=', a: c.a.b, b: c.b.b }];
|
|
98
|
+
return openH(positive ? { op: 'and', xs: parts } : { op: 'or', xs: parts.map((x) => ({ op: 'not', x })) }, path, out, true);
|
|
99
|
+
}
|
|
90
100
|
const before = out.length;
|
|
91
101
|
openE(c.a, path, out), openE(c.b, path, out);
|
|
92
102
|
if (out.length === before && !positive && c.op === '=' && truth(c, path) === undefined)
|
|
@@ -112,7 +122,7 @@ export const cellPair = (a, b) => {
|
|
|
112
122
|
cellPairsN = 1;
|
|
113
123
|
cellPairs.set(a, (row = new Map()));
|
|
114
124
|
}
|
|
115
|
-
const d = sub(cellKey(a).key, cellKey(b).key);
|
|
125
|
+
const d = sub(cellKey(a).key ?? {}, cellKey(b).key ?? {});
|
|
116
126
|
row.set(b, (pair = { d, neg: scale(d, -1) }));
|
|
117
127
|
}
|
|
118
128
|
return pair;
|
|
@@ -120,8 +130,39 @@ export const cellPair = (a, b) => {
|
|
|
120
130
|
const cellKey = (n) => { let c = cellKeys.get(n); if (!c) {
|
|
121
131
|
if (cellKeys.size > 100_000)
|
|
122
132
|
cellKeys.clear();
|
|
123
|
-
cellKeys.set(n, (c =
|
|
133
|
+
cellKeys.set(n, (c = cellParts(n)));
|
|
124
134
|
} return c; };
|
|
135
|
+
// Two tuple cells of one map: their parts compared one at a time, the first the path leaves open (each way), none
|
|
136
|
+
// once a part is decided apart. (Each part's difference made once per pair, as a plain key's.)
|
|
137
|
+
const tuplePairs = new Map();
|
|
138
|
+
// Two cells' parts as pairs of differences: [] for two keys of different shapes (never equal), undefined for plain keys.
|
|
139
|
+
export const tupleCellPairs = (a, b) => {
|
|
140
|
+
const ka = cellKey(a).keys, kb = cellKey(b).keys;
|
|
141
|
+
if (!ka && !kb)
|
|
142
|
+
return undefined;
|
|
143
|
+
if (!ka || !kb || ka.length !== kb.length)
|
|
144
|
+
return [];
|
|
145
|
+
const id = `${a} ${b}`;
|
|
146
|
+
let ds = tuplePairs.get(id);
|
|
147
|
+
if (!ds) {
|
|
148
|
+
if (tuplePairs.size > 200_000)
|
|
149
|
+
tuplePairs.clear();
|
|
150
|
+
tuplePairs.set(id, (ds = ka.map((k, i) => { const d = sub(k, kb[i]); return [d, scale(d, -1)]; })));
|
|
151
|
+
}
|
|
152
|
+
return ds;
|
|
153
|
+
};
|
|
154
|
+
const tupleOpen = (a, b, _ka, _kb, dec) => {
|
|
155
|
+
for (const [d, neg] of tupleCellPairs(a, b)) {
|
|
156
|
+
const x = dec(d), y = dec(neg);
|
|
157
|
+
if (x === undefined)
|
|
158
|
+
return d;
|
|
159
|
+
if (x === true && y === undefined)
|
|
160
|
+
return neg;
|
|
161
|
+
if (!(x && y))
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
return undefined;
|
|
165
|
+
};
|
|
125
166
|
function openCells(rows, path) {
|
|
126
167
|
const seen = new Set(), names = [];
|
|
127
168
|
for (const r of rows)
|
|
@@ -138,6 +179,12 @@ function openCells(rows, path) {
|
|
|
138
179
|
for (let j = i + 1; j < names.length; j++) {
|
|
139
180
|
if (cs[i].map !== cs[j].map)
|
|
140
181
|
continue;
|
|
182
|
+
if (cs[i].keys || cs[j].keys) {
|
|
183
|
+
const t = cs[i].keys && cs[j].keys ? tupleOpen(names[i], names[j], cs[i].keys, cs[j].keys, dec) : undefined;
|
|
184
|
+
if (t)
|
|
185
|
+
out.push(t);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
141
188
|
const pair = cellPair(names[i], names[j]), d = pair.d;
|
|
142
189
|
if (pairedKeys.skip && Object.keys(d).some(isMonomial))
|
|
143
190
|
continue;
|
|
@@ -241,7 +288,10 @@ export const cellProducts = { on: false };
|
|
|
241
288
|
// clock inside `counted` and in the cost model's work outside it (`withWork`); past either the goal is left `unknown`. A goal with many instances (a law about two keys at its pairs) has that many more rows per leaf.
|
|
242
289
|
// A deadline every goal grown inside `withDeadline` keeps, beside its own budget: a search that proves many things (core/
|
|
243
290
|
// infer.ts, core/discover.ts, the search proveRule falls back on) bounds them all; a goal past it is left `unknown`.
|
|
244
|
-
let deadline = Infinity;
|
|
291
|
+
let deadline = Infinity, deadlineEpr = 0;
|
|
292
|
+
// EPR has its own work counter. Debit it from a counted deadline, not from clock(): the protocol engine already
|
|
293
|
+
// accounts for EPR in its own clock. A scope's anchor charges all its queries, including nested and failed ones.
|
|
294
|
+
const eprTimeSince = (start) => rate ? (eprMeter.n - start) / rate : 0;
|
|
245
295
|
// The clock every budget here reads (grow's `until`, withDeadline's; core/cyclic.ts's and core/data.ts's searches): wall
|
|
246
296
|
// time, or within `counted` the work the prover has done (the solver's rows read and made, each node's rows), `perMs`
|
|
247
297
|
// units a millisecond, so that what a search's budget lets it try, and so its verdict, doesn't depend on the machine's
|
|
@@ -311,15 +361,17 @@ const ranOut = () => pastWall() || withinDeadline(Infinity) <= clock();
|
|
|
311
361
|
export const wallAt = () => wallEnd;
|
|
312
362
|
export const late = (until) => clock() > until || (workCap !== Infinity && fullWork() > workCap) || pastWall();
|
|
313
363
|
// A budget's end, within the deadline (a translation's own bound, core/cyclic.ts's, kept by the export's GDP_CERT_MS).
|
|
314
|
-
export const withinDeadline = (until) => Math.min(until, deadline);
|
|
364
|
+
export const withinDeadline = (until) => Math.min(until, deadline - eprTimeSince(deadlineEpr));
|
|
315
365
|
export function withDeadline(until, f) {
|
|
316
|
-
const outer = deadline;
|
|
317
|
-
deadline =
|
|
366
|
+
const outer = deadline, outerEpr = deadlineEpr;
|
|
367
|
+
deadline = withinDeadline(until);
|
|
368
|
+
deadlineEpr = eprMeter.n;
|
|
318
369
|
try {
|
|
319
370
|
return f();
|
|
320
371
|
}
|
|
321
372
|
finally {
|
|
322
373
|
deadline = outer;
|
|
374
|
+
deadlineEpr = outerEpr;
|
|
323
375
|
}
|
|
324
376
|
}
|
|
325
377
|
// `units: false`: the goal's own order, no units first (a caller after a model, not a proof: a run guided by the
|
|
@@ -333,8 +385,9 @@ export function grow(goal, path = new Map(), budget) {
|
|
|
333
385
|
return withWork(fullWork() + groundRate * ms, () => grow(goal, path, { nodes: 0 }));
|
|
334
386
|
budget = { nodes: 0, until: clock() + ms };
|
|
335
387
|
}
|
|
336
|
-
|
|
337
|
-
|
|
388
|
+
const end = withinDeadline(budget.until ?? Infinity);
|
|
389
|
+
if (end < (budget.until ?? Infinity))
|
|
390
|
+
budget.until = end;
|
|
338
391
|
if (budget.units === false && unitsNow) {
|
|
339
392
|
unitsNow = false;
|
|
340
393
|
try {
|
|
@@ -441,9 +494,13 @@ const withPatterns = (m, laws, f) => {
|
|
|
441
494
|
// (`refuted`: the last decision refuted the goal and its core's proof didn't finish: a model from fewer instances, asked
|
|
442
495
|
// before, is then no answer, as the abstraction refutes it at these)
|
|
443
496
|
const eprLast = { refuted: false };
|
|
444
|
-
function eprFirst(goal, budget, whole = true,
|
|
497
|
+
function eprFirst(goal, budget, whole = true, stop = () => pastWall() || pastEprCap()) {
|
|
445
498
|
eprLast.refuted = false;
|
|
446
|
-
const
|
|
499
|
+
const start = eprMeter.n, until = budget.until ?? Infinity;
|
|
500
|
+
const d = decide(goal, eprScope.patterns, { exact: true, late: () => stop() || late(withinDeadline(until - eprTimeSince(start))) });
|
|
501
|
+
// The local goal's remaining allowance also reaches the core proof or fallback search.
|
|
502
|
+
if (budget.until !== undefined)
|
|
503
|
+
budget.until = until - eprTimeSince(start);
|
|
447
504
|
if ('unknown' in d)
|
|
448
505
|
return undefined;
|
|
449
506
|
if (d.sat)
|
|
@@ -452,7 +509,8 @@ function eprFirst(goal, budget, whole = true, late = () => pastWall() || pastEpr
|
|
|
452
509
|
const now = clock(), end = withinDeadline(budget.until ?? Infinity), w = fullWork();
|
|
453
510
|
eprScope.busy = true;
|
|
454
511
|
try {
|
|
455
|
-
const
|
|
512
|
+
const share = whole ? 0.5 : 1;
|
|
513
|
+
const out = withWork(workCap === Infinity ? Infinity : w + share * (workCap - w), () => grow(part, new Map(), { nodes: 0, until: end === Infinity ? end : now + share * (end - now) }));
|
|
456
514
|
if (!('tree' in out)) {
|
|
457
515
|
eprLast.refuted = true;
|
|
458
516
|
return undefined;
|
|
@@ -486,16 +544,17 @@ const cellsIn = (c) => { const out = new Set(); walkOnce(c, o => { const x = o;
|
|
|
486
544
|
out.add(`${x.map}${JSON.stringify(x.key)}`); }); return out; };
|
|
487
545
|
// (the hypotheses a model breaks among `ids` (all where none are given), the model read as a state, the conclusion first;
|
|
488
546
|
// `first`: the first one broken alone)
|
|
547
|
+
// (`defaults`: a map's cells the model leaves out read at that value, not the map's start)
|
|
489
548
|
export const brokenOf = (goal) => {
|
|
490
549
|
const maps = new Set();
|
|
491
550
|
walkOnce(goal.hyps, o => { const x = o; if (x.op === 'get' && typeof x.map === 'string')
|
|
492
551
|
maps.add(x.map); });
|
|
493
552
|
const mm = { maps: Object.fromEntries([...maps].map(mp => [mp, 0])) };
|
|
494
|
-
return (w0, ids = goal.hyps.map((_, i) => i), first = false) => {
|
|
553
|
+
return (w0, ids = goal.hyps.map((_, i) => i), first = false, defaults) => {
|
|
495
554
|
// (a term column's value is its term's at the point, not the point's own where its choice is open: each cell is put
|
|
496
555
|
// at its key's value with the columns so read, twice, as a column's term may read a cell)
|
|
497
556
|
const w = { ...w0 }, at = new Proxy(w, { get: (t, q) => t[q] ?? 0 }), out = [];
|
|
498
|
-
let st = { scalars: {}, maps: {} };
|
|
557
|
+
let st = { scalars: {}, maps: {}, ...(defaults ? { defaults } : {}) };
|
|
499
558
|
for (let pass = 0; pass < 3; pass++) {
|
|
500
559
|
if (pass)
|
|
501
560
|
for (const n in w) {
|
|
@@ -506,7 +565,7 @@ export const brokenOf = (goal) => {
|
|
|
506
565
|
}
|
|
507
566
|
catch { /* left */ }
|
|
508
567
|
}
|
|
509
|
-
st = { scalars: {}, maps: Object.fromEntries([...maps].map(mp => [mp, new Map()])) };
|
|
568
|
+
st = { scalars: {}, maps: Object.fromEntries([...maps].map(mp => [mp, new Map()])), ...(defaults ? { defaults } : {}) };
|
|
510
569
|
for (const [cell, value] of Object.entries(w)) {
|
|
511
570
|
const br = cell.indexOf('['), key = br > 0 && cell.endsWith(']') && st.maps[cell.slice(0, br)] ? keyValue(cell, w) : undefined;
|
|
512
571
|
if (key !== undefined)
|
|
@@ -537,7 +596,9 @@ const termsOf = (goal) => { let n = termsSeen.get(goal); if (n === undefined) {
|
|
|
537
596
|
termsSeen.set(goal, n);
|
|
538
597
|
} return n; };
|
|
539
598
|
export const wideFor = (goal) => !wideBusy && goal.hyps.length >= wideAt && termsOf(goal) >= wideTerms;
|
|
540
|
-
|
|
599
|
+
// (`keep`: a part's tree kept as the part's, with the part and its hypotheses' indices in the whole as its core, not
|
|
600
|
+
// widened: settle's, whose final proof is made over the instances its proofs read)
|
|
601
|
+
export function growWide(goal, budget, ask = (g, until) => grow(g, new Map(), { nodes: 0, until }), keep = false) {
|
|
541
602
|
const hyps = goal.hyps, last = hyps.length - 1, broken = brokenOf(goal), now = clock(), w = fullWork();
|
|
542
603
|
const end = withinDeadline(budget.until ?? Infinity), span = wideShare * (end - now), room = wideShare * (workCap - w), until = now + span;
|
|
543
604
|
const part = new Set([last]), near = new Set(cellsIn(hyps[last])), cells = new Map();
|
|
@@ -565,6 +626,10 @@ export function growWide(goal, budget, ask = (g, until) => grow(g, new Map(), {
|
|
|
565
626
|
wideHook.on?.(g, out);
|
|
566
627
|
if (wideTrace)
|
|
567
628
|
console.error(`[wide] ${goal.name.slice(0, 40)}: part ${g.hyps.length} of ${hyps.length}, ${'tree' in out ? 'tree' : out.stuck} in ${Math.round(performance.now() - t0)} ms${'tree' in out ? '' : ` ${out.why?.slice(0, 50) ?? ''}`}`);
|
|
629
|
+
if ('tree' in out && keep) {
|
|
630
|
+
wideStats.trees++;
|
|
631
|
+
return { tree: out.tree, nodes: out.nodes, part: g, core: ids };
|
|
632
|
+
}
|
|
568
633
|
if ('tree' in out) {
|
|
569
634
|
const tree = withWork(w + room, () => withDeadline(until, () => widen(g, goal, out.tree)));
|
|
570
635
|
if (tree)
|
|
@@ -602,15 +667,25 @@ export function growWide(goal, budget, ask = (g, until) => grow(g, new Map(), {
|
|
|
602
667
|
wideBusy = false;
|
|
603
668
|
}
|
|
604
669
|
}
|
|
670
|
+
// (the abstraction of a whole wide goal, quadratic in its cells, within GDP_WIDE_EPR units: i4's learning switch's
|
|
671
|
+
// largest decision otherwise 0.47M, its engine set's step goal of 7,590 hypotheses 19M, past its caller's end, in 10 GB)
|
|
672
|
+
const wideEprUnits = Number(env.GDP_WIDE_EPR ?? 2_000_000), wideParts = env.GDP_WIDE_PARTS !== '0';
|
|
673
|
+
// (only where the rule has tuple keys, its patterns n zeros: radix-keyed rules keep main's path, consensus_wo_decide's
|
|
674
|
+
// and ring_leader_election's proofs among them, lost to it at 60 s)
|
|
675
|
+
const tupledScope = () => !!eprScope.patterns && Object.values(eprScope.patterns).some(c => c.length > 1 && c[0] === 0);
|
|
676
|
+
// (a part of a wide goal by the EPR path first, its core widened to the part, else the usual search)
|
|
677
|
+
const eprPart = (gp, until) => eprFirst(gp, { nodes: 0, until }) ?? grow(gp, new Map(), { nodes: 0, until });
|
|
605
678
|
function growRoot(goal, path, budget) {
|
|
606
|
-
|
|
607
|
-
|
|
679
|
+
const wide = !path.size && !budget.nodes && wideFor(goal), epr = !!eprScope.patterns && !eprScope.busy;
|
|
680
|
+
// (a wide goal's parts by the EPR path too, where the goal is EPR-shaped)
|
|
681
|
+
if (wide) {
|
|
682
|
+
const out = epr && wideParts && tupledScope() ? growWide(goal, budget, eprPart) : growWide(goal, budget);
|
|
608
683
|
if (out)
|
|
609
684
|
return out;
|
|
610
685
|
}
|
|
611
686
|
// (not for a wide goal's part: its abstraction's search reads no judge, and the whole goal is decided by it after)
|
|
612
|
-
if (
|
|
613
|
-
const out = eprFirst(goal, budget);
|
|
687
|
+
if (epr && !wideBusy && !path.size && !budget.nodes) {
|
|
688
|
+
const out = wide && tupledScope() ? withEprCap(wideEprUnits, () => eprFirst(goal, budget)) : eprFirst(goal, budget);
|
|
614
689
|
if (out)
|
|
615
690
|
return out;
|
|
616
691
|
}
|
|
@@ -626,7 +701,7 @@ function growRoot(goal, path, budget) {
|
|
|
626
701
|
const cdcl = !!root && cdclShare > 0 && !cellProducts.on && Number(/@(\d+) steps/.exec(goal.name)?.[1] ?? 1) <= 1 && !root.some(r => Object.keys(r.lin).some(isMonomial));
|
|
627
702
|
// At the root: plainly first; where the cases multiply past a budget, through cuts. The plain budget halves with each
|
|
628
703
|
// two open choices (what a plain search's cases grow by), so a long run's steps reach the cuts early.
|
|
629
|
-
if (root && unitFirst && unitsNow) {
|
|
704
|
+
if (root && unitFirst && unitsNow && !(eprScope.busy && tupledScope())) {
|
|
630
705
|
// A goal that a few cases settle needs no units (finding them costs a Farkas check per atom); the rest get them.
|
|
631
706
|
unitsNow = false;
|
|
632
707
|
try {
|
|
@@ -1370,9 +1445,9 @@ const eachRead = (f) => {
|
|
|
1370
1445
|
}
|
|
1371
1446
|
else if (e.op === 'if')
|
|
1372
1447
|
(inC(e.c), inE(e.then), inE(e.else));
|
|
1373
|
-
else if (e.op === 'mul')
|
|
1448
|
+
else if (e.op === 'mul' || e.op === 'proj')
|
|
1374
1449
|
inE(e.a);
|
|
1375
|
-
else if ('
|
|
1450
|
+
else if ('b' in e)
|
|
1376
1451
|
(inE(e.a), inE(e.b)); };
|
|
1377
1452
|
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)));
|
|
1378
1453
|
return { inE, inC };
|
|
@@ -1382,13 +1457,17 @@ function readKeys(m, laws) {
|
|
|
1382
1457
|
const out = new Map();
|
|
1383
1458
|
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] : []))]);
|
|
1384
1459
|
const free = (e) => !JSON.stringify(e).match(/"name":"([^"]+)"/g)?.some(n => bound.has(n.slice(8, -1)));
|
|
1385
|
-
|
|
1386
|
-
|
|
1460
|
+
// (a tuple key's parts are the keys: a law about every tuple of keys is assumed at them)
|
|
1461
|
+
const put = (key) => { for (const p of tupleParts(key))
|
|
1462
|
+
if (free(p))
|
|
1463
|
+
out.set(JSON.stringify(p), p); };
|
|
1464
|
+
const { inE, inC } = eachRead(e => put(e.key));
|
|
1387
1465
|
Object.values(m.step.state ?? {}).forEach(inE);
|
|
1388
1466
|
Object.values(m.step.flags ?? {}).forEach(inC);
|
|
1389
1467
|
for (const w of Object.values(m.step.maps ?? {})) {
|
|
1390
1468
|
if (!('each' in w)) {
|
|
1391
|
-
|
|
1469
|
+
for (const p of tupleParts(w.key))
|
|
1470
|
+
out.set(JSON.stringify(p), p);
|
|
1392
1471
|
inE(w.key);
|
|
1393
1472
|
}
|
|
1394
1473
|
inE(w.value);
|
|
@@ -1412,8 +1491,15 @@ const shifts = (m) => Object.values(m.step.maps ?? {}).some(w => 'each' in w &&
|
|
|
1412
1491
|
// The keys some goals read a map at, and at each map, in one walk.
|
|
1413
1492
|
function mapReads(goals) {
|
|
1414
1493
|
const all = new Map(), out = new Map();
|
|
1415
|
-
|
|
1416
|
-
|
|
1494
|
+
// (a tuple key: its parts are the keys, each part read back from a tuple as the part; the map's key the tuple of them)
|
|
1495
|
+
const { inC } = eachRead(e0 => {
|
|
1496
|
+
const key = e0.key.op === 'tup' || e0.key.op === 'proj' ? projected(e0.key) : e0.key, id = JSON.stringify(key);
|
|
1497
|
+
for (const p of tupleParts(key))
|
|
1498
|
+
all.set(JSON.stringify(p), p);
|
|
1499
|
+
if (!out.has(e0.map))
|
|
1500
|
+
out.set(e0.map, new Map());
|
|
1501
|
+
out.get(e0.map).set(id, key);
|
|
1502
|
+
});
|
|
1417
1503
|
for (const g of goals)
|
|
1418
1504
|
g.hyps.forEach(inC);
|
|
1419
1505
|
return { keys: [...all.values()], byMap: new Map([...out].map(([mp, ks]) => [mp, [...ks.values()]])) };
|
|
@@ -1422,6 +1508,18 @@ function mapReads(goals) {
|
|
|
1422
1508
|
// where the names have these (a name left out is 0, as a model leaves it).
|
|
1423
1509
|
export const keyValue = (cell, w) => {
|
|
1424
1510
|
const inner = cell.slice(cell.indexOf('[') + 1, -1);
|
|
1511
|
+
// (a tuple's parts each valued so, the key their pairing)
|
|
1512
|
+
if (inner.startsWith('⟨')) {
|
|
1513
|
+
const parts = cellParts(cell).keys.map(k => keyValue(`_[${canon(k)}]`, w));
|
|
1514
|
+
if (parts.some(x => x === undefined))
|
|
1515
|
+
return undefined;
|
|
1516
|
+
try {
|
|
1517
|
+
return parts.slice(0, -1).reduceRight((b, a) => cpair(a, b), parts.at(-1));
|
|
1518
|
+
}
|
|
1519
|
+
catch {
|
|
1520
|
+
return undefined;
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1425
1523
|
// (its parts split at the commas outside brackets: a part may be a cell itself, Pending[idn[n:1]:64,n:1], valued as the
|
|
1426
1524
|
// model values it)
|
|
1427
1525
|
const parts = [];
|
|
@@ -1458,7 +1556,11 @@ export const keyValue = (cell, w) => {
|
|
|
1458
1556
|
// the values the goal's keys take, and each tuple where one fails added, as the goal's terms with those values, to its
|
|
1459
1557
|
// instances. None found: the model is one on every tuple of the goal's keys. Untrusted: it chooses instances only.
|
|
1460
1558
|
export const modelRounds = 4;
|
|
1461
|
-
|
|
1559
|
+
// A condition as the disjuncts it is the or of (¬(a ∧ b) as ¬a, ¬b).
|
|
1560
|
+
// (GDP_MODEL_CUTS=0: every tuple evaluated whole, for comparing)
|
|
1561
|
+
const modelCuts = env.GDP_MODEL_CUTS !== '0';
|
|
1562
|
+
const disjuncts = (c) => (c.op === 'or' ? c.xs.flatMap(disjuncts) : c.op === 'not' && c.x.op === 'and' ? c.x.xs.flatMap(y => disjuncts({ op: 'not', x: y })) : c.op === 'not' && c.x.op === 'not' ? disjuncts(c.x.x) : [c]);
|
|
1563
|
+
export function modelInstances(m, laws, inst, goal, w, most = 64, sorted = false) {
|
|
1462
1564
|
const pm = plainOf(m), qs = Object.entries(pm.step.flags ?? {}).filter((e) => e[1].op === 'all' && w[`?${e[0]}`] === 1);
|
|
1463
1565
|
const keyed = laws.filter(l => l.forall);
|
|
1464
1566
|
if (!keyed.length && !qs.length)
|
|
@@ -1475,6 +1577,21 @@ export function modelInstances(m, laws, inst, goal, w, most = 64) {
|
|
|
1475
1577
|
maps[cell.slice(0, br)].set(key, value);
|
|
1476
1578
|
}
|
|
1477
1579
|
const st = { scalars: {}, maps }, read = (at) => new Proxy(at, { get: (t, p) => (p in t ? t[p] : w[p] ?? 0), has: (t, p) => p in t || p in w });
|
|
1580
|
+
// (a count's cell the model has not: its definition, its body summed over the model's cells below its bound, so a law
|
|
1581
|
+
// reading it is read as the model's state reads it, not at 0)
|
|
1582
|
+
for (const [c, d] of Object.entries(pm.counts ?? {})) {
|
|
1583
|
+
const had = maps[c], sum = (x) => {
|
|
1584
|
+
const e1 = read(d.base ? { [d.j]: Math.floor(x / d.base), [d.lo]: x % d.base } : { [d.j]: x }), n = Math.min(256, evalE(d.below, e1, st, mm));
|
|
1585
|
+
let t = 0;
|
|
1586
|
+
for (let k = 0; k < n; k++)
|
|
1587
|
+
t += evalE(d.body, read({ ...e1, [d.key]: k }), st, mm);
|
|
1588
|
+
return t;
|
|
1589
|
+
};
|
|
1590
|
+
maps[c] = new (class extends Map {
|
|
1591
|
+
get(x) { if (!super.has(x))
|
|
1592
|
+
super.set(x, 0), super.set(x, sum(x)); return super.get(x); }
|
|
1593
|
+
})(had);
|
|
1594
|
+
}
|
|
1478
1595
|
const ev = (f) => { try {
|
|
1479
1596
|
return f();
|
|
1480
1597
|
}
|
|
@@ -1490,7 +1607,9 @@ export function modelInstances(m, laws, inst, goal, w, most = 64) {
|
|
|
1490
1607
|
// Each bound key over its own sort as the model fills it: the terms its body's map reads bind matched against the
|
|
1491
1608
|
// goal's keys (M[x·N + y] against M[a·N + b] binds x to a), one term a value; a key no read binds (or only a
|
|
1492
1609
|
// function's), every key of the goal.
|
|
1493
|
-
const keys = mapReads([goal])
|
|
1610
|
+
const { keys, byMap } = mapReads([goal]), all = new Map();
|
|
1611
|
+
// (a law's key read at a tuple's place is matched against that map's tuples: its sort is the place's)
|
|
1612
|
+
const tupled = [...byMap.values()].some(ks => ks.some(k => k.op === 'tup'));
|
|
1494
1613
|
for (const e of keys) {
|
|
1495
1614
|
const v2 = valueOf(e);
|
|
1496
1615
|
if (v2 !== undefined && !all.has(v2))
|
|
@@ -1509,20 +1628,22 @@ export function modelInstances(m, laws, inst, goal, w, most = 64) {
|
|
|
1509
1628
|
// (a key no read binds is a value, an epoch say, over the naturals: 0, their least, is one of its terms too, as Ivy's
|
|
1510
1629
|
// ordered sorts have their zero; a law before the start, nothing above 0, is assumed there)
|
|
1511
1630
|
const zero = { op: 'const', value: 0 };
|
|
1512
|
-
const
|
|
1631
|
+
const accepts = instanceSortGuard(m, laws);
|
|
1632
|
+
const sortsOf = (body, names, atoms) => sortTerms(body, names, fns, mp => (tupled ? [...keys, ...(byMap.get(mp) ?? [])] : keys)).map(ts => {
|
|
1513
1633
|
const p = new Map();
|
|
1514
1634
|
for (const e of ts ?? []) {
|
|
1515
1635
|
const v2 = valueOf(e);
|
|
1516
1636
|
if (v2 !== undefined && !p.has(v2) && (!atoms || e.op === 'var'))
|
|
1517
1637
|
p.set(v2, e);
|
|
1518
1638
|
}
|
|
1519
|
-
const
|
|
1639
|
+
const fallback = new Map([...all].filter(([, e]) => !atoms || e.op === 'var'));
|
|
1640
|
+
const q = p.size ? p : fallback, r = witnessFirst(q);
|
|
1520
1641
|
return ts || r.has(0) ? r : r.set(0, zero);
|
|
1521
1642
|
});
|
|
1522
1643
|
const out = { ...inst };
|
|
1523
1644
|
// (the 20,000 evaluations shared: each law and flag at most an even share of what is left, so the laws about five keys
|
|
1524
1645
|
// first don't leave none to those after: sharded KV's "a key in transfer has no owner", broken at the goal's own keys)
|
|
1525
|
-
let added = 0, evals = 0, left = 0;
|
|
1646
|
+
let added = 0, evals = 0, left = 0, ineligible = false;
|
|
1526
1647
|
const each = (id, names, body, atoms) => {
|
|
1527
1648
|
if (pastWall())
|
|
1528
1649
|
return;
|
|
@@ -1536,9 +1657,23 @@ export function modelInstances(m, laws, inst, goal, w, most = 64) {
|
|
|
1536
1657
|
}
|
|
1537
1658
|
for (let t = 0; t + n <= had.length; t += n)
|
|
1538
1659
|
have.add(JSON.stringify(had.slice(t, t + n)));
|
|
1660
|
+
// (the body's disjuncts, each checked as soon as the keys it reads are bound: one that holds there holds the body at
|
|
1661
|
+
// every tuple below, so transitivity's T(t, x, y) false cuts its z; a law about four keys over ten values each, 10,000
|
|
1662
|
+
// tuples, took the whole share before, its broken tuples never reached)
|
|
1663
|
+
const ready = Array.from({ length: n + 1 }, () => []);
|
|
1664
|
+
if (modelCuts)
|
|
1665
|
+
for (const d of disjuncts(body)) {
|
|
1666
|
+
const t = JSON.stringify(d);
|
|
1667
|
+
ready[names.reduce((a, x, j) => (t.includes(`"name":${JSON.stringify(x)}`) ? j + 1 : a), 0)].push(d);
|
|
1668
|
+
}
|
|
1539
1669
|
const go = (i, at, terms) => {
|
|
1540
1670
|
if (added >= most || evals > until || (evals % 512 === 0 && pastWall()))
|
|
1541
1671
|
return;
|
|
1672
|
+
for (const d of ready[i]) {
|
|
1673
|
+
evals++;
|
|
1674
|
+
if (ev(() => evalC(d, read(at), st, mm)) === true)
|
|
1675
|
+
return;
|
|
1676
|
+
}
|
|
1542
1677
|
if (i === n) {
|
|
1543
1678
|
evals++;
|
|
1544
1679
|
if (ev(() => evalC(body, read(at), st, mm)) !== false)
|
|
@@ -1546,6 +1681,11 @@ export function modelInstances(m, laws, inst, goal, w, most = 64) {
|
|
|
1546
1681
|
const id2 = JSON.stringify(terms);
|
|
1547
1682
|
if (have.has(id2))
|
|
1548
1683
|
return;
|
|
1684
|
+
// Sort-aware consumers must not count tuples they would discard after this pass.
|
|
1685
|
+
if (sorted && terms.some((e, j) => !accepts(id, j, e))) {
|
|
1686
|
+
ineligible = true;
|
|
1687
|
+
return;
|
|
1688
|
+
}
|
|
1549
1689
|
have.add(id2);
|
|
1550
1690
|
out[id] = [...(out[id] ?? []), ...terms];
|
|
1551
1691
|
added++;
|
|
@@ -1555,6 +1695,8 @@ export function modelInstances(m, laws, inst, goal, w, most = 64) {
|
|
|
1555
1695
|
go(i + 1, { ...at, [names[i]]: v2 }, [...terms, e]);
|
|
1556
1696
|
};
|
|
1557
1697
|
go(0, {}, []);
|
|
1698
|
+
if (modelsTrace)
|
|
1699
|
+
console.error(`[models] ${atoms ? 'atoms' : 'all'} ${id.slice(0, 30)}: sorts ${sorts.map(x => x.size).join('x')}, evals ${evals} of ${until}, added ${added}`);
|
|
1558
1700
|
};
|
|
1559
1701
|
// the goal's own names first; every key it reads where they show nothing
|
|
1560
1702
|
for (const atoms of [true, false]) {
|
|
@@ -1567,7 +1709,8 @@ export function modelInstances(m, laws, inst, goal, w, most = 64) {
|
|
|
1567
1709
|
for (const [f, q] of qs)
|
|
1568
1710
|
each(`?${f}`, boundOf(q), q.c, atoms);
|
|
1569
1711
|
}
|
|
1570
|
-
|
|
1712
|
+
// A rejected-only refinement is not evidence that the model satisfies every assumed law.
|
|
1713
|
+
return added || ineligible ? out : undefined;
|
|
1571
1714
|
}
|
|
1572
1715
|
// A goal (or a law's goals) asked at some instances, and again at those its model asks for (modelInstances), up to
|
|
1573
1716
|
// modelRounds times. `ask` is the caller's own question; `modelOf` reads a model from its answer, `settled` says it is
|
|
@@ -1576,6 +1719,8 @@ export function modelInstances(m, laws, inst, goal, w, most = 64) {
|
|
|
1576
1719
|
// not the goal's usual budget again; a later round left unsettled gives back the first round's answer, so the verdict is
|
|
1577
1720
|
// never one the model's tuples made worse. Untrusted.
|
|
1578
1721
|
export const modelShare = 3;
|
|
1722
|
+
// (GDP_MODELS_TRACE=1: each model round, its goal and the tuples a model adds, on stderr)
|
|
1723
|
+
const modelsTrace = !!env.GDP_MODELS_TRACE, modelFloor = Number(env.GDP_MODEL_FLOOR ?? 1_000);
|
|
1579
1724
|
const costNow = () => (rate ? clock() : fullWork() / groundRate);
|
|
1580
1725
|
const within = (ms, f) => (rate ? withDeadline(clock() + ms, f) : withWork(fullWork() + groundRate * ms, f));
|
|
1581
1726
|
export function withModels(m, laws, inst, goalOf, ask, modelOf, settled) {
|
|
@@ -1588,13 +1733,18 @@ function modelsLoop(m, laws, inst, goalOf, ask, modelOf, settled) {
|
|
|
1588
1733
|
if (round)
|
|
1589
1734
|
cap -= costNow() - c0;
|
|
1590
1735
|
else
|
|
1591
|
-
cap = Math.max(
|
|
1592
|
-
if (round && !settled(result))
|
|
1736
|
+
cap = Math.max(modelFloor, modelShare * (costNow() - c0));
|
|
1737
|
+
if (round && !settled(result)) {
|
|
1738
|
+
if (modelsTrace)
|
|
1739
|
+
console.error(`[models] round ${round} unsettled in ${Math.round(costNow() - c0)} cost`);
|
|
1593
1740
|
return first;
|
|
1741
|
+
}
|
|
1594
1742
|
if (pastWall())
|
|
1595
1743
|
return first ?? { result, inst: at };
|
|
1596
1744
|
first ??= { result, inst: at };
|
|
1597
1745
|
const mw = modelOf(result), more = mw && round < modelRounds && cap > 0 ? modelInstances(m, laws, at, mw.goal, mw.w) : undefined;
|
|
1746
|
+
if (modelsTrace)
|
|
1747
|
+
console.error(`[models] round ${round} ${mw ? `model at ${mw.goal.name} (${mw.goal.hyps.length} hyps)` : settled(result) ? 'settled' : 'unsettled'} ${Math.round(costNow() - c0)} cost, cap ${Math.round(cap)}; ${more ? `+${Object.entries(more).map(([n, ks]) => `${n.slice(0, 24)}:${ks.length - (at[n]?.length ?? 0)}`).filter(x => !x.endsWith(':0')).join(' ')}` : 'no more'}`);
|
|
1598
1748
|
if (!more)
|
|
1599
1749
|
return { result, inst: at };
|
|
1600
1750
|
at = more;
|
|
@@ -1918,10 +2068,14 @@ const triggers = (body, key) => {
|
|
|
1918
2068
|
const substKey = (e, key, by) => JSON.parse(JSON.stringify(e).replaceAll(`{"op":"var","name":${JSON.stringify(key)}}`, JSON.stringify(by)));
|
|
1919
2069
|
// GDP_TRIGGER=0 keeps every instance (for comparing).
|
|
1920
2070
|
const triggerOn = env.GDP_TRIGGER !== '0';
|
|
1921
|
-
function triggered(m, laws, inst, build, focus = []) {
|
|
2071
|
+
export function triggered(m, laws, inst, build, focus = []) {
|
|
1922
2072
|
if (!triggerOn)
|
|
1923
2073
|
return inst;
|
|
1924
2074
|
// Per name: its bound keys, and for each the triggers that read it alone (a key with none takes any value).
|
|
2075
|
+
// Tuple-keyed function images (including generated witnesses) introduce key
|
|
2076
|
+
// terms outside relational reads. Keep legacy focus seeds for that shape.
|
|
2077
|
+
const tupleFunctions = Object.entries(m.step.maps ?? {}).some(([name, w]) => !m.relations?.[name] && !('each' in w) && w.key.op === 'tup');
|
|
2078
|
+
const tupled = !!Object.keys(m.relations ?? {}).length && !tupleFunctions;
|
|
1925
2079
|
const bodies = new Map();
|
|
1926
2080
|
for (const [n, ks] of Object.entries(inst)) {
|
|
1927
2081
|
if (!ks.length)
|
|
@@ -1930,15 +2084,26 @@ function triggered(m, laws, inst, build, focus = []) {
|
|
|
1930
2084
|
const body = q?.op === 'all' ? q.c : l?.forall ? l.holds : undefined, keys = q?.op === 'all' ? boundOf(q) : l?.forall ? [l.forall, ...(l.keys ?? [])] : [];
|
|
1931
2085
|
if (!body)
|
|
1932
2086
|
continue;
|
|
1933
|
-
const per = keys.map(key =>
|
|
2087
|
+
const per = keys.map(key => {
|
|
2088
|
+
const ts = triggers(body, key).filter(t => tupled || keys.every(o => o === key || !JSON.stringify(t.at).includes(`"name":${JSON.stringify(o)}`)));
|
|
2089
|
+
// A joint read constrains the tuple; independent field reads would admit
|
|
2090
|
+
// its Cartesian product again. Missing useful tuples can still enter by MBQI.
|
|
2091
|
+
const joint = tupled ? ts.filter(t => keys.filter(k => JSON.stringify(t.at).includes(`"name":${JSON.stringify(k)}`)).length > 1) : [];
|
|
2092
|
+
return joint.length ? joint : ts;
|
|
2093
|
+
});
|
|
1934
2094
|
if (per.some(t => t.length))
|
|
1935
2095
|
bodies.set(n, { keys, per });
|
|
1936
2096
|
}
|
|
1937
2097
|
if (!bodies.size)
|
|
1938
2098
|
return inst;
|
|
1939
2099
|
const tuplesOf = (n, ks) => { const a = bodies.get(n).keys.length; return Array.from({ length: Math.floor(ks.length / a) }, (_, t) => ks.slice(t * a, (t + 1) * a)); };
|
|
1940
|
-
const kept = (tuple) => tuple.some(e => e.op === 'var' && focus.includes(e.name));
|
|
2100
|
+
const kept = (tuple) => !tupled && tuple.some(e => e.op === 'var' && focus.includes(e.name));
|
|
1941
2101
|
const out = Object.fromEntries(Object.entries(inst).map(([n, ks]) => [n, bodies.has(n) ? tuplesOf(n, ks).filter(kept).flat() : ks]));
|
|
2102
|
+
// Tuple substitution is independent of the growing read set. Cache each
|
|
2103
|
+
// candidate's trigger text once, rather than rebuilding it every round.
|
|
2104
|
+
const candidates = new Map();
|
|
2105
|
+
for (const n of bodies.keys())
|
|
2106
|
+
candidates.set(n, tuplesOf(n, inst[n]).map(tuple => ({ tuple, id: JSON.stringify(tuple), tests: [] })));
|
|
1942
2107
|
for (let round = 0; round < 8 && !pastWall(); round++) {
|
|
1943
2108
|
const reads = new Set();
|
|
1944
2109
|
const { inC } = eachRead(e => { reads.add(`${e.map}|${JSON.stringify(e.key)}`); });
|
|
@@ -1947,9 +2112,11 @@ function triggered(m, laws, inst, build, focus = []) {
|
|
|
1947
2112
|
let grew = false;
|
|
1948
2113
|
for (const [n, { keys, per }] of bodies) {
|
|
1949
2114
|
const have = new Set(tuplesOf(n, out[n]).map(t => JSON.stringify(t)));
|
|
1950
|
-
for (const tuple of
|
|
1951
|
-
|
|
1952
|
-
|
|
2115
|
+
for (const { tuple, id, tests } of candidates.get(n)) {
|
|
2116
|
+
if (have.has(id) || !keys.every((key, i) => {
|
|
2117
|
+
const at = tests[i] ??= per[i].map(({ map, at }) => `${map}|${JSON.stringify(tupled ? substE(at, { vars: Object.fromEntries(keys.map((k, j) => [k, tuple[j]])), maps: {}, flags: {} }) : substKey(at, key, tuple[i]))}`);
|
|
2118
|
+
return !at.length || at.some(t => reads.has(t));
|
|
2119
|
+
}))
|
|
1953
2120
|
continue;
|
|
1954
2121
|
out[n].push(...tuple);
|
|
1955
2122
|
have.add(id);
|
|
@@ -2063,7 +2230,9 @@ function substVar(c, name, by) {
|
|
|
2063
2230
|
case 'sub':
|
|
2064
2231
|
case 'min':
|
|
2065
2232
|
case 'max':
|
|
2066
|
-
case 'prod':
|
|
2233
|
+
case 'prod':
|
|
2234
|
+
case 'tup': return { ...t, a: e(t.a), b: e(t.b) };
|
|
2235
|
+
case 'proj': return { ...t, a: e(t.a) };
|
|
2067
2236
|
}
|
|
2068
2237
|
};
|
|
2069
2238
|
return c.op === 'flag' ? c : c.op === 'all' ? { ...c, c: substVar(c.c, name, by) } : c.op === 'not' ? { op: 'not', x: substVar(c.x, name, by) } : c.op === 'and' || c.op === 'or' ? { op: c.op, xs: c.xs.map(y => substVar(y, name, by)) } : { ...c, a: e(c.a), b: e(c.b) };
|
|
@@ -2137,6 +2306,7 @@ export function decideLaw(m, laws, i, rounds = modelRounds) {
|
|
|
2137
2306
|
export const decideNote = { refuted: false };
|
|
2138
2307
|
function decideLaw0(m, laws, i, rounds) {
|
|
2139
2308
|
decideNote.refuted = false;
|
|
2309
|
+
delete decideNote.hint;
|
|
2140
2310
|
if (!fastShape(m, laws))
|
|
2141
2311
|
return undefined;
|
|
2142
2312
|
return withPatterns(m, laws, () => {
|
|
@@ -2185,7 +2355,7 @@ function settled(m, laws, i, rounds, usual) {
|
|
|
2185
2355
|
}
|
|
2186
2356
|
memoHits.miss++;
|
|
2187
2357
|
const mo = rounds === modelRounds ? memo.models.get(law.name) : undefined;
|
|
2188
|
-
if (mo && mo.text === text && laws.every(l => mo.set.get(l.name) === textOfLaw(l)))
|
|
2358
|
+
if (mo && (!strict(usual) || mo.strict) && mo.text === text && laws.every(l => mo.set.get(l.name) === textOfLaw(l)))
|
|
2189
2359
|
return mo.model;
|
|
2190
2360
|
const out = settle(m, laws, i, rounds, usual, prev);
|
|
2191
2361
|
const cap = (x) => { if (x.size >= 4096)
|
|
@@ -2193,7 +2363,7 @@ function settled(m, laws, i, rounds, usual) {
|
|
|
2193
2363
|
if (out && 'proofs' in out)
|
|
2194
2364
|
cap(memo.proven).set(law.name, out);
|
|
2195
2365
|
else if (out?.stuck === 'sat' && rounds === modelRounds)
|
|
2196
|
-
cap(memo.models).set(law.name, { text, model: out, set: new Map(laws.map(l => [l.name, textOfLaw(l)])) });
|
|
2366
|
+
cap(memo.models).set(law.name, { text, model: out, strict: strict(usual), set: new Map(laws.map(l => [l.name, textOfLaw(l)])) });
|
|
2197
2367
|
return out;
|
|
2198
2368
|
}
|
|
2199
2369
|
// The fast path's machines: no history, sums or "there exists" (their goals are other machines' or need witnesses).
|
|
@@ -2238,10 +2408,11 @@ function settle(m, laws, i, rounds, usual, prev) {
|
|
|
2238
2408
|
const law = laws[i], byName = new Map(laws.map(l => [l.name, l]));
|
|
2239
2409
|
// (decideLaw's and the fast set proof's: each law's keys of its sort alone, `bySort`; proveLaw's and the join's as they
|
|
2240
2410
|
// were. The fast set proof is checked over the tuples its proofs read, and the usual proof follows where it fails)
|
|
2241
|
-
|
|
2411
|
+
const reuse = prev && laws.every(l => !l.forall || l.name in prev.inst);
|
|
2412
|
+
let inst = reuse ? prev.inst : bySort(m, laws, lawInstances(m, laws, i));
|
|
2242
2413
|
// (GDP_DLTRIG=1: decideLaw's first instances only those a goal's reads trigger (proveOne's `triggered`), the model
|
|
2243
2414
|
// rounds adding the instances a model breaks (MBQI's))
|
|
2244
|
-
if (!
|
|
2415
|
+
if (!reuse && (Object.keys(m.relations ?? {}).length ? env.GDP_DLTRIG !== '0' : !usual && env.GDP_DLTRIG === '1'))
|
|
2245
2416
|
inst = triggered(plainOf(m), laws, inst, i2 => obligations(m, laws, { [law.name]: i2 }, i), law.forall ? [`${law.forall}#`] : []);
|
|
2246
2417
|
const proofs = Object.fromEntries(Object.entries(prev?.proofs ?? {}).filter(([, p]) => stands(p, byName)));
|
|
2247
2418
|
const unknown = (g, why = 'past the search\'s end') => (usual ? { goal: g.name, stuck: 'unknown', why } : undefined);
|
|
@@ -2257,7 +2428,13 @@ function settle(m, laws, i, rounds, usual, prev) {
|
|
|
2257
2428
|
continue;
|
|
2258
2429
|
if (late())
|
|
2259
2430
|
return strict(usual) ? unknown(g) : last ?? unknown(g);
|
|
2260
|
-
|
|
2431
|
+
// (a wide goal decided over parts (growWide), each part by the EPR path: the abstraction of the whole is quadratic in
|
|
2432
|
+
// its cells, i4's engine set's step goal of 7,590 hypotheses ran 19M units past its caller's end and 10 GB)
|
|
2433
|
+
let o = !eprScope.patterns ? undefined : wideFor(g) && tupledScope() ? eprWide(g, late) ?? withEprCap(wideEprUnits, () => eprFirst(g, { nodes: 0, until: clock() + 4_000 }, false, late)) : eprFirst(g, { nodes: 0, until: clock() + 4_000 }, false, late);
|
|
2434
|
+
// Initial states often erase every map read, leaving a small arithmetic goal
|
|
2435
|
+
// outside EPR. Do not require a whole-set proof just to seed its start tree.
|
|
2436
|
+
if (!o && g.name.endsWith(' @start') && !late())
|
|
2437
|
+
o = grow(g, new Map(), { nodes: 0, until: end });
|
|
2261
2438
|
// (a refutation whose core's proof didn't finish: a model from fewer instances, which these refute, is no answer;
|
|
2262
2439
|
// decideLaw's unknown, the usual search's next)
|
|
2263
2440
|
if (!o && eprLast.refuted) {
|
|
@@ -2290,13 +2467,15 @@ function settle(m, laws, i, rounds, usual, prev) {
|
|
|
2290
2467
|
last = { goal: g.name, stuck: 'sat', witness: o.witness, ...(o.diagram ? { diagram: o.diagram } : {}), why: 'a model' };
|
|
2291
2468
|
// (strict, decideLaw's: a model is returned only where confirmed, no assumed law broken at it over its own domain;
|
|
2292
2469
|
// one that breaks only instances of another sort, or that the rounds or the wall cut off, is no answer)
|
|
2293
|
-
const capped = !(round < rounds || (round < 4 * rounds && end !== Infinity && clock() < end)), raw = capped ? undefined : modelInstances(m, laws, inst, g, o.witness);
|
|
2470
|
+
const capped = !(round < rounds || (round < 4 * rounds && end !== Infinity && clock() < end)), raw = capped ? undefined : modelInstances(m, laws, inst, g, o.witness, undefined, true);
|
|
2294
2471
|
if (!capped && !raw)
|
|
2295
2472
|
return last;
|
|
2296
2473
|
more = raw && bySort(m, laws, raw);
|
|
2297
2474
|
const count = (x) => Object.values(x).reduce((s2, ks) => s2 + ks.length, 0);
|
|
2298
|
-
if (strict(usual) && (capped || pastWall() || !more || count(more) <= count(inst)))
|
|
2475
|
+
if (strict(usual) && (capped || pastWall() || !more || count(more) <= count(inst))) {
|
|
2476
|
+
decideNote.hint = { goal: g.name, witness: o.witness };
|
|
2299
2477
|
return undefined;
|
|
2478
|
+
}
|
|
2300
2479
|
// (the model's only broken instances another sort's: the next round would find it again; decideLaw's no answer)
|
|
2301
2480
|
if (more && count(more) <= count(inst))
|
|
2302
2481
|
return usual ? last : undefined;
|
|
@@ -2309,6 +2488,14 @@ function settle(m, laws, i, rounds, usual, prev) {
|
|
|
2309
2488
|
inst = more;
|
|
2310
2489
|
}
|
|
2311
2490
|
}
|
|
2491
|
+
// A wide goal over parts, each asked by the EPR path (its core widened to the part) or else the usual search: a tree is
|
|
2492
|
+
// the part's, a model one of the whole. Parts for four times eprFirst's window (growWide's share of it), each part
|
|
2493
|
+
// within that window.
|
|
2494
|
+
function eprWide(g, late) {
|
|
2495
|
+
const out = growWide(g, { nodes: 0, until: clock() + 16_000 }, (gp, until) => { const u = Math.max(until, clock() + 4_000); return eprFirst(gp, { nodes: 0, until: u }, true, late) ?? grow(gp, new Map(), { nodes: 0, until: u }); }, true);
|
|
2496
|
+
eprLast.refuted = false;
|
|
2497
|
+
return out && ('tree' in out || (out.stuck === 'sat' && out.witness)) ? out : undefined;
|
|
2498
|
+
}
|
|
2312
2499
|
// A set of laws proven as proveLaws proves it, for a search that drops a law the proof fails at and asks again (the
|
|
2313
2500
|
// enumeration's set proof): each law's goals settled in order (kept from this call or decideLaw's where they stand), the
|
|
2314
2501
|
// first law not proven returned with its goal's model; when every law is, the proof made once: each law's instances only
|
|
@@ -2379,24 +2566,50 @@ export function proveLaw(m, laws, i) {
|
|
|
2379
2566
|
}
|
|
2380
2567
|
function proveOne(m, laws, i) {
|
|
2381
2568
|
const law = laws[i], pm = plainOf(m), inst = lawInstances(m, laws, i);
|
|
2569
|
+
// Keep the ordinary fallback's actual trees too. A local proof can use a
|
|
2570
|
+
// ghost value as a key where EPR's sorted instances were insufficient. The
|
|
2571
|
+
// complete-set path widens these trees and checks every obligation afresh.
|
|
2572
|
+
const remember = (at, trees) => {
|
|
2573
|
+
if (!Object.values(m.step.maps ?? {}).some(w => !('each' in w) && w.key.op === 'tup') || !fastShape(m, laws))
|
|
2574
|
+
return;
|
|
2575
|
+
const byName = new Map(laws.map(l => [l.name, l])), proofs = {};
|
|
2576
|
+
for (const g of obligations(m, laws, { [law.name]: at }, i)) {
|
|
2577
|
+
const tree = trees[g.name];
|
|
2578
|
+
if (!tree)
|
|
2579
|
+
return;
|
|
2580
|
+
const src = sourcesOf(m, laws, at, g, usedHyps(g, tree));
|
|
2581
|
+
proofs[g.name] = { part: g, tree, uses: new Map((src ? [...src.keys()] : laws.map(l => l.name)).map(n => [n, textOfLaw(byName.get(n))])), ...(src ? { tuples: src } : {}) };
|
|
2582
|
+
}
|
|
2583
|
+
const memo = memoOf(m);
|
|
2584
|
+
if (memo.proven.size >= 4096)
|
|
2585
|
+
memo.proven.clear();
|
|
2586
|
+
memo.proven.set(law.name, { text: textOfLaw(law), inst: at, proofs });
|
|
2587
|
+
};
|
|
2382
2588
|
const few = triggered(pm, laws, inst, i2 => obligations(m, laws, { [law.name]: i2 }, i), law.forall ? [`${law.forall}#`] : []);
|
|
2383
2589
|
if (!sameInstances(few, inst)) {
|
|
2384
2590
|
let proven = true;
|
|
2591
|
+
const done = {};
|
|
2385
2592
|
for (const goal of obligations(m, laws, { [law.name]: few }, i)) {
|
|
2386
2593
|
const o = grow(goal);
|
|
2387
|
-
if ('tree' in o)
|
|
2594
|
+
if ('tree' in o) {
|
|
2595
|
+
done[goal.name] = o.tree;
|
|
2388
2596
|
continue;
|
|
2597
|
+
}
|
|
2389
2598
|
proven = false;
|
|
2390
2599
|
// (a goal that ran out past the deadline: the next instances can't be tried, and it is the verdict's goal)
|
|
2391
2600
|
if (o.stuck === 'unknown' && ranOut())
|
|
2392
2601
|
return { proven: false, goal: goal.name, stuck: 'unknown' };
|
|
2393
2602
|
break;
|
|
2394
2603
|
}
|
|
2395
|
-
if (proven)
|
|
2604
|
+
if (proven) {
|
|
2605
|
+
remember(few, done);
|
|
2396
2606
|
return { proven: true };
|
|
2607
|
+
}
|
|
2397
2608
|
}
|
|
2398
2609
|
// (a model breaking a law at a tuple of the goal's keys: those added, the law asked again)
|
|
2399
|
-
const { result: a } = withModels(m, laws, inst, i2 => obligations(m, laws, { [law.name]: i2 }, i), growAll, grownModel, grownSettled);
|
|
2610
|
+
const { result: a, inst: at } = withModels(m, laws, inst, i2 => obligations(m, laws, { [law.name]: i2 }, i), growAll, grownModel, grownSettled);
|
|
2611
|
+
if (!a.out)
|
|
2612
|
+
remember(at, a.done);
|
|
2400
2613
|
return a.out ? { proven: false, goal: a.goal.name, stuck: a.out.stuck, ...(a.out.witness ? { witness: a.out.witness } : {}), ...(a.out.diagram ? { diagram: a.out.diagram } : {}) } : { proven: true };
|
|
2401
2614
|
}
|
|
2402
2615
|
function growAll(gs) {
|
|
@@ -2439,12 +2652,20 @@ finally {
|
|
|
2439
2652
|
} };
|
|
2440
2653
|
// (by machine and by the law set's names: one machine is asked with many sets)
|
|
2441
2654
|
const sortsMemo = new WeakMap();
|
|
2655
|
+
const sortPlacesOn = env.GDP_SORT_PLACES !== '0';
|
|
2442
2656
|
function sortsOf(m, laws) {
|
|
2443
2657
|
const par = new Map(), find = (a) => { const q = par.get(a); if (q === undefined || q === a)
|
|
2444
2658
|
return a; const r = find(q); par.set(a, r); return r; };
|
|
2445
2659
|
const named = new Set(), union = (a, b) => { named.add(a); named.add(b); const ra = find(a), rb = find(b); if (ra !== rb)
|
|
2446
2660
|
par.set(ra, rb); };
|
|
2447
2661
|
const pats = patternsOf(m, laws), whole = new Map();
|
|
2662
|
+
// (only on machines with tuple keys, whose patterns are n zeros: elsewhere the sorts are as before, distributed_lock's
|
|
2663
|
+
// instances among them)
|
|
2664
|
+
const sortPlaces = sortPlacesOn && Object.values(pats).some(c => c.length > 1 && c[0] === 0);
|
|
2665
|
+
// (a map of one part read at a name, Src[p]: its value a sort too, F:Src, as a function's, what it is compared with and
|
|
2666
|
+
// the places it is read at: Src[Src[p]] is no key of Src where Src's values are nodes and its keys packets)
|
|
2667
|
+
// (GDP_SORT_PLACES=0: neither, for comparing)
|
|
2668
|
+
const valued = (e) => sortPlaces && !((pats[e.map]?.length ?? 0) > 1) && e.key.op !== 'tup' && (e.key.op === 'var' || e.key.op === 'get');
|
|
2448
2669
|
const leaves = (e, k, out) => { if (e.op === 'add') {
|
|
2449
2670
|
leaves(e.a, k, out);
|
|
2450
2671
|
leaves(e.b, k, out);
|
|
@@ -2454,7 +2675,7 @@ function sortsOf(m, laws) {
|
|
|
2454
2675
|
else if (e.op !== 'const')
|
|
2455
2676
|
out.push([e, k]); };
|
|
2456
2677
|
const walkC = (c, name) => {
|
|
2457
|
-
const node = (e) => (e.op === 'var' ? name(e.name) : e.op === 'get' && m.fns?.[e.map] ? `F:${e.map}` : undefined);
|
|
2678
|
+
const node = (e) => (e.op === 'var' ? name(e.name) : e.op === 'get' && (m.fns?.[e.map] || valued(e)) ? `F:${e.map}` : undefined);
|
|
2458
2679
|
const visit = (o) => {
|
|
2459
2680
|
if (!o || typeof o !== 'object')
|
|
2460
2681
|
return;
|
|
@@ -2465,6 +2686,10 @@ function sortsOf(m, laws) {
|
|
|
2465
2686
|
if (n)
|
|
2466
2687
|
union(n, `A:${x.map}`);
|
|
2467
2688
|
}
|
|
2689
|
+
// (a tuple key: each part of its place's sort, M:map:i)
|
|
2690
|
+
else if (x.key.op === 'tup' && sortPlaces)
|
|
2691
|
+
tupleParts(x.key).forEach((e, i) => { const n = node(e); if (n)
|
|
2692
|
+
union(n, `M:${x.map}:${i}`); });
|
|
2468
2693
|
else {
|
|
2469
2694
|
const ls = [];
|
|
2470
2695
|
leaves(x.key, 1, ls);
|
|
@@ -2556,13 +2781,13 @@ function sortsOf(m, laws) {
|
|
|
2556
2781
|
return mp ? `K:${mp}` : `K:?${cs}`;
|
|
2557
2782
|
}
|
|
2558
2783
|
const x = ls[0][0];
|
|
2559
|
-
return x.op === 'var' ? (x.name.endsWith('#') ? undefined : `V:${x.name}`) : x.op === 'get' && m.fns?.[x.map] ? `F:${x.map}` : undefined;
|
|
2784
|
+
return x.op === 'var' ? (x.name.endsWith('#') ? undefined : `V:${x.name}`) : x.op === 'get' && (m.fns?.[x.map] || valued(x)) ? `F:${x.map}` : undefined;
|
|
2560
2785
|
};
|
|
2561
2786
|
return { key: (law, k) => `L:${law}:${k}`, of, find, anchored: (a) => /^K:/.test(a) || !!anchorOf.get(find(a)) };
|
|
2562
2787
|
}
|
|
2563
|
-
function
|
|
2788
|
+
function instanceSortGuard(m, laws) {
|
|
2564
2789
|
if (!sortedOn)
|
|
2565
|
-
return
|
|
2790
|
+
return () => true;
|
|
2566
2791
|
let byLaws = sortsMemo.get(m);
|
|
2567
2792
|
if (!byLaws)
|
|
2568
2793
|
sortsMemo.set(m, (byLaws = new Map()));
|
|
@@ -2582,14 +2807,28 @@ function bySort(m, laws, inst) {
|
|
|
2582
2807
|
const l = laws.find(x => x.name === n);
|
|
2583
2808
|
return l?.forall ? [l.forall, ...(l.keys ?? [])].map(k => S.key(n, k)) : undefined;
|
|
2584
2809
|
};
|
|
2810
|
+
const wanted = new Map();
|
|
2811
|
+
return (n, j, e) => {
|
|
2812
|
+
if (!wanted.has(n))
|
|
2813
|
+
wanted.set(n, keysOf(n));
|
|
2814
|
+
const want = wanted.get(n)?.[j], se = S.of(e);
|
|
2815
|
+
return !want || !se || !S.anchored(se) || !S.anchored(want) || S.find(se) === S.find(want);
|
|
2816
|
+
};
|
|
2817
|
+
}
|
|
2818
|
+
function bySort(m, laws, inst) {
|
|
2819
|
+
if (!sortedOn)
|
|
2820
|
+
return inst;
|
|
2821
|
+
const accepts = instanceSortGuard(m, laws);
|
|
2585
2822
|
return Object.fromEntries(Object.entries(inst).map(([n, ks]) => {
|
|
2586
|
-
const
|
|
2823
|
+
const q = n.startsWith('?') ? m.step.flags?.[n.slice(1)] : undefined;
|
|
2824
|
+
const l = laws.find(l => l.name === n);
|
|
2825
|
+
const want = q?.op === 'all' ? boundOf(q) : l?.forall ? [l.forall, ...(l.keys ?? [])] : undefined;
|
|
2587
2826
|
if (!want || !ks.length)
|
|
2588
2827
|
return [n, ks];
|
|
2589
2828
|
const a = want.length, out = [];
|
|
2590
2829
|
for (let t = 0; t + a <= ks.length; t += a) {
|
|
2591
2830
|
const tuple = ks.slice(t, t + a);
|
|
2592
|
-
const ok = tuple.every((e, j) =>
|
|
2831
|
+
const ok = tuple.every((e, j) => accepts(n, j, e));
|
|
2593
2832
|
if (ok)
|
|
2594
2833
|
out.push(...tuple);
|
|
2595
2834
|
}
|
|
@@ -2605,6 +2844,18 @@ export function lawInstances(m, laws, i) {
|
|
|
2605
2844
|
focus: [...(law.forall ? [`${law.forall}#`] : []), ...(law.keys ?? [])],
|
|
2606
2845
|
});
|
|
2607
2846
|
}
|
|
2847
|
+
// (GDP_SET_FIRST=0: the usual way alone, for comparing)
|
|
2848
|
+
const setFirstOn = env.GDP_SET_FIRST !== '0';
|
|
2849
|
+
const setFirst = (m, laws) => {
|
|
2850
|
+
// (machines with tuple keys alone, patterns of zeros: on radix keys the usual way is the one tuned, and a set proof
|
|
2851
|
+
// first cost sharded KV's no-lost-keys, whose witness passes ask the whole set again and again, 2.8M of work to 45M)
|
|
2852
|
+
if (!eprOn || !setFirstOn || pastWall() || !fastShape(m, laws) || !Object.values(patternsOf(plainOf(m), laws)).some(c => c.length > 1 && c.every(x => x === 0)))
|
|
2853
|
+
return undefined;
|
|
2854
|
+
const out = proveSetFast(m, laws);
|
|
2855
|
+
if (modelsTrace)
|
|
2856
|
+
console.error(`[models] the set first: ${out.proven ? out.checked ? 'proven' : 'proven, not checked' : `not proven at ${out.failed?.goal}`}`);
|
|
2857
|
+
return out.proven && out.checked && out.proof ? out : undefined;
|
|
2858
|
+
};
|
|
2608
2859
|
// `defer`: the usual trees now, their certificate and check given to it as `finish`, which proveStepLaws runs once every
|
|
2609
2860
|
// step law is proven too: a verdict that fails needs neither (TigerBeetle's laws spent 50 s of 67 on the laws' certificate
|
|
2610
2861
|
// and check before a step law failed). Deferred, a certificate not made leaves the check to checkStepLaws, which reads
|
|
@@ -2613,12 +2864,18 @@ function proveLawsAsGiven(m, laws, defer) {
|
|
|
2613
2864
|
// Each law's two goals (start and step) get their own instances, seeded with its own keys.
|
|
2614
2865
|
// (a machine with sums: its instances are its plain machine's, whose flags hold each sum's facts at every key)
|
|
2615
2866
|
const pm = plainOf(m), keys = [...readKeys(pm, laws), ...witnesses(pm)], instances = {};
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2867
|
+
// (an EPR-shaped machine's set over tuple keys proved first as proveSetFast proves it: each law settled by the EPR
|
|
2868
|
+
// path, its instances sorted and only the tuples its proofs read, its cores widened to goals that small; i4's learning
|
|
2869
|
+
// switch over relations 6 s there against 80 s here, whose check alone read goals of 1,200 hypotheses for 55 s. Not
|
|
2870
|
+
// proven, the usual way)
|
|
2871
|
+
const fast = defer ? undefined : setFirst(m, laws);
|
|
2872
|
+
if (!fast)
|
|
2873
|
+
laws.forEach((law, i) => {
|
|
2874
|
+
instances[law.name] = instancesFor(pm, laws, inst => obligations(m, laws, { ...instances, [law.name]: inst }, i), {
|
|
2875
|
+
seed: [...keys, ...(law.forall ? [{ op: 'var', name: `${law.forall}#` }] : []), ...(law.keys ?? []).map((name) => ({ op: 'var', name }))],
|
|
2876
|
+
focus: [...(law.forall ? [`${law.forall}#`] : []), ...(law.keys ?? [])],
|
|
2877
|
+
});
|
|
2620
2878
|
});
|
|
2621
|
-
});
|
|
2622
2879
|
// (by default a covered machine's certificate is its cyclic proof, core/cyclic.ts's certCyclic, the usual trees its
|
|
2623
2880
|
// input, not checked again; where none is made, the usual trees are checked and the proof counted uncovered)
|
|
2624
2881
|
// (what no instance covers, read only where a cyclic mode is on: the usual route's own proofs, inferLaws' trial ones
|
|
@@ -2627,7 +2884,7 @@ function proveLawsAsGiven(m, laws, defer) {
|
|
|
2627
2884
|
const modes = cyclicOn() || certOn(), hist = modes && m.history ? historyMachine(m) : undefined, mc = hist ? hist.machine : m;
|
|
2628
2885
|
const why = modes ? (sumsWhy(m) ?? uncoveredWhy(mc, laws)) : undefined, cert = certOn() && !why;
|
|
2629
2886
|
usualCheck.on = !cert && !defer;
|
|
2630
|
-
const t0 = performance.now(), out = (() => { try {
|
|
2887
|
+
const t0 = performance.now(), out = fast ?? (() => { try {
|
|
2631
2888
|
return proveThinned(m, laws, { ...instances });
|
|
2632
2889
|
}
|
|
2633
2890
|
finally {
|
|
@@ -2692,6 +2949,8 @@ function thinned(m, laws, instances) {
|
|
|
2692
2949
|
for (const [i, law] of laws.entries()) {
|
|
2693
2950
|
const full = instances[law.name], focus = law.forall ? [`${law.forall}#`] : [];
|
|
2694
2951
|
const few = triggered(plainOf(m), laws, full, inst => obligations(m, laws, { ...instances, [law.name]: inst }, i), focus);
|
|
2952
|
+
if (modelsTrace)
|
|
2953
|
+
console.error(`[models] law ${law.name}: ${Object.values(full).reduce((a, ks) => a + ks.length, 0)} keys, ${Object.values(few).reduce((a, ks) => a + ks.length, 0)} triggered`);
|
|
2695
2954
|
// (thinned instances first, then the full ones; each asked again at the tuples its models ask for)
|
|
2696
2955
|
for (const inst of sameInstances(few, full) ? [full] : [few, full]) {
|
|
2697
2956
|
const { result: a, inst: at } = withModels(m, laws, inst, i2 => obligations(m, laws, { ...instances, [law.name]: i2 }, i), growAll, grownModel, grownSettled);
|
|
@@ -3072,12 +3331,12 @@ export function certLoop(l, laws, rank, trees, usualMs) {
|
|
|
3072
3331
|
function readKeysC(c) {
|
|
3073
3332
|
const out = [];
|
|
3074
3333
|
const inE = (e) => { if (e.op === 'get')
|
|
3075
|
-
(out.push(e.key), inE(e.key));
|
|
3334
|
+
(out.push(...tupleParts(e.key)), inE(e.key));
|
|
3076
3335
|
else if (e.op === 'if')
|
|
3077
3336
|
(inC(e.c), inE(e.then), inE(e.else));
|
|
3078
|
-
else if (e.op === 'mul')
|
|
3337
|
+
else if (e.op === 'mul' || e.op === 'proj')
|
|
3079
3338
|
inE(e.a);
|
|
3080
|
-
else if ('
|
|
3339
|
+
else if ('b' in e)
|
|
3081
3340
|
(inE(e.a), inE(e.b)); };
|
|
3082
3341
|
const inC = (x) => (x.op === 'flag' || x.op === 'all' ? undefined : x.op === 'not' ? inC(x.x) : x.op === 'and' || x.op === 'or' ? x.xs.forEach(inC) : (inE(x.a), inE(x.b)));
|
|
3083
3342
|
inC(c);
|
|
@@ -3113,7 +3372,9 @@ export function concretize(goal, bound = 12) {
|
|
|
3113
3372
|
case 'mul': return e.k * ev(e.a, env);
|
|
3114
3373
|
case 'prod': return ev(e.a, env) * ev(e.b, env);
|
|
3115
3374
|
case 'if': return holds(e.c, env) ? ev(e.then, env) : ev(e.else, env);
|
|
3116
|
-
case 'get':
|
|
3375
|
+
case 'get':
|
|
3376
|
+
case 'tup':
|
|
3377
|
+
case 'proj': return NaN;
|
|
3117
3378
|
}
|
|
3118
3379
|
};
|
|
3119
3380
|
const holds = (c, env) => c.op === 'not' ? !holds(c.x, env) : c.op === 'and' ? c.xs.every(y => holds(y, env)) : c.op === 'or' ? c.xs.some(y => holds(y, env))
|