gdp-wired 0.49.0 → 0.50.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 +4 -0
- package/dist/core/candidate-seeds.d.ts +25 -0
- package/dist/core/candidate-seeds.js +90 -0
- package/dist/core/cli.js +3 -0
- 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.d.ts +23 -2
- package/dist/core/dsl.js +49 -16
- package/dist/core/exists.js +2 -1
- package/dist/core/field-laws.js +23 -5
- package/dist/core/infer.js +4 -3
- 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 +5 -1
package/dist/kernel/prove.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { retainFamily, retainFrom } from "../core/proof-output.js";
|
|
1
2
|
// An untrusted prover for the kernel: grows a split tree until every leaf's constraints are refuted by solve(), splitting
|
|
2
3
|
// on whatever atom the hypotheses leave open (an if's condition, a min's or ∸'s comparison, a disjunction's atoms, two
|
|
3
4
|
// reads of one map at keys not yet known equal or apart). Its trees go to kernel.check; nothing it says is trusted.
|
|
@@ -23,6 +24,7 @@ import { allowNode, allowTranslated, certCyclic, certOn, certSearch, stepCertFlo
|
|
|
23
24
|
import { proveSome, someLaws } from "../core/exists.js";
|
|
24
25
|
import { REFUTED, growCdcl } from "./cdcl.js";
|
|
25
26
|
import { decide, eprMeter, pastEprCap, patternsOf, withEprCap } from "./epr.js";
|
|
27
|
+
import { extendFunctionInstances, hasFunctionInstances } from "./function-instances.js";
|
|
26
28
|
import { projected, tupleParts } from "./kernel.js";
|
|
27
29
|
import { modelValueTerms } from "./model-values.js";
|
|
28
30
|
import { proverRows } from "./prover-rows.js";
|
|
@@ -1823,15 +1825,50 @@ export const keyValue = (cell, w) => {
|
|
|
1823
1825
|
// the values the goal's keys take, and each tuple where one fails added, as the goal's terms with those values, to its
|
|
1824
1826
|
// instances. None found: the model is one on every tuple of the goal's keys. Untrusted: it chooses instances only.
|
|
1825
1827
|
export const modelRounds = 4;
|
|
1828
|
+
let scopedModelRounds;
|
|
1829
|
+
export function validateModelRounds(value) {
|
|
1830
|
+
if (value === 'progress' || typeof value === 'number' && Number.isSafeInteger(value) && value >= 0)
|
|
1831
|
+
return value;
|
|
1832
|
+
throw new RangeError('modelRounds must be a nonnegative safe integer or progress');
|
|
1833
|
+
}
|
|
1834
|
+
export function effectiveModelRounds() {
|
|
1835
|
+
if (scopedModelRounds !== undefined)
|
|
1836
|
+
return scopedModelRounds;
|
|
1837
|
+
const value = env.GDP_MODEL_ROUNDS;
|
|
1838
|
+
return value === undefined ? modelRounds : validateModelRounds(/^(0|[1-9][0-9]*)$/.test(value) ? Number(value) : value);
|
|
1839
|
+
}
|
|
1840
|
+
export function withModelRounds(value, f) {
|
|
1841
|
+
const policy = value === undefined ? effectiveModelRounds() : validateModelRounds(value), old = scopedModelRounds;
|
|
1842
|
+
scopedModelRounds = policy;
|
|
1843
|
+
try {
|
|
1844
|
+
return f();
|
|
1845
|
+
}
|
|
1846
|
+
finally {
|
|
1847
|
+
scopedModelRounds = old;
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1826
1850
|
// A condition as the disjuncts it is the or of (¬(a ∧ b) as ¬a, ¬b).
|
|
1827
1851
|
// (GDP_MODEL_CUTS=0: every tuple evaluated whole, for comparing)
|
|
1828
1852
|
const modelCuts = env.GDP_MODEL_CUTS !== '0';
|
|
1829
1853
|
const disjuncts = (c) => (c.op === 'or' ? c.xs.flatMap(disjuncts) : c.op === 'not' && c.x.op === 'and' ? c.x.xs.flatMap(y => disjuncts({ op: 'not', x: y })) : c.op === 'not' && c.x.op === 'not' ? disjuncts(c.x.x) : [c]);
|
|
1830
|
-
export function modelInstances(m, laws, inst, goal, w, most = 64, sorted = false) {
|
|
1854
|
+
export function modelInstances(m, laws, inst, goal, w, most = 64, sorted = false, confirmation) {
|
|
1855
|
+
if (confirmation) {
|
|
1856
|
+
confirmation.confirmed = false;
|
|
1857
|
+
confirmation.why = 'model domain not checked';
|
|
1858
|
+
}
|
|
1859
|
+
let incomplete, violated = false;
|
|
1860
|
+
const unfinished = (why) => { incomplete ??= why; };
|
|
1831
1861
|
const pm = plainOf(m), qs = Object.entries(pm.step.flags ?? {}).filter((e) => e[1].op === 'all' && w[`?${e[0]}`] === 1);
|
|
1832
|
-
|
|
1833
|
-
|
|
1862
|
+
// Start obligations assume facts, not the invariants being established.
|
|
1863
|
+
const keyed = [...(pm.facts ?? []), ...(goal.name.endsWith(' @start') ? [] : laws)].filter(l => l.forall);
|
|
1864
|
+
if (!keyed.length && !qs.length) {
|
|
1865
|
+
if (confirmation) {
|
|
1866
|
+
confirmation.confirmed = true;
|
|
1867
|
+
delete confirmation.why;
|
|
1868
|
+
}
|
|
1869
|
+
;
|
|
1834
1870
|
return undefined;
|
|
1871
|
+
}
|
|
1835
1872
|
// (the maps a request carries read as maps too: a quantified flag over one, wo's ∀k. Q has k → Votes[src, k])
|
|
1836
1873
|
const fns = Object.keys(pm.fns ?? {}), mm = { ...pm, fns: undefined, maps: { ...(pm.maps ?? {}), ...Object.fromEntries([...fns, ...(pm.inputMaps ?? []), ...Object.keys(pm.counts ?? {})].map(f => [f, 0])) } };
|
|
1837
1874
|
const maps = Object.fromEntries(Object.keys(mm.maps).map(mp => [mp, new Map()]));
|
|
@@ -1842,6 +1879,8 @@ export function modelInstances(m, laws, inst, goal, w, most = 64, sorted = false
|
|
|
1842
1879
|
const key = keyValue(cell, w);
|
|
1843
1880
|
if (key !== undefined)
|
|
1844
1881
|
maps[cell.slice(0, br)].set(key, value);
|
|
1882
|
+
else
|
|
1883
|
+
unfinished('model cell could not be decoded');
|
|
1845
1884
|
}
|
|
1846
1885
|
const st = { scalars: {}, maps }, read = (at) => new Proxy(at, { get: (t, p) => (p in t ? t[p] : w[p] ?? 0), has: (t, p) => p in t || p in w });
|
|
1847
1886
|
// (a count's cell the model has not: its definition, its body summed over the model's cells below its bound, so a law
|
|
@@ -1849,6 +1888,8 @@ export function modelInstances(m, laws, inst, goal, w, most = 64, sorted = false
|
|
|
1849
1888
|
for (const [c, d] of Object.entries(pm.counts ?? {})) {
|
|
1850
1889
|
const had = maps[c], sum = (x) => {
|
|
1851
1890
|
const e1 = read(d.base ? { [d.j]: Math.floor(x / d.base), [d.lo]: x % d.base } : { [d.j]: x }), n = Math.min(256, evalE(d.below, e1, st, mm));
|
|
1891
|
+
if (n === 256 && evalE(d.below, e1, st, mm) > n)
|
|
1892
|
+
unfinished('model count evaluation truncated');
|
|
1852
1893
|
let t = 0;
|
|
1853
1894
|
for (let k = 0; k < n; k++)
|
|
1854
1895
|
t += evalE(d.body, read({ ...e1, [d.key]: k }), st, mm);
|
|
@@ -1863,12 +1904,23 @@ export function modelInstances(m, laws, inst, goal, w, most = 64, sorted = false
|
|
|
1863
1904
|
return f();
|
|
1864
1905
|
}
|
|
1865
1906
|
catch {
|
|
1907
|
+
unfinished('model hypothesis evaluation incomplete');
|
|
1866
1908
|
return undefined;
|
|
1867
1909
|
} };
|
|
1910
|
+
if (confirmation)
|
|
1911
|
+
for (const h of goal.hyps) {
|
|
1912
|
+
if (pastWall()) {
|
|
1913
|
+
unfinished('model confirmation wall');
|
|
1914
|
+
break;
|
|
1915
|
+
}
|
|
1916
|
+
if (ev(() => evalC(h, read({}), st, mm)) === false)
|
|
1917
|
+
violated = true;
|
|
1918
|
+
}
|
|
1868
1919
|
const valueOf = (e) => { try {
|
|
1869
1920
|
return evalE(e, read({}), st, mm);
|
|
1870
1921
|
}
|
|
1871
1922
|
catch {
|
|
1923
|
+
unfinished('model term evaluation incomplete');
|
|
1872
1924
|
return undefined;
|
|
1873
1925
|
} };
|
|
1874
1926
|
// Each bound key over its own sort as the model fills it: the terms its body's map reads bind matched against the
|
|
@@ -1882,8 +1934,11 @@ export function modelInstances(m, laws, inst, goal, w, most = 64, sorted = false
|
|
|
1882
1934
|
if (v2 !== undefined && !all.has(v2))
|
|
1883
1935
|
all.set(v2, e);
|
|
1884
1936
|
}
|
|
1885
|
-
if (!all.size)
|
|
1937
|
+
if (!all.size) {
|
|
1938
|
+
if (confirmation)
|
|
1939
|
+
confirmation.why = 'model has no evaluable key domain';
|
|
1886
1940
|
return undefined;
|
|
1941
|
+
}
|
|
1887
1942
|
// (each sort's witnesses first: an ∃ law's ghost, a quantified flag's witness, the terms a model most often breaks a
|
|
1888
1943
|
// law at and no read's matching orders well)
|
|
1889
1944
|
const witnessFirst = (p) => {
|
|
@@ -1912,8 +1967,10 @@ export function modelInstances(m, laws, inst, goal, w, most = 64, sorted = false
|
|
|
1912
1967
|
// first don't leave none to those after: sharded KV's "a key in transfer has no owner", broken at the goal's own keys)
|
|
1913
1968
|
let added = 0, evals = 0, left = 0, ineligible = false;
|
|
1914
1969
|
const each = (id, names, body, atoms) => {
|
|
1915
|
-
if (pastWall())
|
|
1970
|
+
if (pastWall()) {
|
|
1971
|
+
unfinished('model confirmation wall');
|
|
1916
1972
|
return;
|
|
1973
|
+
}
|
|
1917
1974
|
const until = evals + Math.max(256, Math.floor((20_000 - evals) / Math.max(1, left--)));
|
|
1918
1975
|
const have = new Set(), had = out[id] ?? [], n = names.length, sorts = sortsOf(body, names, atoms);
|
|
1919
1976
|
const keyNames = new Set();
|
|
@@ -1928,7 +1985,7 @@ export function modelInstances(m, laws, inst, goal, w, most = 64, sorted = false
|
|
|
1928
1985
|
// Arithmetic-only naturals range over comparison boundaries, not map keys.
|
|
1929
1986
|
// The model chooses constants; assumed/check still validate ordinary law instances.
|
|
1930
1987
|
// (a law at one key assumed at a term of every value its sort takes already: nothing to add)
|
|
1931
|
-
if (n === 1 && keyNames.has(names[0])) {
|
|
1988
|
+
if (!confirmation && n === 1 && keyNames.has(names[0])) {
|
|
1932
1989
|
const covered = new Set(had.map(valueOf));
|
|
1933
1990
|
if ([...sorts[0].keys()].every(v2 => covered.has(v2)))
|
|
1934
1991
|
return;
|
|
@@ -1945,8 +2002,10 @@ export function modelInstances(m, laws, inst, goal, w, most = 64, sorted = false
|
|
|
1945
2002
|
ready[names.reduce((a, x, j) => (t.includes(`"name":${JSON.stringify(x)}`) ? j + 1 : a), 0)].push(d);
|
|
1946
2003
|
}
|
|
1947
2004
|
const go = (i, at, terms) => {
|
|
1948
|
-
if (added >= most || evals > until || (evals % 512 === 0 && pastWall()))
|
|
2005
|
+
if (added >= most || evals > until || (evals % 512 === 0 && pastWall())) {
|
|
2006
|
+
unfinished('model confirmation budget');
|
|
1949
2007
|
return;
|
|
2008
|
+
}
|
|
1950
2009
|
for (const d of ready[i]) {
|
|
1951
2010
|
evals++;
|
|
1952
2011
|
if (ev(() => evalC(d, read(at), st, mm)) === true)
|
|
@@ -1956,6 +2015,7 @@ export function modelInstances(m, laws, inst, goal, w, most = 64, sorted = false
|
|
|
1956
2015
|
evals++;
|
|
1957
2016
|
if (ev(() => evalC(body, read(at), st, mm)) !== false)
|
|
1958
2017
|
return;
|
|
2018
|
+
violated = true;
|
|
1959
2019
|
const id2 = JSON.stringify(terms);
|
|
1960
2020
|
if (have.has(id2))
|
|
1961
2021
|
return;
|
|
@@ -2017,44 +2077,62 @@ export function modelInstances(m, laws, inst, goal, w, most = 64, sorted = false
|
|
|
2017
2077
|
for (const [f, q] of qs)
|
|
2018
2078
|
each(`?${f}`, boundOf(q), q.c, atoms);
|
|
2019
2079
|
}
|
|
2020
|
-
//
|
|
2080
|
+
// No new tuple is not confirmation: a cap, an evaluation failure, an already
|
|
2081
|
+
// assumed false instance, or a rejected tuple still leaves this model unconfirmed.
|
|
2082
|
+
if (confirmation) {
|
|
2083
|
+
confirmation.confirmed = !incomplete && !violated && !ineligible;
|
|
2084
|
+
if (confirmation.confirmed)
|
|
2085
|
+
delete confirmation.why;
|
|
2086
|
+
else
|
|
2087
|
+
confirmation.why = incomplete ?? (ineligible ? 'model violates an ineligible hypothesis instance' : 'model violates a hypothesis instance');
|
|
2088
|
+
}
|
|
2021
2089
|
return added || ineligible ? out : undefined;
|
|
2022
2090
|
}
|
|
2023
|
-
// A
|
|
2024
|
-
//
|
|
2025
|
-
//
|
|
2026
|
-
//
|
|
2027
|
-
// not the goal's usual budget again; a later round left unsettled gives back the first round's answer, so the verdict is
|
|
2028
|
-
// never one the model's tuples made worse. Untrusted.
|
|
2091
|
+
// A model of only the current instances is a proposal, never a deletion witness.
|
|
2092
|
+
// Refinement keeps the existing work share/round limits; failure to finish is
|
|
2093
|
+
// UNKNOWN, not the first SAT. Only a completed model-domain check admits SAT.
|
|
2094
|
+
// Untrusted: proof trees and instances still go through the unchanged checker.
|
|
2029
2095
|
export const modelShare = 3;
|
|
2030
|
-
// (GDP_MODELS_TRACE=1: each model round, its goal and the tuples a model adds, on stderr)
|
|
2031
2096
|
const modelsTrace = !!env.GDP_MODELS_TRACE, modelFloor = Number(env.GDP_MODEL_FLOOR ?? 1_000);
|
|
2032
2097
|
const costNow = () => (searchRate() ? clock() : searchWork() / groundRate);
|
|
2033
2098
|
const within = (ms, f) => (searchRate() ? withDeadline(clock() + ms, f) : withSearchWork(searchWork() + groundRate * ms, f));
|
|
2034
|
-
export function withModels(m, laws, inst, goalOf, ask, modelOf, settled) {
|
|
2035
|
-
return withPatterns(m, laws, () => modelsLoop(m, laws, inst, goalOf, ask, modelOf, settled));
|
|
2036
|
-
}
|
|
2037
|
-
function modelsLoop(m, laws, inst, goalOf, ask, modelOf, settled) {
|
|
2038
|
-
let at = inst,
|
|
2099
|
+
export function withModels(m, laws, inst, goalOf, ask, modelOf, settled, unknown) {
|
|
2100
|
+
return withPatterns(m, laws, () => modelsLoop(m, laws, inst, goalOf, ask, modelOf, settled, unknown));
|
|
2101
|
+
}
|
|
2102
|
+
function modelsLoop(m, laws, inst, goalOf, ask, modelOf, settled, unknown) {
|
|
2103
|
+
let at = inst, cap = 0;
|
|
2104
|
+
const rounds = effectiveModelRounds();
|
|
2105
|
+
// Progress may use the caller's existing bounded allowance, never a new one.
|
|
2106
|
+
// Without an outer endpoint, retain the old finite local work share.
|
|
2107
|
+
const progressBudget = rounds === 'progress' && (inBudget() || Number.isFinite(wallAt()) || Number.isFinite(withinDeadline(Infinity)));
|
|
2039
2108
|
for (let round = 0;; round++) {
|
|
2040
|
-
const c0 = costNow(), result = round ? within(Math.max(0, cap), () => ask(goalOf(at))) : ask(goalOf(at));
|
|
2109
|
+
const c0 = costNow(), result = round && !progressBudget ? within(Math.max(0, cap), () => ask(goalOf(at))) : ask(goalOf(at));
|
|
2041
2110
|
if (round)
|
|
2042
2111
|
cap -= costNow() - c0;
|
|
2043
2112
|
else
|
|
2044
2113
|
cap = Math.max(modelFloor, modelShare * (costNow() - c0));
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2114
|
+
const abandon = (why) => ({ result: unknown(result, `unconfirmed model: ${why}`), inst: at });
|
|
2115
|
+
if (!settled(result))
|
|
2116
|
+
return abandon('refinement unsettled');
|
|
2117
|
+
const mw = modelOf(result);
|
|
2118
|
+
if (!mw)
|
|
2119
|
+
return { result, inst: at };
|
|
2050
2120
|
if (pastWall())
|
|
2051
|
-
return
|
|
2052
|
-
|
|
2053
|
-
|
|
2121
|
+
return abandon('wall reached');
|
|
2122
|
+
if (!progressBudget && cap <= 0)
|
|
2123
|
+
return abandon('work share exhausted');
|
|
2124
|
+
const confirmation = { confirmed: false };
|
|
2125
|
+
const more = modelInstances(m, laws, at, mw.goal, mw.w, undefined, false, confirmation);
|
|
2054
2126
|
if (modelsTrace)
|
|
2055
|
-
console.error(`[models] round ${round} ${mw
|
|
2056
|
-
if (
|
|
2127
|
+
console.error(`[models] round ${round} ${mw.goal.name}: ${confirmation.confirmed ? 'confirmed' : confirmation.why}, cap ${Math.round(cap)}`);
|
|
2128
|
+
if (confirmation.confirmed)
|
|
2057
2129
|
return { result, inst: at };
|
|
2130
|
+
if (pastWall())
|
|
2131
|
+
return abandon('wall reached');
|
|
2132
|
+
if (rounds !== 'progress' && round >= rounds)
|
|
2133
|
+
return abandon('round limit reached');
|
|
2134
|
+
if (!more || sameInstances(at, more))
|
|
2135
|
+
return abandon(confirmation.why ?? 'no eligible progress');
|
|
2058
2136
|
at = more;
|
|
2059
2137
|
}
|
|
2060
2138
|
}
|
|
@@ -2352,7 +2430,7 @@ export function instancesFor(m, laws, build, opts = {}) {
|
|
|
2352
2430
|
const reads = opts.reads ?? (!opts.seed || shifts(m) || laws.some(l => l.keys?.length) || pairFlags(m));
|
|
2353
2431
|
for (let round = 0; round < 2 && !pastWall(); round++) {
|
|
2354
2432
|
if (m.facts?.length)
|
|
2355
|
-
inst = withFacts(m, inst, fnKeys(m, build(inst)));
|
|
2433
|
+
inst = hasFunctionInstances(m) ? extendFunctionInstances(m, inst, build(inst), (rest, prior, goals) => withFacts(rest, prior, fnKeys(rest, goals))) : withFacts(m, inst, fnKeys(m, build(inst)));
|
|
2356
2434
|
if (reads) {
|
|
2357
2435
|
const { keys, byMap } = mapReads(build(inst));
|
|
2358
2436
|
inst = union(withReads(laws, inst, keys, opts.focus ?? [], byMap, Object.keys(m.fns ?? {})), flagInstances(m, keys, opts.focus), m);
|
|
@@ -2579,7 +2657,8 @@ export function proveLaws(m, laws) {
|
|
|
2579
2657
|
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 }));
|
|
2580
2658
|
if ('stuck' in out)
|
|
2581
2659
|
return { proven: false, nodes: 0, leaves: 0, failed: { goal: 'witnesses', stuck: out.stuck }, checked: false };
|
|
2582
|
-
|
|
2660
|
+
const result = proveLawsAsGiven(m, out.items);
|
|
2661
|
+
return retainFrom({ ...result, laws: out.items }, [result], { kind: 'some-key', originalLaws: laws, resolvedLaws: out.items });
|
|
2583
2662
|
}
|
|
2584
2663
|
// One law's two goals, every law assumed (core/infer.ts adds laws one at a time and reproves only what isn't proven
|
|
2585
2664
|
// yet); not a proof of the set, which proveLaws gives. Laws with some key go through proveLaws.
|
|
@@ -2602,12 +2681,14 @@ const pointed = (laws, f) => {
|
|
|
2602
2681
|
};
|
|
2603
2682
|
// (a probe's hook: each decision with its machine, set, index and ms)
|
|
2604
2683
|
export const decideLawHook = {};
|
|
2605
|
-
export function decideLaw(m, laws, i, rounds =
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2684
|
+
export function decideLaw(m, laws, i, rounds = effectiveModelRounds()) {
|
|
2685
|
+
return withModelRounds(rounds, () => {
|
|
2686
|
+
if (!decideLawHook.on)
|
|
2687
|
+
return decideLaw0(m, laws, i, rounds);
|
|
2688
|
+
const t0 = traceNow(), out = decideLaw0(m, laws, i, rounds);
|
|
2689
|
+
decideLawHook.on(m, laws, i, out, traceNow() - t0);
|
|
2690
|
+
return out;
|
|
2691
|
+
});
|
|
2611
2692
|
}
|
|
2612
2693
|
// (why decideLaw last answered nothing: `refuted`, the abstraction refuted a goal whose core's proof didn't finish, a
|
|
2613
2694
|
// goal the CDCL search after it would find no quicker)
|
|
@@ -2679,8 +2760,8 @@ function checkMemoLaw(m, laws, i, cached) {
|
|
|
2679
2760
|
}
|
|
2680
2761
|
return { text: textOfLaw(laws[i]), context: memoContext(m, laws), inst: cached.inst, proofs };
|
|
2681
2762
|
}
|
|
2682
|
-
function memoOf(m) {
|
|
2683
|
-
const key = textsOfMachine(m).text
|
|
2763
|
+
function memoOf(m, rounds = effectiveModelRounds()) {
|
|
2764
|
+
const key = `${textsOfMachine(m).text}\0model-rounds:${rounds}`;
|
|
2684
2765
|
let memo = memos.get(key);
|
|
2685
2766
|
if (!memo) {
|
|
2686
2767
|
if (memos.size >= memoCap)
|
|
@@ -2693,7 +2774,7 @@ const stands = (p, byName) => [...p.uses].every(([n, t]) => { const l = byName.g
|
|
|
2693
2774
|
// Law i settled, from what was kept where it still stands (a proof whose support is in the set, a model of a set holding
|
|
2694
2775
|
// this one): else its goals settled again, those whose proofs stand kept.
|
|
2695
2776
|
function settled(m, laws, i, rounds, usual, consumer = 'decision', attempt = memoAttempt()) {
|
|
2696
|
-
const law = laws[i], memo = memoOf(m), byName = new Map(laws.map(l => [l.name, l])), text = textOfLaw(law);
|
|
2777
|
+
const law = laws[i], memo = memoOf(m, rounds), byName = new Map(laws.map(l => [l.name, l])), text = textOfLaw(law);
|
|
2697
2778
|
if (attempt.fresh.has(law.name))
|
|
2698
2779
|
return attempt.fresh.get(law.name);
|
|
2699
2780
|
const was = !attempt.cold.has(law.name) ? memo.proven.get(law.name) : undefined;
|
|
@@ -2722,7 +2803,7 @@ function settled(m, laws, i, rounds, usual, consumer = 'decision', attempt = mem
|
|
|
2722
2803
|
prev = undefined;
|
|
2723
2804
|
}
|
|
2724
2805
|
memoHits.miss++;
|
|
2725
|
-
const mo = !attempt.cold.has(law.name)
|
|
2806
|
+
const mo = !attempt.cold.has(law.name) ? memo.models.get(law.name) : undefined;
|
|
2726
2807
|
if (mo && (!strict(usual) || mo.strict) && mo.text === text && laws.every(l => mo.set.get(l.name) === textOfLaw(l))) {
|
|
2727
2808
|
if (exactMemoContext(mo.context, m, laws)) {
|
|
2728
2809
|
memoReuseStats.modelHits++;
|
|
@@ -2738,7 +2819,7 @@ function settled(m, laws, i, rounds, usual, consumer = 'decision', attempt = mem
|
|
|
2738
2819
|
x.clear(); return x; };
|
|
2739
2820
|
if (out && 'proofs' in out)
|
|
2740
2821
|
cap(memo.proven).set(law.name, out);
|
|
2741
|
-
else if (out?.stuck === 'sat'
|
|
2822
|
+
else if (out?.stuck === 'sat')
|
|
2742
2823
|
cap(memo.models).set(law.name, { text, context: memoContext(m, laws), model: out, strict: strict(usual), set: new Map(laws.map(l => [l.name, textOfLaw(l)])) });
|
|
2743
2824
|
if (attempt.cold.has(law.name))
|
|
2744
2825
|
attempt.fresh.set(law.name, out);
|
|
@@ -2794,18 +2875,16 @@ function settle(m, laws, i, rounds, usual, prev) {
|
|
|
2794
2875
|
inst = triggered(plainOf(m), laws, inst, i2 => obligations(m, laws, { [law.name]: i2 }, i), law.forall ? [`${law.forall}#`] : []);
|
|
2795
2876
|
const proofs = Object.fromEntries(Object.entries(prev?.proofs ?? {}).filter(([, p]) => stands(p, byName)));
|
|
2796
2877
|
const unknown = (g, why = 'past the search\'s end') => (usual ? { goal: g.name, stuck: 'unknown', why } : undefined);
|
|
2797
|
-
//
|
|
2798
|
-
// finish: a model of fewer instances is still one of the goal as it was asked)
|
|
2878
|
+
// No model of fewer instances survives an unfinished refinement round.
|
|
2799
2879
|
const end = withinDeadline(Infinity);
|
|
2800
|
-
let last;
|
|
2801
2880
|
for (let round = 0;; round++) {
|
|
2802
2881
|
let more;
|
|
2803
|
-
const late = round > rounds ? () => pastWall() || pastEprCap() || clock() > end : () => pastWall() || pastEprCap();
|
|
2882
|
+
const late = rounds !== 'progress' && round > rounds ? () => pastWall() || pastEprCap() || clock() > end : () => pastWall() || pastEprCap();
|
|
2804
2883
|
for (const g of obligations(m, laws, { [law.name]: inst }, i)) {
|
|
2805
2884
|
if (proofs[g.name])
|
|
2806
2885
|
continue;
|
|
2807
2886
|
if (late())
|
|
2808
|
-
return
|
|
2887
|
+
return unknown(g, 'unconfirmed model: search end reached');
|
|
2809
2888
|
// (a wide goal decided over parts (growWide), each part by the EPR path: the abstraction of the whole is quadratic in
|
|
2810
2889
|
// its cells, i4's engine set's step goal of 7,590 hypotheses ran 19M units past its caller's end and 10 GB)
|
|
2811
2890
|
let o = !eprScope.patterns ? undefined : wideFor(g) && tupledScope() ? eprWide(g, late) ?? withEprCap(wideEprUnits, () => eprFirst(g, { nodes: 0, until: clock() + 4_000 }, false, late)) : eprFirst(g, { nodes: 0, until: clock() + 4_000 }, false, late);
|
|
@@ -2821,8 +2900,8 @@ function settle(m, laws, i, rounds, usual, prev) {
|
|
|
2821
2900
|
return undefined;
|
|
2822
2901
|
}
|
|
2823
2902
|
}
|
|
2824
|
-
else if (!o &&
|
|
2825
|
-
return
|
|
2903
|
+
else if (!o && !usual)
|
|
2904
|
+
return undefined;
|
|
2826
2905
|
// (the usual search, the EPR path not asked again)
|
|
2827
2906
|
if (!o) {
|
|
2828
2907
|
const busy = eprScope.busy;
|
|
@@ -2841,24 +2920,25 @@ function settle(m, laws, i, rounds, usual, prev) {
|
|
|
2841
2920
|
continue;
|
|
2842
2921
|
}
|
|
2843
2922
|
if (o.stuck !== 'sat' || !o.witness)
|
|
2844
|
-
return
|
|
2845
|
-
|
|
2846
|
-
// (strict, decideLaw's: a model is returned only where confirmed, no assumed law broken at it over its own domain;
|
|
2847
|
-
// one that breaks only instances of another sort, or that the rounds or the wall cut off, is no answer)
|
|
2848
|
-
const capped = !(round < rounds || (round < 4 * rounds && end !== Infinity && clock() < end)), raw = capped ? undefined : modelInstances(m, laws, inst, g, o.witness, undefined, true);
|
|
2849
|
-
if (!capped && !raw)
|
|
2850
|
-
return last;
|
|
2851
|
-
more = raw && bySort(m, laws, raw);
|
|
2852
|
-
const count = (x) => Object.values(x).reduce((s2, ks) => s2 + ks.length, 0);
|
|
2853
|
-
if (strict(usual) && (capped || pastWall() || !more || count(more) <= count(inst))) {
|
|
2923
|
+
return unknown(g, o.why);
|
|
2924
|
+
const unconfirmed = (why) => {
|
|
2854
2925
|
decideNote.hint = { goal: g.name, witness: o.witness };
|
|
2855
|
-
return
|
|
2856
|
-
}
|
|
2857
|
-
|
|
2858
|
-
if (
|
|
2859
|
-
return
|
|
2860
|
-
|
|
2861
|
-
|
|
2926
|
+
return unknown(g, `unconfirmed model: ${why}`);
|
|
2927
|
+
};
|
|
2928
|
+
const capped = rounds !== 'progress' && !(round < rounds || (round < 4 * rounds && end !== Infinity && clock() < end));
|
|
2929
|
+
if (capped || pastWall())
|
|
2930
|
+
return unconfirmed(capped ? 'round limit reached' : 'wall reached');
|
|
2931
|
+
const confirmation = { confirmed: false };
|
|
2932
|
+
const raw = modelInstances(m, laws, inst, g, o.witness, undefined, true, confirmation);
|
|
2933
|
+
if (modelsTrace)
|
|
2934
|
+
console.error(`[models] settle round ${round} ${g.name}: ${confirmation.confirmed ? 'confirmed' : confirmation.why}`);
|
|
2935
|
+
if (confirmation.confirmed)
|
|
2936
|
+
return { goal: g.name, stuck: 'sat', witness: o.witness, ...(o.diagram ? { diagram: o.diagram } : {}), why: 'a confirmed model' };
|
|
2937
|
+
more = raw && bySort(m, laws, raw);
|
|
2938
|
+
if (pastWall())
|
|
2939
|
+
return unconfirmed('wall reached');
|
|
2940
|
+
if (!more || sameInstances(more, inst))
|
|
2941
|
+
return unconfirmed(confirmation.why ?? 'no eligible progress');
|
|
2862
2942
|
break;
|
|
2863
2943
|
}
|
|
2864
2944
|
if (!more)
|
|
@@ -2893,7 +2973,7 @@ export function proveSetFast(m, laws) {
|
|
|
2893
2973
|
const run = () => {
|
|
2894
2974
|
const at = [];
|
|
2895
2975
|
for (let i = 0; i < laws.length; i++) {
|
|
2896
|
-
const out = settled(m, laws, i,
|
|
2976
|
+
const out = settled(m, laws, i, effectiveModelRounds(), true, 'set', attempt);
|
|
2897
2977
|
if (!('proofs' in out))
|
|
2898
2978
|
return { proven: false, nodes: 0, leaves: 0, checked: false, failed: { goal: out.goal, stuck: out.stuck, ...(out.witness ? { witness: out.witness } : {}), ...(out.why ? { why: out.why } : {}), ...(out.diagram ? { diagram: out.diagram } : {}) } };
|
|
2899
2979
|
at.push(out);
|
|
@@ -2923,7 +3003,7 @@ export function proveSetFast(m, laws) {
|
|
|
2923
3003
|
}
|
|
2924
3004
|
}
|
|
2925
3005
|
const proof = { instances, trees };
|
|
2926
|
-
return { proven: true, nodes, leaves, checked: checkLaws(m, laws, proof), proof };
|
|
3006
|
+
return retainFamily({ proven: true, nodes, leaves, checked: checkLaws(m, laws, proof), proof }, m, laws, proof);
|
|
2927
3007
|
};
|
|
2928
3008
|
const out = run(), retry = [...attempt.reused].filter(name => !attempt.cold.has(name));
|
|
2929
3009
|
if ((!out.proven || !out.checked) && retry.length) {
|
|
@@ -2939,14 +3019,14 @@ export function proveSetFast(m, laws) {
|
|
|
2939
3019
|
export function proveLaw(m, laws, i) {
|
|
2940
3020
|
if (laws.some(l => someKeys(l.holds).length) || someLaws(laws)) {
|
|
2941
3021
|
const r = proveLaws(m, laws);
|
|
2942
|
-
return r.proven ? { proven: true } : { proven: false, goal: r.failed.goal, stuck: r.failed.stuck, ...(r.failed.witness ? { witness: r.failed.witness } : {}) };
|
|
3022
|
+
return r.proven ? { proven: true } : { proven: false, goal: r.failed.goal, stuck: r.failed.stuck, ...(r.failed.witness ? { witness: r.failed.witness } : {}), ...(r.failed.why ? { why: r.failed.why } : {}) };
|
|
2943
3023
|
}
|
|
2944
3024
|
// (the thinned goals too by the EPR path where the rule's keys are composed: withModels' scope, entered here; first
|
|
2945
3025
|
// the law settled by the EPR path as decideLaw settles it, kept where it stands: a caller's verdict rests on its final
|
|
2946
3026
|
// proof, which widens and checks; wo's "a leader has the voting quorum's votes" from its 40-law set, 0.45 s there
|
|
2947
3027
|
// against 25 s to unknown here)
|
|
2948
3028
|
return withPatterns(m, laws, () => {
|
|
2949
|
-
const out = eprScope.patterns && fastShape(m, laws) ? settled(m, laws, i,
|
|
3029
|
+
const out = eprScope.patterns && fastShape(m, laws) ? settled(m, laws, i, effectiveModelRounds(), false, 'law') : undefined;
|
|
2950
3030
|
if (out && 'proofs' in out)
|
|
2951
3031
|
return { proven: true };
|
|
2952
3032
|
if (out?.stuck === 'sat')
|
|
@@ -2997,10 +3077,10 @@ function proveOne(m, laws, i) {
|
|
|
2997
3077
|
}
|
|
2998
3078
|
}
|
|
2999
3079
|
// (a model breaking a law at a tuple of the goal's keys: those added, the law asked again)
|
|
3000
|
-
const { result: a, inst: at } = withModels(m, laws, inst, i2 => obligations(m, laws, { [law.name]: i2 }, i), growAll, grownModel, grownSettled);
|
|
3080
|
+
const { result: a, inst: at } = withModels(m, laws, inst, i2 => obligations(m, laws, { [law.name]: i2 }, i), growAll, grownModel, grownSettled, grownUnknown);
|
|
3001
3081
|
if (!a.out)
|
|
3002
3082
|
remember(at, a.done);
|
|
3003
|
-
return a.out ? { proven: false, goal: a.goal.name, stuck: a.out.stuck, ...(a.out.witness ? { witness: a.out.witness } : {}), ...(a.out.diagram ? { diagram: a.out.diagram } : {}) } : { proven: true };
|
|
3083
|
+
return a.out ? { proven: false, goal: a.goal.name, stuck: a.out.stuck, ...(a.out.witness ? { witness: a.out.witness } : {}), ...(a.out.diagram ? { diagram: a.out.diagram } : {}), ...(a.out.why ? { why: a.out.why } : {}) } : { proven: true };
|
|
3004
3084
|
}
|
|
3005
3085
|
function growAll(gs) {
|
|
3006
3086
|
const done = {};
|
|
@@ -3016,7 +3096,8 @@ function growAll(gs) {
|
|
|
3016
3096
|
return { done, n, lv };
|
|
3017
3097
|
}
|
|
3018
3098
|
const grownModel = (x) => (x.out?.stuck === 'sat' && x.out.witness ? { goal: x.goal, w: x.out.witness } : undefined);
|
|
3019
|
-
const grownSettled = (x) => !x.out || x.out.stuck === 'sat';
|
|
3099
|
+
const grownSettled = (x) => !x.out || (x.out.stuck === 'sat' && !!x.out.witness);
|
|
3100
|
+
const grownUnknown = (x, why) => ({ ...x, out: { stuck: 'unknown', path: x.out?.path ?? new Map(), why } });
|
|
3020
3101
|
// Each law's keys only at keys of their sort (Ivy's sorts; untrusted: an instance left out only weakens a goal, and a
|
|
3021
3102
|
// set's proof is checked over its own instances). A sort is a class of a union-find over places: each part of a map's
|
|
3022
3103
|
// key (by its pattern, `M:map:i`), a map's whole key where a law's key is the whole key (`K:map`), a function's
|
|
@@ -3026,20 +3107,11 @@ const grownSettled = (x) => !x.out || x.out.stuck === 'sat';
|
|
|
3026
3107
|
// anchored sort is left out of the law's tuples there; a composed term is a whole key, of the map whose pattern its
|
|
3027
3108
|
// factors are. GDP_SORTED=0 keeps every instance.
|
|
3028
3109
|
const sortedOn = env.GDP_SORTED !== '0';
|
|
3029
|
-
//
|
|
3030
|
-
//
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
// wrong against Z3 on 43 of wo's 143 top-down goals; GDP_STRICT=0 gives the old answer)
|
|
3035
|
-
const strict = (usual) => !usual && (strictOn || env.GDP_STRICT !== '0');
|
|
3036
|
-
// (strict models for a caller's own decisions: the engine's top-down phase, whose drops an unconfirmed model would make wrong)
|
|
3037
|
-
export const withStrict = (f) => { const o = strictOn; strictOn = true; try {
|
|
3038
|
-
return f();
|
|
3039
|
-
}
|
|
3040
|
-
finally {
|
|
3041
|
-
strictOn = o;
|
|
3042
|
-
} };
|
|
3110
|
+
// SAT admission is always strict, including the usual fallback and cached models.
|
|
3111
|
+
// GDP_STRICT=0 must not turn an unfinished refinement into a deletion witness.
|
|
3112
|
+
const strict = (_usual) => true;
|
|
3113
|
+
// Compatibility scope: all callers now have this conservative admission policy.
|
|
3114
|
+
export const withStrict = (f) => f();
|
|
3043
3115
|
// By immutable machine and ordered, exact law context, including all binding metadata.
|
|
3044
3116
|
export const sortMemoStats = { hits: 0, misses: 0 };
|
|
3045
3117
|
const sortsMemo = new WeakMap();
|
|
@@ -3325,6 +3397,8 @@ function proveLawsAsGiven(m, laws, defer) {
|
|
|
3325
3397
|
defer(finish);
|
|
3326
3398
|
else
|
|
3327
3399
|
finish();
|
|
3400
|
+
if (!defer)
|
|
3401
|
+
retainFamily(out, m, laws, out.proof);
|
|
3328
3402
|
return out;
|
|
3329
3403
|
}
|
|
3330
3404
|
// Whether the usual proof's trees are checked (off while GDP_CERT=cyclic makes the certificate a cyclic proof).
|
|
@@ -3347,7 +3421,7 @@ function thinned(m, laws, instances) {
|
|
|
3347
3421
|
console.error(`[models] law ${law.name}: ${Object.values(full).reduce((a, ks) => a + ks.length, 0)} keys, ${Object.values(few).reduce((a, ks) => a + ks.length, 0)} triggered`);
|
|
3348
3422
|
// (thinned instances first, then the full ones; each asked again at the tuples its models ask for)
|
|
3349
3423
|
for (const inst of sameInstances(few, full) ? [full] : [few, full]) {
|
|
3350
|
-
const { result: a, inst: at } = withModels(m, laws, inst, i2 => obligations(m, laws, { ...instances, [law.name]: i2 }, i), growAll, grownModel, grownSettled);
|
|
3424
|
+
const { result: a, inst: at } = withModels(m, laws, inst, i2 => obligations(m, laws, { ...instances, [law.name]: i2 }, i), growAll, grownModel, grownSettled, grownUnknown);
|
|
3351
3425
|
instances[law.name] = at;
|
|
3352
3426
|
if (inst === full)
|
|
3353
3427
|
fulls[law.name] = at;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const standard: string[];
|
|
2
|
+
export declare function asked(source: string): string[];
|
|
3
|
+
export declare function answers(out: string): {
|
|
4
|
+
name: string;
|
|
5
|
+
axioms: string[];
|
|
6
|
+
}[];
|
|
7
|
+
export declare function gate(out: string, sources: string[], native?: boolean): string[];
|
|
8
|
+
export declare function auditLiftLog(out: string, sources: string[], required: string[], expectedAxioms?: Record<string, string[]>): {
|
|
9
|
+
name: string;
|
|
10
|
+
axioms: string[];
|
|
11
|
+
}[];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Pure audit of native Lean output. This is not a proof checker or a substitute
|
|
2
|
+
// for executing Lean; callers must bind the log to the exact generated sources.
|
|
3
|
+
export const standard = ['propext', 'Classical.choice', 'Quot.sound'];
|
|
4
|
+
const nativeAxiom = (a) => a === 'Lean.ofReduceBool' || a === 'Lean.trustCompiler' || /native_decide\.ax_/.test(a);
|
|
5
|
+
export function asked(source) {
|
|
6
|
+
const code = source.replace(/\/-[\s\S]*?-\//g, '').replace(/--.*$/gm, '');
|
|
7
|
+
return [...code.matchAll(/^#print axioms\s+(\S+)/gm)].map(m => m[1]);
|
|
8
|
+
}
|
|
9
|
+
export function answers(out) {
|
|
10
|
+
const deps = [...out.matchAll(/^'([^\r\n]+)' depends on axioms: \[([^\]]*)\]\r?$/gm)].map(m => ({ name: m[1], axioms: m[2].split(',').map(a => a.trim()).filter(Boolean) }));
|
|
11
|
+
const none = [...out.matchAll(/^'([^\r\n]+)' does not depend on any axioms\r?$/gm)].map(m => ({ name: m[1], axioms: [] }));
|
|
12
|
+
return [...deps, ...none];
|
|
13
|
+
}
|
|
14
|
+
export function gate(out, sources, native = false) {
|
|
15
|
+
const why = [];
|
|
16
|
+
if (/declaration uses 'sorry'/.test(out))
|
|
17
|
+
why.push("a declaration uses 'sorry'");
|
|
18
|
+
for (const a of answers(out)) {
|
|
19
|
+
const extra = a.axioms.filter(x => !standard.includes(x) && !(native && nativeAxiom(x)));
|
|
20
|
+
if (extra.length)
|
|
21
|
+
why.push(`${a.name} depends on ${extra.join(', ')}`);
|
|
22
|
+
}
|
|
23
|
+
const want = sources.flatMap(asked).length, got = answers(out).length;
|
|
24
|
+
if (got < want)
|
|
25
|
+
why.push(`${want} #print axioms asked, ${got} answered`);
|
|
26
|
+
return why;
|
|
27
|
+
}
|
|
28
|
+
export function auditLiftLog(out, sources, required, expectedAxioms) {
|
|
29
|
+
if (!required.length || required.some(n => !/^[A-Za-z_][A-Za-z0-9_.']*$/.test(n)) || new Set(required).size !== required.length)
|
|
30
|
+
throw Error('invalid or empty source theorem coverage');
|
|
31
|
+
const errors = gate(out, sources, false);
|
|
32
|
+
if (/\berror:/.test(out))
|
|
33
|
+
errors.push('Lean reported an error');
|
|
34
|
+
const rows = answers(out), names = [...new Set([...sources.flatMap(asked), ...required])];
|
|
35
|
+
for (const name of names) {
|
|
36
|
+
const found = rows.filter(r => r.name === name);
|
|
37
|
+
if (found.length !== 1)
|
|
38
|
+
errors.push(`expected one axiom answer for ${name}, got ${found.length}`);
|
|
39
|
+
const expected = expectedAxioms?.[name];
|
|
40
|
+
if (expected && found.length === 1 && JSON.stringify([...expected].sort()) !== JSON.stringify([...found[0].axioms].sort()))
|
|
41
|
+
errors.push(`axiom set changed for ${name}`);
|
|
42
|
+
}
|
|
43
|
+
if (expectedAxioms)
|
|
44
|
+
for (const name of Object.keys(expectedAxioms))
|
|
45
|
+
if (!names.includes(name))
|
|
46
|
+
errors.push(`baseline theorem missing: ${name}`);
|
|
47
|
+
if (errors.length)
|
|
48
|
+
throw Error(errors.join('; '));
|
|
49
|
+
return rows.filter(r => names.includes(r.name));
|
|
50
|
+
}
|
|
@@ -68,7 +68,19 @@ export declare function cmachineToLean(id: string, m: Machine, laws: Law[], proo
|
|
|
68
68
|
}, tampers?: {
|
|
69
69
|
what: string;
|
|
70
70
|
certs: Record<string, CountCert>;
|
|
71
|
-
}[]
|
|
71
|
+
}[], options?: {
|
|
72
|
+
extraVars?: string[];
|
|
73
|
+
extraMaps?: string[];
|
|
74
|
+
after?: (basis: {
|
|
75
|
+
vars: readonly string[];
|
|
76
|
+
maps: readonly string[];
|
|
77
|
+
ix: (name: string) => number;
|
|
78
|
+
mx: (name: string) => number;
|
|
79
|
+
machine: (m: Machine) => string;
|
|
80
|
+
condition: (c: C) => string;
|
|
81
|
+
decls: (counts: Machine['counts']) => string;
|
|
82
|
+
}) => string;
|
|
83
|
+
}): string;
|
|
72
84
|
export declare function machineToLean(id: string, m: Machine, laws: Law[], corollary?: string): string;
|
|
73
85
|
export declare const TRUE = ".le (.const 0) (.const 0)";
|
|
74
86
|
export declare const grown: (g: Goal) => Tree;
|
|
@@ -103,6 +115,7 @@ export declare function readable(id: string, laws: Law[], vars: string[], maps:
|
|
|
103
115
|
lit?: (c: C) => string;
|
|
104
116
|
eLit?: (e: E) => string;
|
|
105
117
|
ghosts?: boolean;
|
|
118
|
+
explicitExistentials?: ReadonlySet<string>;
|
|
106
119
|
}): string;
|
|
107
120
|
export type ProgressCase = {
|
|
108
121
|
id: string;
|
|
@@ -156,7 +169,7 @@ export declare function smachineToLean(id: string, given: Machine, laws: Law[],
|
|
|
156
169
|
simp?: string[];
|
|
157
170
|
free?: string[];
|
|
158
171
|
ghosts?: string[];
|
|
159
|
-
after?: (ix: (name: string) => number, mx: (name: string) => number, lit: (m: Machine) => string) => string;
|
|
172
|
+
after?: (ix: (name: string) => number, mx: (name: string) => number, lit: (m: Machine) => string, c: (condition: C) => string) => string;
|
|
160
173
|
historyTampers?: {
|
|
161
174
|
what: string;
|
|
162
175
|
relations: {
|
|
@@ -176,6 +189,7 @@ export declare function smachineToLean(id: string, given: Machine, laws: Law[],
|
|
|
176
189
|
law: string;
|
|
177
190
|
body: C;
|
|
178
191
|
sub: Record<string, E>;
|
|
192
|
+
boundGhosts?: boolean;
|
|
179
193
|
}[];
|
|
180
194
|
refined?: {
|
|
181
195
|
impl: Machine;
|
|
@@ -208,6 +222,14 @@ export declare function smachineToLean(id: string, given: Machine, laws: Law[],
|
|
|
208
222
|
}[];
|
|
209
223
|
}): string;
|
|
210
224
|
export declare const seedStepProof: (m: Machine, laws: Law[], stepLaws: StepLaw[], r: ReturnType<typeof proveStepLaws>) => void;
|
|
225
|
+
export declare function retainedCMachineToLean(id: string, m: Machine, laws: Law[], proof: {
|
|
226
|
+
instances: Record<string, Instances>;
|
|
227
|
+
certs: Record<string, CountCert>;
|
|
228
|
+
}, options?: NonNullable<Parameters<typeof cmachineToLean>[5]>): string;
|
|
229
|
+
export declare function retainedSMachineToLean(id: string, m: Machine, laws: Law[], proof: {
|
|
230
|
+
instances: Record<string, Instances>;
|
|
231
|
+
trees: Record<string, Tree>;
|
|
232
|
+
}, projection?: Pick<NonNullable<Parameters<typeof smachineToLean>[3]>, 'ghosts' | 'ghosted' | 'ghostSubst' | 'forallSome' | 'free' | 'after'>): string;
|
|
211
233
|
export declare const cyclicCerts: () => boolean;
|
|
212
234
|
export declare const certReport: {
|
|
213
235
|
cyclic: string[];
|
|
@@ -351,6 +373,7 @@ export declare function toLean(items: LeanItem[], opts?: {
|
|
|
351
373
|
export { rationalsToLean } from './qlean.js';
|
|
352
374
|
export declare function leanProject(file: string, opts?: {
|
|
353
375
|
name?: string;
|
|
376
|
+
currentFamily?: boolean;
|
|
354
377
|
}): Record<string, string>;
|
|
355
378
|
export type CycBridge = {
|
|
356
379
|
machine: Machine;
|