gdp-wired 0.49.0 → 0.50.1
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 +4 -0
- package/dist/core/candidate-seeds.d.ts +25 -0
- package/dist/core/candidate-seeds.js +90 -0
- package/dist/core/chart.js +28 -4
- package/dist/core/cli.js +3 -0
- package/dist/core/compose.js +4 -3
- package/dist/core/count-support.d.ts +1 -0
- package/dist/core/count-support.js +23 -2
- package/dist/core/counted-candidate-seeds.d.ts +12 -0
- package/dist/core/counted-candidate-seeds.js +31 -0
- package/dist/core/counts.js +9 -2
- package/dist/core/dsl-binders.d.ts +15 -0
- package/dist/core/dsl-binders.js +129 -0
- package/dist/core/dsl.d.ts +28 -2
- package/dist/core/dsl.js +147 -52
- package/dist/core/exists.js +2 -1
- package/dist/core/field-laws.js +23 -5
- package/dist/core/infer.js +10 -5
- package/dist/core/laws.js +2 -1
- package/dist/core/lift-cli.d.ts +11 -0
- package/dist/core/lift-cli.js +113 -0
- package/dist/core/proof-output.d.ts +53 -0
- package/dist/core/proof-output.js +38 -0
- package/dist/core/quorum-laws.js +55 -16
- package/dist/kernel/function-instances.d.ts +45 -0
- package/dist/kernel/function-instances.js +460 -0
- package/dist/kernel/prove.d.ts +12 -3
- package/dist/kernel/prove.js +164 -90
- package/dist/lean-kernel/axiom-audit.d.ts +11 -0
- package/dist/lean-kernel/axiom-audit.js +50 -0
- package/dist/lean-kernel/emit.d.ts +25 -2
- package/dist/lean-kernel/emit.js +75 -10
- package/dist/lean-kernel/legacy-family-order.d.ts +1 -0
- package/dist/lean-kernel/legacy-family-order.js +26 -0
- package/dist/lean-kernel/library.js +22 -0
- package/dist/lean-kernel/lift/counted-source-data.d.ts +7 -0
- package/dist/lean-kernel/lift/counted-source-data.js +78 -0
- package/dist/lean-kernel/lift/index.d.ts +82 -0
- package/dist/lean-kernel/lift/index.js +116 -0
- package/dist/lean-kernel/lift/project.d.ts +4 -0
- package/dist/lean-kernel/lift/project.js +15 -0
- package/dist/lean-kernel/lift/proof-capture.d.ts +104 -0
- package/dist/lean-kernel/lift/proof-capture.js +216 -0
- package/dist/lean-kernel/lift/proof-codec.d.ts +28 -0
- package/dist/lean-kernel/lift/proof-codec.js +299 -0
- package/dist/lean-kernel/lift/proof-counted-source.d.ts +16 -0
- package/dist/lean-kernel/lift/proof-counted-source.js +68 -0
- package/dist/lean-kernel/lift/proof-frontier.d.ts +19 -0
- package/dist/lean-kernel/lift/proof-frontier.js +153 -0
- package/dist/lean-kernel/lift/proof-graph.d.ts +17 -0
- package/dist/lean-kernel/lift/proof-graph.js +130 -0
- package/dist/lean-kernel/lift/proof-parts.d.ts +29 -0
- package/dist/lean-kernel/lift/proof-parts.js +131 -0
- package/dist/lean-kernel/lift/proof-prelude.d.ts +2 -0
- package/dist/lean-kernel/lift/proof-prelude.js +38 -0
- package/dist/lean-kernel/lift/proof-witness.d.ts +30 -0
- package/dist/lean-kernel/lift/proof-witness.js +283 -0
- package/dist/lean-kernel/lift/shape.d.ts +5 -0
- package/dist/lean-kernel/lift/shape.js +57 -0
- package/dist/lean-kernel/lift/source-projection.d.ts +16 -0
- package/dist/lean-kernel/lift/source-projection.js +81 -0
- package/dist/lean-kernel/lift/source.d.ts +23 -0
- package/dist/lean-kernel/lift/source.js +111 -0
- package/dist/lean-kernel/lift/witness-alpha.d.ts +9 -0
- package/dist/lean-kernel/lift/witness-alpha.js +31 -0
- package/dist/lean-kernel/lift-legacy.d.ts +58 -0
- package/dist/lean-kernel/lift-legacy.js +84 -0
- package/dist/lean-kernel/lift-names.d.ts +22 -0
- package/dist/lean-kernel/lift-names.js +36 -0
- package/dist/lean-kernel/lift-simulation/index.d.ts +29 -0
- package/dist/lean-kernel/lift-simulation/index.js +352 -0
- package/dist/lean-kernel/lift-simulation/shape.d.ts +41 -0
- package/dist/lean-kernel/lift-simulation/shape.js +173 -0
- package/dist/lean-kernel/lift-special/index.d.ts +36 -0
- package/dist/lean-kernel/lift-special/index.js +241 -0
- package/dist/lean-kernel/lift-special/structural.d.ts +25 -0
- package/dist/lean-kernel/lift-special/structural.js +126 -0
- package/dist/lean-kernel/lift-typed/index.d.ts +35 -0
- package/dist/lean-kernel/lift-typed/index.js +256 -0
- package/dist/lean-kernel/lift-typed/roles.d.ts +17 -0
- package/dist/lean-kernel/lift-typed/roles.js +170 -0
- package/dist/lean-kernel/lift-typed/shape.d.ts +1 -0
- package/dist/lean-kernel/lift-typed/shape.js +12 -0
- package/dist/lean-kernel/lift.d.ts +30 -0
- package/dist/lean-kernel/lift.js +97 -0
- package/package.json +8 -2
package/dist/core/dsl.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { retainFrom, retainCounted, publishProof, withPublicRule } from "./proof-output.js";
|
|
1
2
|
import { searchNow as countedSearchNow } from "./wall.js";
|
|
2
3
|
// Typed builders for machines, decisions and loops: names are declared once and come back as typed values, so a
|
|
3
4
|
// misspelled name, a law that reads a request, or a step that sets an undeclared variable is a TypeScript error, and
|
|
@@ -16,14 +17,17 @@ import { searchNow as countedSearchNow } from "./wall.js";
|
|
|
16
17
|
//
|
|
17
18
|
// A step returns its updates as one object: every right-hand side reads the state before the step, as the kernel and
|
|
18
19
|
// both runtimes do.
|
|
20
|
+
import { binder, copyVariable, encodeBinders, generatedVariable, guardReserved, internalName, plainDeclaration, variable } from "./dsl-binders.js";
|
|
19
21
|
import { candidates, cone, searchCounted } from "./counts.js";
|
|
22
|
+
import { proveCandidateSeeds } from "./candidate-seeds.js";
|
|
23
|
+
import { proveCountedCandidateSeeds } from "./counted-candidate-seeds.js";
|
|
20
24
|
import { inheritSource, translationVerdict } from "./source-check.js";
|
|
21
25
|
import { env as knobs } from "./solver.js";
|
|
22
26
|
import { argsKey, bindDirect, directOf, machineTerms, part, tuple, carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, fnCall, hasFinite, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, seeded, sourceFreeFn, withArithmetic } from "./machine.js";
|
|
23
27
|
import { allowed, keysOf, requestEnv, watch, watchWork } from "./watch.js";
|
|
24
28
|
import { ghostOf, proveSome, skolemOf, someHolds, substVars, substVarsE, witnessSupport } from "./exists.js";
|
|
25
29
|
import { check, mapArities, checkRecur, foldObligations, ghostedMachine, loopObligations, someOfGhostsOk, substC, sumMachine } from "../kernel/kernel.js";
|
|
26
|
-
import { certLoop, clock, counted, factsFor, fullRate, grow, pastWall, proveLaw, proveLaws, proveLiveness, proveSetFast, proveStepLaws, usualProof, withWall } from "../kernel/prove.js";
|
|
30
|
+
import { certLoop, clock, counted, factsFor, fullRate, grow, pastWall, proveLaw, proveLaws, proveLiveness, proveSetFast, proveStepLaws, usualProof, withModelRounds, withWall } from "../kernel/prove.js";
|
|
27
31
|
import { WallExpired, checkWall, checkWorkEndpoint, searchWall, withBudget, BudgetExpired } from "./wall.js";
|
|
28
32
|
import { completeWorkProfile } from "./work-profile.js";
|
|
29
33
|
import { workLedger } from "./work-admission.js";
|
|
@@ -221,7 +225,7 @@ export class Kind {
|
|
|
221
225
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
222
226
|
from(init) { return { kind: this, init }; }
|
|
223
227
|
}
|
|
224
|
-
const v = (name) => new Term(
|
|
228
|
+
const v = (name) => new Term(variable(name), scope?.vars[name]);
|
|
225
229
|
let scope;
|
|
226
230
|
const inScope = (s, f) => { const outer = scope; scope = s; try {
|
|
227
231
|
return f();
|
|
@@ -874,7 +878,7 @@ let boundCounter = 0;
|
|
|
874
878
|
// on its own, and compared with another only plainly (i < j, i <= j, i = j); the runtimes decide it on every tuple of
|
|
875
879
|
// a few keys per breakpoint, so it costs the square of the cells (the cube, over three keys).
|
|
876
880
|
export const everyKey = (f) => {
|
|
877
|
-
const names = Array.from({ length: Math.max(1, f.length) }, () =>
|
|
881
|
+
const names = Array.from({ length: Math.max(1, f.length) }, () => binder('k', ++boundCounter)), g = f;
|
|
878
882
|
const ok = (picked) => (picked.length === names.length ? g(...picked).ok : everyOk(scope?.keys, k => ok([...picked, keyTerm(k)])));
|
|
879
883
|
return new Cond({ op: 'all', key: names[0], ...(names.length > 1 ? { keys: names.slice(1) } : {}), c: g(...names.map(v)).c }, ok([]));
|
|
880
884
|
};
|
|
@@ -883,13 +887,13 @@ export const desc = (t) => ({ desc: t });
|
|
|
883
887
|
// Some key where f holds, in a law or a step law's conclusion (¬∀k. ¬f(k)): proven through a witness, a term naming the
|
|
884
888
|
// key, given here or found by the prover among a few candidates (kernel/prove.ts).
|
|
885
889
|
export const someKey = (f, witness) => {
|
|
886
|
-
const key =
|
|
890
|
+
const key = binder('s', ++boundCounter);
|
|
887
891
|
const none = everyOk(scope?.keys, k => f(keyTerm(k)).not().ok);
|
|
888
892
|
return new Cond({ op: 'not', x: { op: 'all', key, c: f(v(key)).not().c, ...(witness === undefined ? {} : { witness: termOf(witness) }) } }, none === undefined ? undefined : !none);
|
|
889
893
|
};
|
|
890
894
|
export function exists(a, b, c) {
|
|
891
895
|
const [kind, f, w] = (a instanceof Kind ? [a, b, c] : [nat, a, b]);
|
|
892
|
-
const name =
|
|
896
|
+
const name = binder('some', ++boundCounter), value = kind.value(name), body = all(...kind.assume(name), f(value));
|
|
893
897
|
const store = (x) => Object.fromEntries(Object.entries(kind.store(name, x)).map(([n, t]) => [n, termOf(t)]));
|
|
894
898
|
const ghost = typeof w === 'object' && w !== null && 'step' in w && 'start' in w && typeof w.step === 'function';
|
|
895
899
|
const given = w === undefined ? {} : ghost
|
|
@@ -908,7 +912,7 @@ function pulledOut(cs, what, prefix) {
|
|
|
908
912
|
bs.forEach((b, i) => b.vars.forEach(n => { ren[n] = { op: 'var', name: n.endsWith('$neg') ? `${prefix}${i}$neg` : `${prefix}${i}` }; }));
|
|
909
913
|
const r = (c) => (prefix === undefined ? c : substVars(c, ren));
|
|
910
914
|
const vars = bs.flatMap(b => b.vars.map(n => (prefix === undefined ? n : ren[n].name)));
|
|
911
|
-
const out = cs.map(c => r(c.c)), stray = out.flatMap(c => namesIn(c)).filter(n => n.startsWith('some
|
|
915
|
+
const out = cs.map(c => r(c.c)), stray = out.flatMap(c => namesIn(c)).filter(n => n.startsWith('?some') && !vars.includes(n) && !/^some\$[ap]\d/.test(n));
|
|
912
916
|
if (stray.length)
|
|
913
917
|
throw new Error(`${what}: ${stray[0]} is bound by an exists(...) whose condition was taken apart; keep it whole (and, or, not, implies)`);
|
|
914
918
|
return { cs: out, vars, bodies: bs.map(b => ({ vars: b.vars.map(n => (prefix === undefined ? n : ren[n].name)), body: r(b.body) })) };
|
|
@@ -924,12 +928,17 @@ export const declaredSum = (name) => sumDecls.get(name);
|
|
|
924
928
|
const fnv = (text) => { let h = 0x811c9dc5; for (let i = 0; i < text.length; i++)
|
|
925
929
|
h = Math.imul(h ^ text.charCodeAt(i), 0x01000193) >>> 0; return h.toString(36); };
|
|
926
930
|
function sumOver(map, at, plain) {
|
|
927
|
-
const
|
|
928
|
-
const
|
|
931
|
+
const placeholder = internalName('?sumKey', 'k$sum$');
|
|
932
|
+
const probe = termOf(at(v(placeholder)));
|
|
933
|
+
// Hash the old spelling, never the private token; the actual substitution
|
|
934
|
+
// still distinguishes a same-spelled free user parameter.
|
|
935
|
+
const legacyProbe = substVarsE(probe, { [placeholder]: { op: 'var', name: 'k$sum$' } });
|
|
936
|
+
const id = plain ? `sum$${map}` : `sum$${map}$${fnv(JSON.stringify(legacyProbe))}`, key = `${id}$k`;
|
|
937
|
+
const term = substVarsE(probe, { [placeholder]: generatedVariable(key) }), had = sumDecls.get(id);
|
|
929
938
|
if (had && JSON.stringify(had.term) !== JSON.stringify(term))
|
|
930
939
|
throw new Error(`${id}: two sums by one name`);
|
|
931
940
|
sumDecls.set(id, { key, term });
|
|
932
|
-
return
|
|
941
|
+
return new Term(generatedVariable(id), scope?.vars[id]);
|
|
933
942
|
}
|
|
934
943
|
// The sums a set of terms reads (by name), declared.
|
|
935
944
|
export const sumsIn = (ts, more = []) => {
|
|
@@ -955,7 +964,7 @@ export class MapRef {
|
|
|
955
964
|
// key's cell plus `by` where `c` holds (the counter every cap keeps).
|
|
956
965
|
bump(key, c = yes, by = 1) { return this.set(key, when(c, this.at(key).plus(by), this.at(key))); }
|
|
957
966
|
// Every key at once: the value at each key, the key read only as a map's key (Other.at(k)).
|
|
958
|
-
each(f) { const each =
|
|
967
|
+
each(f) { const each = binder('k', ++boundCounter); return { map: this.name, each, value: termOf(f(v(each))), concrete: { at: f } }; }
|
|
959
968
|
// As a set (cells 0 or 1): a member, and, as whole flags, every member of this one in another, none shared, the same.
|
|
960
969
|
has(key) { return this.at(key).atLeast(1); }
|
|
961
970
|
subsetOf(other) { return everyKey(k => this.at(k).atMost(other.at(k))); }
|
|
@@ -990,7 +999,7 @@ export class RelRef {
|
|
|
990
999
|
has(...xs) { return this.at(...xs).atLeast(1); }
|
|
991
1000
|
// The relation after the step: each tuple in it where f holds (its parts as f reads them).
|
|
992
1001
|
each(f) {
|
|
993
|
-
const each =
|
|
1002
|
+
const each = binder('k', ++boundCounter), n = this.sorts.length, k = v(each);
|
|
994
1003
|
const parts = n === 1 ? [k] : Array.from({ length: n }, (_, i) => new Term(part(k.e, i, n)));
|
|
995
1004
|
return { map: this.name, each, value: when(f(...parts), 1, 0).e };
|
|
996
1005
|
}
|
|
@@ -1020,7 +1029,7 @@ export class ListRef {
|
|
|
1020
1029
|
removeAt(i, when = yes) { return { when, at: k => when_(k.lt(i), this.at(k), this.at(k.plus(1))), len: this.len.minus(1) }; }
|
|
1021
1030
|
// The updates for the step: the first operation whose condition holds, else the list as it was.
|
|
1022
1031
|
apply(...ops) {
|
|
1023
|
-
const each =
|
|
1032
|
+
const each = binder('k', ++boundCounter);
|
|
1024
1033
|
const at = (k) => ops.reduceRight((acc, op) => when_(op.when, op.at(k), acc), this.at(k));
|
|
1025
1034
|
const len = ops.reduceRight((acc, op) => when_(op.when, op.len, acc), this.len);
|
|
1026
1035
|
return { [this.name]: { map: this.name, each, value: at(v(each)).e, concrete: { at } }, [`${this.name}_len`]: len };
|
|
@@ -1074,7 +1083,7 @@ export function sizedSort(name, size) {
|
|
|
1074
1083
|
throw new Error('a sized sort needs a name');
|
|
1075
1084
|
const below = termOf(size);
|
|
1076
1085
|
const every = (f) => {
|
|
1077
|
-
const key =
|
|
1086
|
+
const key = binder('k', ++boundCounter);
|
|
1078
1087
|
const body = f(v(key));
|
|
1079
1088
|
if (body.ex?.length || hasAll(body.c))
|
|
1080
1089
|
throw new Error('a finite sort body must be unquantified in this slice');
|
|
@@ -1364,7 +1373,7 @@ const termAt = (t) => (t instanceof Term ? t : lit(t));
|
|
|
1364
1373
|
// With two parameters or more, about every two keys or more: forall((i, j) => i.lt(j).implies(...)).
|
|
1365
1374
|
export function forall(f) { return { forall: f }; }
|
|
1366
1375
|
// The keys a law's callback names: one, or two when it takes two.
|
|
1367
|
-
const keysFor = (out) => [
|
|
1376
|
+
const keysFor = (out) => [binder('key', ++keyCounter), Array.from({ length: Math.max(0, out.forall.length - 1) }, () => binder('key', ++keyCounter))];
|
|
1368
1377
|
// For histories: `holds` (a <= b, homogeneous over sums and queries) wherever `when` (params and plain inputs) holds.
|
|
1369
1378
|
export const relation = (holds, whenever = yes) => ({ when: whenever, holds });
|
|
1370
1379
|
// --- quantifiers anywhere ---------------------------------------------------------------------------------------------
|
|
@@ -1514,25 +1523,50 @@ export function nameQuantifiers(m) {
|
|
|
1514
1523
|
// is two keys at once. A quantifier under a not is some key (someKey), left for the prover's witness.
|
|
1515
1524
|
const hasForall = (c, positive = true) => c.op === 'all' ? positive || hasForall(c.c, positive) : c.op === 'not' ? hasForall(c.x, !positive) : c.op === 'and' || c.op === 'or' ? c.xs.some(y => hasForall(y, positive)) : false;
|
|
1516
1525
|
const hasAll = (c) => JSON.stringify(c).includes('"op":"all"');
|
|
1517
|
-
|
|
1526
|
+
export class QuantifierAdmissionError extends Error {
|
|
1527
|
+
code;
|
|
1528
|
+
kind = 'quantifier-admission';
|
|
1529
|
+
constructor(code, reason) {
|
|
1530
|
+
super(reason);
|
|
1531
|
+
this.code = code;
|
|
1532
|
+
this.name = 'QuantifierAdmissionError';
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
function freeKey(value, name) {
|
|
1536
|
+
if (!value || typeof value !== 'object')
|
|
1537
|
+
return false;
|
|
1538
|
+
if (Array.isArray(value))
|
|
1539
|
+
return value.some(v => freeKey(v, name));
|
|
1540
|
+
const node = value;
|
|
1541
|
+
if (node.op === 'var')
|
|
1542
|
+
return node.name === name;
|
|
1543
|
+
if (node.op === 'all' && [node.key, ...(Array.isArray(node.keys) ? node.keys : [])].includes(name))
|
|
1544
|
+
return false;
|
|
1545
|
+
return Object.values(node).some(v => freeKey(v, name));
|
|
1546
|
+
}
|
|
1547
|
+
function prenex(c, what, key, alreadyBound = false) {
|
|
1518
1548
|
if (hasFinite(c) && (what.startsWith('step law') || (c.op !== 'all' && hasForall(c))))
|
|
1519
1549
|
throw new Error(`${what}: a finite universal is one whole law in this slice (not nested or a step law)`);
|
|
1550
|
+
if (!alreadyBound && hasForall(c) && freeKey(c, key))
|
|
1551
|
+
throw new QuantifierAdmissionError('binder-capture', `${what}: generated law key ${key} would capture a free variable; rename it`);
|
|
1520
1552
|
let found = false;
|
|
1521
|
-
const walk = (d, positive) => {
|
|
1553
|
+
const walk = (d, positive, insideUniversal) => {
|
|
1522
1554
|
switch (d.op) {
|
|
1523
1555
|
case 'all':
|
|
1524
1556
|
if (d.keys?.length)
|
|
1525
1557
|
throw new Error(`${what}: a condition at every two keys in a law is the law's own keys (forall((i, j) => ...))`);
|
|
1526
1558
|
if (!positive)
|
|
1527
1559
|
return d;
|
|
1560
|
+
if (insideUniversal)
|
|
1561
|
+
throw new QuantifierAdmissionError('nested-universal', `${what}: nested universal keys are two keys at once; name them together with forall((i, j) => ...), not nested everyKey calls`);
|
|
1528
1562
|
found = true;
|
|
1529
|
-
return walk(substKey(d.c, d.key, key), positive);
|
|
1530
|
-
case 'not': return { op: 'not', x: walk(d.x, !positive) };
|
|
1563
|
+
return walk(substKey(d.c, d.key, key), positive, true);
|
|
1564
|
+
case 'not': return { op: 'not', x: walk(d.x, !positive, insideUniversal) };
|
|
1531
1565
|
case 'and':
|
|
1532
1566
|
case 'or': {
|
|
1533
1567
|
if ((d.op === 'or') === positive && d.xs.some(y => hasForall(y, positive)) && d.xs.filter(y => hasForall(y, positive) || namesIn(y).includes(key)).length > 1)
|
|
1534
1568
|
throw new Error(`${what}: a condition at every key in an or beside another part that reads a key is two keys at once`);
|
|
1535
|
-
return { op: d.op, xs: d.xs.map(y => walk(y, positive)) };
|
|
1569
|
+
return { op: d.op, xs: d.xs.map(y => walk(y, positive, insideUniversal)) };
|
|
1536
1570
|
}
|
|
1537
1571
|
case 'flag': return d;
|
|
1538
1572
|
case '<':
|
|
@@ -1543,10 +1577,33 @@ function prenex(c, what, key) {
|
|
|
1543
1577
|
return d;
|
|
1544
1578
|
}
|
|
1545
1579
|
};
|
|
1546
|
-
const out = walk(c, true);
|
|
1580
|
+
const out = walk(c, true, alreadyBound);
|
|
1547
1581
|
return found ? out : undefined;
|
|
1548
1582
|
}
|
|
1549
|
-
const substKey = (c, from, to) =>
|
|
1583
|
+
const substKey = (c, from, to) => {
|
|
1584
|
+
const walk = (value) => {
|
|
1585
|
+
if (!value || typeof value !== 'object')
|
|
1586
|
+
return value;
|
|
1587
|
+
if (Array.isArray(value))
|
|
1588
|
+
return value.map(walk);
|
|
1589
|
+
const node = value;
|
|
1590
|
+
if (node.op === 'all') {
|
|
1591
|
+
const bound = [node.key, ...(Array.isArray(node.keys) ? node.keys : [])];
|
|
1592
|
+
if (bound.includes(from))
|
|
1593
|
+
return value; // An inner binder shadows this occurrence.
|
|
1594
|
+
if (bound.includes(to) && freeKey(node.c, from))
|
|
1595
|
+
throw new QuantifierAdmissionError('binder-capture', `renaming ${from} to ${to} would capture an inner binder; use forall((i, j) => ...)`);
|
|
1596
|
+
}
|
|
1597
|
+
if (node.op === 'var') {
|
|
1598
|
+
if (node.name !== from)
|
|
1599
|
+
return node;
|
|
1600
|
+
guardReserved(node); // A user-written reserved name must not be laundered by substitution.
|
|
1601
|
+
return variable(to);
|
|
1602
|
+
}
|
|
1603
|
+
return Object.fromEntries(Object.entries(node).map(([k, v]) => [k, walk(v)]));
|
|
1604
|
+
};
|
|
1605
|
+
return walk(c);
|
|
1606
|
+
};
|
|
1550
1607
|
// The definitions actually flattened into a rule may have changed since recur captured its inlined helpers.
|
|
1551
1608
|
const sourceFreeDef = (d) => sourceFreeFn(d) && Object.values(d.uses ?? {}).every(sourceFreeDef);
|
|
1552
1609
|
export const fn = (arity, js, opts = {}) => {
|
|
@@ -1815,10 +1872,10 @@ const skolemsOf = new WeakMap();
|
|
|
1815
1872
|
const withSource = (x, src) => (sources.set(x, src), x);
|
|
1816
1873
|
// A k-step law's later requests are built over marked names (j:name, which no rule can declare: ':' is reserved); the
|
|
1817
1874
|
// kernel reads them as name@j.
|
|
1818
|
-
const markedName = (name) => { const m =
|
|
1875
|
+
const markedName = (name) => { const m = /^\?step(\d+):(.*)$/.exec(name); return m ? `${m[2]}@${m[1]}` : name; };
|
|
1819
1876
|
const markedE = (e) => {
|
|
1820
1877
|
switch (e.op) {
|
|
1821
|
-
case 'var': return { op: 'var', name: markedName(e.name) };
|
|
1878
|
+
case 'var': return copyVariable(e, { op: 'var', name: markedName(e.name) });
|
|
1822
1879
|
case 'const': return e;
|
|
1823
1880
|
case 'mul': return { ...e, a: markedE(e.a) };
|
|
1824
1881
|
case 'if': return { op: 'if', c: marked(e.c), then: markedE(e.then), else: markedE(e.else) };
|
|
@@ -1832,7 +1889,7 @@ const markedE = (e) => {
|
|
|
1832
1889
|
case 'proj': return { ...e, a: markedE(e.a) };
|
|
1833
1890
|
}
|
|
1834
1891
|
};
|
|
1835
|
-
const marked = (c) => c.op === 'flag' ? c : c.op === 'all' ? { ...c, c: marked(c.c) } : c.op === 'not' ? { op: 'not', x: marked(c.x) } : c.op === 'and' || c.op === 'or' ? { op: c.op, xs: c.xs.map(marked) } : { ...c, a: markedE(c.a), b: markedE(c.b) };
|
|
1892
|
+
const marked = (c) => c.op === 'flag' ? c : c.op === 'all' ? { ...c, c: marked(c.c), ...(c.witness ? { witness: markedE(c.witness) } : {}) } : c.op === 'not' ? { op: 'not', x: marked(c.x) } : c.op === 'and' || c.op === 'or' ? { op: c.op, xs: c.xs.map(marked) } : { ...c, a: markedE(c.a), b: markedE(c.b) };
|
|
1836
1893
|
// P params, I inputs, S state, M maps, F flags, R a history's record, Su its sums, Q its queries: each a record of the
|
|
1837
1894
|
// values the builders hand out, grown by each call.
|
|
1838
1895
|
export class Rule {
|
|
@@ -2059,7 +2116,7 @@ export class Rule {
|
|
|
2059
2116
|
// A law about the params, the state, the maps and the sums (not a request): `forall` for every key of a map.
|
|
2060
2117
|
law(name, f) { return withSource(this.lawOf(name, f(this.env({ flags: false, inputs: false, queries: false }))), { law: f }); }
|
|
2061
2118
|
lawOf(name, out) {
|
|
2062
|
-
const key =
|
|
2119
|
+
const key = binder('key', ++keyCounter);
|
|
2063
2120
|
if (out instanceof Cond) {
|
|
2064
2121
|
const p = prenex(out.c, `law ${name}`, key);
|
|
2065
2122
|
return this.divides(this.someOf(name, out, p ? { name, forall: key, holds: p, ...(out.c.op === 'all' && out.c.finite !== undefined ? { finite: out.c.finite } : {}) } : { name, holds: out.c }));
|
|
@@ -2067,7 +2124,7 @@ export class Rule {
|
|
|
2067
2124
|
const [k1, more] = keysFor(out), inner = out.forall(v(k1), ...more.map(v)), holds = inner.c;
|
|
2068
2125
|
if (hasFinite(holds))
|
|
2069
2126
|
throw new Error(`law ${name}: a finite universal is one whole law, not inside forall`);
|
|
2070
|
-
return this.divides(this.someOf(name, inner, more.length ? { name, forall: k1, keys: more, holds } : { name, forall: k1, holds: prenex(holds, `law ${name}`, k1) ?? holds }));
|
|
2127
|
+
return this.divides(this.someOf(name, inner, more.length ? { name, forall: k1, keys: more, holds } : { name, forall: k1, holds: prenex(holds, `law ${name}`, k1, true) ?? holds }));
|
|
2071
2128
|
}
|
|
2072
2129
|
// A law's existentials (exists), pulled out before it: `some` its naturals, `witness` the ones given (a ghost's step
|
|
2073
2130
|
// read with the step's own values).
|
|
@@ -2082,7 +2139,7 @@ export class Rule {
|
|
|
2082
2139
|
if (b.start && b.step) {
|
|
2083
2140
|
const st = b.step(env);
|
|
2084
2141
|
for (const n of b.vars)
|
|
2085
|
-
ghost[n] = { start: b.start[n] ?? { op: 'const', value: 0 }, step: st[n] ??
|
|
2142
|
+
ghost[n] = { start: b.start[n] ?? { op: 'const', value: 0 }, step: st[n] ?? variable(n) };
|
|
2086
2143
|
}
|
|
2087
2144
|
const witness = { ...(Object.keys(terms).length ? { terms } : {}), ...(Object.keys(ghost).length ? { ghost } : {}) };
|
|
2088
2145
|
return { ...law, some: vars, ...(Object.keys(witness).length ? { witness } : {}) };
|
|
@@ -2091,7 +2148,8 @@ export class Rule {
|
|
|
2091
2148
|
divides(x) {
|
|
2092
2149
|
if (this.spec.arith)
|
|
2093
2150
|
divisorsIn([x], this.spec.arith);
|
|
2094
|
-
|
|
2151
|
+
const names = this.names().map(([n]) => n);
|
|
2152
|
+
return encodeBinders(x, names, 'then' in x ? names.map(n => `${n}'`) : []);
|
|
2095
2153
|
}
|
|
2096
2154
|
// The same rule declaring every sum over a map's keys these read (laws, step laws, a liveness, a decision's goal), as
|
|
2097
2155
|
// each prover entry takes it; this rule itself unchanged. The rule where they read none it doesn't already declare.
|
|
@@ -2137,13 +2195,13 @@ export class Rule {
|
|
|
2137
2195
|
const env = this.env();
|
|
2138
2196
|
const after = this.afterEnv();
|
|
2139
2197
|
const out = then(env, after), w = when ? { when: when(env).c } : {};
|
|
2140
|
-
const key =
|
|
2198
|
+
const key = binder('key', ++keyCounter), src = { step: { then: then, ...(when ? { when: when } : {}) } };
|
|
2141
2199
|
if (out instanceof Cond) {
|
|
2142
2200
|
const p = prenex(out.c, `step law ${name}`, key);
|
|
2143
2201
|
return withSource(this.divides(p ? { name, forall: key, then: p, ...w } : { name, then: out.c, ...w }), src);
|
|
2144
2202
|
}
|
|
2145
2203
|
const [k1, more] = keysFor(out), c = out.forall(v(k1), ...more.map(v)).c;
|
|
2146
|
-
return withSource(this.divides(more.length ? { name, forall: k1, keys: more, then: c, ...w } : { name, forall: k1, then: prenex(c, `step law ${name}`, k1) ?? c, ...w }), src);
|
|
2204
|
+
return withSource(this.divides(more.length ? { name, forall: k1, keys: more, then: c, ...w } : { name, forall: k1, then: prenex(c, `step law ${name}`, k1, true) ?? c, ...w }), src);
|
|
2147
2205
|
}
|
|
2148
2206
|
// A law about k steps in a row (k from 2 to 64): `then(first, last, requests)` relates what the first step reads to the
|
|
2149
2207
|
// state, maps and sums after the last, with each step's request and queries (requests[0] is the first's); `when(before,
|
|
@@ -2153,7 +2211,7 @@ export class Rule {
|
|
|
2153
2211
|
const env = this.env();
|
|
2154
2212
|
const after = this.afterEnv();
|
|
2155
2213
|
// The j-th request's values over marked names, renamed to the kernel's input@j once built.
|
|
2156
|
-
const mark = (j) =>
|
|
2214
|
+
const mark = (j) => `?step${j}:`;
|
|
2157
2215
|
const requests = Array.from({ length: k }, (_, j) => {
|
|
2158
2216
|
if (j === 0)
|
|
2159
2217
|
return Object.fromEntries([...this.spec.inputs.map(([n]) => n), ...this.spec.queries.map(([n]) => n)].map(n => [n, env[n]]));
|
|
@@ -2164,13 +2222,18 @@ export class Rule {
|
|
|
2164
2222
|
while (whens.length && whens.at(-1) === undefined)
|
|
2165
2223
|
whens.pop();
|
|
2166
2224
|
const w = whens.length ? { when: whens.map(c => (c ?? lit(0).atMost(0)).c) } : {};
|
|
2167
|
-
const key =
|
|
2225
|
+
const key = binder('key', ++keyCounter);
|
|
2226
|
+
const allowedMarks = [...this.names().map(([n]) => `${n}'`), ...namesIn(requests)];
|
|
2227
|
+
const markLaw = (c, keys = []) => {
|
|
2228
|
+
guardReserved({ ...(keys.length ? { forall: keys[0], keys: keys.slice(1) } : {}), then: c }, allowedMarks);
|
|
2229
|
+
return marked(c);
|
|
2230
|
+
};
|
|
2168
2231
|
if (out instanceof Cond) {
|
|
2169
2232
|
const p = prenex(out.c, `step law ${name}`, key);
|
|
2170
|
-
return this.divides(p ? { name, steps: k, forall: key, then:
|
|
2233
|
+
return this.divides(p ? { name, steps: k, forall: key, then: markLaw(p, [key]), ...w } : { name, steps: k, then: markLaw(out.c), ...w });
|
|
2171
2234
|
}
|
|
2172
2235
|
const [k1, more] = keysFor(out), c = out.forall(v(k1), ...more.map(v)).c;
|
|
2173
|
-
return this.divides(more.length ? { name, steps: k, forall: k1, keys: more, then:
|
|
2236
|
+
return this.divides(more.length ? { name, steps: k, forall: k1, keys: more, then: markLaw(c, [k1, ...more]), ...w } : { name, steps: k, forall: k1, then: markLaw(prenex(c, `step law ${name}`, k1, true) ?? c, [k1]), ...w });
|
|
2174
2237
|
}
|
|
2175
2238
|
// "Whenever `from` holds, `to` holds later", in every run that takes each helpful request infinitely often: proven by
|
|
2176
2239
|
// a rank (a natural over the state and params, or several compared in order) that no step raises while `from` holds
|
|
@@ -2194,7 +2257,7 @@ export class Rule {
|
|
|
2194
2257
|
leadsTo(name, spec) {
|
|
2195
2258
|
const env = this.env({ flags: false, inputs: false, queries: false });
|
|
2196
2259
|
const fs = [spec.from, spec.to, spec.rank, ...(typeof spec.helpful === 'function' ? [spec.helpful] : spec.helpful.flatMap(h => [h.when, h.request]))];
|
|
2197
|
-
const forall = fs.some(f => f && f.length > 1) ?
|
|
2260
|
+
const forall = fs.some(f => f && f.length > 1) ? binder('key', ++keyCounter) : undefined, key = (forall ? v(forall) : undefined);
|
|
2198
2261
|
const req = (f) => Object.fromEntries(Object.entries(f(env, key)).map(([n, t]) => [n, termOf(t)]));
|
|
2199
2262
|
const r = spec.rank ? spec.rank(env, key) : [], rank = Array.isArray(r) ? r.map(termOf) : termOf(r);
|
|
2200
2263
|
const base = { name, from: spec.from(env, key).c, to: spec.to(env, key).c, rank, ...(spec.fairness === 'strong' ? { fairness: 'strong' } : {}), ...(spec.levels ? { levels: spec.levels } : {}), ...(forall ? { forall } : {}) };
|
|
@@ -2360,6 +2423,7 @@ export class Rule {
|
|
|
2360
2423
|
distinct() {
|
|
2361
2424
|
const seen = new Map();
|
|
2362
2425
|
for (const [n, what] of this.names()) {
|
|
2426
|
+
plainDeclaration(this.spec.name, n);
|
|
2363
2427
|
const had = seen.get(n);
|
|
2364
2428
|
if (had)
|
|
2365
2429
|
throw new Error(`${this.spec.name}: ${n} is ${had} and ${had === what ? 'declared again' : what}; give each a name of its own`);
|
|
@@ -2429,7 +2493,7 @@ export class Rule {
|
|
|
2429
2493
|
// The least keys: inputs the runtimes find, assumed least.
|
|
2430
2494
|
const leasts = {}, leastAssume = [];
|
|
2431
2495
|
for (const [n, f] of s.leasts ?? []) {
|
|
2432
|
-
const d = f(env), key =
|
|
2496
|
+
const d = f(env), key = binder('k', ++boundCounter), best = env[n];
|
|
2433
2497
|
const parts = (k) => d.by(k).map(b => (typeof b === 'object' && !(b instanceof Term) && !(b instanceof Int) && 'desc' in b ? { t: Int.of(b.desc), desc: true } : { t: Int.of(b), desc: false }));
|
|
2434
2498
|
const zero = (e) => e.op === 'const' && e.value === 0;
|
|
2435
2499
|
leasts[n] = { some: `${n}$some`, key, where: d.where(v(key)).c, by: parts(v(key)).map(b => ({ e: b.t.pos.e, ...(zero(b.t.neg.e) ? {} : { neg: b.t.neg.e }), ...(b.desc ? { desc: true } : {}) })) };
|
|
@@ -2485,7 +2549,8 @@ export class Rule {
|
|
|
2485
2549
|
// (each sum a state variable from 0 the step never sets: sumMachine sets it, exact)
|
|
2486
2550
|
const sums = sumsIn(machineTerms(m), s.sumsRead ?? []);
|
|
2487
2551
|
const out = withArithmetic(sums ? { ...m, state: { ...m.state, ...Object.fromEntries(Object.keys(sums).map(n => [n, { op: 'const', value: 0 }])) }, sums } : m, [], s.arith ?? []);
|
|
2488
|
-
|
|
2552
|
+
const encoded = encodeBinders(out, this.names().map(([n]) => n));
|
|
2553
|
+
return s.ghost ? s.ghost(encoded) : encoded;
|
|
2489
2554
|
}
|
|
2490
2555
|
// The same rule with ghosts its machine gains (the search's, over a law with "there exists" made plain: skolemOf).
|
|
2491
2556
|
withGhosts(ghost) { return this.with({ ghost }); }
|
|
@@ -3277,7 +3342,7 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
|
|
|
3277
3342
|
return undefined;
|
|
3278
3343
|
}
|
|
3279
3344
|
// The kernel's report as a verdict: its first goal left unproven, with its counterexample and why.
|
|
3280
|
-
export const verdictOf = (out) => ({ proven: out.proven, checked: out.checked, ...(out.failed ? { goal: out.failed.goal, stuck: out.failed.stuck, ...(out.failed.witness ? { witness: out.failed.witness } : {}), ...(out.failed.why ? { why: out.failed.why } : {}) } : {}) });
|
|
3345
|
+
export const verdictOf = (out) => retainFrom(({ proven: out.proven, checked: out.checked, ...(out.failed ? { goal: out.failed.goal, stuck: out.failed.stuck, ...(out.failed.witness ? { witness: out.failed.witness } : {}), ...(out.failed.why ? { why: out.failed.why } : {}) } : {}) }), [out]);
|
|
3281
3346
|
const refutedVerdict = (out) => ({ proven: false, checked: false, goal: out.goal, stuck: 'sat', witness: out.witness, ...(out.run ? { run: out.run } : {}) });
|
|
3282
3347
|
// The divisors some laws read (modBy, divBy), noted on the rule so its machine declares them: a law may come from
|
|
3283
3348
|
// another instance of the same rule (a factory called twice).
|
|
@@ -3320,8 +3385,11 @@ function workVerdict(opts, supported, run) {
|
|
|
3320
3385
|
}
|
|
3321
3386
|
}
|
|
3322
3387
|
export function proveRule(r, laws, opts = {}) {
|
|
3323
|
-
|
|
3324
|
-
|
|
3388
|
+
return withModelRounds(opts.modelRounds, () => withPublicRule(outermost => {
|
|
3389
|
+
const captureMachine = r.machine, hasCounts = !!Object.keys(captureMachine.counts ?? {}).length;
|
|
3390
|
+
const result = workVerdict(opts, hasCounts, plan => withPublicSearchPolicy(hasCounts, () => proveRuleWall(r, laws, plan)));
|
|
3391
|
+
return outermost ? publishProof(result, captureMachine, laws) : result;
|
|
3392
|
+
}));
|
|
3325
3393
|
}
|
|
3326
3394
|
function proveRuleWall(r, laws, opts) {
|
|
3327
3395
|
const ms = typeof opts.search === 'object' ? opts.search.ms : undefined;
|
|
@@ -3340,11 +3408,36 @@ function proveRuleWall(r, laws, opts) {
|
|
|
3340
3408
|
};
|
|
3341
3409
|
// One absolute wall for setup, sampling, generation and proof, not a fresh
|
|
3342
3410
|
// allowance for each phase. Nested callers can only shorten it.
|
|
3343
|
-
|
|
3411
|
+
const result = ms === undefined ? run() : withWall(searchWall(ms), run);
|
|
3412
|
+
return retainFrom(translationVerdict(r, laws, result), [result]);
|
|
3344
3413
|
}
|
|
3345
3414
|
function proveRuleIn(r, laws, opts) {
|
|
3346
|
-
r = r.withSumsOf(laws);
|
|
3415
|
+
r = r.withSumsOf(laws, opts.candidateSeeds?.laws ?? []);
|
|
3347
3416
|
noting(r, laws);
|
|
3417
|
+
if (opts.candidateSeeds) {
|
|
3418
|
+
if (opts.search === false || opts.from === 'any')
|
|
3419
|
+
throw Error('candidate seeds require reachable-state search');
|
|
3420
|
+
const machine = r.machine, extraCounts = opts.candidateSeeds.counts ?? {};
|
|
3421
|
+
if (opts.candidateSeeds.kind === 'counted' || Object.keys(machine.counts ?? {}).length || Object.keys(extraCounts).length) {
|
|
3422
|
+
const reserved = new Set([...Object.keys(machine.maps ?? {}), ...Object.keys(machine.counts ?? {}), ...Object.keys(machine.state), ...Object.keys(machine.fns ?? {}), ...(machine.inputMaps ?? []), ...machine.params, ...machine.inputs]);
|
|
3423
|
+
if (Object.keys(extraCounts).some(n => reserved.has(n)))
|
|
3424
|
+
throw Error('candidate count declaration must not override the source');
|
|
3425
|
+
const producer = { ...machine, counts: { ...machine.counts, ...extraCounts } };
|
|
3426
|
+
const seeded = proveCountedCandidateSeeds(producer, withKinds(r, laws), opts.candidateSeeds.laws, typeof opts.search === 'object' ? opts.search.ms ?? 60_000 : 60_000);
|
|
3427
|
+
opts.candidateSeeds.report?.({ status: seeded.status, kind: 'counted', kept: seeded.status === 'checked' ? seeded.kept.map(l => l.name) : [],
|
|
3428
|
+
dropped: seeded.status === 'checked' ? seeded.dropped.map(l => ({ name: l.name, reason: 'not retained by counted admission' })) : [],
|
|
3429
|
+
...(seeded.status === 'inconclusive' ? { reason: seeded.reason } : {}) });
|
|
3430
|
+
if (seeded.status === 'checked')
|
|
3431
|
+
return retainCounted({ proven: true, checked: true, found: { laws: seeded.closure.laws.map(l => ({ text: l.name })) } }, seeded.closure);
|
|
3432
|
+
}
|
|
3433
|
+
else {
|
|
3434
|
+
const seeded = proveCandidateSeeds(machine, withKinds(r, laws), opts.candidateSeeds.laws, opts.candidateSeeds.witnesses, opts.candidateSeeds.ghosts);
|
|
3435
|
+
opts.candidateSeeds.report?.({ status: seeded.status, kept: seeded.kept.map(l => l.name), dropped: seeded.dropped,
|
|
3436
|
+
...(seeded.status === 'inconclusive' ? { reason: seeded.reason } : {}) });
|
|
3437
|
+
if (seeded.status === 'checked')
|
|
3438
|
+
return retainFrom(verdictOf(seeded.closure), [seeded.closure], { kind: 'inference', original: machine, laws });
|
|
3439
|
+
}
|
|
3440
|
+
}
|
|
3348
3441
|
const refuted = refuteByRuns(r, laws);
|
|
3349
3442
|
checkWorkEndpoint('refutation result');
|
|
3350
3443
|
// A state the laws allow whose step breaks one, with no run to it (a wide rule's: what the kernel's step goal would end
|
|
@@ -3355,7 +3448,7 @@ function proveRuleIn(r, laws, opts) {
|
|
|
3355
3448
|
// A rule with counts: its goals are the counted ones (core/counts.ts searches them; the kernel checks the set).
|
|
3356
3449
|
if (r.machine.counts && Object.keys(r.machine.counts).length) {
|
|
3357
3450
|
const c = searchCounted(r.machine, withKinds(r, laws), typeof opts.search === 'object' ? opts.search.ms ?? 60_000 : 60_000);
|
|
3358
|
-
return { proven: c.proven, checked: c.proven, ...(c.why ? { why: c.why } : {}), found: { laws: c.laws.map(l => ({ text: l.name })) } };
|
|
3451
|
+
return retainCounted({ proven: c.proven, checked: c.proven, ...(c.why ? { why: c.why } : {}), found: { laws: c.laws.map(l => ({ text: l.name })) } }, c);
|
|
3359
3452
|
}
|
|
3360
3453
|
// (with a search budget, the laws as given within it on the wall: a step goal of hundreds of hypotheses has a second
|
|
3361
3454
|
// each by its own budget, so the search would never start)
|
|
@@ -3370,6 +3463,8 @@ function proveRuleIn(r, laws, opts) {
|
|
|
3370
3463
|
const out = ms === undefined ? given() : withStageWall(countedSearchNow() + ms / share, () => share === 1 ? given() : counted(inferRates.work, () => withStageDeadline(clock() + ms / share, given, () => undefined)), () => undefined);
|
|
3371
3464
|
const v = out ? { ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) }
|
|
3372
3465
|
: { proven: false, checked: false, stuck: 'unknown' };
|
|
3466
|
+
if (out)
|
|
3467
|
+
retainFrom(v, [out]);
|
|
3373
3468
|
return searched(r, laws, [], v, opts);
|
|
3374
3469
|
}
|
|
3375
3470
|
export function proveSteps(r, laws, stepLaws, opts = {}) {
|
|
@@ -3500,7 +3595,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3500
3595
|
if (lists.length || fns.some(([, d]) => recurOf(d))) {
|
|
3501
3596
|
const d = withStageDeadline(until, () => discover(r, laws, stepLaws, v), () => undefined);
|
|
3502
3597
|
if (d?.verdict.proven && d.verdict.checked)
|
|
3503
|
-
return { ...d.verdict, found: { lemmas: d.found } };
|
|
3598
|
+
return retainFrom({ ...d.verdict, found: { lemmas: d.found } }, [d.verdict]);
|
|
3504
3599
|
if (d && Object.keys(d.found).length)
|
|
3505
3600
|
(rule = d.rule, lemmas = d.found);
|
|
3506
3601
|
}
|
|
@@ -3524,7 +3619,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3524
3619
|
// (counted, as the laws' own search: the same verdict on any machine)
|
|
3525
3620
|
const given = [...withKinds(rule, laws), ...fresh.map(f => f.law)], out = counted(fullRate, () => withStageDeadline(clock() + share, () => (stepLaws.length ? proveStepLaws(fm, given, stepLaws) : proveLaws(fm, given)), () => undefined), true);
|
|
3526
3621
|
if (out?.proven && out.checked)
|
|
3527
|
-
return { proven: true, checked: true, found: { laws: fresh, ...(lemmas ? { lemmas } : {}) }, assumes: reachableBy(fresh) };
|
|
3622
|
+
return retainFrom({ proven: true, checked: true, found: { laws: fresh, ...(lemmas ? { lemmas } : {}) }, assumes: reachableBy(fresh) }, [out]);
|
|
3528
3623
|
}
|
|
3529
3624
|
}
|
|
3530
3625
|
let ms = until - clock() - tail;
|
|
@@ -3543,7 +3638,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3543
3638
|
console.error(`exists: cone failed: ${String(e.stack ?? e).slice(0, 600)}`);
|
|
3544
3639
|
}
|
|
3545
3640
|
if (c)
|
|
3546
|
-
return { ...c, found: { ...c.found, ...(lemmas ? { lemmas } : {}) } };
|
|
3641
|
+
return retainFrom({ ...c, found: { ...c.found, ...(lemmas ? { lemmas } : {}) } }, [c]);
|
|
3547
3642
|
if ((ms = until - clock() - tail) < 500)
|
|
3548
3643
|
return v;
|
|
3549
3644
|
}
|
|
@@ -3573,11 +3668,11 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3573
3668
|
console.error(`exists: back: plain ${plain ? `${plain.proven} ${plain.checked}` : 'none'}, machine ${sameMachine(over.machine, ghostedMachine(G))}`);
|
|
3574
3669
|
if (plain?.proven && plain.checked && sameMachine(over.machine, ghostedMachine(G))
|
|
3575
3670
|
&& laws.filter(l => l.some?.length).every(l => { const q = sk.plains[l.name]; return !!q && ls.includes(q.plain) && someOfGhostsOk(G, l, q.plain, q.sub); }))
|
|
3576
|
-
return { proven: true, checked: true, witnesses: sk.witnesses };
|
|
3671
|
+
return retainFrom({ proven: true, checked: true, witnesses: sk.witnesses }, [plain], { kind: 'skolem', original: G.orig, laws, G, plains: sk.plains, family: ls });
|
|
3577
3672
|
// (proveSome over the original: the found laws that read no ghost map)
|
|
3578
3673
|
const own = found.filter(f => Object.keys(sk.maps).every(mp => !JSON.stringify(f.law.holds).includes(`"map":${JSON.stringify(mp)}`)));
|
|
3579
3674
|
const out = proveSome(rule.machine, [...withKinds(rule, laws), ...fresh.map(f => f.law), ...own.map(f => f.law)], { mapMs: Math.max(5_000, (until - clock()) / 2) });
|
|
3580
|
-
return { ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) };
|
|
3675
|
+
return retainFrom({ ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) }, [out]);
|
|
3581
3676
|
};
|
|
3582
3677
|
// (the plain law's candidate supports, exists.ts's ghostSupports: Houdini within half of what is left, each with the
|
|
3583
3678
|
// rest assumed, the failing dropped, until none fails; then the set through `back`, the ∃ verdict as the search's)
|
|
@@ -3623,7 +3718,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3623
3718
|
console.error(`exists: ghost supports set: ${b.proven ? 'proven' : `${b.goal} ${b.stuck} ${b.why ?? ''}`}`);
|
|
3624
3719
|
if (b.proven && b.checked) {
|
|
3625
3720
|
const found = keep.map(law => ({ law, text: law.name }));
|
|
3626
|
-
return { ...b, proven: true, checked: true, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) };
|
|
3721
|
+
return retainFrom({ ...b, proven: true, checked: true, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) }, [b]);
|
|
3627
3722
|
}
|
|
3628
3723
|
break;
|
|
3629
3724
|
}
|
|
@@ -3642,7 +3737,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3642
3737
|
void _s2;
|
|
3643
3738
|
const b = back(summed, found);
|
|
3644
3739
|
if (!sk || (b.proven && b.checked))
|
|
3645
|
-
return { ...(sk ? {} : verdict), ...b, proven: true, checked: true, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) };
|
|
3740
|
+
return retainFrom({ ...(sk ? {} : verdict), ...b, proven: true, checked: true, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) }, sk ? [inf2, b] : [inf2]);
|
|
3646
3741
|
}
|
|
3647
3742
|
}
|
|
3648
3743
|
// (a step law's ghost: at most 10 s of it, as its goals cost more than the laws')
|
|
@@ -3656,7 +3751,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3656
3751
|
const b = back(target, found);
|
|
3657
3752
|
if (sk && !(b.proven && b.checked))
|
|
3658
3753
|
return { ...v, ...b, why: [v.why, 'the set found over the ghost maps is not proven with the laws as stated'].filter(Boolean).join('; ') };
|
|
3659
|
-
return { ...(sk ? { proven: true, checked: true } : verdict), ...b, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) };
|
|
3754
|
+
return retainFrom({ ...(sk ? { proven: true, checked: true } : verdict), ...b, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) }, sk ? [inf, b] : [inf]);
|
|
3660
3755
|
}
|
|
3661
3756
|
// A law with "there exists" about no key, which the join can't take as its goal: its witness core/exists.ts's ghostOf;
|
|
3662
3757
|
// then core/counts.ts's pipeline: the candidates, the engine's template two keys at the bound value's places, framed by
|
|
@@ -3695,7 +3790,7 @@ function someCone(r, laws0, ms) {
|
|
|
3695
3790
|
if (clock() > until)
|
|
3696
3791
|
return undefined;
|
|
3697
3792
|
const v = verdictOf(proveSome(m, [...laws, ...kept.filter(c => !laws.some(l => l.name === c.name))]));
|
|
3698
|
-
return v.proven && v.checked ? { ...v, found: { laws: kept.map(l => ({ law: l, text: l.name })) }, ...withAssumes(kept.map(l => ({ text: l.name }))) } : undefined;
|
|
3793
|
+
return v.proven && v.checked ? retainFrom({ ...v, found: { laws: kept.map(l => ({ law: l, text: l.name })) }, ...withAssumes(kept.map(l => ({ text: l.name }))) }, [v]) : undefined;
|
|
3699
3794
|
}
|
|
3700
3795
|
// What a verdict proven with these found laws rests on: the states reachable from init (each found law is proven so).
|
|
3701
3796
|
const reachableBy = (found) => ({ states: 'reachable', laws: found.map(f => f.text) });
|
package/dist/core/exists.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { retainFrom } from "./proof-output.js";
|
|
1
2
|
import { traceNow as countedTraceNow, BudgetExpired } from "./wall.js";
|
|
2
3
|
import { withReachabilityWork, reachState, reachEdge } from "./work-observe.js";
|
|
3
4
|
import { requestQuotient } from "./request-quotient.js";
|
|
@@ -1364,7 +1365,7 @@ export function proveSome(m, laws, opts = {}) {
|
|
|
1364
1365
|
}
|
|
1365
1366
|
for (let pass = 1;; pass++) {
|
|
1366
1367
|
const { machine, laws: plain, ghosts } = current(), t0 = countedTraceNow();
|
|
1367
|
-
const out = (opts.whole ?? proveLaws)(machine, plain), done = { ...out, laws: out.laws ?? plain, machine, ghosts, witnesses: Object.fromEntries([...plans.values()].map(p => [p.law.name, describe(p, cases)])) };
|
|
1368
|
+
const out = (opts.whole ?? proveLaws)(machine, plain), done = retainFrom({ ...out, laws: out.laws ?? plain, machine, ghosts, witnesses: Object.fromEntries([...plans.values()].map(p => [p.law.name, describe(p, cases)])) }, [out], { kind: 'witness', original: m, laws, machine, plain, ghosts, plans, cases });
|
|
1368
1369
|
if (log)
|
|
1369
1370
|
console.error(`exists: pass ${pass} the whole set: ${out.proven ? 'proven' : `${out.failed?.goal} ${out.failed?.stuck}`} (${Math.round(countedTraceNow() - t0)} ms)`);
|
|
1370
1371
|
const j = out.proven || !out.failed || pass > 8 ? undefined : [...plans.keys()].find(k => out.failed.goal.startsWith(`${laws[k].name} @`));
|
package/dist/core/field-laws.js
CHANGED
|
@@ -104,16 +104,23 @@ export function fieldLaws(m, composed = true, loaded = true) {
|
|
|
104
104
|
const old = rows.get(o.map);
|
|
105
105
|
rows.set(o.map, old === undefined || old === key.a.k ? key.a.k : 0);
|
|
106
106
|
});
|
|
107
|
+
// Zero is reserved for ambiguous packed strides; -1 denotes a native tuple.
|
|
108
|
+
for (const [map, sorts] of Object.entries(m.relations ?? {}))
|
|
109
|
+
if (sorts.length === 2 && sorts[0] === sorts[1])
|
|
110
|
+
rows.set(map, -1);
|
|
107
111
|
const agrees = [];
|
|
108
112
|
for (const [map, base] of rows)
|
|
109
113
|
if (base)
|
|
110
114
|
for (let i = 0; i < fs.length; i++)
|
|
111
115
|
for (let j = i + 1; j < fs.length; j++) {
|
|
112
|
-
const f = fs[i], g = fs[j], cell = (row) => get(map, plus(times(base, row), c));
|
|
116
|
+
const f = fs[i], g = fs[j], cell = (row) => get(map, base === -1 ? tuple([row, c]) : plus(times(base, row), c));
|
|
113
117
|
const guard = all(da, db, less(c, bound), same(get(f, a), get(f, b)), same(get(g, a), get(g, b)));
|
|
114
118
|
const law = { name: `fields: ${f}[a]=${f}[b] and ${g}[a]=${g}[b] -> ${map} rows agree`, forall: ka, keys: [kb, kc], holds: any(not(guard), same(cell(a), cell(b))) };
|
|
115
|
-
|
|
116
|
-
|
|
119
|
+
// Tuple agreement was already emitted above; use that same stronger law.
|
|
120
|
+
const existing = base === -1 ? out.find(l => l.name === law.name) : undefined;
|
|
121
|
+
if (!existing)
|
|
122
|
+
out.push(law);
|
|
123
|
+
agrees.push({ map, f, g, law: existing ?? law });
|
|
117
124
|
}
|
|
118
125
|
if (!loaded)
|
|
119
126
|
return out;
|
|
@@ -193,7 +200,18 @@ export function fieldLaws(m, composed = true, loaded = true) {
|
|
|
193
200
|
}
|
|
194
201
|
const here = t.op === 'and' ? [...positive, ...atoms(t)] : positive;
|
|
195
202
|
const key = t.key, row = key?.b, input = row?.a?.name, src = t.map;
|
|
196
|
-
if (t.op === 'get' && src !== map && src in maps && !rows.has(src)
|
|
203
|
+
if (base === -1 && t.op === 'get' && src !== map && src in maps && !rows.has(src)) {
|
|
204
|
+
const first = { op: 'proj', k: 0, a: x(w.each) }, second = { op: 'proj', k: 1, a: x(w.each) };
|
|
205
|
+
if (sameTerm(t.key, second))
|
|
206
|
+
for (const input of m.inputs)
|
|
207
|
+
if (here.some(q => sameTerm(q, same(first, x(input))) || sameTerm(q, same(x(input), first))))
|
|
208
|
+
for (const q of here)
|
|
209
|
+
if (q.op === 'flag') {
|
|
210
|
+
const flag = q.name;
|
|
211
|
+
loads.set(`${src}:${input}:${flag}`, { src, input, flag });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (base !== -1 && t.op === 'get' && src !== map && src in maps && !rows.has(src) && key?.op === 'sub' && key.a.op === 'var' && key.a.name === w.each
|
|
197
215
|
&& row?.op === 'mul' && row.k === base && row.a.op === 'var' && input !== undefined && m.inputs.includes(input)
|
|
198
216
|
&& here.some(q => sameTerm(q, atMost(times(base, x(input)), x(w.each))))
|
|
199
217
|
&& here.some(q => sameTerm(q, less(x(w.each), plus(times(base, x(input)), n(base))))))
|
|
@@ -206,7 +224,7 @@ export function fieldLaws(m, composed = true, loaded = true) {
|
|
|
206
224
|
visit(u, here);
|
|
207
225
|
};
|
|
208
226
|
visit(w.value, []);
|
|
209
|
-
const cell = (r) => get(map, plus(times(base, r), c));
|
|
227
|
+
const cell = (r) => get(map, base === -1 ? tuple([r, c]) : plus(times(base, r), c));
|
|
210
228
|
for (const { src, input, flag } of loads.values())
|
|
211
229
|
for (const [mk, mw] of Object.entries(m.step.maps ?? {})) {
|
|
212
230
|
if ('each' in mw || mw.key.op !== 'var' || mw.key.name !== input || !(mk in maps) || rows.has(mk) || mk === src)
|