gdp-wired 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -7
- package/dist/core/cycles.d.ts +12 -0
- package/dist/core/cycles.js +7 -0
- package/dist/core/cyclic.d.ts +6 -1
- package/dist/core/cyclic.js +13 -1
- package/dist/core/data.d.ts +139 -13
- package/dist/core/data.js +845 -146
- package/dist/core/dsl.d.ts +27 -1
- package/dist/core/dsl.js +150 -32
- package/dist/core/exists.d.ts +26 -0
- package/dist/core/exists.js +625 -0
- package/dist/core/infer.d.ts +13 -0
- package/dist/core/infer.js +258 -41
- package/dist/core/machine.d.ts +27 -0
- package/dist/core/machine.js +45 -0
- package/dist/core/transfer.d.ts +17 -0
- package/dist/core/transfer.js +476 -0
- package/dist/core/watch.js +5 -1
- package/dist/kernel/cdcl.d.ts +40 -0
- package/dist/kernel/cdcl.js +543 -0
- package/dist/kernel/prove.d.ts +25 -2
- package/dist/kernel/prove.js +130 -49
- package/dist/kernel/reader.d.ts +79 -0
- package/dist/kernel/reader.js +539 -0
- package/dist/kernel/simplex.d.ts +32 -0
- package/dist/kernel/simplex.js +232 -0
- package/dist/lean-kernel/emit.d.ts +2 -0
- package/dist/lean-kernel/emit.js +196 -15
- package/dist/lean-kernel/library.js +2 -2
- package/package.json +2 -2
package/dist/kernel/prove.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { add, k, refuteFast, scale, solve, sub, v, work } from "../core/solver.js";
|
|
2
2
|
import { checkRefutation } from "../core/check.js";
|
|
3
|
-
import { allowNode, allowTranslated, certCyclic, certOn, certSearch, closingInsts, crossCyclic, cyclicOn, cycLog, hasQuantified, machineNodes, proveCyclic, reqTS, searchedStepNodes, skMachine, timedKind, withWitness, translatedProof, uncovered, uncoveredWhy } from "../core/cyclic.js";
|
|
4
|
-
import {
|
|
3
|
+
import { allowNode, allowTranslated, certCyclic, certOn, certSearch, closingInsts, crossCyclic, cyclicOn, cycLog, hasQuantified, loopNodes, machineNodes, proveCyclic, reqTS, searchedStepNodes, skMachine, timedKind, withWitness, translatedProof, uncovered, uncoveredWhy } from "../core/cyclic.js";
|
|
4
|
+
import { proveSome, someLaws } from "../core/exists.js";
|
|
5
|
+
import { growCdcl } from "./cdcl.js";
|
|
6
|
+
import { assumed, atomOf, boundOf, canon, canonFlip, columnTerm, decided, factorsOf, isCell, isMonomial, stepZone, check, checkLaws, checkStepLaws, historyMachine, leafConstraints, leafConstraintsReusing, reusing, linear, livenessHelpful, livenessParts, loopMachine, obligations, plainKey, progressObligations, stepLawObligations, trueC, truth, unreachable, witnessesOf, withProducts } from "./kernel.js";
|
|
5
7
|
// The atoms the path leaves open, in evaluation order: deciding any of them makes progress.
|
|
6
8
|
function openE(e, path, out) {
|
|
7
9
|
switch (e.op) {
|
|
@@ -82,7 +84,7 @@ function openH(c, path, out, positive = true) {
|
|
|
82
84
|
// keys a pairing builds ((a + b)² + b, keys whose difference has monomials) are left uncompared: that encoding states
|
|
83
85
|
// their congruence as facts, and comparing their keys only brings products into leaves its linear rows decide.
|
|
84
86
|
export const pairedKeys = { skip: false };
|
|
85
|
-
function openCells(rows, path) {
|
|
87
|
+
export function openCells(rows, path) {
|
|
86
88
|
const names = [...new Set(rows.flatMap(r => Object.keys(r.lin)))].filter(isCell);
|
|
87
89
|
const out = [];
|
|
88
90
|
const keyText = (n) => n.slice(n.indexOf('[') + 1, -1);
|
|
@@ -254,14 +256,25 @@ export function grow(goal, path = new Map(), budget = { nodes: 0, until: clock()
|
|
|
254
256
|
profile.goals.push({ name: goal.name, ms: performance.now() - t, nodes: profile.nodes - n0, solves: profile.solves - s0, solveMs: profile.solveMs - m0, rowsMs: profile.rowsMs - r0, proven: 'tree' in out });
|
|
255
257
|
return out;
|
|
256
258
|
}
|
|
259
|
+
// The share of a root goal's budget the CDCL search gets (GDP_CDCL_SHARE; 0 turns it off), and the quick search's nodes
|
|
260
|
+
// before it (GDP_QUICK_CAP; 64 where the CDCL search isn't tried, as before it): research/step's comparisons.
|
|
261
|
+
const proveEnv = globalThis.process?.env ?? {};
|
|
262
|
+
const cdclShare = Number(proveEnv.GDP_CDCL_SHARE ?? 0.75), quickCap = Number(proveEnv.GDP_QUICK_CAP ?? 16);
|
|
257
263
|
function growRoot(goal, path, budget) {
|
|
264
|
+
// Past a few cases, CDCL over the atoms (kernel/cdcl.ts), with most of the budget: a linear goal's refutation there
|
|
265
|
+
// is a resolution of short clauses, which the tree search would find again in every case that reaches one. Unknown
|
|
266
|
+
// there, the plain search, the cuts and the plain search again have the rest. Not for a law over k steps in a row
|
|
267
|
+
// (kernel.ts names its goals `@k steps`): the cuts make its tree a chain of one step's refutations, which the CDCL
|
|
268
|
+
// search's tree, unfolded, repeats (research/step: four times the Lean text of examples/steps.ts). Nor for products.
|
|
269
|
+
const root = path.size === 0 && budget.nodes === 0 ? leafConstraints(goal, path) : undefined;
|
|
270
|
+
const cdcl = !!root && cdclShare > 0 && !cellProducts.on && Number(/@(\d+) steps/.exec(goal.name)?.[1] ?? 1) <= 1 && !root.some(r => Object.keys(r.lin).some(isMonomial));
|
|
258
271
|
// At the root: plainly first; where the cases multiply past a budget, through cuts. The plain budget halves with each
|
|
259
272
|
// two open choices (what a plain search's cases grow by), so a long run's steps reach the cuts early.
|
|
260
|
-
if (
|
|
273
|
+
if (root && unitFirst && unitsNow) {
|
|
261
274
|
// A goal that a few cases settle needs no units (finding them costs a Farkas check per atom); the rest get them.
|
|
262
275
|
unitsNow = false;
|
|
263
276
|
try {
|
|
264
|
-
const quick = growPlain(goal, path, { nodes: 0, until: budget.until, cap: 64 });
|
|
277
|
+
const quick = growPlain(goal, path, { nodes: 0, until: budget.until, cap: cdcl ? quickCap : 64 });
|
|
265
278
|
if ('tree' in quick || quick.stuck === 'sat' || quick.why === undefined)
|
|
266
279
|
return quick;
|
|
267
280
|
}
|
|
@@ -269,8 +282,14 @@ function growRoot(goal, path, budget) {
|
|
|
269
282
|
unitsNow = true;
|
|
270
283
|
}
|
|
271
284
|
}
|
|
272
|
-
if (
|
|
273
|
-
|
|
285
|
+
if (root) {
|
|
286
|
+
if (cdcl) {
|
|
287
|
+
const now = clock(), end = withinDeadline(budget.until ?? Infinity);
|
|
288
|
+
const out = growCdcl(goal, path, { nodes: 0, until: end === Infinity ? end : now + cdclShare * (end - now) });
|
|
289
|
+
if ('tree' in out || out.stuck === 'sat')
|
|
290
|
+
return out;
|
|
291
|
+
}
|
|
292
|
+
const open = new Set(root.flatMap(r => Object.keys(r.lin)).filter(n => n.startsWith('⟦') && columnTerm(n)?.op === 'if')).size;
|
|
274
293
|
const plain = growPlain(goal, path, { nodes: 0, until: budget.until, cap: Math.max(32, Math.round(4_000 / 2 ** (open / 2))) });
|
|
275
294
|
if ('tree' in plain || plain.stuck === 'sat' || plain.why === undefined)
|
|
276
295
|
return plain;
|
|
@@ -298,30 +317,7 @@ function growPlain(goal, path, budget) {
|
|
|
298
317
|
const { steps, products, squares } = products0 || squares0 ? trimmed(rows.length, steps0, products0 ?? [], squares0 ?? []) : { steps: steps0, products: undefined, squares: undefined };
|
|
299
318
|
return { leaf: steps.map(st => (st.kind === 'input' ? { ...st, index: at(st.index) } : st)), ...(products?.length ? { products: products.map(([i, j]) => [at(i), at(j)]) } : {}), ...(squares?.length ? { squares } : {}) };
|
|
300
319
|
};
|
|
301
|
-
|
|
302
|
-
// one no refutation needs, and splitting it first multiplies every case after it.
|
|
303
|
-
const open = [];
|
|
304
|
-
const hyps = goal.hyps, last = hyps.length - 1;
|
|
305
|
-
let byHyp = openSeen.get(goal);
|
|
306
|
-
if (!byHyp)
|
|
307
|
-
openSeen.set(goal, (byHyp = new Map()));
|
|
308
|
-
const openOf = (h) => { let seen = byHyp.get(h); if (!seen)
|
|
309
|
-
byHyp.set(h, (seen = {})); return reusing(seen, path, p => { const out = []; openH(h, p, out); return out; }); };
|
|
310
|
-
// Then the hypotheses about only the names the conclusion reads (an assumption about another key, a witness, can
|
|
311
|
-
// wait: a refutation seldom needs it), then the rest, each group in the goal's order.
|
|
312
|
-
if (unitFirst && unitsNow)
|
|
313
|
-
open.push(...unitsOf(goal));
|
|
314
|
-
if (last >= 0)
|
|
315
|
-
open.push(...openOf(hyps[last]));
|
|
316
|
-
const near = nearOf(goal);
|
|
317
|
-
for (const [i, h] of hyps.entries())
|
|
318
|
-
if (i !== last && near[i])
|
|
319
|
-
open.push(...openOf(h));
|
|
320
|
-
for (const [i, h] of hyps.entries())
|
|
321
|
-
if (i !== last && !near[i])
|
|
322
|
-
open.push(...openOf(h));
|
|
323
|
-
open.push(...openCells(rows, path));
|
|
324
|
-
const next = open.find(lin => Object.keys(lin).some(key => key !== '1') && !path.has(canon(lin)) && !path.has(canonFlip(lin)));
|
|
320
|
+
const next = openAt(goal, path, rows).find(lin => Object.keys(lin).some(key => key !== '1') && !path.has(canon(lin)) && !path.has(canonFlip(lin)));
|
|
325
321
|
// With a case still to split, only "refuted or not" matters (a witness here goes unused): a large system is tried by
|
|
326
322
|
// its Farkas rows alone, and left to the split if they don't refute it. Elimination to the last variable, which a
|
|
327
323
|
// satisfiable system needs to say so, is kept for small systems and for the leaves, where its answer is the outcome.
|
|
@@ -583,7 +579,7 @@ function squareForms(rows) {
|
|
|
583
579
|
// A leaf's rows, by its path's decisions in order (what they are a function of): a lift reads every leaf of a subtree
|
|
584
580
|
// at its own path, found when it was grown, and at the path without the split, which the next lift up reads again.
|
|
585
581
|
const rowsSeen = new WeakMap();
|
|
586
|
-
function rowsAt(goal, path) {
|
|
582
|
+
export function rowsAt(goal, path) {
|
|
587
583
|
let byPath = rowsSeen.get(goal);
|
|
588
584
|
if (!byPath)
|
|
589
585
|
rowsSeen.set(goal, (byPath = new Map()));
|
|
@@ -721,7 +717,7 @@ export function widen(part, whole, tree, opaque = {}, pp = new Map(), wp = pp) {
|
|
|
721
717
|
// Whether each hypothesis reads only names the goal's conclusion (its last hypothesis) reads.
|
|
722
718
|
const nearSeen = new WeakMap();
|
|
723
719
|
const namesOf = (t) => (t === undefined ? [] : [...JSON.stringify(t).matchAll(/"(?:name|map)":"([^"]+)"/g)].map(m => m[1]));
|
|
724
|
-
function nearOf(goal) {
|
|
720
|
+
export function nearOf(goal) {
|
|
725
721
|
let out = nearSeen.get(goal);
|
|
726
722
|
if (!out) {
|
|
727
723
|
const theirs = new Set(namesOf(goal.hyps.at(-1)));
|
|
@@ -735,6 +731,8 @@ function nearOf(goal) {
|
|
|
735
731
|
// GDP_UNITS=0 leaves them in the goal's order (for comparing).
|
|
736
732
|
const unitFirst = globalThis.process?.env?.GDP_UNITS !== '0';
|
|
737
733
|
let unitsNow = true;
|
|
734
|
+
// The units growPlain splits first, where it does (kernel/cdcl.ts reads them too).
|
|
735
|
+
export const unitAtoms = (goal) => (unitFirst && unitsNow ? unitsOf(goal) : []);
|
|
738
736
|
const unitSeen = new WeakMap();
|
|
739
737
|
function unitsOf(goal) {
|
|
740
738
|
let out = unitSeen.get(goal);
|
|
@@ -776,6 +774,36 @@ function unitsOf(goal) {
|
|
|
776
774
|
}
|
|
777
775
|
// Each hypothesis' open atoms, as at an earlier path that decided the same atoms it reads (kernel.ts's reusing).
|
|
778
776
|
const openSeen = new WeakMap();
|
|
777
|
+
// The atoms a split may take at the path, in the order growPlain tries them (some may be decided already). The
|
|
778
|
+
// conclusion's own atoms first (the goal's last hypothesis is the law refuted): a case it doesn't read is often one no
|
|
779
|
+
// refutation needs, and splitting it first multiplies every case after it. Then the hypotheses about only the names
|
|
780
|
+
// the conclusion reads (an assumption about another key, a witness, can wait: a refutation seldom needs it), then the
|
|
781
|
+
// rest, each group in the goal's order, then pairs of cells.
|
|
782
|
+
export function openAt(goal, path, rows) {
|
|
783
|
+
const open = [];
|
|
784
|
+
const hyps = goal.hyps, last = hyps.length - 1;
|
|
785
|
+
let byHyp = openSeen.get(goal);
|
|
786
|
+
if (!byHyp)
|
|
787
|
+
openSeen.set(goal, (byHyp = new Map()));
|
|
788
|
+
const openOf = (h) => { let seen = byHyp.get(h); if (!seen)
|
|
789
|
+
byHyp.set(h, (seen = {})); return reusing(seen, path, p => { const out = []; openH(h, p, out); return out; }); };
|
|
790
|
+
// (pushed one by one: a k-step unrolling's lists outgrow a spread's argument limit)
|
|
791
|
+
const put = (xs) => { for (const x of xs)
|
|
792
|
+
open.push(x); };
|
|
793
|
+
if (unitFirst && unitsNow)
|
|
794
|
+
put(unitsOf(goal));
|
|
795
|
+
if (last >= 0)
|
|
796
|
+
put(openOf(hyps[last]));
|
|
797
|
+
const near = nearOf(goal);
|
|
798
|
+
for (const [i, h] of hyps.entries())
|
|
799
|
+
if (i !== last && near[i])
|
|
800
|
+
put(openOf(h));
|
|
801
|
+
for (const [i, h] of hyps.entries())
|
|
802
|
+
if (i !== last && !near[i])
|
|
803
|
+
put(openOf(h));
|
|
804
|
+
put(openCells(rows, path));
|
|
805
|
+
return open;
|
|
806
|
+
}
|
|
779
807
|
// What ran out, for a goal left unknown: its size, how deep the case splits went, and the two shapes that usually cause it.
|
|
780
808
|
function outOfBudget(goal, limit, depth) {
|
|
781
809
|
const steps = Number(/@(\d+) steps/.exec(goal.name)?.[1] ?? 1);
|
|
@@ -1346,6 +1374,9 @@ function chooseWitnesses(items, body, names, m, proves, rebuild) {
|
|
|
1346
1374
|
return { items: resolved(true) };
|
|
1347
1375
|
}
|
|
1348
1376
|
export function proveLaws(m, laws) {
|
|
1377
|
+
// Laws with "there exists" (core/exists.ts): proven through witnesses, as plain laws of the machine with its ghosts.
|
|
1378
|
+
if (someLaws(laws))
|
|
1379
|
+
return proveSome(m, laws);
|
|
1349
1380
|
if (!laws.some(l => someKeys(l.holds).length))
|
|
1350
1381
|
return proveLawsAsGiven(m, laws);
|
|
1351
1382
|
const out = chooseWitnesses(laws, l => l.holds, l => (l.forall ? [l.forall] : []), m, ls => { const r = proveLawsAsGiven(m, ls); return r.proven && r.checked; }, (l, holds) => ({ ...l, holds, stated: l.stated ?? l.holds }));
|
|
@@ -1357,7 +1388,7 @@ export function proveLaws(m, laws) {
|
|
|
1357
1388
|
// yet); not a proof of the set, which proveLaws gives. Laws with some key go through proveLaws.
|
|
1358
1389
|
export function proveLaw(m, laws, i) {
|
|
1359
1390
|
const law = laws[i];
|
|
1360
|
-
if (laws.some(l => someKeys(l.holds).length)) {
|
|
1391
|
+
if (laws.some(l => someKeys(l.holds).length) || someLaws(laws)) {
|
|
1361
1392
|
const r = proveLaws(m, laws);
|
|
1362
1393
|
return r.proven ? { proven: true } : { proven: false, goal: r.failed.goal, stuck: r.failed.stuck, ...(r.failed.witness ? { witness: r.failed.witness } : {}) };
|
|
1363
1394
|
}
|
|
@@ -1497,20 +1528,22 @@ function proveWith(m, laws, instances) {
|
|
|
1497
1528
|
const proof = { instances, trees };
|
|
1498
1529
|
return { proven: true, nodes, leaves, checked: !usualCheck.on || checkLaws(m, laws, proof), proof };
|
|
1499
1530
|
}
|
|
1500
|
-
export function proveStepLaws(
|
|
1501
|
-
const base = proveLaws(
|
|
1531
|
+
export function proveStepLaws(given0, given, stepLaws) {
|
|
1532
|
+
const base = proveLaws(given0, given);
|
|
1502
1533
|
if (!base.proven || !base.proof)
|
|
1503
1534
|
return { proven: false, nodes: base.nodes, leaves: base.leaves, ...(base.failed ? { failed: base.failed } : {}), checked: false };
|
|
1504
1535
|
const laws = base.laws ?? given;
|
|
1536
|
+
// (laws with "there exists": the step laws over the machine with the ghosts their witnesses are)
|
|
1537
|
+
const m = base.machine ?? given0, mx = base.machine ? { machine: base.machine } : {};
|
|
1505
1538
|
if (stepLaws.some(sl => someKeys(sl.then).length)) {
|
|
1506
1539
|
// Each step law's witnesses on its own (a step law assumes no other), the request and the state after among them.
|
|
1507
1540
|
const plain = m.history ? historyMachine(m).machine : m, after = Object.keys(plain.state).map(n => `${n}'`);
|
|
1508
1541
|
const out = chooseWitnesses(stepLaws, sl => sl.then, sl => [...(sl.forall ? [sl.forall] : []), ...plain.inputs, ...after], plain, sls => sls.every(sl => { const r = proveStepLawsAsGiven(m, laws, [sl], base); return r.proven && r.checked; }), (sl, then) => ({ ...sl, then }));
|
|
1509
1542
|
if ('stuck' in out)
|
|
1510
1543
|
return { proven: false, nodes: base.nodes, leaves: base.leaves, failed: { goal: 'witnesses', stuck: out.stuck }, checked: false };
|
|
1511
|
-
return { ...proveStepLawsAsGiven(m, laws, out.items, base), ...(base.laws ? { laws } : {}), stepLaws: out.items };
|
|
1544
|
+
return { ...proveStepLawsAsGiven(m, laws, out.items, base), ...(base.laws ? { laws } : {}), ...mx, stepLaws: out.items };
|
|
1512
1545
|
}
|
|
1513
|
-
return { ...proveStepLawsAsGiven(m, laws, stepLaws, base), ...(base.laws ? { laws } : {}) };
|
|
1546
|
+
return { ...proveStepLawsAsGiven(m, laws, stepLaws, base), ...(base.laws ? { laws } : {}), ...mx };
|
|
1514
1547
|
}
|
|
1515
1548
|
function proveStepLawsAsGiven(m, laws, stepLaws, base) {
|
|
1516
1549
|
if (!base.proof)
|
|
@@ -1579,7 +1612,10 @@ function proveStepLawsAsGiven(m, laws, stepLaws, base) {
|
|
|
1579
1612
|
// trees are its input, as a machine's laws' are: checkStepLaws (the laws' usual trees again, then the step laws') runs
|
|
1580
1613
|
// only where no certificate is made.
|
|
1581
1614
|
const byCert = certOn() && !cyclicOn() && !why && one.length > 0 && base.checked;
|
|
1582
|
-
|
|
1615
|
+
// (`uncovered`: why each step law left on the usual rule is, where the certificate is on: none, every step law has its
|
|
1616
|
+
// cyclic certificate; proveLiveness reads it)
|
|
1617
|
+
const left = [], miss = (sl, why) => { uncovered((sl.steps ?? 1) > 1 ? 'k-step law' : 'step law', m.name, why); left.push(why); };
|
|
1618
|
+
const out = { proven: true, nodes, leaves, checked: byCert || checkStepLaws(m, laws, stepLaws, proof), proof, ...(certOn() ? { uncovered: left } : {}) };
|
|
1583
1619
|
if (!modes)
|
|
1584
1620
|
return out;
|
|
1585
1621
|
if (!why && one.length && out.checked) {
|
|
@@ -1597,7 +1633,7 @@ function proveStepLawsAsGiven(m, laws, stepLaws, base) {
|
|
|
1597
1633
|
for (const x of all) {
|
|
1598
1634
|
const c = all.length > 1 ? certCyclic('step law', m.name, translatedOf([x]), undefined, usualMs) : together;
|
|
1599
1635
|
if (!c.checked)
|
|
1600
|
-
|
|
1636
|
+
miss(x.sl, c.why);
|
|
1601
1637
|
}
|
|
1602
1638
|
}
|
|
1603
1639
|
}
|
|
@@ -1611,11 +1647,11 @@ function proveStepLawsAsGiven(m, laws, stepLaws, base) {
|
|
|
1611
1647
|
};
|
|
1612
1648
|
const c = certCyclic('step law', m.name, undefined, searchedSteps, performance.now() - t0);
|
|
1613
1649
|
for (const sl of c.checked ? [] : rest)
|
|
1614
|
-
|
|
1650
|
+
miss(sl, `${restWhy(sl)}: ${c.why}`);
|
|
1615
1651
|
}
|
|
1616
1652
|
else if (cyclicOn() || certOn())
|
|
1617
1653
|
for (const sl of rest)
|
|
1618
|
-
|
|
1654
|
+
miss(sl, restWhy(sl));
|
|
1619
1655
|
return out;
|
|
1620
1656
|
}
|
|
1621
1657
|
// Progress (kernel.ts's progressObligations): the laws proven first, then each goal, the every-key laws assumed at every
|
|
@@ -1665,25 +1701,39 @@ export function proveProgress(m, laws, p) {
|
|
|
1665
1701
|
return found?.out ?? last;
|
|
1666
1702
|
};
|
|
1667
1703
|
const c = certCyclic('progress', m.name, translated, certSearch() ? allowed : undefined, performance.now() - t0);
|
|
1668
|
-
if (!c.checked)
|
|
1669
|
-
|
|
1704
|
+
if (!c.checked) {
|
|
1705
|
+
const why = `a request allowed: ${c.why}`;
|
|
1706
|
+
uncovered('progress', m.name, why);
|
|
1707
|
+
return { proven: true, nodes, leaves, checked, instances, trees, uncovered: why };
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
else if (cyclicOn() || certOn()) {
|
|
1711
|
+
const why = alone ? 'a request allowed' : 'a request allowed and a claim after it';
|
|
1712
|
+
uncovered('progress', m.name, why);
|
|
1713
|
+
if (certOn())
|
|
1714
|
+
return { proven: true, nodes, leaves, checked, instances, trees, uncovered: why };
|
|
1670
1715
|
}
|
|
1671
|
-
else if (cyclicOn() || certOn())
|
|
1672
|
-
uncovered('progress', m.name, alone ? 'a request allowed' : 'a request allowed and a claim after it');
|
|
1673
1716
|
return { proven: true, nodes, leaves, checked, instances, trees };
|
|
1674
1717
|
}
|
|
1675
1718
|
// Liveness (kernel.ts's livenessParts): its step laws, proven together. The claim needs no more (a run takes the
|
|
1676
1719
|
// request, so it is allowed); but a request never allowed would leave the claim about no run, so where a helpful request
|
|
1677
1720
|
// names every input a client sends and carries no maps, it is proven allowed in its region too.
|
|
1721
|
+
// The certificate is its parts': the step laws' cyclic proof (translated, as any machine's step laws), and each helpful
|
|
1722
|
+
// request's allowed node. The claim about runs that never end is no certificate's, under either: the rank that can't
|
|
1723
|
+
// drop forever, the region that stays once it stops and the request that comes there are Live.lean's `leads_of_lex`,
|
|
1724
|
+
// read from the step laws' meaning (BridgeRules.lean's `sleads_of_holds`, of a cyclic proof's step laws through
|
|
1725
|
+
// `cyc_kstep_sound`) as from their usual trees (Live.lean's `sleads_sound`): one claim, its statement the same. So a
|
|
1726
|
+
// liveness is covered exactly where every part has its cyclic certificate (`cyclic: {kind: 'liveness', ...}`), and
|
|
1727
|
+
// uncovered, with the part's why, where one is on the usual rule.
|
|
1728
|
+
// (`uncovered`, where the certificate is on: why each part is on the usual rule; none, the liveness is covered)
|
|
1678
1729
|
export function proveLiveness(m, laws, l) {
|
|
1679
|
-
if (cyclicOn() || certOn())
|
|
1680
|
-
uncovered('liveness', m.name, 'a claim about runs that never end');
|
|
1681
1730
|
const { stay, cover, helps } = livenessParts(m, l);
|
|
1682
1731
|
const a = proveStepLaws(m, laws, [stay, cover, ...helps]);
|
|
1683
1732
|
if (!a.proven || !a.checked)
|
|
1684
1733
|
return { proven: false, nodes: a.nodes, leaves: a.leaves, ...(a.failed ? { failed: a.failed } : {}), checked: false };
|
|
1685
1734
|
const plain = m.history ? historyMachine(m).machine : m;
|
|
1686
1735
|
let nodes = a.nodes, leaves = a.leaves;
|
|
1736
|
+
const left = [...(a.uncovered ?? []).map(why => `a step law: ${why}`)];
|
|
1687
1737
|
for (const [i, h] of livenessHelpful(l).entries()) {
|
|
1688
1738
|
if (m.history || plain.inputMaps?.length || !plain.assume || !plain.inputs.every(inp => inp in h.request))
|
|
1689
1739
|
continue;
|
|
@@ -1692,8 +1742,39 @@ export function proveLiveness(m, laws, l) {
|
|
|
1692
1742
|
leaves += b.leaves;
|
|
1693
1743
|
if (!b.proven || !b.checked)
|
|
1694
1744
|
return { proven: false, nodes, leaves, ...(b.failed ? { failed: b.failed } : {}), checked: false };
|
|
1745
|
+
if (b.uncovered)
|
|
1746
|
+
left.push(`helpful request ${i + 1} allowed: ${b.uncovered}`);
|
|
1747
|
+
}
|
|
1748
|
+
if (certOn()) {
|
|
1749
|
+
if (left.length)
|
|
1750
|
+
uncovered('liveness', m.name, left.join('; '));
|
|
1751
|
+
else
|
|
1752
|
+
cycLog({ kind: 'liveness', name: m.name, cert: true, usual: true, cyclic: true, route: 'its step laws', parts: 2 + helps.length });
|
|
1753
|
+
}
|
|
1754
|
+
else if (cyclicOn())
|
|
1755
|
+
uncovered('liveness', m.name, 'a claim about runs that never end');
|
|
1756
|
+
return { proven: true, checked: true, nodes, leaves, steps: a, ...(certOn() ? { uncovered: left } : {}) };
|
|
1757
|
+
}
|
|
1758
|
+
// A loop's halting (kernel.ts's loopObligations: its machine's laws, and its liveness's step laws, `while` failing later
|
|
1759
|
+
// from anywhere, every request helpful), its usual trees given: translated to one cyclic proof as proveStepLaws
|
|
1760
|
+
// translates a machine's step laws (core/cyclic.ts's machineNodes, the laws' nodes and the step laws' after them), the
|
|
1761
|
+
// proof Lean reads (lean-kernel/emit.ts's cycMachineToLean: Live.lean's loop_halts_of from BridgeRules.lean's
|
|
1762
|
+
// sleads_of_holds). The claim is the usual one: loop_halts_of reads the liveness's meaning, from either certificate.
|
|
1763
|
+
// Undefined where the cyclic certificate is off (GDP_CERT=usual; with GDP_CYCLIC=1 the cross-check runs); else checked,
|
|
1764
|
+
// the proof, and why not.
|
|
1765
|
+
export function certLoop(l, laws, rank, trees, usualMs) {
|
|
1766
|
+
if (!certOn() && !cyclicOn())
|
|
1767
|
+
return undefined;
|
|
1768
|
+
// (a proof made from the same loop, laws and rank before is that proof: it proves the same claim)
|
|
1769
|
+
const translated = (st) => translatedProof(() => JSON.stringify(['loop', loopMachine(l), laws, rank]), () => timedKind('instance', 0, () => loopNodes(l, laws, rank, trees, st)), st);
|
|
1770
|
+
if (!certOn()) {
|
|
1771
|
+
crossCyclic('loop', l.name, true, undefined, usualMs, translated);
|
|
1772
|
+
return undefined;
|
|
1695
1773
|
}
|
|
1696
|
-
|
|
1774
|
+
const c = certCyclic('loop', l.name, translated, undefined, usualMs);
|
|
1775
|
+
if (!c.checked)
|
|
1776
|
+
uncovered('loop', l.name, c.why);
|
|
1777
|
+
return c;
|
|
1697
1778
|
}
|
|
1698
1779
|
// The key terms a condition reads maps at; a primed map's key is a key of the map before the step too.
|
|
1699
1780
|
function readKeysC(c) {
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { C, E } from '../core/machine.js';
|
|
2
|
+
import { type Lin } from '../core/solver.js';
|
|
3
|
+
import { type Goal } from './kernel.js';
|
|
4
|
+
export type W = ReadonlySet<string>;
|
|
5
|
+
export declare const none: W;
|
|
6
|
+
export declare const join: (a: W, b: W) => W;
|
|
7
|
+
export type Trail = {
|
|
8
|
+
get(name: string): {
|
|
9
|
+
val?: boolean;
|
|
10
|
+
at: number;
|
|
11
|
+
} | undefined;
|
|
12
|
+
stamp(at: number): number;
|
|
13
|
+
size(): number;
|
|
14
|
+
lin(at: number): {
|
|
15
|
+
name: string;
|
|
16
|
+
lin: Lin;
|
|
17
|
+
holds: boolean;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
type R = {
|
|
21
|
+
w: W;
|
|
22
|
+
pos: number;
|
|
23
|
+
fin: boolean;
|
|
24
|
+
};
|
|
25
|
+
type Kept = {
|
|
26
|
+
pos: number;
|
|
27
|
+
stamp: number;
|
|
28
|
+
node: number;
|
|
29
|
+
};
|
|
30
|
+
type TV = R & Kept & {
|
|
31
|
+
t: boolean | undefined;
|
|
32
|
+
};
|
|
33
|
+
type LV = R & Kept & {
|
|
34
|
+
lin: Lin | undefined;
|
|
35
|
+
};
|
|
36
|
+
type FV = Kept & {
|
|
37
|
+
rows: Row[];
|
|
38
|
+
fin: boolean;
|
|
39
|
+
};
|
|
40
|
+
export type Row = {
|
|
41
|
+
lin: Lin;
|
|
42
|
+
w: W;
|
|
43
|
+
label: '';
|
|
44
|
+
};
|
|
45
|
+
export declare class Reader {
|
|
46
|
+
readonly goal: Goal;
|
|
47
|
+
readonly trail: Trail;
|
|
48
|
+
private node;
|
|
49
|
+
private natRows;
|
|
50
|
+
private atomRows;
|
|
51
|
+
private ls;
|
|
52
|
+
private ts;
|
|
53
|
+
private fs;
|
|
54
|
+
constructor(goal: Goal, trail: Trail);
|
|
55
|
+
begin(): void;
|
|
56
|
+
private ok;
|
|
57
|
+
private kept;
|
|
58
|
+
private units;
|
|
59
|
+
private unit;
|
|
60
|
+
dec(lin: Lin): R & {
|
|
61
|
+
t: boolean | undefined;
|
|
62
|
+
};
|
|
63
|
+
linear(e: E): LV;
|
|
64
|
+
private atoms;
|
|
65
|
+
truth(c: C): TV;
|
|
66
|
+
private factsOf;
|
|
67
|
+
facts(i: number): FV;
|
|
68
|
+
termRows(name: string): Row[];
|
|
69
|
+
private decided;
|
|
70
|
+
rows(): Row[];
|
|
71
|
+
leafRows(): Row[];
|
|
72
|
+
open(i: number, out: Lin[]): void;
|
|
73
|
+
private openE;
|
|
74
|
+
private openC;
|
|
75
|
+
private openH;
|
|
76
|
+
}
|
|
77
|
+
export declare const namesOf: (lin: Lin) => string[];
|
|
78
|
+
export declare const keyLin: (cell: string) => Lin;
|
|
79
|
+
export {};
|