gdp-wired 0.44.0 → 0.45.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/c/reader.js +22 -7
- package/dist/core/check.js +3 -2
- package/dist/core/cli.d.ts +1 -0
- package/dist/core/cli.js +136 -6
- package/dist/core/counts.d.ts +1 -1
- package/dist/core/counts.js +30 -12
- package/dist/core/data.d.ts +6 -1
- package/dist/core/data.js +894 -152
- package/dist/core/dsl.d.ts +2 -0
- package/dist/core/dsl.js +88 -10
- package/dist/core/effect-prims.js +2 -2
- package/dist/core/ex/reader.exs +17 -1
- package/dist/core/exists.d.ts +15 -1
- package/dist/core/exists.js +263 -41
- package/dist/core/extract-c.js +19 -12
- package/dist/core/extract-check.d.ts +6 -0
- package/dist/core/extract-check.js +49 -3
- package/dist/core/extract-ex.js +3 -3
- package/dist/core/extract-go-check.js +19 -12
- package/dist/core/extract-go.js +20 -5
- package/dist/core/extract-jvm.js +63 -14
- package/dist/core/extract-print.js +3 -0
- package/dist/core/extract-py.js +3 -3
- package/dist/core/extract-rb.js +3 -3
- package/dist/core/extract-read.d.ts +8 -0
- package/dist/core/extract-read.js +55 -0
- package/dist/core/extract-rs.js +17 -19
- package/dist/core/extract-shapes.js +20 -0
- package/dist/core/extract-sol.js +19 -8
- package/dist/core/extract-step.d.ts +50 -3
- package/dist/core/extract-step.js +289 -58
- package/dist/core/extract-swift.js +20 -13
- package/dist/core/extract.d.ts +1 -0
- package/dist/core/extract.js +27 -2
- package/dist/core/fresh.d.ts +2 -2
- package/dist/core/fresh.js +7 -3
- package/dist/core/go/reader.go +7 -1
- package/dist/core/infer.js +115 -42
- package/dist/core/jvm/JavaReader.java +10 -2
- package/dist/core/jvm/Jvm.java +17 -1
- package/dist/core/jvm/KtReader.java +57 -5
- package/dist/core/machine.d.ts +1 -2
- package/dist/core/machine.js +27 -15
- package/dist/core/py/harness.py +77 -11
- package/dist/core/py/reader.py +50 -5
- package/dist/core/rb/reader.rb +52 -5
- package/dist/core/rs/src/main.rs +10 -0
- package/dist/core/sol/harness.py +6 -3
- package/dist/core/solver.js +5 -4
- package/dist/core/system.d.ts +62 -1
- package/dist/core/system.js +262 -3
- package/dist/core/transfer.js +17 -0
- package/dist/core/watch.js +1 -1
- package/dist/interchange/check.js +10 -10
- package/dist/interchange/format.d.ts +4 -0
- package/dist/interchange/format.js +13 -5
- package/dist/kernel/cdcl.js +33 -2
- package/dist/kernel/epr.js +35 -5
- package/dist/kernel/kernel.d.ts +2 -0
- package/dist/kernel/kernel.js +67 -40
- package/dist/kernel/prove.d.ts +22 -0
- package/dist/kernel/prove.js +156 -7
- package/dist/lean-kernel/emit.d.ts +9 -3
- package/dist/lean-kernel/emit.js +170 -29
- package/dist/lean-kernel/library.js +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { canon, columnTerm, factorsOf, isCell, isMonomial, termColumn } from "../kernel/kernel.js";
|
|
2
|
-
// 1.1 adds a liveness's fairness and levels (strong fairness, Live.lean's
|
|
3
|
-
//
|
|
2
|
+
// 1.1 adds a liveness's fairness and levels (strong fairness, Live.lean's sleads_sf_soundA) and a measure part's fold (a
|
|
3
|
+
// fold function's value at a parameter, core/data.ts's Measure): a document is written at the lowest version that holds
|
|
4
|
+
// it (1.0 unless it has one of these), and read at either.
|
|
4
5
|
export const FORMAT = 'gdp-wired-interchange', VERSION = '1.1', VERSIONS = ['1.0', '1.1'];
|
|
5
6
|
export const KINDS = ['goals', 'laws', 'stepLaws', 'kInduction', 'progress', 'liveness', 'loop', 'recur', 'fold', 'cyclic', 'qgoals', 'qmachine', 'termination'];
|
|
6
7
|
// Why a value is outside the format: where, and what.
|
|
@@ -561,10 +562,15 @@ const decRecur = (x, cols, at) => {
|
|
|
561
562
|
const o = obj(x, at, ['start', 'stem', 'set', 'wit', 'tree']);
|
|
562
563
|
return { start: record(o.start, nat, `${at}.start`), stem: arr(o.stem, `${at}.stem`).map((t, i) => record(t, nat, `${at}.stem[${i}]`)), set: decC(o.set, `${at}.set`), wit: record(o.wit, decE, `${at}.wit`), tree: decTree(o.tree, cols, `${at}.tree`) };
|
|
563
564
|
};
|
|
564
|
-
const
|
|
565
|
+
const encFoldPart = (f, at) => ({ fn: name(f.fn, `${at}.fn`), of: nat(f.of, `${at}.of`) });
|
|
566
|
+
const encMeasure = (m, at) => ({ comps: arr(m.comps, `${at}.comps`).map((c, i) => { const q = c; return clean({ coef: arr(q.coef, `${at}.comps[${i}].coef`).map((k, j) => int(k, `${at}.comps[${i}].coef[${j}]`)), c: int(q.c, `${at}.comps[${i}].c`), fold: q.fold && encFoldPart(q.fold, `${at}.comps[${i}].fold`) }); }) });
|
|
565
567
|
const decMeasure = (x, at) => {
|
|
566
568
|
const o = obj(x, at, ['comps']);
|
|
567
|
-
return { comps: arr(o.comps, `${at}.comps`).map((c, i) => {
|
|
569
|
+
return { comps: arr(o.comps, `${at}.comps`).map((c, i) => {
|
|
570
|
+
const q = obj(c, `${at}.comps[${i}]`, ['coef', 'c'], ['fold']);
|
|
571
|
+
return clean({ coef: arr(q.coef, `${at}.comps[${i}].coef`).map((k, j) => int(k, `${at}.comps[${i}].coef[${j}]`)), c: int(q.c, `${at}.comps[${i}].c`),
|
|
572
|
+
fold: opt(q, 'fold', (y, a) => { const f = obj(y, a, ['fn', 'of']); return { fn: name(f.fn, `${a}.fn`), of: nat(f.of, `${a}.of`) }; }, `${at}.comps[${i}]`) });
|
|
573
|
+
}) };
|
|
568
574
|
};
|
|
569
575
|
// --- documents ---------------------------------------------------------------------------------------------------------------
|
|
570
576
|
// The fields each kind has, in the order a document is written.
|
|
@@ -600,7 +606,7 @@ export function toInterchange(c, meta) {
|
|
|
600
606
|
default: return fail('kind', `no kind ${JSON.stringify(c.kind)}`);
|
|
601
607
|
}
|
|
602
608
|
})();
|
|
603
|
-
const v11 = c.kind === 'liveness' && (c.liveness.fairness !== undefined || c.liveness.levels !== undefined);
|
|
609
|
+
const v11 = (c.kind === 'liveness' && (c.liveness.fairness !== undefined || c.liveness.levels !== undefined)) || (c.kind === 'termination' && c.measures.some(m => m.comps.some(q => q.fold !== undefined)));
|
|
604
610
|
return clean({ format: FORMAT, version: v11 ? '1.1' : '1.0', kind: c.kind, meta, columns: 'terms' in cols && cols.terms.length ? cols.terms : undefined, ...body });
|
|
605
611
|
}
|
|
606
612
|
// A document read back into the kernel's objects, or a FormatError saying where it leaves the format.
|
|
@@ -612,6 +618,8 @@ export function fromInterchange(doc) {
|
|
|
612
618
|
fail('version', `one of ${VERSIONS.join(', ')} (this reader's)`);
|
|
613
619
|
if (head.version === '1.0' && head.kind === 'liveness' && isObj(head.liveness) && ('fairness' in head.liveness || 'levels' in head.liveness))
|
|
614
620
|
fail('liveness', 'no fairness or levels in a 1.0 document (1.1\'s)');
|
|
621
|
+
if (head.version === '1.0' && head.kind === 'termination' && JSON.stringify(head.measures ?? []).includes('"fold"'))
|
|
622
|
+
fail('measures', 'no fold in a 1.0 document (1.1\'s)');
|
|
615
623
|
const kind = head.kind;
|
|
616
624
|
if (!KINDS.includes(kind))
|
|
617
625
|
fail('kind', `one of ${KINDS.join(', ')}`);
|
package/dist/kernel/cdcl.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
import { costs, env, refuteFast, solve, work } from "../core/solver.js";
|
|
21
21
|
import { checkRefutation } from "../core/check.js";
|
|
22
22
|
import { atomOf, canon, canonFlip, isMonomial, leafConstraints } from "./kernel.js";
|
|
23
|
-
import { atPoint, cellPair, late, leafRowsOf, logged, nearOf, openAt, pairedKeys, queryHook, rowsAt, unitAtoms } from "./prove.js";
|
|
23
|
+
import { atPoint, cellPair, growWide, late, leafRowsOf, logged, nearOf, openAt, pairedKeys, queryHook, rowsAt, unitAtoms, wideFor, wideScope } from "./prove.js";
|
|
24
24
|
import { Clausal, Reader, namesOf } from "./reader.js";
|
|
25
25
|
import { Simplex } from "./simplex.js";
|
|
26
26
|
// A derivation's own inputs: the rows it reads, in order, and the steps renumbered to them.
|
|
@@ -63,6 +63,12 @@ export const cdclStats = { on: false, runs: 0, proven: 0, conflicts: 0, decision
|
|
|
63
63
|
// any value: the trail's atoms, the naturals, the term columns' definitions), as core/infer.ts's join reads it.
|
|
64
64
|
export const REFUTED = 'refuted, not unfolded';
|
|
65
65
|
export function growCdcl(goal, root, budget, opts = {}) {
|
|
66
|
+
// (a wide goal's model or refutation: over parts first, prove.ts's growWide)
|
|
67
|
+
if (opts.model && !opts.dag && !opts.clausal && !root.size && wideFor(goal)) {
|
|
68
|
+
const out = growWide(goal, budget, (g, until) => growCdcl(g, root, { nodes: 0, until }, opts));
|
|
69
|
+
if (out)
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
66
72
|
const go = () => cdclSession(goal, root, opts).run(budget, opts.wall);
|
|
67
73
|
return queryHook.on && !queryHook.depth ? logged(opts.model ? 'model' : 'cdcl', goal, go) : go();
|
|
68
74
|
}
|
|
@@ -537,6 +543,19 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
537
543
|
}
|
|
538
544
|
return w;
|
|
539
545
|
};
|
|
546
|
+
// (the point rounded, each name the rows read; undefined where the simplex doesn't know one)
|
|
547
|
+
const roundedOf = (lp, rows) => {
|
|
548
|
+
const w = {};
|
|
549
|
+
for (const r of rows)
|
|
550
|
+
for (const n of namesOf(r.lin))
|
|
551
|
+
if (!(n in w)) {
|
|
552
|
+
const j = lp.indexOf(n);
|
|
553
|
+
if (j === undefined)
|
|
554
|
+
return undefined;
|
|
555
|
+
w[n] = Math.max(0, Math.round(lp.value(j)));
|
|
556
|
+
}
|
|
557
|
+
return w;
|
|
558
|
+
};
|
|
540
559
|
let qhead = 0;
|
|
541
560
|
// Unit propagation: a clause whose literals all hold is a conflict (its index); all but one, the last is flipped.
|
|
542
561
|
const propagateKernel = () => {
|
|
@@ -1093,7 +1112,7 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
1093
1112
|
continue;
|
|
1094
1113
|
}
|
|
1095
1114
|
}
|
|
1096
|
-
let steps, lpSat = false;
|
|
1115
|
+
let steps, lpSat = false, judged = false;
|
|
1097
1116
|
let verdict;
|
|
1098
1117
|
t(() => {
|
|
1099
1118
|
// The simplex first (warm from the node before): a conflict's rows, refuted exactly, are the leaf. With a case
|
|
@@ -1145,6 +1164,16 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
1145
1164
|
st.lpMisses++;
|
|
1146
1165
|
}
|
|
1147
1166
|
lpSat = lp.kind === 'sat';
|
|
1167
|
+
// (a wide goal's part, prove.ts's growWide: the simplex's point rounded, where it holds every hypothesis of the part
|
|
1168
|
+
// read as a state, is the part's model, whatever atoms are still open)
|
|
1169
|
+
if (open && lpSat && wideScope.judge) {
|
|
1170
|
+
const w = roundedOf(sx, rowsR);
|
|
1171
|
+
if (w && wideScope.judge(w)) {
|
|
1172
|
+
verdict = { kind: 'sat', witness: w };
|
|
1173
|
+
judged = true;
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1148
1177
|
if (steps || (open && lp.kind === 'sat'))
|
|
1149
1178
|
return;
|
|
1150
1179
|
// (the clausal mode, every clause satisfied: the simplex's point, where it is integral, is a model)
|
|
@@ -1174,6 +1203,8 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
1174
1203
|
steps = fast.steps.map(s => (s.kind === 'input' ? { ...s, index: k[s.index] } : s));
|
|
1175
1204
|
}
|
|
1176
1205
|
}, ms => { st.solveMs += ms; });
|
|
1206
|
+
if (judged && verdict?.kind === 'sat')
|
|
1207
|
+
return stuck('sat', 'a model', { witness: verdict.witness });
|
|
1177
1208
|
if (steps)
|
|
1178
1209
|
conflict = leafAt(rowsR, steps);
|
|
1179
1210
|
else {
|
package/dist/kernel/epr.js
CHANGED
|
@@ -16,13 +16,13 @@ const textOfE = (o) => { let s = textsOf.get(o); if (s === undefined)
|
|
|
16
16
|
// The patterns of a rule: of each map's reads in the step, the assumption, the flags and the laws (not the kinds' laws,
|
|
17
17
|
// whose key is a whole key), the one with the most parts. A read keyed by a write-at-every-key's own name is left out.
|
|
18
18
|
export function patternsOf(m, laws) {
|
|
19
|
-
const out =
|
|
19
|
+
const out = Object.create(null);
|
|
20
20
|
const each = new Set(Object.values(m.step.maps ?? {}).flatMap(w => ('each' in w ? [w.each] : [])));
|
|
21
21
|
const scan = (o) => {
|
|
22
22
|
if (!o || typeof o !== 'object')
|
|
23
23
|
return;
|
|
24
24
|
const x = o;
|
|
25
|
-
if (x.op === 'get' && !x.args && !(x.key.op === 'var' && each.has(x.key.name)) && !(m.fns &&
|
|
25
|
+
if (x.op === 'get' && !x.args && !(x.key.op === 'var' && each.has(x.key.name)) && !(m.fns && Object.hasOwn(m.fns, x.map))) {
|
|
26
26
|
const t = tupleOf(x.key);
|
|
27
27
|
if (t && t.coefs.length > (out[x.map]?.length ?? 0))
|
|
28
28
|
out[x.map] = t.coefs;
|
|
@@ -38,6 +38,26 @@ export function patternsOf(m, laws) {
|
|
|
38
38
|
for (const l of laws)
|
|
39
39
|
if (!(l.name.startsWith('every ') && l.name.endsWith('of its kind')))
|
|
40
40
|
scan(l.holds);
|
|
41
|
+
// (a map read inside another read's key, a Skolem function a ghost map keeps (Sent[W[s]·N + s]): a function of its key
|
|
42
|
+
// too, its reads parts; the step's writes to it are substituted into the goal's reads, so within a goal it is one
|
|
43
|
+
// function)
|
|
44
|
+
const inKey = (o, under) => {
|
|
45
|
+
if (!o || typeof o !== 'object')
|
|
46
|
+
return;
|
|
47
|
+
const x = o;
|
|
48
|
+
if (x.op === 'get' && !x.args && under && !(m.fns && Object.hasOwn(m.fns, x.map)))
|
|
49
|
+
out[x.map] = [0];
|
|
50
|
+
if (x.op === 'get' && !x.args) {
|
|
51
|
+
inKey(x.key, true);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
for (const y of Object.values(o))
|
|
55
|
+
inKey(y, under);
|
|
56
|
+
};
|
|
57
|
+
inKey(m.step, false);
|
|
58
|
+
inKey(m.assume, false);
|
|
59
|
+
for (const l of laws)
|
|
60
|
+
inKey(l.holds, false);
|
|
41
61
|
return out;
|
|
42
62
|
}
|
|
43
63
|
const T = { k: 'c', b: true }, Fa = { k: 'c', b: false };
|
|
@@ -157,6 +177,16 @@ const liftC = (c) => {
|
|
|
157
177
|
if (c.op === 'flag')
|
|
158
178
|
return c;
|
|
159
179
|
const a = liftE(c.a), b = liftE(c.b);
|
|
180
|
+
// (a comparison whose side holds an if over a map's read, a key a ghost's write is read in (64·W'[k] + k = 64·s + d),
|
|
181
|
+
// as the if of the comparisons of its two sides: c ∧ (a₁ ⋈ b) ∨ ¬c ∧ (a₂ ⋈ b), equal to it; at most three ifs in all,
|
|
182
|
+
// counted before they are distributed, 8 leaves)
|
|
183
|
+
const ifs = (e) => textOfE(e).split('"op":"if"').length - 1, reads = (e) => textOfE(e).includes('"op":"get"');
|
|
184
|
+
const few = (hasIf(a) || hasIf(b)) && ifs(a) + ifs(b) <= 3, ha = few ? hoisted(a) : a, hb = few ? hoisted(b) : b;
|
|
185
|
+
if (few && ((ha.op === 'if' && reads(ha)) || (hb.op === 'if' && reads(hb))) && keysOf(ha) * keysOf(hb) <= 8) {
|
|
186
|
+
const split = (x, y) => (x.op === 'if' ? { op: 'or', xs: [{ op: 'and', xs: [x.c, split(x.then, y)] }, { op: 'and', xs: [{ op: 'not', x: x.c }, split(x.else, y)] }] }
|
|
187
|
+
: y.op === 'if' ? { op: 'or', xs: [{ op: 'and', xs: [y.c, split(x, y.then)] }, { op: 'and', xs: [{ op: 'not', x: y.c }, split(x, y.else)] }] } : { ...c, a: x, b: y });
|
|
188
|
+
return liftC(split(ha, hb));
|
|
189
|
+
}
|
|
160
190
|
return a === c.a && b === c.b ? c : { ...c, a, b };
|
|
161
191
|
};
|
|
162
192
|
const liftedKeys = (c) => { let x = liftMemo.get(c); if (!x)
|
|
@@ -1355,7 +1385,7 @@ function encoder(st, patterns) {
|
|
|
1355
1385
|
// grouping, as without one)
|
|
1356
1386
|
const finish = (model, theoryVal) => {
|
|
1357
1387
|
const val = (l) => model[l] === true;
|
|
1358
|
-
const w =
|
|
1388
|
+
const w = Object.create(null); // (a name __proto__ kept, constructor read as no value)
|
|
1359
1389
|
for (const f of gFinsL) {
|
|
1360
1390
|
let x = 0;
|
|
1361
1391
|
for (let val2 = 0; val2 <= f.cap; val2++)
|
|
@@ -1505,7 +1535,7 @@ function encoder(st, patterns) {
|
|
|
1505
1535
|
allMaps.add(x.map);
|
|
1506
1536
|
const st2 = { scalars: {}, maps: Object.fromEntries([...allMaps].map(mp => [mp, maps.get(mp) ?? new Map()])) };
|
|
1507
1537
|
const m = { name: goal.name, params: [], inputs: [], state: {}, step: {}, maps: Object.fromEntries([...allMaps].map(mp => [mp, 0])) };
|
|
1508
|
-
const env = new Proxy({ ...w }, { get: (t, q) => t[q]
|
|
1538
|
+
const env = new Proxy({ ...w }, { get: (t, q) => (Object.hasOwn(t, q) ? t[q] : 0) });
|
|
1509
1539
|
for (const [i, f] of fs.entries()) {
|
|
1510
1540
|
tick();
|
|
1511
1541
|
try {
|
|
@@ -1527,7 +1557,7 @@ function encoder(st, patterns) {
|
|
|
1527
1557
|
}
|
|
1528
1558
|
// the structure
|
|
1529
1559
|
const values = [...new Set([...[...parts].map(x => w[x]), ...[...ordVal].filter(([t]) => !t.startsWith('k:') && !t.includes('#')).map(([, x]) => x)].filter((x) => x !== undefined))].sort((a, b) => a - b), elem = new Map(values.map((x, i) => [x, i]));
|
|
1530
|
-
const diagram = { elements: values.length, parts:
|
|
1560
|
+
const diagram = { elements: values.length, parts: Object.create(null), scalars: Object.create(null), cells: Object.create(null), fns: Object.create(null) };
|
|
1531
1561
|
for (const x of [...parts, ...ordScalars].sort())
|
|
1532
1562
|
if (w[x] !== undefined)
|
|
1533
1563
|
diagram.parts[x] = elem.get(w[x]);
|
package/dist/kernel/kernel.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ export type Subst = {
|
|
|
54
54
|
maps: Record<string, (key: E) => E>;
|
|
55
55
|
flags: Record<string, C>;
|
|
56
56
|
};
|
|
57
|
+
export declare const own: <T>(r: Record<string, T>, k: string) => T | undefined;
|
|
57
58
|
export declare function substE(e: E, s: Subst): E;
|
|
58
59
|
export declare function substC(c: C, s: Subst): C;
|
|
59
60
|
export type Instances = Record<string, E[]>;
|
|
@@ -356,4 +357,5 @@ export declare const checkGhostedLaws: (g: Ghosted, laws: Law[], proof: {
|
|
|
356
357
|
instances: Record<string, Instances>;
|
|
357
358
|
trees: Record<string, Tree>;
|
|
358
359
|
}) => boolean;
|
|
360
|
+
export declare function someOfGhostsOk(g: Ghosted, law: Law, plain: Law, sub: Record<string, E>): boolean;
|
|
359
361
|
export {};
|
package/dist/kernel/kernel.js
CHANGED
|
@@ -244,7 +244,7 @@ export function termRows(name, path) {
|
|
|
244
244
|
// Every coefficient, product and partial sum a safe integer, else no product: a rounded product is past 2^53, but a
|
|
245
245
|
// monomial's other products could bring its sum back under it (and a square's form is the prover's, any float).
|
|
246
246
|
function times(a, b) {
|
|
247
|
-
const out =
|
|
247
|
+
const out = Object.create(null);
|
|
248
248
|
for (const [p, cp] of Object.entries(a))
|
|
249
249
|
for (const [q, cq] of Object.entries(b)) {
|
|
250
250
|
if (p.includes('⟦') || q.includes('⟦'))
|
|
@@ -504,7 +504,7 @@ function leafRows(goal, path, factsOf) {
|
|
|
504
504
|
}
|
|
505
505
|
const keyOf = (cell) => {
|
|
506
506
|
const inner = cell.slice(cell.indexOf('[') + 1, -1);
|
|
507
|
-
const out =
|
|
507
|
+
const out = Object.create(null);
|
|
508
508
|
// Keys are canonical texts `name:coef` joined by ',' at the outer level; a name may itself be a cell with brackets.
|
|
509
509
|
let depth = 0, start = 0;
|
|
510
510
|
const parts = [];
|
|
@@ -569,16 +569,20 @@ function natural(e) {
|
|
|
569
569
|
}
|
|
570
570
|
}
|
|
571
571
|
const naturalC = (c) => c.op === 'flag' ? true : c.op === 'all' ? naturalC(c.c) : c.op === 'not' ? naturalC(c.x) : c.op === 'and' || c.op === 'or' ? c.xs.every(naturalC) : natural(c.a) && natural(c.b);
|
|
572
|
+
// (a substitution's own entries only: a name like `constructor` or `toString` is no entry of {}; terra's review. Every
|
|
573
|
+
// record the kernel reads by a name of the rule or the certificate reads it so, and every Lin is built on no prototype,
|
|
574
|
+
// where a name __proto__ is a key like any other.)
|
|
575
|
+
export const own = (r, k) => (Object.hasOwn(r, k) ? r[k] : undefined);
|
|
572
576
|
export function substE(e, s) {
|
|
573
577
|
switch (e.op) {
|
|
574
|
-
case 'var': return s.vars
|
|
578
|
+
case 'var': return own(s.vars, e.name) ?? e;
|
|
575
579
|
case 'const': return e;
|
|
576
580
|
case 'mul': return { ...e, a: substE(e.a, s) };
|
|
577
581
|
case 'prod': return { ...e, a: substE(e.a, s), b: substE(e.b, s) };
|
|
578
582
|
case 'if': return { op: 'if', c: substC(e.c, s), then: substE(e.then, s), else: substE(e.else, s) };
|
|
579
583
|
case 'get': {
|
|
580
|
-
const key = substE(e.key, s);
|
|
581
|
-
return
|
|
584
|
+
const key = substE(e.key, s), f = own(s.maps, e.map);
|
|
585
|
+
return f ? f(key) : { op: 'get', map: e.map, key };
|
|
582
586
|
}
|
|
583
587
|
case 'add':
|
|
584
588
|
case 'sub':
|
|
@@ -589,7 +593,7 @@ export function substE(e, s) {
|
|
|
589
593
|
}
|
|
590
594
|
export function substC(c, s) {
|
|
591
595
|
if (c.op === 'flag') {
|
|
592
|
-
const f = s.flags
|
|
596
|
+
const f = own(s.flags, c.name);
|
|
593
597
|
if (!f)
|
|
594
598
|
throw new Error(`unknown flag ${c.name}`);
|
|
595
599
|
return f;
|
|
@@ -623,7 +627,7 @@ const reading = (r, vars, maps = {}) => ({ hyps: r.hyps, at: { ...r.at, vars: {
|
|
|
623
627
|
// One step: each name the update sets is its term read where the run is; a map read after it is the written value at
|
|
624
628
|
// the written key, and what the map held before elsewhere (or, written at every key, its value at the key read).
|
|
625
629
|
const step = (r, u) => {
|
|
626
|
-
const at = r.at, before = (map, key) => (at.maps
|
|
630
|
+
const at = r.at, before = (map, key) => { const f = own(at.maps, map); return f ? f(key) : { op: 'get', map, key }; };
|
|
627
631
|
return { hyps: r.hyps, at: {
|
|
628
632
|
vars: { ...at.vars, ...Object.fromEntries(Object.entries(u.vars).map(([n, e]) => [n, substE(e, at)])) },
|
|
629
633
|
maps: { ...at.maps, ...Object.fromEntries(Object.entries(u.maps).map(([map, w]) => [map, 'each' in w
|
|
@@ -636,7 +640,7 @@ const step = (r, u) => {
|
|
|
636
640
|
// so a run of k steps is k small frames rather than a term nesting each state in the next (which grows as 3^k when a
|
|
637
641
|
// step reads its state thrice). The names are new to the goal; each equation holds of the run that took the steps.
|
|
638
642
|
const nameState = (r, state, j) => ({
|
|
639
|
-
hyps: [...r.hyps, ...state.map(n => ({ op: '=', a: { op: 'var', name: stateName(n, j) }, b: r.at.vars
|
|
643
|
+
hyps: [...r.hyps, ...state.map(n => ({ op: '=', a: { op: 'var', name: stateName(n, j) }, b: own(r.at.vars, n) ?? { op: 'var', name: n } }))],
|
|
640
644
|
at: { ...r.at, vars: { ...r.at.vars, ...Object.fromEntries(state.map(n => [n, { op: 'var', name: stateName(n, j) }])) } },
|
|
641
645
|
});
|
|
642
646
|
export const stateName = (n, j) => `${n}~${j}`;
|
|
@@ -645,8 +649,8 @@ const atEnd = (r, c) => substC(c, r.at);
|
|
|
645
649
|
// The conclusion read across the run: plain names at the first frame, primed names (s', and M'[k] as a read of the map
|
|
646
650
|
// named M') at the last; the first step's inputs as it read them, and its flags, decided where it was taken.
|
|
647
651
|
const across = (r, c, state, maps, first) => substC(c, {
|
|
648
|
-
vars: { ...first.inputs, ...Object.fromEntries(state.map(n => [`${n}'`, r.at.vars
|
|
649
|
-
maps: Object.fromEntries(maps.map(map => [`${map}'`, (key) => (r.at.maps
|
|
652
|
+
vars: { ...first.inputs, ...Object.fromEntries(state.map(n => [`${n}'`, own(r.at.vars, n) ?? { op: 'var', name: n }])) },
|
|
653
|
+
maps: Object.fromEntries(maps.map(map => [`${map}'`, (key) => { const f = own(r.at.maps, map); return f ? f(key) : { op: 'get', map, key }; }])),
|
|
650
654
|
flags: first.flags,
|
|
651
655
|
});
|
|
652
656
|
const goal = (name, r, conclusion) => ({ name, hyps: [...r.hyps, { op: 'not', x: conclusion }] });
|
|
@@ -654,7 +658,7 @@ const goal = (name, r, conclusion) => ({ name, hyps: [...r.hyps, { op: 'not', x:
|
|
|
654
658
|
// condition (through the flags before it), a quantified flag (one whose condition holds at every key) its 0/1 variable
|
|
655
659
|
// ?f, which `closing` ties to the condition.
|
|
656
660
|
const flagsOf = (m) => {
|
|
657
|
-
const out =
|
|
661
|
+
const out = Object.create(null);
|
|
658
662
|
for (const [f, c] of Object.entries(m.step.flags ?? {}))
|
|
659
663
|
out[f] = c.op === 'all' ? { op: '=', a: { op: 'var', name: `?${f}` }, b: { op: 'const', value: 1 } } : substC(c, { vars: {}, maps: {}, flags: out });
|
|
660
664
|
return out;
|
|
@@ -710,7 +714,7 @@ const laterNames = (m, j) => ({
|
|
|
710
714
|
});
|
|
711
715
|
// The laws assumed where the run is: each plain law, and each every-key law at the keys the proof names.
|
|
712
716
|
export const assumed = (laws, instances) => laws.flatMap(l => {
|
|
713
|
-
const keys = instances
|
|
717
|
+
const keys = own(instances, l.name) ?? [];
|
|
714
718
|
if (l.keys?.length) {
|
|
715
719
|
const names = [l.forall, ...l.keys], n = names.length;
|
|
716
720
|
return Array.from({ length: Math.floor(keys.length / n) }, (_, t) => substC(l.holds, { vars: Object.fromEntries(names.map((name, i) => [name, keys[t * n + i]])), maps: {}, flags: {} }));
|
|
@@ -1109,7 +1113,7 @@ export function sumCovers(m) {
|
|
|
1109
1113
|
return Object.fromEntries(Object.entries(m.sums ?? {}).map(([s, sum]) => {
|
|
1110
1114
|
const out = new Map();
|
|
1111
1115
|
for (const map of [...new Set([...JSON.stringify(sum.term).matchAll(/"op":"get","map":"([^"]+)"/g)].map(x2 => x2[1]))]) {
|
|
1112
|
-
const w = m.step.maps
|
|
1116
|
+
const w = own(m.step.maps ?? {}, map);
|
|
1113
1117
|
if (!w)
|
|
1114
1118
|
continue;
|
|
1115
1119
|
if ('each' in w)
|
|
@@ -1138,21 +1142,21 @@ export function sumMachine(m, given, laws = []) {
|
|
|
1138
1142
|
const same = Object.fromEntries(Object.keys(flags).map(f => [f, { op: 'flag', name: f }]));
|
|
1139
1143
|
// (a sum may be declared in the state, at 0, which no step sets: a state variable the plain machine moves)
|
|
1140
1144
|
for (const [s] of sums)
|
|
1141
|
-
if (
|
|
1145
|
+
if (Object.hasOwn(m.state, s) && JSON.stringify(m.state[s]) !== JSON.stringify(ZERO) || Object.hasOwn(m.step.state ?? {}, s))
|
|
1142
1146
|
throw new Error(`${m.name}: the sum ${s} starts at 0 and no step sets it`);
|
|
1143
1147
|
// (every name the machine has, as the Lean twin numbers them: a flag f's variable ?f, a quantified flag's witnesses,
|
|
1144
1148
|
// the keys writes at every key and quantified flags bind)
|
|
1145
|
-
const names = [...m.params, ...m.inputs, ...Object.keys(m.state).filter(n => !(
|
|
1149
|
+
const names = [...m.params, ...m.inputs, ...Object.keys(m.state).filter(n => !Object.hasOwn(m.sums, n)), ...Object.keys(m.maps ?? {}), ...(m.inputMaps ?? []), ...Object.keys(m.fns ?? {}),
|
|
1146
1150
|
...Object.keys(flags), ...Object.keys(flags).map(f => `?${f}`), ...Object.entries(flags).flatMap(([f, c]) => (c.op === 'all' ? [...witnessesOf(f, c), ...boundOf(c)] : [])),
|
|
1147
1151
|
...Object.values(m.step.maps ?? {}).flatMap(w => ('each' in w ? [w.each] : []))];
|
|
1148
|
-
const steps =
|
|
1152
|
+
const steps = Object.create(null), qflags = Object.create(null), facts = [], goals = [];
|
|
1149
1153
|
for (const [s, sum] of sums) {
|
|
1150
|
-
const { term, key } = sum, { flag, x } = sumParts(s), cs = covers
|
|
1154
|
+
const { term, key } = sum, { flag, x } = sumParts(s), cs = own(covers, s);
|
|
1151
1155
|
const read = [...new Set([...JSON.stringify(term).matchAll(/"op":"get","map":"([^"]+)"/g)].map(x2 => x2[1]))];
|
|
1152
1156
|
const bad = (why) => { throw new Error(`${m.name}: the sum ${s}: ${why}`); };
|
|
1153
1157
|
for (const name of [s, key, flag, x]) {
|
|
1154
1158
|
plainName(m.name, name);
|
|
1155
|
-
if (names.includes(name) ||
|
|
1159
|
+
if (names.includes(name) || Object.hasOwn(m.sums ?? {}, name) && name !== s)
|
|
1156
1160
|
bad(`${name} is already a name of the machine`);
|
|
1157
1161
|
}
|
|
1158
1162
|
if (new Set([s, key, flag, x, `?${flag}`, `w?${flag}`]).size !== 6 || names.includes(`?${flag}`) || names.includes(`w?${flag}`))
|
|
@@ -1160,7 +1164,7 @@ export function sumMachine(m, given, laws = []) {
|
|
|
1160
1164
|
if (!natural(term) || !sumTermOk(term, key))
|
|
1161
1165
|
bad(`its term reads the maps at ${key} alone, and no other name`);
|
|
1162
1166
|
for (const map of read) {
|
|
1163
|
-
if ((m.inputMaps ?? []).includes(map) || (m.fns ?? {})
|
|
1167
|
+
if ((m.inputMaps ?? []).includes(map) || Object.hasOwn(m.fns ?? {}, map) || !Object.hasOwn(m.maps ?? {}, map))
|
|
1164
1168
|
bad(`${map} is not a map of the machine's state`);
|
|
1165
1169
|
}
|
|
1166
1170
|
// 0 where every map holds its start value (Sums.lean's startVal: the term with each read its map's start).
|
|
@@ -1172,14 +1176,14 @@ export function sumMachine(m, given, laws = []) {
|
|
|
1172
1176
|
bad('a key a step writes it at reads a flag');
|
|
1173
1177
|
// (Sums.lean's sumOk1: a map the term reads written at one key has that key among the cover keys)
|
|
1174
1178
|
for (const map of read) {
|
|
1175
|
-
const w = m.step.maps
|
|
1179
|
+
const w = own(m.step.maps ?? {}, map);
|
|
1176
1180
|
if (w && !('each' in w) && !cs.some(c => JSON.stringify(c) === JSON.stringify(w.key)))
|
|
1177
1181
|
bad(`the key ${map} is written at is no cover key`);
|
|
1178
1182
|
}
|
|
1179
1183
|
const here = (t) => substE(term, { vars: { [key]: t }, maps: {}, flags: same });
|
|
1180
1184
|
// A map read after the step, over the step's view (Sums.lean's postRd).
|
|
1181
1185
|
const post = (map) => (k2) => {
|
|
1182
|
-
const w = m.step.maps
|
|
1186
|
+
const w = own(m.step.maps ?? {}, map);
|
|
1183
1187
|
if (!w)
|
|
1184
1188
|
return { op: 'get', map, key: k2 };
|
|
1185
1189
|
if ('each' in w)
|
|
@@ -1250,14 +1254,15 @@ export function obligations(m, laws, instances = {}, only) {
|
|
|
1250
1254
|
return [];
|
|
1251
1255
|
// At the start: the precondition, and no request. One step: from a state where the laws hold, a request allowed.
|
|
1252
1256
|
// The facts hold throughout, read where the run begins (they read no state).
|
|
1253
|
-
const
|
|
1254
|
-
const
|
|
1257
|
+
const inst = own(instances, law.name) ?? {};
|
|
1258
|
+
const start = given(m, holds(from(startOf(m)), pre), inst);
|
|
1259
|
+
const turn = step(holds(given(m, from(), inst), [...pre, ...assume, ...assumed(laws, inst), ...closing(m, inst)]), u);
|
|
1255
1260
|
return [goal(`${law.name} @start`, start, atEnd(start, proven(law))), goal(`${law.name} @step`, turn, atEnd(turn, proven(law)))];
|
|
1256
1261
|
});
|
|
1257
1262
|
}
|
|
1258
1263
|
// The whole set at once: every goal has a tree, and every tree checks.
|
|
1259
1264
|
export function checkLaws(m, laws, proof) {
|
|
1260
|
-
return obligations(m, laws, proof.instances).every(g => proof.trees
|
|
1265
|
+
return obligations(m, laws, proof.instances).every(g => { const t = own(proof.trees, g.name); return t !== undefined && check(g, t); });
|
|
1261
1266
|
}
|
|
1262
1267
|
// A loop is a machine: its state, a turn's inputs as a request, its body taken where `while` holds and the state kept
|
|
1263
1268
|
// where it fails. Its invariants are the machine's laws, and that it halts is a liveness: from anywhere, `while` fails
|
|
@@ -1279,7 +1284,7 @@ export function loopObligations(l, laws, rank) {
|
|
|
1279
1284
|
const names = [...l.params, ...l.inputs, ...Object.keys(l.state)];
|
|
1280
1285
|
distinct(l.name, names);
|
|
1281
1286
|
for (const name of Object.keys(l.body))
|
|
1282
|
-
if (!(
|
|
1287
|
+
if (!Object.hasOwn(l.state, name))
|
|
1283
1288
|
throw new Error(`${l.name}'s body sets ${name}, which isn't in its state`);
|
|
1284
1289
|
inScope(`${l.name}'s start`, Object.values(l.state), l.params);
|
|
1285
1290
|
inScope(l.name, [...Object.values(l.body), ...(l.assume ? [l.assume] : [])], names);
|
|
@@ -1303,7 +1308,7 @@ export function recurGoal(l, r) {
|
|
|
1303
1308
|
// Lean's evalE and evalC over naturals with every map cell 0 (NonTerm.lean's noMaps): exact, never rounded.
|
|
1304
1309
|
const natE = (e, env) => {
|
|
1305
1310
|
switch (e.op) {
|
|
1306
|
-
case 'var': return env
|
|
1311
|
+
case 'var': return own(env, e.name) ?? 0n;
|
|
1307
1312
|
case 'const': return BigInt(e.value);
|
|
1308
1313
|
case 'add': return natE(e.a, env) + natE(e.b, env);
|
|
1309
1314
|
case 'sub': {
|
|
@@ -1347,7 +1352,7 @@ function stemOk(l, r) {
|
|
|
1347
1352
|
const names = [...l.params, ...l.inputs, ...Object.keys(l.state)], values = (o) => Object.values(o).every(x => Number.isSafeInteger(x) && x >= 0);
|
|
1348
1353
|
distinct(l.name, names);
|
|
1349
1354
|
for (const name of Object.keys(l.body))
|
|
1350
|
-
if (!(
|
|
1355
|
+
if (!Object.hasOwn(l.state, name))
|
|
1351
1356
|
throw new Error(`${l.name}'s body sets ${name}, which isn't in its state`);
|
|
1352
1357
|
inScope(`${l.name}'s start`, Object.values(l.state), l.params);
|
|
1353
1358
|
inScope(l.name, [...Object.values(l.body), ...(l.assume ? [l.assume] : [])], names);
|
|
@@ -1360,13 +1365,13 @@ function stemOk(l, r) {
|
|
|
1360
1365
|
throw new Error(`${l.name}: a start names params and a stem's turn inputs, each a natural`);
|
|
1361
1366
|
if (!Object.keys(r.wit).every(n => l.inputs.includes(n)))
|
|
1362
1367
|
return false;
|
|
1363
|
-
let env = Object.fromEntries(names.map(n => [n, BigInt(r.start
|
|
1368
|
+
let env = Object.fromEntries(names.map(n => [n, BigInt(own(r.start, n) ?? 0)]));
|
|
1364
1369
|
if (!natC(l.pre ?? trueC, env))
|
|
1365
1370
|
return false;
|
|
1366
1371
|
const apply = (body, at) => ({ ...at, ...Object.fromEntries(Object.entries(body).map(([n, e]) => [n, natE(e, at)])) });
|
|
1367
1372
|
env = apply(l.state, env);
|
|
1368
1373
|
for (const turn of r.stem) {
|
|
1369
|
-
const at = { ...env, ...Object.fromEntries(l.inputs.map(n => [n, BigInt(turn
|
|
1374
|
+
const at = { ...env, ...Object.fromEntries(l.inputs.map(n => [n, BigInt(own(turn, n) ?? 0)])) };
|
|
1370
1375
|
if (!natC(l.while, at) || !natC(l.assume ?? trueC, at))
|
|
1371
1376
|
return false;
|
|
1372
1377
|
env = apply(l.body, at);
|
|
@@ -1462,7 +1467,7 @@ const substituter = (vars) => {
|
|
|
1462
1467
|
let o;
|
|
1463
1468
|
switch (e.op) {
|
|
1464
1469
|
case 'var':
|
|
1465
|
-
o = vars
|
|
1470
|
+
o = own(vars, e.name) ?? e;
|
|
1466
1471
|
break;
|
|
1467
1472
|
case 'const':
|
|
1468
1473
|
o = e;
|
|
@@ -1540,7 +1545,7 @@ export function checkRecurCases(l, r) {
|
|
|
1540
1545
|
export function progressObligations(m0, laws, instances, p) {
|
|
1541
1546
|
const m = plainOf(m0), own = m0.sums && Object.keys(m0.sums).length ? m0.assume : m.assume;
|
|
1542
1547
|
scope(m, laws); // (as obligations scopes it: a param ?f would be read as the flag f's variable here too)
|
|
1543
|
-
if (!m.inputs.every(i =>
|
|
1548
|
+
if (!m.inputs.every(i => Object.hasOwn(p.request, i)) || !Object.values(p.request).every(natural) || mentions(p.when, m.inputs))
|
|
1544
1549
|
throw new Error('outside the kernel');
|
|
1545
1550
|
for (const e of Object.values(p.request))
|
|
1546
1551
|
if (mentions({ op: '=', a: e, b: e }, m.inputs))
|
|
@@ -1671,10 +1676,10 @@ export function stepLawObligations(machine, laws, instances, sl) {
|
|
|
1671
1676
|
const lawsOnly = (inst) => Object.fromEntries(Object.entries(inst).filter(([n]) => !n.startsWith('?')));
|
|
1672
1677
|
export function checkStepLaws(m, laws, stepLaws, proof) {
|
|
1673
1678
|
return checkLaws(m, laws, proof.laws) && stepLaws.every(sl => {
|
|
1674
|
-
const inst = proof.perStep
|
|
1679
|
+
const inst = own(proof.perStep ?? {}, sl.name) ?? proof.instances, plain = plainOf(m);
|
|
1675
1680
|
const zone = stepZone(plain, sl.steps ?? 1);
|
|
1676
1681
|
return [...assumed(laws, inst), ...assumed(plain.facts ?? [], inst), ...closing(plain, lawsOnly(inst))].every(c => !mentions(c, zone))
|
|
1677
|
-
&& stepLawObligations(m, laws, inst, sl).every(g => proof.trees
|
|
1682
|
+
&& stepLawObligations(m, laws, inst, sl).every(g => { const t = own(proof.trees, g.name); return t !== undefined && check(g, t); });
|
|
1678
1683
|
});
|
|
1679
1684
|
}
|
|
1680
1685
|
// The names a k-step law's run introduces past its first frame: each later step's inputs, quantified flags and their
|
|
@@ -1712,8 +1717,9 @@ export const kInductionStart = (machine, kl, instances) => {
|
|
|
1712
1717
|
export function checkKInduction(m, laws, kl, proof) {
|
|
1713
1718
|
const steps = kInductionSteps(m, kl), plain = plainOf(m);
|
|
1714
1719
|
scope(plain, [...laws, kl.law]);
|
|
1715
|
-
const start = kInductionStart(m, kl, proof.perStep
|
|
1716
|
-
|
|
1720
|
+
const start = kInductionStart(m, kl, own(proof.perStep ?? {}, `${kl.law.name} @start`) ?? proof.instances);
|
|
1721
|
+
const t = own(proof.trees, start.name);
|
|
1722
|
+
return t !== undefined && check(start, t) && checkStepLaws(m, laws, steps, proof);
|
|
1717
1723
|
}
|
|
1718
1724
|
export function foldObligations(f, laws) {
|
|
1719
1725
|
if (![...Object.values(f.leaf), ...Object.values(f.node)].every(natural) || !laws.every(law => !law.forall && !law.keys?.length && naturalC(law.holds) && !mentions(law.holds, f.inputs)))
|
|
@@ -1765,7 +1771,7 @@ export const qdif = (a, b) => radd(rscale(b.den, a.row), rscale(-a.den, b.row));
|
|
|
1765
1771
|
// A row as a Lin, its coefficients safe integers (else undefined: a row past 2^53 is not read, so the check is weaker,
|
|
1766
1772
|
// never wrong); and its key, as `canon` writes a Lin (zero coefficients dropped: Lean's `same` compares by value).
|
|
1767
1773
|
export const qLin = (r) => {
|
|
1768
|
-
const out =
|
|
1774
|
+
const out = Object.create(null);
|
|
1769
1775
|
for (const [x, c] of r.cs) {
|
|
1770
1776
|
if (c < -(2n ** 53n) + 1n || c > 2n ** 53n - 1n)
|
|
1771
1777
|
return undefined;
|
|
@@ -1968,7 +1974,7 @@ export function checkQMachine(m, laws, trees) {
|
|
|
1968
1974
|
if (m.pre && qOccurs(m.pre, assigned))
|
|
1969
1975
|
return false;
|
|
1970
1976
|
return laws.every(law => {
|
|
1971
|
-
const t = trees
|
|
1977
|
+
const t = own(trees, law.name), goals = qObligations(m, laws, law);
|
|
1972
1978
|
return !!t && !qOccurs(law.holds, m.inputs) && checkQTree(goals.start, t.start) && checkQTree(goals.step, t.step);
|
|
1973
1979
|
});
|
|
1974
1980
|
}
|
|
@@ -2173,8 +2179,9 @@ export function countedObligations(m, laws, instances = {}, only) {
|
|
|
2173
2179
|
return laws.flatMap((law, i) => {
|
|
2174
2180
|
if (only !== undefined && i !== only)
|
|
2175
2181
|
return [];
|
|
2176
|
-
const
|
|
2177
|
-
const
|
|
2182
|
+
const inst = own(instances, law.name) ?? {};
|
|
2183
|
+
const start = given(m, holds(from(startOf(m)), pre), inst);
|
|
2184
|
+
const turn = step(holds(given(m, from(), inst), [...pre, ...assume, ...assumed(laws, inst), ...closing(m, inst)]), u);
|
|
2178
2185
|
return [{ goal: goal(`${law.name} @start`, start, atEnd(start, proven(law))), decls: after(start.at) },
|
|
2179
2186
|
{ goal: goal(`${law.name} @step`, turn, atEnd(turn, proven(law))), decls: [...all, ...after(turn.at)] }];
|
|
2180
2187
|
});
|
|
@@ -2191,7 +2198,7 @@ function witsOk(m, laws, k) {
|
|
|
2191
2198
|
}
|
|
2192
2199
|
// Lean's checkCMachine: every goal has a certificate, its witnesses fresh, and every certificate checks.
|
|
2193
2200
|
export function checkCountedLaws(m, laws, proof) {
|
|
2194
|
-
return countedObligations(m, laws, proof.instances).every(({ goal: g, decls }) => { const k = proof.certs
|
|
2201
|
+
return countedObligations(m, laws, proof.instances).every(({ goal: g, decls }) => { const k = own(proof.certs, g.name); return k !== undefined && witsOk(m, laws, k) && checkMC(g.hyps, decls, k); });
|
|
2195
2202
|
}
|
|
2196
2203
|
// SGhostedM.full: the original with each ghost's start and step after its own (Lean: lists appended; here records, whose
|
|
2197
2204
|
// names smghostOk keeps apart from the original's).
|
|
@@ -2225,3 +2232,23 @@ export function ghostedOk(g) {
|
|
|
2225
2232
|
// The laws of a ghosted machine, checked: the ghosts as smghostOk says, and the laws of the ghosted machine as checkLaws
|
|
2226
2233
|
// says (Lean: smghostOk and checkSMachine of SGhostedM.full).
|
|
2227
2234
|
export const checkGhostedLaws = (g, laws, proof) => ghostedOk(g) && checkLaws(ghostedMachine(g), laws, proof);
|
|
2235
|
+
// GhostMap.lean's forall_some_of_ghostsubst, the ∃ reading: a law with "there exists" (`some`, its body c) holds of the
|
|
2236
|
+
// original (Lean's ExHolds: for every value of its keys, some natural for each bound name where c holds) where the
|
|
2237
|
+
// ghosted machine's law `plain` is c with each bound name x replaced by a term sub[x] (Lean's substC σ c: a term over
|
|
2238
|
+
// anything of the ghosted machine, a ghost map at a key, several, the law's keys). The caller has the plain law proven
|
|
2239
|
+
// of ghostedMachine(g) (checkLaws). What Lean takes: the ghosts smghostOk's (ghostedOk); the plain law exactly c with sub
|
|
2240
|
+
// in place, about the law's keys (e.law.key, e.keys2); c reading no ghost variable and no ghost map (avoids, avoidsMaps);
|
|
2241
|
+
// the bound names sub's (σ's names). And where the law's reading and Lean's statement would part: c in Lean's terms (no
|
|
2242
|
+
// quantified condition, no flag), each bound name once, none a key of the law (ExHolds writes the bound names over the
|
|
2243
|
+
// keys' values) nor a name of the original or of a ghost.
|
|
2244
|
+
export function someOfGhostsOk(g, law, plain, sub) {
|
|
2245
|
+
const xs = law.some ?? [], keys = [...(law.forall ? [law.forall] : []), ...(law.keys ?? [])], o = g.orig, r = reads(law.holds), text = JSON.stringify(law.holds);
|
|
2246
|
+
const vs = Object.keys(g.vars), ms = Object.keys(g.maps);
|
|
2247
|
+
const names = [...o.params, ...o.inputs, ...Object.keys(o.state), ...Object.keys(o.maps ?? {}), ...(o.inputMaps ?? []), ...Object.keys(o.fns ?? {}), ...vs, ...ms];
|
|
2248
|
+
return ghostedOk(g) && xs.length > 0 && new Set(xs).size === xs.length && Object.keys(sub).length === xs.length && xs.every(x => Object.hasOwn(sub, x))
|
|
2249
|
+
&& !text.includes('"op":"all"') && !text.includes('"op":"flag"') && !plain.some?.length
|
|
2250
|
+
&& plain.forall === law.forall && JSON.stringify(plain.keys ?? []) === JSON.stringify(law.keys ?? [])
|
|
2251
|
+
&& JSON.stringify(plain.holds) === JSON.stringify(substC(law.holds, { vars: Object.assign(Object.create(null), sub), maps: {}, flags: {} }))
|
|
2252
|
+
&& vs.every(v => !r.vars.has(v)) && ms.every(mp => !r.maps.has(mp))
|
|
2253
|
+
&& xs.every(x => !keys.includes(x) && !names.includes(x));
|
|
2254
|
+
}
|
package/dist/kernel/prove.d.ts
CHANGED
|
@@ -82,6 +82,28 @@ export declare const eprScope: {
|
|
|
82
82
|
patterns?: Patterns;
|
|
83
83
|
busy?: boolean;
|
|
84
84
|
};
|
|
85
|
+
export declare const wideScope: {
|
|
86
|
+
judge?: (w: Record<string, number>) => boolean;
|
|
87
|
+
};
|
|
88
|
+
export declare const wideStats: {
|
|
89
|
+
goals: number;
|
|
90
|
+
trees: number;
|
|
91
|
+
models: number;
|
|
92
|
+
rounds: number;
|
|
93
|
+
};
|
|
94
|
+
export declare const wideHook: {
|
|
95
|
+
on?: (part: Goal, out: Outcome) => void;
|
|
96
|
+
};
|
|
97
|
+
export declare const brokenOf: (goal: Goal) => ((w: Record<string, number>, ids?: number[], first?: boolean) => number[]);
|
|
98
|
+
export declare const wideFor: (goal: Goal) => boolean;
|
|
99
|
+
export declare function growWide(goal: Goal, budget: {
|
|
100
|
+
nodes: number;
|
|
101
|
+
until?: number;
|
|
102
|
+
}, ask?: (g: Goal, until: number) => Outcome & {
|
|
103
|
+
core?: number[];
|
|
104
|
+
}): (Outcome & {
|
|
105
|
+
core?: number[];
|
|
106
|
+
}) | undefined;
|
|
85
107
|
export declare const realModels: {
|
|
86
108
|
on: boolean;
|
|
87
109
|
};
|