gdp-wired 0.26.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/accel.d.ts +24 -0
- package/dist/core/accel.js +557 -207
- package/dist/core/bmc.d.ts +4 -1
- package/dist/core/bmc.js +18 -15
- package/dist/core/cycles.d.ts +2 -0
- package/dist/core/cycles.js +1 -1
- package/dist/core/cyclic.js +17 -10
- package/dist/core/data.d.ts +1 -0
- package/dist/core/data.js +73 -18
- package/dist/core/discover.js +64 -25
- package/dist/core/dsl.js +108 -18
- package/dist/core/extract-check.d.ts +52 -2
- package/dist/core/extract-check.js +155 -104
- package/dist/core/extract-read.d.ts +25 -0
- package/dist/core/extract-read.js +55 -14
- package/dist/core/extract-shapes.js +94 -18
- package/dist/core/extract-xstate.js +16 -3
- package/dist/core/extract.d.ts +1 -0
- package/dist/core/extract.js +16 -8
- package/dist/core/fresh.d.ts +9 -0
- package/dist/core/fresh.js +91 -0
- package/dist/core/infer.d.ts +1 -0
- package/dist/core/infer.js +64 -46
- package/dist/core/live.d.ts +15 -0
- package/dist/core/live.js +317 -0
- package/dist/core/machine.js +0 -1
- package/dist/core/nonterm.d.ts +3 -1
- package/dist/core/nonterm.js +103 -25
- package/dist/core/solver.d.ts +21 -0
- package/dist/core/solver.js +8 -0
- package/dist/core/translate.js +69 -19
- package/dist/kernel/cdcl.js +212 -78
- package/dist/kernel/kernel.d.ts +17 -1
- package/dist/kernel/kernel.js +158 -2
- package/dist/kernel/prove.d.ts +30 -4
- package/dist/kernel/prove.js +119 -25
- package/dist/kernel/reader.d.ts +74 -5
- package/dist/kernel/reader.js +531 -75
- package/dist/kernel/simplex.d.ts +26 -1
- package/dist/kernel/simplex.js +148 -14
- package/dist/lean-kernel/emit.d.ts +15 -3
- package/dist/lean-kernel/emit.js +144 -12
- package/dist/lean-kernel/library.js +1 -1
- package/package.json +2 -2
package/dist/kernel/kernel.js
CHANGED
|
@@ -1139,7 +1139,9 @@ const natC = (c, env) => {
|
|
|
1139
1139
|
// Lean's checkRecur: the witness sets only inputs; the start meets the precondition; the stem's turns meet `while` and
|
|
1140
1140
|
// the assumption, and the state after them is in the set; the closure goal's tree checks. A certificate outside the
|
|
1141
1141
|
// language (names the loop doesn't declare, values that aren't naturals, a set reading a turn's input) is refused.
|
|
1142
|
-
export function checkRecur(l, r) {
|
|
1142
|
+
export function checkRecur(l, r) { return 'cases' in r ? checkRecurCases(l, r) : stemOk(l, r) && check(recurGoal(l, r), r.tree); }
|
|
1143
|
+
// Everything but the closure: the language, the witness's names, the start and the stem.
|
|
1144
|
+
function stemOk(l, r) {
|
|
1143
1145
|
const names = [...l.params, ...l.inputs, ...Object.keys(l.state)], values = (o) => Object.values(o).every(x => Number.isSafeInteger(x) && x >= 0);
|
|
1144
1146
|
distinct(l.name, names);
|
|
1145
1147
|
for (const name of Object.keys(l.body))
|
|
@@ -1167,7 +1169,161 @@ export function checkRecur(l, r) {
|
|
|
1167
1169
|
return false;
|
|
1168
1170
|
env = apply(l.body, at);
|
|
1169
1171
|
}
|
|
1170
|
-
return natC(r.set, env)
|
|
1172
|
+
return natC(r.set, env);
|
|
1173
|
+
}
|
|
1174
|
+
const isTC = (c) => c.op === '<=' && c.a.op === 'const' && c.b.op === 'const' && c.a.value <= c.b.value;
|
|
1175
|
+
const isFC = (c) => c.op === '<' && c.a.op === 'const' && c.b.op === 'const' ? c.b.value <= c.a.value : c.op === '<=' && c.a.op === 'const' && c.b.op === 'const' && c.b.value < c.a.value;
|
|
1176
|
+
const kE = (value) => ({ op: 'const', value });
|
|
1177
|
+
// Lean's folds, on kernel.ts's terms: an and of several (Lean: each and of two, nested to the right) is false if one is,
|
|
1178
|
+
// else the rest that aren't true, and so for or; read through the Lean text, the two give the same terms.
|
|
1179
|
+
const foldMul = (k0, a) => (k0 === 0 ? kE(0) : k0 === 1 ? a : a.op === 'const' ? kE(k0 * a.value) : { op: 'mul', k: k0, a });
|
|
1180
|
+
function foldTerm(e, f, fc) {
|
|
1181
|
+
switch (e.op) {
|
|
1182
|
+
case 'var':
|
|
1183
|
+
case 'const': return e;
|
|
1184
|
+
case 'add': {
|
|
1185
|
+
const a = f(e.a), b = f(e.b);
|
|
1186
|
+
return a.op === 'const' && a.value === 0 ? b : b.op === 'const' && b.value === 0 ? a : a.op === 'const' && b.op === 'const' ? kE(a.value + b.value) : { op: 'add', a, b };
|
|
1187
|
+
}
|
|
1188
|
+
case 'sub': {
|
|
1189
|
+
const a = f(e.a), b = f(e.b);
|
|
1190
|
+
return b.op === 'const' && b.value === 0 ? a : a.op === 'const' && b.op === 'const' ? kE(Math.max(0, a.value - b.value)) : { op: 'sub', a, b };
|
|
1191
|
+
}
|
|
1192
|
+
case 'mul': return foldMul(e.k, f(e.a));
|
|
1193
|
+
case 'min':
|
|
1194
|
+
case 'max': {
|
|
1195
|
+
const a = f(e.a), b = f(e.b);
|
|
1196
|
+
return a.op === 'const' && b.op === 'const' ? kE(Math[e.op](a.value, b.value)) : { op: e.op, a, b };
|
|
1197
|
+
}
|
|
1198
|
+
case 'prod': {
|
|
1199
|
+
const a = f(e.a), b = f(e.b);
|
|
1200
|
+
return a.op === 'const' ? foldMul(a.value, b) : b.op === 'const' ? foldMul(b.value, a) : { op: 'prod', a, b };
|
|
1201
|
+
}
|
|
1202
|
+
case 'if': {
|
|
1203
|
+
const c = fc(e.c);
|
|
1204
|
+
return isTC(c) ? f(e.then) : isFC(c) ? f(e.else) : { op: 'if', c, then: f(e.then), else: f(e.else) };
|
|
1205
|
+
}
|
|
1206
|
+
case 'get': return { op: 'get', map: e.map, key: f(e.key) };
|
|
1207
|
+
default: return unreachable(e);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
function foldCond(c, f, fc) {
|
|
1211
|
+
switch (c.op) {
|
|
1212
|
+
case '<=':
|
|
1213
|
+
case '<':
|
|
1214
|
+
case '=': {
|
|
1215
|
+
const a = f(c.a), b = f(c.b);
|
|
1216
|
+
if (a.op !== 'const' || b.op !== 'const')
|
|
1217
|
+
return { op: c.op, a, b };
|
|
1218
|
+
return (c.op === '<=' ? a.value <= b.value : c.op === '<' ? a.value < b.value : a.value === b.value) ? trueC : falseC;
|
|
1219
|
+
}
|
|
1220
|
+
case 'and':
|
|
1221
|
+
case 'or': {
|
|
1222
|
+
const ys = c.xs.map(fc), stop = c.op === 'and' ? isFC : isTC, unit = c.op === 'and' ? isTC : isFC;
|
|
1223
|
+
if (ys.some(stop))
|
|
1224
|
+
return c.op === 'and' ? falseC : trueC;
|
|
1225
|
+
const zs = ys.filter(y => !unit(y));
|
|
1226
|
+
return zs.length === 0 ? (c.op === 'and' ? trueC : falseC) : zs.length === 1 ? zs[0] : { op: c.op, xs: zs };
|
|
1227
|
+
}
|
|
1228
|
+
case 'not': {
|
|
1229
|
+
const x = fc(c.x);
|
|
1230
|
+
return isTC(x) ? falseC : isFC(x) ? trueC : { op: 'not', x };
|
|
1231
|
+
}
|
|
1232
|
+
case 'flag':
|
|
1233
|
+
case 'all': throw new Error('a loop reads no flag');
|
|
1234
|
+
default: return unreachable(c);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
// Lean's simpC ∘ substC: the variables substituted, then the constants folded, each shared part once (a folder keeps
|
|
1238
|
+
// what it folded, so its terms are folded once for every use).
|
|
1239
|
+
const folder = () => {
|
|
1240
|
+
const me = new WeakMap(), mc = new WeakMap();
|
|
1241
|
+
const f = (e) => { let o = me.get(e); if (!o) {
|
|
1242
|
+
o = foldTerm(e, f, fc);
|
|
1243
|
+
me.set(e, o);
|
|
1244
|
+
} return o; };
|
|
1245
|
+
const fc = (x) => { let o = mc.get(x); if (!o) {
|
|
1246
|
+
o = foldCond(x, f, fc);
|
|
1247
|
+
mc.set(x, o);
|
|
1248
|
+
} return o; };
|
|
1249
|
+
return { f, fc };
|
|
1250
|
+
};
|
|
1251
|
+
const substituter = (vars) => {
|
|
1252
|
+
const me = new WeakMap(), mc = new WeakMap();
|
|
1253
|
+
const se = (e) => {
|
|
1254
|
+
const had = me.get(e);
|
|
1255
|
+
if (had)
|
|
1256
|
+
return had;
|
|
1257
|
+
let o;
|
|
1258
|
+
switch (e.op) {
|
|
1259
|
+
case 'var':
|
|
1260
|
+
o = vars[e.name] ?? e;
|
|
1261
|
+
break;
|
|
1262
|
+
case 'const':
|
|
1263
|
+
o = e;
|
|
1264
|
+
break;
|
|
1265
|
+
case 'mul':
|
|
1266
|
+
o = { op: 'mul', k: e.k, a: se(e.a) };
|
|
1267
|
+
break;
|
|
1268
|
+
case 'if':
|
|
1269
|
+
o = { op: 'if', c: sc(e.c), then: se(e.then), else: se(e.else) };
|
|
1270
|
+
break;
|
|
1271
|
+
case 'get':
|
|
1272
|
+
o = { op: 'get', map: e.map, key: se(e.key) };
|
|
1273
|
+
break;
|
|
1274
|
+
case 'add':
|
|
1275
|
+
case 'sub':
|
|
1276
|
+
case 'min':
|
|
1277
|
+
case 'max':
|
|
1278
|
+
case 'prod':
|
|
1279
|
+
o = { op: e.op, a: se(e.a), b: se(e.b) };
|
|
1280
|
+
break;
|
|
1281
|
+
default: return unreachable(e);
|
|
1282
|
+
}
|
|
1283
|
+
me.set(e, o);
|
|
1284
|
+
return o;
|
|
1285
|
+
};
|
|
1286
|
+
const sc = (c) => {
|
|
1287
|
+
const had = mc.get(c);
|
|
1288
|
+
if (had)
|
|
1289
|
+
return had;
|
|
1290
|
+
if (c.op === 'flag' || c.op === 'all')
|
|
1291
|
+
throw new Error('a loop reads no flag');
|
|
1292
|
+
const o = c.op === 'not' ? { op: 'not', x: sc(c.x) } : c.op === 'and' || c.op === 'or' ? { op: c.op, xs: c.xs.map(sc) } : { op: c.op, a: se(c.a), b: se(c.b) };
|
|
1293
|
+
mc.set(c, o);
|
|
1294
|
+
return o;
|
|
1295
|
+
};
|
|
1296
|
+
return { se, sc };
|
|
1297
|
+
};
|
|
1298
|
+
export const foldPinned = (c, pins) => folder().fc(substituter(Object.fromEntries(pins.map(([n, x]) => [n, kE(x)]))).sc(c));
|
|
1299
|
+
// The pins as a condition, as Lean's pinC: each variable equal to its value, nested to the right; none: true.
|
|
1300
|
+
export const pinC = (pins) => (pins.length === 0 ? trueC : pins.length === 1 ? { op: '=', a: { op: 'var', name: pins[0][0] }, b: kE(pins[0][1]) }
|
|
1301
|
+
: { op: 'and', xs: [{ op: '=', a: { op: 'var', name: pins[0][0] }, b: kE(pins[0][1]) }, pinC(pins.slice(1))] });
|
|
1302
|
+
export const coverGoal = (r) => ({ name: 'the set is covered by its cases', hyps: [r.set, ...r.cases.map((c) => ({ op: 'not', x: { op: 'and', xs: [pinC(c.pins), c.cond] } }))] });
|
|
1303
|
+
// Each case's goal, as Lean's caseGoal: its condition at the pins, then the witnessed turn failing, built at the pins
|
|
1304
|
+
// (caseNeg): the witness's terms at the pins and the pins (`w`), the body's terms read there and folded, then `w` (a
|
|
1305
|
+
// state variable's term first); the guard and the assumption read at `w`, the set at those terms, each folded.
|
|
1306
|
+
export function caseGoals(l, r, cases) {
|
|
1307
|
+
return cases.map(({ pins, cond }) => {
|
|
1308
|
+
const { f, fc } = folder(), at = substituter(Object.fromEntries(pins.map(([n, x]) => [n, kE(x)])));
|
|
1309
|
+
const w = { ...Object.fromEntries(Object.entries(r.wit).map(([n, t]) => [n, f(at.se(t))])), ...Object.fromEntries(pins.map(([n, x]) => [n, kE(x)])) };
|
|
1310
|
+
const sw = substituter(w), b = { ...w, ...Object.fromEntries(Object.entries(l.body).map(([n, t]) => [n, f(sw.se(t))])) };
|
|
1311
|
+
const neg = { op: 'not', x: { op: 'and', xs: [fc(sw.sc(l.while)), fc(sw.sc(l.assume ?? trueC)), fc(substituter(b).sc(r.set))] } };
|
|
1312
|
+
return { name: `${l.name} never ends: the set is closed where ${pins.map(([n, x]) => `${n} = ${x}`).join(', ')}`, hyps: [foldPinned(cond, pins), neg] };
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
// Lean's checkRecurCases: as checkRecur, the closure by its cases.
|
|
1316
|
+
export function checkRecurCases(l, r) {
|
|
1317
|
+
const scope = [...l.params, ...Object.keys(l.state)];
|
|
1318
|
+
for (const c of r.cases) {
|
|
1319
|
+
inScope(`${l.name}'s case`, [c.cond], scope);
|
|
1320
|
+
if (!naturalC(c.cond) || !c.pins.every(([n, x]) => scope.includes(n) && Number.isSafeInteger(x) && x >= 0) || new Set(c.pins.map(([n]) => n)).size < c.pins.length)
|
|
1321
|
+
throw new Error('outside the kernel');
|
|
1322
|
+
}
|
|
1323
|
+
if (!stemOk(l, r) || !check(coverGoal(r), r.cover))
|
|
1324
|
+
return false;
|
|
1325
|
+
const goals = caseGoals(l, r, r.cases);
|
|
1326
|
+
return r.cases.every((c, j) => check(goals[j], c.tree));
|
|
1171
1327
|
}
|
|
1172
1328
|
// --- progress: laws with "there is a request" ----------------------------------------------------------------------
|
|
1173
1329
|
// "In every reachable state where `when` holds, some request makes `then` true of the step": proven by naming the
|
package/dist/kernel/prove.d.ts
CHANGED
|
@@ -5,9 +5,12 @@ import { type Goal, type Instances, type Liveness, type Loop, type Path, type St
|
|
|
5
5
|
export declare const pairedKeys: {
|
|
6
6
|
skip: boolean;
|
|
7
7
|
};
|
|
8
|
-
export declare
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export declare const cellPair: (a: string, b: string) => {
|
|
9
|
+
d: Lin;
|
|
10
|
+
neg: Lin;
|
|
11
|
+
q0?: Lin;
|
|
12
|
+
q1?: Lin;
|
|
13
|
+
};
|
|
11
14
|
export declare function parseKey(text: string): Lin;
|
|
12
15
|
export declare const profile: {
|
|
13
16
|
on: boolean;
|
|
@@ -45,7 +48,10 @@ export type Outcome = {
|
|
|
45
48
|
why?: string;
|
|
46
49
|
};
|
|
47
50
|
export declare const clock: () => number;
|
|
48
|
-
export declare function counted<T>(perMs: number, f: () => T): T;
|
|
51
|
+
export declare function counted<T>(perMs: number, f: () => T, full?: boolean): T;
|
|
52
|
+
export declare const fullRate = 250;
|
|
53
|
+
export declare const fullWork: () => number;
|
|
54
|
+
export declare const late: (until: number) => boolean;
|
|
49
55
|
export declare const withinDeadline: (until: number) => number;
|
|
50
56
|
export declare function withDeadline<T>(until: number, f: () => T): T;
|
|
51
57
|
export declare function grow(goal: Goal, path?: Path, budget?: {
|
|
@@ -54,6 +60,18 @@ export declare function grow(goal: Goal, path?: Path, budget?: {
|
|
|
54
60
|
units?: boolean;
|
|
55
61
|
}): Outcome;
|
|
56
62
|
export declare function withTrees<T>(f: () => T): T;
|
|
63
|
+
export declare const queryHook: {
|
|
64
|
+
on?: (q: {
|
|
65
|
+
kind: string;
|
|
66
|
+
goal: Goal;
|
|
67
|
+
ms: number;
|
|
68
|
+
work: number;
|
|
69
|
+
out: Outcome;
|
|
70
|
+
depth: number;
|
|
71
|
+
}) => void;
|
|
72
|
+
depth: number;
|
|
73
|
+
};
|
|
74
|
+
export declare function logged(kind: string, goal: Goal, f: () => Outcome): Outcome;
|
|
57
75
|
export declare const realModels: {
|
|
58
76
|
on: boolean;
|
|
59
77
|
};
|
|
@@ -67,6 +85,14 @@ export declare function openAt(goal: Goal, path: Path, rows: {
|
|
|
67
85
|
export declare const minimal: {
|
|
68
86
|
on: boolean;
|
|
69
87
|
};
|
|
88
|
+
export type LeafRows = {
|
|
89
|
+
n: number;
|
|
90
|
+
at: Map<number, {
|
|
91
|
+
lin: Lin;
|
|
92
|
+
src: number | [string, string];
|
|
93
|
+
}>;
|
|
94
|
+
};
|
|
95
|
+
export declare const leafRowsOf: WeakMap<object, LeafRows>;
|
|
70
96
|
export declare function usedHyps(goal: Goal, tree: Tree, path?: Path, out?: Set<number>): Set<number>;
|
|
71
97
|
export type Report = {
|
|
72
98
|
proven: boolean;
|
package/dist/kernel/prove.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
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
11
|
import { walkOnce } from "../core/machine.js";
|
|
12
|
-
import { add, env, k, refuteFast, scale, solve, sub, v, work } from "../core/solver.js";
|
|
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, 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";
|
|
@@ -95,43 +95,68 @@ function openH(c, path, out, positive = true) {
|
|
|
95
95
|
// keys a pairing builds ((a + b)² + b, keys whose difference has monomials) are left uncompared: that encoding states
|
|
96
96
|
// their congruence as facts, and comparing their keys only brings products into leaves its linear rows decide.
|
|
97
97
|
export const pairedKeys = { skip: false };
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
// (each cell's map and key, and each pair's difference both ways, made once: the pairs are quadratic in the names, and
|
|
99
|
+
// the same forms at every node keep what is remembered per form)
|
|
100
|
+
const cellKeys = new Map(), cellPairs = new Map();
|
|
101
|
+
export const cellPair = (a, b) => {
|
|
102
|
+
const pk = `${a}\u0000${b}`;
|
|
103
|
+
let pair = cellPairs.get(pk);
|
|
104
|
+
if (!pair) {
|
|
105
|
+
if (cellPairs.size > 200_000)
|
|
106
|
+
cellPairs.clear();
|
|
107
|
+
const d = sub(cellKey(a).key, cellKey(b).key);
|
|
108
|
+
cellPairs.set(pk, (pair = { d, neg: scale(d, -1) }));
|
|
109
|
+
}
|
|
110
|
+
return pair;
|
|
111
|
+
};
|
|
112
|
+
const cellKey = (n) => { let c = cellKeys.get(n); if (!c) {
|
|
113
|
+
if (cellKeys.size > 100_000)
|
|
114
|
+
cellKeys.clear();
|
|
115
|
+
cellKeys.set(n, (c = { map: n.slice(0, n.indexOf('[')), key: parseKey(n.slice(n.indexOf('[') + 1, -1)) }));
|
|
116
|
+
} return c; };
|
|
117
|
+
function openCells(rows, path) {
|
|
118
|
+
const seen = new Set(), names = [];
|
|
119
|
+
for (const r of rows)
|
|
120
|
+
for (const n in r.lin)
|
|
121
|
+
if (!seen.has(n)) {
|
|
122
|
+
seen.add(n);
|
|
123
|
+
if (isCell(n))
|
|
124
|
+
names.push(n);
|
|
125
|
+
}
|
|
100
126
|
const out = [];
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
const maps = names.map(n => n.slice(0, n.indexOf('['))), keys = names.map(n => parseKey(keyText(n)));
|
|
127
|
+
const cs = names.map(cellKey);
|
|
128
|
+
const dec = (lin) => path.get(canon(lin))?.holds ?? (path.has(canonFlip(lin)) ? !path.get(canonFlip(lin)).holds : undefined);
|
|
104
129
|
for (let i = 0; i < names.length; i++)
|
|
105
130
|
for (let j = i + 1; j < names.length; j++) {
|
|
106
|
-
if (
|
|
131
|
+
if (cs[i].map !== cs[j].map)
|
|
107
132
|
continue;
|
|
108
|
-
const
|
|
133
|
+
const pair = cellPair(names[i], names[j]), d = pair.d;
|
|
109
134
|
if (pairedKeys.skip && Object.keys(d).some(isMonomial))
|
|
110
135
|
continue;
|
|
111
|
-
const dec = (lin) => path.get(canon(lin))?.holds ?? (path.has(canonFlip(lin)) ? !path.get(canonFlip(lin)).holds : undefined);
|
|
112
136
|
// Two cells of a run's map (core/cyclic.ts: time u and key k at u + k·Ω) at keys k·Ω and k'·Ω: k = k' first, a
|
|
113
137
|
// linear atom; the keys' own difference only where k = k' (its other side then refuted by (k − k')·Ω = 0, a product).
|
|
114
|
-
const q0 = cellProducts.on ? quotient(d) : undefined;
|
|
138
|
+
const q0 = cellProducts.on ? ('q0' in pair ? pair.q0 : (pair.q0 = quotient(d))) : undefined;
|
|
115
139
|
if (q0) {
|
|
116
|
-
const
|
|
140
|
+
const q1 = (pair.q1 ??= scale(q0, -1));
|
|
141
|
+
const qa = dec(q0), qb = dec(q1);
|
|
117
142
|
if (qa === undefined) {
|
|
118
143
|
out.push(q0);
|
|
119
144
|
continue;
|
|
120
145
|
}
|
|
121
146
|
if (qa === true && qb === undefined) {
|
|
122
|
-
out.push(
|
|
147
|
+
out.push(q1);
|
|
123
148
|
continue;
|
|
124
149
|
}
|
|
125
150
|
if (!(qa && qb))
|
|
126
151
|
continue;
|
|
127
152
|
cellDiffs.set(canon(d), q0);
|
|
128
|
-
cellDiffs.set(canon(
|
|
153
|
+
cellDiffs.set(canon(pair.neg), q1);
|
|
129
154
|
}
|
|
130
|
-
const a = dec(d), b = dec(
|
|
155
|
+
const a = dec(d), b = dec(pair.neg);
|
|
131
156
|
if (a === undefined)
|
|
132
157
|
out.push(d);
|
|
133
158
|
else if (a === true && b === undefined)
|
|
134
|
-
out.push(
|
|
159
|
+
out.push(pair.neg);
|
|
135
160
|
}
|
|
136
161
|
return out;
|
|
137
162
|
}
|
|
@@ -204,8 +229,8 @@ const proveTrace = !!env.PROVE_TRACE;
|
|
|
204
229
|
// `why`, when the budget ran out: which limit, at what size, and what usually helps.
|
|
205
230
|
// Set while core/cyclic.ts grows its goals.
|
|
206
231
|
export const cellProducts = { on: false };
|
|
207
|
-
// The budget: 200,000 nodes and, by default, a second per hypothesis (at least 20 seconds) per goal
|
|
208
|
-
// is left `unknown`. A goal with many instances (a law about two keys at its pairs) has that many more rows per leaf.
|
|
232
|
+
// The budget: 200,000 nodes and, by default, a second per hypothesis (at least 20 seconds) per goal, on the counted
|
|
233
|
+
// 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.
|
|
209
234
|
// A deadline every goal grown inside `withDeadline` keeps, beside its own budget: a search that proves many things (core/
|
|
210
235
|
// infer.ts, core/discover.ts, the search proveRule falls back on) bounds them all; a goal past it is left `unknown`.
|
|
211
236
|
let deadline = Infinity;
|
|
@@ -213,14 +238,16 @@ let deadline = Infinity;
|
|
|
213
238
|
// time, or within `counted` the work the prover has done (the solver's rows read and made, each node's rows), `perMs`
|
|
214
239
|
// units a millisecond, so that what a search's budget lets it try, and so its verdict, doesn't depend on the machine's
|
|
215
240
|
// speed. A counted search inside another reads the outer's clock.
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
export
|
|
241
|
+
// With `full`, the clock reads the cost model below in place of work.n.
|
|
242
|
+
let rate = 0, meter = () => work.n;
|
|
243
|
+
export const clock = () => (rate ? meter() / rate : performance.now());
|
|
244
|
+
export function counted(perMs, f, full = false) {
|
|
219
245
|
if (rate)
|
|
220
246
|
return f();
|
|
221
247
|
const outer = deadline;
|
|
222
248
|
rate = perMs;
|
|
223
249
|
deadline = Infinity;
|
|
250
|
+
meter = full ? fullWork : () => work.n;
|
|
224
251
|
try {
|
|
225
252
|
return f();
|
|
226
253
|
}
|
|
@@ -229,6 +256,33 @@ export function counted(perMs, f) {
|
|
|
229
256
|
deadline = outer;
|
|
230
257
|
}
|
|
231
258
|
}
|
|
259
|
+
// The cost model: what a query does, by kind (core/solver.ts's costs), each weighed to the milliseconds a Modal 2-vCPU
|
|
260
|
+
// container takes for it, `fullRate` units a millisecond at the median query: elimination's pairs and the float
|
|
261
|
+
// simplex's cells, the plain search's rows a node (kernel.ts's reading, whole at each node), the values reader.ts finds
|
|
262
|
+
// again, the live rows' copies it keeps and the read edges a change walks, the candidates scanned, the pivots' rows,
|
|
263
|
+
// the root's rows for units, the unfolding's rows a leaf, the goal's nodes where a query starts. work.n counts the rows
|
|
264
|
+
// the solver and each node read, which the incremental search reads whole no more: on 7,027 root queries of 20 ms or
|
|
265
|
+
// more (research/query/fit.py on runs/query/cal2: the 332 step goals, CHC sat and unsat, ITS, the false step goals and
|
|
266
|
+
// the real-world corpus), work.n did 28 to 377 units a ms (p10, p90), the model 120 to 401.
|
|
267
|
+
const model = [['fm', 2.33], ['fcells', 0.0123], ['plainRows', 7.93], ['values', 0.672], ['copies', 0.735], ['edges', 0.0435],
|
|
268
|
+
['scan', 0.0765], ['pivotRows', 0.599], ['unitRows', 15.6], ['unfoldRows', 0.735], ['goalNodes', 0.492], ['translateRows', 7.93]];
|
|
269
|
+
export const fullRate = 250;
|
|
270
|
+
export const fullWork = () => { let n = 0; for (const [k, w] of model)
|
|
271
|
+
n += w * costs[k]; return n; };
|
|
272
|
+
// A goal's own budget where its caller gives none, outside a counted search: the cost model's work, groundRate units a
|
|
273
|
+
// millisecond of the budget (below fullRate: the queries of 10 s or more did 163 to 271 units a ms at their median, by
|
|
274
|
+
// group of the run above, so a long goal's budget takes about the wall time it had), so a goal left unknown is left so
|
|
275
|
+
// on any machine; a deadline it is grown within stays.
|
|
276
|
+
const groundRate = 180;
|
|
277
|
+
let workCap = Infinity;
|
|
278
|
+
const withWork = (cap, f) => { const outer = workCap; workCap = Math.min(outer, cap); try {
|
|
279
|
+
return f();
|
|
280
|
+
}
|
|
281
|
+
finally {
|
|
282
|
+
workCap = outer;
|
|
283
|
+
} };
|
|
284
|
+
// Past a budget's end on the clock, or past the work a goal's own budget allows.
|
|
285
|
+
export const late = (until) => clock() > until || (workCap !== Infinity && fullWork() > workCap);
|
|
232
286
|
// A budget's end, within the deadline (a translation's own bound, core/cyclic.ts's, kept by the export's GDP_CERT_MS).
|
|
233
287
|
export const withinDeadline = (until) => Math.min(until, deadline);
|
|
234
288
|
export function withDeadline(until, f) {
|
|
@@ -243,7 +297,13 @@ export function withDeadline(until, f) {
|
|
|
243
297
|
}
|
|
244
298
|
// `units: false`: the goal's own order, no units first (a caller after a model, not a proof: a run guided by the
|
|
245
299
|
// prover's witnesses, say, whose models units would steer).
|
|
246
|
-
export function grow(goal, path = new Map(), budget
|
|
300
|
+
export function grow(goal, path = new Map(), budget) {
|
|
301
|
+
if (!budget) {
|
|
302
|
+
const ms = Math.max(20_000, 1_000 * goal.hyps.length);
|
|
303
|
+
if (!rate)
|
|
304
|
+
return withWork(fullWork() + groundRate * ms, () => grow(goal, path, { nodes: 0 }));
|
|
305
|
+
budget = { nodes: 0, until: clock() + ms };
|
|
306
|
+
}
|
|
247
307
|
if (deadline < (budget.until ?? Infinity))
|
|
248
308
|
budget.until = deadline;
|
|
249
309
|
if (budget.units === false && unitsNow) {
|
|
@@ -295,7 +355,27 @@ export function withTrees(f) {
|
|
|
295
355
|
treeCache.trees.clear();
|
|
296
356
|
}
|
|
297
357
|
}
|
|
358
|
+
// Each root query as it ends, for research's logs (research/query/log.ts sets it; off otherwise): the kind, the goal,
|
|
359
|
+
// its wall time and counted work, its outcome, and how many queries it is inside.
|
|
360
|
+
export const queryHook = { depth: 0 };
|
|
361
|
+
export function logged(kind, goal, f) {
|
|
362
|
+
const t0 = performance.now(), w0 = work.n;
|
|
363
|
+
queryHook.depth++;
|
|
364
|
+
try {
|
|
365
|
+
const out = f();
|
|
366
|
+
queryHook.on?.({ kind, goal, ms: performance.now() - t0, work: work.n - w0, out, depth: queryHook.depth - 1 });
|
|
367
|
+
return out;
|
|
368
|
+
}
|
|
369
|
+
finally {
|
|
370
|
+
queryHook.depth--;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
298
373
|
function growKept(goal, path, budget) {
|
|
374
|
+
if (queryHook.on && !path.size && !budget.nodes && !queryHook.depth)
|
|
375
|
+
return logged('grow', goal, () => growKept0(goal, path, budget));
|
|
376
|
+
return growKept0(goal, path, budget);
|
|
377
|
+
}
|
|
378
|
+
function growKept0(goal, path, budget) {
|
|
299
379
|
if (!profile.on || path.size || budget.nodes)
|
|
300
380
|
return growRoot(goal, path, budget);
|
|
301
381
|
const t = performance.now(), s0 = profile.solves, m0 = profile.solveMs, r0 = profile.rowsMs, n0 = profile.nodes;
|
|
@@ -330,8 +410,8 @@ function growRoot(goal, path, budget) {
|
|
|
330
410
|
}
|
|
331
411
|
if (root) {
|
|
332
412
|
if (cdcl) {
|
|
333
|
-
const now = clock(), end = withinDeadline(budget.until ?? Infinity);
|
|
334
|
-
const out = growCdcl(goal, path, { nodes: 0, until: end === Infinity ? end : now + cdclShare * (end - now) });
|
|
413
|
+
const now = clock(), end = withinDeadline(budget.until ?? Infinity), w = fullWork();
|
|
414
|
+
const out = withWork(workCap === Infinity ? Infinity : w + cdclShare * (workCap - w), () => growCdcl(goal, path, { nodes: 0, until: end === Infinity ? end : now + cdclShare * (end - now) }));
|
|
335
415
|
// (with `realModels.on`, a model whose products don't multiply out is no model: the CDCL search reads a product as
|
|
336
416
|
// a name of its own, where the plain search below multiplies rows; a goal whose products only its cases bring,
|
|
337
417
|
// core/nonterm.ts's x' := x·y)
|
|
@@ -355,12 +435,14 @@ function growPlain(goal, path, budget) {
|
|
|
355
435
|
return { stuck: 'unknown', path, why: 'cap' };
|
|
356
436
|
if (profile.on)
|
|
357
437
|
profile.nodes++;
|
|
358
|
-
if (++budget.nodes > 200_000 || (budget.until
|
|
438
|
+
if (++budget.nodes > 200_000 || late(budget.until ?? Infinity))
|
|
359
439
|
return { stuck: 'unknown', path, why: outOfBudget(goal, budget.nodes > 200_000 ? 'nodes' : 'time', path.size) };
|
|
360
440
|
// Rows that read a term column only once a cut has put one on the path; before, the rows a choice-free search uses
|
|
361
441
|
// (what it saw before term columns), renumbered to the whole leaf's when a leaf is found.
|
|
362
442
|
const full = timed(() => rowsAt(goal, path), ms => { profile.rowsMs += ms; });
|
|
363
443
|
work.n += 1 + full.length;
|
|
444
|
+
costs.plainNodes++;
|
|
445
|
+
costs.plainRows += full.length;
|
|
364
446
|
const columns = [...path.values()].some(a => Object.keys(a.lin).some(key => key.startsWith('⟦')));
|
|
365
447
|
const idx = full.flatMap((r, i) => (columns || !Object.keys(r.lin).some(key => key.startsWith('⟦')) ? [i] : []));
|
|
366
448
|
const rows = idx.map(i => full[i]), at = (i) => (i < rows.length ? idx[i] : full.length + i - rows.length);
|
|
@@ -770,7 +852,7 @@ const nearSeen = new WeakMap();
|
|
|
770
852
|
// (the names a term reads, its shared parts walked once: a witness read at each of its uses is one object)
|
|
771
853
|
const namesOf = (t) => {
|
|
772
854
|
const out = new Set();
|
|
773
|
-
walkOnce(t, o => { for (const [key, v] of Object.entries(o))
|
|
855
|
+
walkOnce(t, o => { costs.goalNodes++; for (const [key, v] of Object.entries(o))
|
|
774
856
|
if ((key === 'name' || key === 'map') && typeof v === 'string')
|
|
775
857
|
out.add(v); });
|
|
776
858
|
return out;
|
|
@@ -799,6 +881,7 @@ function unitsOf(goal) {
|
|
|
799
881
|
// Forced by the root's rows without a solver: a row the atom is (or is the negation of), or the bounds the rows give
|
|
800
882
|
// single variables (x <= c, x >= c) deciding it whichever way its variables go.
|
|
801
883
|
const root = new Map(), rows = leafConstraints(goal, root), seen = new Set(), given = new Set();
|
|
884
|
+
costs.unitRows += rows.length;
|
|
802
885
|
const lo = new Map(), hi = new Map();
|
|
803
886
|
for (const r of rows) {
|
|
804
887
|
given.add(canon(r.lin));
|
|
@@ -1281,8 +1364,19 @@ function triggered(m, laws, inst, build, focus = []) {
|
|
|
1281
1364
|
// found that its leaves refute with, the proof grown again with those alone. The checked goal is then built from far
|
|
1282
1365
|
// fewer hypotheses (a law about pairs of items with 900 instance hypotheses and 30 leaves using a few of them, say).
|
|
1283
1366
|
export const minimal = { on: false };
|
|
1367
|
+
export const leafRowsOf = new WeakMap();
|
|
1284
1368
|
// The hypotheses a tree's leaves read: each leaf's input rows, and the rows its products multiply.
|
|
1285
1369
|
export function usedHyps(goal, tree, path = new Map(), out = new Set()) {
|
|
1370
|
+
const known = 'leaf' in tree && !tree.products && !tree.squares ? leafRowsOf.get(tree) : undefined;
|
|
1371
|
+
if (known && 'leaf' in tree) {
|
|
1372
|
+
for (const st of tree.leaf)
|
|
1373
|
+
if (st.kind === 'input') {
|
|
1374
|
+
const s = known.at.get(st.index)?.src;
|
|
1375
|
+
if (typeof s === 'number' && s >= 0)
|
|
1376
|
+
out.add(s);
|
|
1377
|
+
}
|
|
1378
|
+
return out;
|
|
1379
|
+
}
|
|
1286
1380
|
if ('leaf' in tree) {
|
|
1287
1381
|
const rows = rowsAt(goal, path), n = rows.length, sq = tree.squares?.length ?? 0;
|
|
1288
1382
|
const mark = (i) => {
|
package/dist/kernel/reader.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export type Row = {
|
|
|
43
43
|
label: '';
|
|
44
44
|
};
|
|
45
45
|
export declare function times(a: Lin, b: Lin): Lin | undefined;
|
|
46
|
+
export declare const keepClean: boolean;
|
|
46
47
|
export declare class Reader {
|
|
47
48
|
readonly goal: Goal;
|
|
48
49
|
readonly trail: Trail;
|
|
@@ -57,17 +58,17 @@ export declare class Reader {
|
|
|
57
58
|
begin(): void;
|
|
58
59
|
private up;
|
|
59
60
|
private byAtom;
|
|
61
|
+
private found;
|
|
62
|
+
private lastUp;
|
|
60
63
|
private clean;
|
|
61
|
-
private frame;
|
|
62
64
|
private factKeys;
|
|
63
65
|
private openKeys;
|
|
64
|
-
private
|
|
66
|
+
private finding;
|
|
65
67
|
private read;
|
|
66
68
|
private readAtom;
|
|
67
69
|
private within;
|
|
68
70
|
touch(name: string): void;
|
|
69
71
|
private ok;
|
|
70
|
-
private kept;
|
|
71
72
|
private units;
|
|
72
73
|
private unit;
|
|
73
74
|
dec(lin: Lin): R & {
|
|
@@ -80,11 +81,79 @@ export declare class Reader {
|
|
|
80
81
|
private truth0;
|
|
81
82
|
private factsOf;
|
|
82
83
|
facts(i: number): FV;
|
|
84
|
+
private factsFin;
|
|
85
|
+
private partsOf;
|
|
86
|
+
private ps;
|
|
87
|
+
private parts;
|
|
88
|
+
private part;
|
|
83
89
|
termRows(name: string): Row[];
|
|
84
90
|
private decided;
|
|
85
91
|
rows(): Row[];
|
|
86
|
-
|
|
87
|
-
|
|
92
|
+
private forms;
|
|
93
|
+
private formIds;
|
|
94
|
+
private nameIds;
|
|
95
|
+
private nameText;
|
|
96
|
+
private nameKind;
|
|
97
|
+
private formSeen;
|
|
98
|
+
private formAt;
|
|
99
|
+
private nameSeen;
|
|
100
|
+
private termSeen;
|
|
101
|
+
private gen;
|
|
102
|
+
form(lin: Lin): {
|
|
103
|
+
id: number;
|
|
104
|
+
names: number[];
|
|
105
|
+
};
|
|
106
|
+
readsColumn(lin: Lin): boolean;
|
|
107
|
+
private trailRows;
|
|
108
|
+
private trailStamps;
|
|
109
|
+
private pairs;
|
|
110
|
+
leafRows(src?: (number | [string, string])[]): Row[];
|
|
111
|
+
live: Row[];
|
|
112
|
+
entered: number[];
|
|
113
|
+
left: number[];
|
|
114
|
+
private syncing;
|
|
115
|
+
private dirty;
|
|
116
|
+
private slot;
|
|
117
|
+
private copies;
|
|
118
|
+
private c12;
|
|
119
|
+
private cT;
|
|
120
|
+
private inTrail;
|
|
121
|
+
private inParts;
|
|
122
|
+
private hypsIn;
|
|
123
|
+
private src;
|
|
124
|
+
hypsOf(rows: Row[]): number[];
|
|
125
|
+
private inSeg;
|
|
126
|
+
private cached;
|
|
127
|
+
private termKeys;
|
|
128
|
+
private pairKeys;
|
|
129
|
+
private liveCells;
|
|
130
|
+
private inNat;
|
|
131
|
+
private syncN;
|
|
132
|
+
private markN;
|
|
133
|
+
private wasLive;
|
|
134
|
+
private changed;
|
|
135
|
+
slotOf(id: number): number;
|
|
136
|
+
hasCells(): boolean;
|
|
137
|
+
private cellsOn;
|
|
138
|
+
readonly cells: Map<string, Set<string>>;
|
|
139
|
+
cellsChanged: number;
|
|
140
|
+
sync(): void;
|
|
141
|
+
private trailRow;
|
|
142
|
+
private segRows;
|
|
143
|
+
private pair;
|
|
144
|
+
private mark;
|
|
145
|
+
private addCopy;
|
|
146
|
+
private removeCopy;
|
|
147
|
+
private countUp;
|
|
148
|
+
private countDown;
|
|
149
|
+
private nameOn;
|
|
150
|
+
private nameOff;
|
|
151
|
+
private segOn;
|
|
152
|
+
private segOff;
|
|
153
|
+
private pairKey;
|
|
154
|
+
private cellOn;
|
|
155
|
+
private cellOff;
|
|
156
|
+
openList(i: number): Lin[];
|
|
88
157
|
private openE;
|
|
89
158
|
private openC;
|
|
90
159
|
private openH;
|