gdp-wired 0.46.0 → 0.48.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 +18 -5
- package/dist/core/carry.d.ts +15 -0
- package/dist/core/carry.js +651 -0
- package/dist/core/cli.d.ts +4 -1
- package/dist/core/cli.js +31 -11
- package/dist/core/count-cases.d.ts +24 -0
- package/dist/core/count-cases.js +320 -0
- package/dist/core/count-cert-grow.d.ts +4 -0
- package/dist/core/count-cert-grow.js +37 -0
- package/dist/core/count-cert-transport.d.ts +3 -0
- package/dist/core/count-cert-transport.js +58 -0
- package/dist/core/count-completion.d.ts +9 -0
- package/dist/core/count-completion.js +27 -0
- package/dist/core/count-cubes.d.ts +8 -0
- package/dist/core/count-cubes.js +69 -0
- package/dist/core/count-demand.d.ts +37 -0
- package/dist/core/count-demand.js +361 -0
- package/dist/core/count-facts.d.ts +52 -0
- package/dist/core/count-facts.js +247 -0
- package/dist/core/count-focus-proof.d.ts +8 -0
- package/dist/core/count-focus-proof.js +140 -0
- package/dist/core/count-focused.d.ts +22 -0
- package/dist/core/count-focused.js +676 -0
- package/dist/core/count-ranges.d.ts +5 -0
- package/dist/core/count-ranges.js +65 -0
- package/dist/core/count-recovery/action-guard.d.ts +5 -0
- package/dist/core/count-recovery/action-guard.js +51 -0
- package/dist/core/count-recovery/boolean-core.d.ts +16 -0
- package/dist/core/count-recovery/boolean-core.js +258 -0
- package/dist/core/count-recovery/carried-case.d.ts +2 -0
- package/dist/core/count-recovery/carried-case.js +24 -0
- package/dist/core/count-recovery/conditional-check-cache.d.ts +23 -0
- package/dist/core/count-recovery/conditional-check-cache.js +130 -0
- package/dist/core/count-recovery/conditional-cuts.d.ts +6 -0
- package/dist/core/count-recovery/conditional-cuts.js +318 -0
- package/dist/core/count-recovery/conditional-proof.d.ts +19 -0
- package/dist/core/count-recovery/conditional-proof.js +306 -0
- package/dist/core/count-recovery/derivability-closure.d.ts +14 -0
- package/dist/core/count-recovery/derivability-closure.js +533 -0
- package/dist/core/count-recovery/empty-count-source.d.ts +2 -0
- package/dist/core/count-recovery/empty-count-source.js +40 -0
- package/dist/core/count-recovery/field-bound-lemmas.d.ts +23 -0
- package/dist/core/count-recovery/field-bound-lemmas.js +640 -0
- package/dist/core/count-recovery/field-case.d.ts +5 -0
- package/dist/core/count-recovery/field-case.js +89 -0
- package/dist/core/count-recovery/field-demand.d.ts +46 -0
- package/dist/core/count-recovery/field-demand.js +47 -0
- package/dist/core/count-recovery/field-only.d.ts +3 -0
- package/dist/core/count-recovery/field-only.js +18 -0
- package/dist/core/count-recovery/fold-path.d.ts +6 -0
- package/dist/core/count-recovery/fold-path.js +35 -0
- package/dist/core/count-recovery/frame-lemmas.d.ts +9 -0
- package/dist/core/count-recovery/frame-lemmas.js +120 -0
- package/dist/core/count-recovery/guard-cases.d.ts +12 -0
- package/dist/core/count-recovery/guard-cases.js +138 -0
- package/dist/core/count-recovery/key-closure.d.ts +14 -0
- package/dist/core/count-recovery/key-closure.js +62 -0
- package/dist/core/count-recovery/leaf-allowance.d.ts +4 -0
- package/dist/core/count-recovery/leaf-allowance.js +7 -0
- package/dist/core/count-recovery/lift-count-proxies.d.ts +6 -0
- package/dist/core/count-recovery/lift-count-proxies.js +175 -0
- package/dist/core/count-recovery/live-dependencies.d.ts +6 -0
- package/dist/core/count-recovery/live-dependencies.js +76 -0
- package/dist/core/count-recovery/member-inclusions.d.ts +11 -0
- package/dist/core/count-recovery/member-inclusions.js +168 -0
- package/dist/core/count-recovery/member-premises.d.ts +29 -0
- package/dist/core/count-recovery/member-premises.js +114 -0
- package/dist/core/count-recovery/natural-cases.d.ts +6 -0
- package/dist/core/count-recovery/natural-cases.js +59 -0
- package/dist/core/count-recovery/ops.d.ts +6 -0
- package/dist/core/count-recovery/ops.js +8 -0
- package/dist/core/count-recovery/pre-state-source.d.ts +8 -0
- package/dist/core/count-recovery/pre-state-source.js +18 -0
- package/dist/core/count-recovery/rebase-path.d.ts +9 -0
- package/dist/core/count-recovery/rebase-path.js +70 -0
- package/dist/core/count-recovery/rename-proof.d.ts +2 -0
- package/dist/core/count-recovery/rename-proof.js +102 -0
- package/dist/core/count-recovery/row-cases.d.ts +16 -0
- package/dist/core/count-recovery/row-cases.js +291 -0
- package/dist/core/count-recovery/scalar-guards.d.ts +7 -0
- package/dist/core/count-recovery/scalar-guards.js +291 -0
- package/dist/core/count-recovery/source-memo.d.ts +12 -0
- package/dist/core/count-recovery/source-memo.js +67 -0
- package/dist/core/count-select.d.ts +16 -0
- package/dist/core/count-select.js +24 -0
- package/dist/core/count-support.d.ts +598 -0
- package/dist/core/count-support.js +2080 -0
- package/dist/core/count-unions.d.ts +2 -0
- package/dist/core/count-unions.js +139 -0
- package/dist/core/count-witness-flags.d.ts +9 -0
- package/dist/core/count-witness-flags.js +37 -0
- package/dist/core/count-write-frames.d.ts +12 -0
- package/dist/core/count-write-frames.js +206 -0
- package/dist/core/counts.d.ts +20 -2
- package/dist/core/counts.js +807 -156
- package/dist/core/dsl.d.ts +50 -6
- package/dist/core/dsl.js +307 -65
- package/dist/core/effect-schema.d.ts +90 -0
- package/dist/core/effect-schema.js +500 -0
- package/dist/core/effect.d.ts +3 -7
- package/dist/core/effect.js +10 -65
- package/dist/core/exists.d.ts +1 -1
- package/dist/core/exists.js +80 -15
- package/dist/core/extract-check.d.ts +7 -1
- package/dist/core/extract-check.js +161 -19
- package/dist/core/extract-go-check.js +24 -4
- package/dist/core/extract-go.d.ts +7 -0
- package/dist/core/extract-go.js +29 -2
- package/dist/core/extract-read.d.ts +31 -9
- package/dist/core/extract-read.js +36 -11
- package/dist/core/extract-rs.js +58 -14
- package/dist/core/extract-shapes.d.ts +1 -0
- package/dist/core/extract-shapes.js +190 -27
- package/dist/core/extract-standalone.d.ts +3 -0
- package/dist/core/extract-standalone.js +265 -0
- package/dist/core/extract.d.ts +1 -0
- package/dist/core/extract.js +25 -5
- package/dist/core/field-laws.d.ts +2 -0
- package/dist/core/field-laws.js +100 -0
- package/dist/core/finite-frontiers.d.ts +5 -0
- package/dist/core/finite-frontiers.js +116 -0
- package/dist/core/finite-houdini.d.ts +52 -0
- package/dist/core/finite-houdini.js +460 -0
- package/dist/core/finite-model.d.ts +13 -0
- package/dist/core/finite-model.js +68 -0
- package/dist/core/finite-tiny.d.ts +72 -0
- package/dist/core/finite-tiny.js +1052 -0
- package/dist/core/infer.d.ts +1 -1
- package/dist/core/infer.js +32 -9
- package/dist/core/laws.d.ts +2 -1
- package/dist/core/laws.js +76 -19
- package/dist/core/lemma-cuts.d.ts +38 -0
- package/dist/core/lemma-cuts.js +365 -0
- package/dist/core/machine.d.ts +39 -2
- package/dist/core/machine.js +240 -35
- package/dist/core/mutate.d.ts +55 -0
- package/dist/core/mutate.js +210 -0
- package/dist/core/native-domain.d.ts +6 -0
- package/dist/core/native-domain.js +114 -0
- package/dist/core/native-law.d.ts +3 -0
- package/dist/core/native-law.js +174 -0
- package/dist/core/quorum-laws.d.ts +5 -0
- package/dist/core/quorum-laws.js +239 -0
- package/dist/core/relational.js +10 -2
- package/dist/core/relevance.d.ts +4 -0
- package/dist/core/relevance.js +79 -0
- package/dist/core/rs/Cargo.toml +1 -1
- package/dist/core/rs/src/main.rs +458 -9
- package/dist/core/runtime-wall.d.ts +3 -0
- package/dist/core/runtime-wall.js +4 -0
- package/dist/core/sample-step.d.ts +16 -0
- package/dist/core/sample-step.js +28 -0
- package/dist/core/source-check.d.ts +44 -0
- package/dist/core/source-check.js +126 -0
- package/dist/core/source-diagnostic.d.ts +1 -0
- package/dist/core/source-diagnostic.js +34 -0
- package/dist/core/support-budget.d.ts +2 -0
- package/dist/core/support-budget.js +6 -0
- package/dist/core/system.js +2 -0
- package/dist/core/wall.d.ts +6 -0
- package/dist/core/wall.js +23 -0
- package/dist/core/watch.js +4 -0
- package/dist/kernel/cdcl.d.ts +4 -0
- package/dist/kernel/cdcl.js +20 -5
- package/dist/kernel/kernel.d.ts +10 -0
- package/dist/kernel/kernel.js +56 -3
- package/dist/kernel/model-sequence.d.ts +2 -2
- package/dist/kernel/model-sequence.js +4 -3
- package/dist/kernel/model-values.d.ts +2 -0
- package/dist/kernel/model-values.js +60 -0
- package/dist/kernel/prove.d.ts +10 -0
- package/dist/kernel/prove.js +56 -8
- package/dist/kernel/prover-rows.d.ts +29 -0
- package/dist/kernel/prover-rows.js +114 -0
- package/dist/lean-kernel/emit.d.ts +39 -2
- package/dist/lean-kernel/emit.js +136 -24
- package/dist/lean-kernel/lean-terms.d.ts +1 -0
- package/dist/lean-kernel/lean-terms.js +13 -5
- package/dist/lean-kernel/library.js +4 -0
- package/dist/lean-kernel/qalpha.d.ts +7 -0
- package/dist/lean-kernel/qalpha.js +40 -0
- package/package.json +5 -1
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
// UNTRUSTED search scopes, not consequences of the source goal. A caller must
|
|
2
|
+
// prove every proposed cut under its scope and retain/check its branch guards.
|
|
3
|
+
import { same, n, walkOnce, x } from "../machine.js";
|
|
4
|
+
import { substC, substE, truth } from "../../kernel/kernel.js";
|
|
5
|
+
import { countsForReads } from "../count-facts.js";
|
|
6
|
+
const id = (value) => JSON.stringify(value);
|
|
7
|
+
// Source goals are shared by many candidate queries. Cache only syntactic
|
|
8
|
+
// hints (never truth/proofs), and do not recursively scan their count-witness
|
|
9
|
+
// tail for each frame. An oversized or cyclic tail cannot suppress count hints.
|
|
10
|
+
const goalHints = new WeakMap();
|
|
11
|
+
function scalarHints(goal) {
|
|
12
|
+
const cached = goalHints.get(goal);
|
|
13
|
+
if (cached?.hyps === goal.hyps)
|
|
14
|
+
return cached.atoms;
|
|
15
|
+
const atoms = [], pending = [goal.hyps], seen = new Set();
|
|
16
|
+
let left = 20000;
|
|
17
|
+
while (pending.length && --left >= 0 && atoms.length < 128) {
|
|
18
|
+
const value = pending.pop();
|
|
19
|
+
if (!value || typeof value !== 'object' || seen.has(value))
|
|
20
|
+
continue;
|
|
21
|
+
seen.add(value);
|
|
22
|
+
const c = value;
|
|
23
|
+
if ((c.op === '<' || c.op === '<=' || c.op === '=') && c.a?.op === 'get' && c.b?.op === 'get'
|
|
24
|
+
&& ['var', 'const'].includes(c.a.key?.op) && ['var', 'const'].includes(c.b.key?.op))
|
|
25
|
+
atoms.push({ op: c.op, a: c.a, b: c.b });
|
|
26
|
+
const children = Object.values(value);
|
|
27
|
+
for (let i = children.length - 1; i >= 0; i--)
|
|
28
|
+
pending.push(children[i]);
|
|
29
|
+
}
|
|
30
|
+
goalHints.set(goal, { hyps: goal.hyps, atoms });
|
|
31
|
+
return atoms;
|
|
32
|
+
}
|
|
33
|
+
// Reject cycles and oversized/deep inputs before the recursive AST helpers run.
|
|
34
|
+
// This is a proposal budget, never a claim about the machine's validity.
|
|
35
|
+
export function bounded(value) {
|
|
36
|
+
const active = new WeakSet(), done = new WeakSet();
|
|
37
|
+
let left = 20000;
|
|
38
|
+
const visit = (v, depth) => {
|
|
39
|
+
if (--left < 0 || depth > 80)
|
|
40
|
+
return false;
|
|
41
|
+
if (!v || typeof v !== 'object')
|
|
42
|
+
return true;
|
|
43
|
+
if (active.has(v))
|
|
44
|
+
return false;
|
|
45
|
+
if (done.has(v))
|
|
46
|
+
return true;
|
|
47
|
+
active.add(v);
|
|
48
|
+
for (const child of Object.values(v))
|
|
49
|
+
if (!visit(child, depth + 1))
|
|
50
|
+
return false;
|
|
51
|
+
active.delete(v);
|
|
52
|
+
done.add(v);
|
|
53
|
+
return true;
|
|
54
|
+
};
|
|
55
|
+
return visit(value, 0);
|
|
56
|
+
}
|
|
57
|
+
// Most source instances are Boolean partitions. They cannot yield a scalar
|
|
58
|
+
// guard; reject them before scanning the machine, flags, or optional goal.
|
|
59
|
+
function scalarSource(ds, reads, inst) {
|
|
60
|
+
const selected = new Set(inst.terms.filter(([k]) => k !== 0).map(([, name]) => name));
|
|
61
|
+
const maps = new Set(reads.filter(([name]) => selected.has(name)).map(r => r[1]));
|
|
62
|
+
let left = 4096;
|
|
63
|
+
for (const d of ds) {
|
|
64
|
+
if (!maps.has(d.map))
|
|
65
|
+
continue;
|
|
66
|
+
const pending = [d.body], seen = new Set();
|
|
67
|
+
while (pending.length && --left >= 0) {
|
|
68
|
+
const value = pending.pop();
|
|
69
|
+
if (!value || typeof value !== 'object' || seen.has(value))
|
|
70
|
+
continue;
|
|
71
|
+
seen.add(value);
|
|
72
|
+
const o = value;
|
|
73
|
+
if ((o.op === '<' || o.op === '<=' || o.op === '=') && o.a?.op === 'get' && o.b?.op === 'get'
|
|
74
|
+
&& [o.a.key, o.b.key].some(key => key.op === 'var' && key.name === d.key))
|
|
75
|
+
return true;
|
|
76
|
+
pending.push(...Object.values(value));
|
|
77
|
+
}
|
|
78
|
+
if (left < 0)
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
/** At most eight deterministic, witness-free scalar comparison conjunctions.
|
|
84
|
+
* Universal equalities only suggest substitutions; nothing here asserts them,
|
|
85
|
+
* adds a hypothesis, mutates the path, or establishes a proof. */
|
|
86
|
+
export function countScalarGuards(m, ds, reads, inst, root, goal) {
|
|
87
|
+
try {
|
|
88
|
+
const selected = new Set(inst.terms.map(([, name]) => name));
|
|
89
|
+
const frame = !!goal && inst.terms.length === 2 && reads.some(([name, map]) => selected.has(name) && map.endsWith('#'));
|
|
90
|
+
if (!frame && !scalarSource(ds, reads, inst))
|
|
91
|
+
return [];
|
|
92
|
+
const picked = reads.filter(([name]) => selected.has(name)), maps = new Set(picked.map(r => r[1]));
|
|
93
|
+
if (!bounded([ds.filter(d => maps.has(d.map)), picked, inst, m.inputs, m.params, m.inputMaps, m.step.flags]))
|
|
94
|
+
return [];
|
|
95
|
+
return propose(m, ds, reads, inst, root, goal);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// Malformed/unsupported ASTs are not a reason to guess a source scope.
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function propose(m, ds, reads, inst, root, goal) {
|
|
103
|
+
const selected = new Set(inst.terms.filter(([k]) => k !== 0).map(([, name]) => name));
|
|
104
|
+
if (!selected.size || inst.terms.some(([k]) => !Number.isSafeInteger(k)))
|
|
105
|
+
return [];
|
|
106
|
+
const flags = Object.entries(m.step.flags ?? {});
|
|
107
|
+
const opaqueFlags = Object.fromEntries(flags.map(([name]) => [name, same(x(`?${name}`), n(1))]));
|
|
108
|
+
const normal = { maps: {}, flags: opaqueFlags };
|
|
109
|
+
// countsForReads substitutes with no flag environment. Encode raw references
|
|
110
|
+
// first, preserving the production ?name representation rather than unfolding
|
|
111
|
+
// a universal predicate into an unbound count member.
|
|
112
|
+
const picked = reads.filter(([name]) => selected.has(name));
|
|
113
|
+
const declarations = ds.filter(d => picked.some(r => r[1] === d.map)).map(d => ({ ...d,
|
|
114
|
+
below: substE(d.below, { ...normal, vars: {} }), body: substE(d.body, { ...normal, vars: {} }) }));
|
|
115
|
+
const counts = countsForReads(declarations, picked);
|
|
116
|
+
if (!counts || counts.length !== selected.size || new Set(picked.map(r => r[0])).size !== picked.length)
|
|
117
|
+
return [];
|
|
118
|
+
const forbidden = new Set([inst.wit, ...reads.map(r => r[0]), ...ds.map(d => d.key)]);
|
|
119
|
+
for (const [name, q] of flags) {
|
|
120
|
+
forbidden.add(`?${name}`);
|
|
121
|
+
if (q.op === 'all')
|
|
122
|
+
for (const key of [q.key, ...q.keys ?? []])
|
|
123
|
+
forbidden.add(key);
|
|
124
|
+
}
|
|
125
|
+
for (const write of Object.values(m.step.maps ?? {}))
|
|
126
|
+
if ('each' in write)
|
|
127
|
+
forbidden.add(write.each);
|
|
128
|
+
const allowed = new Set([...m.inputs, ...m.params]);
|
|
129
|
+
for (const read of picked)
|
|
130
|
+
walkOnce(read[2], (o) => { if (o.op === 'var')
|
|
131
|
+
allowed.add(o.name); });
|
|
132
|
+
for (const name of forbidden)
|
|
133
|
+
allowed.delete(name);
|
|
134
|
+
const used = new Set([...allowed, ...forbidden]);
|
|
135
|
+
walkOnce([declarations, flags], (o) => { if (o.op === 'var')
|
|
136
|
+
used.add(o.name); });
|
|
137
|
+
let member = 'scalar$member';
|
|
138
|
+
while (used.has(member))
|
|
139
|
+
member += '$';
|
|
140
|
+
const countMaps = new Set([...ds.map(d => d.map), ...Object.keys(m.counts ?? {})]);
|
|
141
|
+
const primitiveMaps = (value) => {
|
|
142
|
+
const out = new Set(), followed = new Set();
|
|
143
|
+
const visit = (part) => {
|
|
144
|
+
walkOnce(part, (o) => {
|
|
145
|
+
if (o.op === 'get' && !countMaps.has(o.map))
|
|
146
|
+
out.add(o.map);
|
|
147
|
+
const name = o.op === 'flag' ? o.name : o.op === 'var' && o.name.startsWith('?') ? o.name.slice(1) : undefined;
|
|
148
|
+
if (name !== undefined && !followed.has(name)) {
|
|
149
|
+
followed.add(name);
|
|
150
|
+
const flag = flags.find(([key]) => key === name)?.[1];
|
|
151
|
+
if (flag)
|
|
152
|
+
visit(flag);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
visit(value);
|
|
157
|
+
return out;
|
|
158
|
+
};
|
|
159
|
+
const positive = new Set(inst.terms.filter(([k]) => k > 0).map(([, name]) => name)), carried = new Set(m.inputMaps ?? []);
|
|
160
|
+
const preferred = new Set(counts.filter(c => positive.has(c.v)).flatMap(c => [...primitiveMaps(c.body)].filter(map => carried.has(map))));
|
|
161
|
+
const relevant = preferred.size ? preferred : new Set(counts.flatMap(c => [...primitiveMaps(c.body)]));
|
|
162
|
+
// Named flags remain opaque, rather than recursively following aliases (which
|
|
163
|
+
// may be cyclic). Only active, single-member universal flags supply anchors.
|
|
164
|
+
const cell = (e) => e.op === 'get' && !countMaps.has(e.map)
|
|
165
|
+
&& (e.key.op === 'var' ? allowed.has(e.key.name) : e.key.op === 'const' && Number.isSafeInteger(e.key.value) && e.key.value >= 0);
|
|
166
|
+
const memberCell = (e) => e.op === 'get' && !countMaps.has(e.map) && e.key.op === 'var' && e.key.name === member;
|
|
167
|
+
const anchors = new Map();
|
|
168
|
+
for (const [name, q] of flags) {
|
|
169
|
+
if (q.op !== 'all' || q.keys?.length || truth(same(x(`?${name}`), n(1)), root) !== true)
|
|
170
|
+
continue;
|
|
171
|
+
if (![...primitiveMaps(q.c)].some(map => relevant.has(map)))
|
|
172
|
+
continue;
|
|
173
|
+
const body = substC(q.c, { ...normal, vars: { [q.key]: x(member) } });
|
|
174
|
+
walkOnce(body, (o) => {
|
|
175
|
+
if (o.op !== '=')
|
|
176
|
+
return;
|
|
177
|
+
for (const [from, to] of [[o.a, o.b], [o.b, o.a]]) {
|
|
178
|
+
if (!memberCell(from) || !cell(to))
|
|
179
|
+
continue;
|
|
180
|
+
// Stable first anchor avoids a Cartesian product of equality choices.
|
|
181
|
+
const key = id(from);
|
|
182
|
+
if (!anchors.has(key) && anchors.size < 32)
|
|
183
|
+
anchors.set(key, to);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
const atoms = [], seen = new Set();
|
|
188
|
+
const add = (c) => {
|
|
189
|
+
if (atoms.length >= 32 || !cell(c.a) || !cell(c.b) || id(c.a) === id(c.b) || id(c.a.key) === id(c.b.key))
|
|
190
|
+
return;
|
|
191
|
+
// Equality is symmetric; strict/non-strict comparisons retain direction.
|
|
192
|
+
const key = c.op === '=' ? id([c.op, ...[id(c.a), id(c.b)].sort()]) : id(c);
|
|
193
|
+
if (!seen.has(key)) {
|
|
194
|
+
seen.add(key);
|
|
195
|
+
atoms.push(c);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
const maps = Object.fromEntries([...new Set([...anchors.values()].flatMap(e => e.op === 'get' ? [e.map] : [])),
|
|
199
|
+
...counts.flatMap(c => [...primitiveMaps(c.body)])].map(map => [map, (key) => anchors.get(id({ op: 'get', map, key })) ?? { op: 'get', map, key }]));
|
|
200
|
+
for (const count of counts) {
|
|
201
|
+
const body = substE(count.body, { ...normal, vars: { [count.key]: x(member) } });
|
|
202
|
+
walkOnce(body, (o) => {
|
|
203
|
+
if (o.op !== '<' && o.op !== '<=' && o.op !== '=')
|
|
204
|
+
return;
|
|
205
|
+
let mentions = false;
|
|
206
|
+
walkOnce(o, (v) => { if (v.op === 'var' && v.name === member)
|
|
207
|
+
mentions = true; });
|
|
208
|
+
if (!mentions)
|
|
209
|
+
return;
|
|
210
|
+
const comparison = substC(o, { vars: {}, maps, flags: opaqueFlags });
|
|
211
|
+
if (comparison.op === '<' || comparison.op === '<=' || comparison.op === '=')
|
|
212
|
+
add(comparison);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
const pair = (c) => id([id(c.a.key), id(c.b.key)].sort());
|
|
216
|
+
const goalPairs = new Set(atoms.map(pair)), rowKeys = new Set();
|
|
217
|
+
for (const read of picked)
|
|
218
|
+
walkOnce(read[2], (o) => {
|
|
219
|
+
if (o.op === 'var' && allowed.has(o.name))
|
|
220
|
+
rowKeys.add(id(o));
|
|
221
|
+
});
|
|
222
|
+
// A post body can mention its writing actor only in an update condition,
|
|
223
|
+
// while the carried partner is keyless. Keep those actual input references
|
|
224
|
+
// and active anchor destinations, not all inputs or arbitrary goal rows.
|
|
225
|
+
const inputs = new Set(m.inputs);
|
|
226
|
+
for (const count of counts)
|
|
227
|
+
walkOnce(count.body, (o) => {
|
|
228
|
+
if (o.op === 'var' && inputs.has(o.name) && allowed.has(o.name))
|
|
229
|
+
rowKeys.add(id(o));
|
|
230
|
+
});
|
|
231
|
+
for (const anchor of anchors.values())
|
|
232
|
+
if (cell(anchor))
|
|
233
|
+
rowKeys.add(id(anchor.key));
|
|
234
|
+
// Frame hints must relate a candidate's own row pair, not just any input or
|
|
235
|
+
// witness that occurs in the large source goal. Count comparisons above may
|
|
236
|
+
// also establish the row-to-anchor pair when the carried read is keyless.
|
|
237
|
+
if (goal)
|
|
238
|
+
for (const hint of scalarHints(goal)) {
|
|
239
|
+
if (cell(hint.a) && cell(hint.b)
|
|
240
|
+
&& (goalPairs.has(pair(hint)) || rowKeys.has(id(hint.a.key)) && rowKeys.has(id(hint.b.key))))
|
|
241
|
+
add(hint);
|
|
242
|
+
}
|
|
243
|
+
const fields = (c) => id([c.a.map, c.b.map].sort());
|
|
244
|
+
const out = [], scopes = new Set();
|
|
245
|
+
const emit = (cs) => {
|
|
246
|
+
if (out.length >= 8)
|
|
247
|
+
return;
|
|
248
|
+
const status = cs.map(c => truth(c, root));
|
|
249
|
+
if (status.includes(false))
|
|
250
|
+
return;
|
|
251
|
+
const open = cs.filter((_, i) => status[i] !== true);
|
|
252
|
+
if (!open.length)
|
|
253
|
+
return;
|
|
254
|
+
const key = id(open.map(id).sort());
|
|
255
|
+
if (!scopes.has(key)) {
|
|
256
|
+
scopes.add(key);
|
|
257
|
+
out.push(open);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
const strict = atoms.filter(c => c.op === '<'), equal = atoms.filter(c => c.op === '=');
|
|
261
|
+
// Boolean post/pre frames use equal-view laws, so keep their paired field
|
|
262
|
+
// equalities before optional strict-order alternatives consume the cap.
|
|
263
|
+
if (inst.terms.length === 2 && picked.some(([, map]) => map.endsWith('#'))) {
|
|
264
|
+
for (let i = 0; i < equal.length; i++)
|
|
265
|
+
for (const other of equal.slice(i + 1)) {
|
|
266
|
+
if (pair(equal[i]) === pair(other) && fields(equal[i]) !== fields(other))
|
|
267
|
+
emit([equal[i], other]);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
// Reserve useful lexicographic refinements alongside each strict branch,
|
|
271
|
+
// instead of letting a long tail of singleton comparisons crowd them out.
|
|
272
|
+
for (const c of strict) {
|
|
273
|
+
emit([c]);
|
|
274
|
+
for (const eq of equal)
|
|
275
|
+
if (pair(c) === pair(eq) && fields(c) !== fields(eq))
|
|
276
|
+
emit([eq, c]);
|
|
277
|
+
if (out.length >= 8)
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
for (let i = 0; i < equal.length; i++) {
|
|
281
|
+
const eq = equal[i];
|
|
282
|
+
emit([eq]);
|
|
283
|
+
for (const other of equal.slice(i + 1))
|
|
284
|
+
if (pair(eq) === pair(other) && fields(eq) !== fields(other))
|
|
285
|
+
emit([eq, other]);
|
|
286
|
+
}
|
|
287
|
+
for (const c of atoms)
|
|
288
|
+
if (c.op === '<=')
|
|
289
|
+
emit([c]);
|
|
290
|
+
return out;
|
|
291
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Goal, type Path, type Tree } from '../../kernel/kernel.js';
|
|
2
|
+
export type SourceProofMemo = {
|
|
3
|
+
get: (goal: Goal, path: Path, until: number) => Tree | undefined;
|
|
4
|
+
put: (goal: Goal, path: Path, tree: Tree) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare const sourceMemoStats: {
|
|
7
|
+
foreignAttempts: number;
|
|
8
|
+
foreignHits: number;
|
|
9
|
+
crossLawHits: number;
|
|
10
|
+
localHits: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function sourceProofMemo(scope?: object, context?: string): SourceProofMemo;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { renameProof } from "./rename-proof.js";
|
|
2
|
+
import { clock, widen, withDeadline } from "../../kernel/prove.js";
|
|
3
|
+
import { env } from "../solver.js";
|
|
4
|
+
const scopes = new WeakMap(), fresh = () => ({ entries: new Map(), ids: new WeakMap(), next: 0, indices: new WeakMap() });
|
|
5
|
+
export const sourceMemoStats = { foreignAttempts: 0, foreignHits: 0, crossLawHits: 0, localHits: 0 };
|
|
6
|
+
export function sourceProofMemo(scope, context) {
|
|
7
|
+
const shared = env.GDP_SOURCE_CONTEXTS !== '0';
|
|
8
|
+
let cache = shared && scope ? scopes.get(scope) : undefined;
|
|
9
|
+
if (!cache) {
|
|
10
|
+
cache = fresh();
|
|
11
|
+
if (shared && scope)
|
|
12
|
+
scopes.set(scope, cache);
|
|
13
|
+
}
|
|
14
|
+
const { entries, ids } = cache, data = cache;
|
|
15
|
+
const key = (goal, path) => {
|
|
16
|
+
let id = ids.get(goal);
|
|
17
|
+
if (id === undefined) {
|
|
18
|
+
id = data.next++;
|
|
19
|
+
ids.set(goal, id);
|
|
20
|
+
}
|
|
21
|
+
return (shared ? `${id}/` : '') + JSON.stringify([...path].map(([atom, p]) => [atom, p.holds]).sort(([a], [b]) => String(a).localeCompare(String(b))));
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
get(goal, path, until) {
|
|
25
|
+
if (clock() >= until)
|
|
26
|
+
return undefined;
|
|
27
|
+
const old = entries.get(key(goal, path));
|
|
28
|
+
if (old) {
|
|
29
|
+
const tree = withDeadline(until, () => widen(old.goal, goal, old.tree, {}, old.path, path));
|
|
30
|
+
if (tree) {
|
|
31
|
+
sourceMemoStats.localHits++;
|
|
32
|
+
return tree;
|
|
33
|
+
}
|
|
34
|
+
if (!shared)
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
const distance = (p) => { let n = 0; for (const [id, v] of path)
|
|
38
|
+
if (p.get(id)?.holds !== v.holds)
|
|
39
|
+
n++; for (const id of p.keys())
|
|
40
|
+
if (!path.has(id))
|
|
41
|
+
n++; return n; };
|
|
42
|
+
const nearby = [...entries.values()].filter(e => shared || e.goal === goal).sort((a, b) => Number(b.goal === goal) - Number(a.goal === goal) || distance(a.path) - distance(b.path)).slice(0, 8);
|
|
43
|
+
const foreignEnd = Math.min(until, clock() + 50);
|
|
44
|
+
for (const e of nearby) {
|
|
45
|
+
const foreign = e.goal !== goal;
|
|
46
|
+
if (foreign && clock() >= foreignEnd)
|
|
47
|
+
break;
|
|
48
|
+
if (foreign)
|
|
49
|
+
sourceMemoStats.foreignAttempts++;
|
|
50
|
+
const tree = renameProof(e.goal, e.tree, e.path, path, {}, Math.min(until, clock() + (foreign ? 10 : 25)), goal, shared && env.GDP_SOURCE_INDEX !== '0' ? data.indices : undefined);
|
|
51
|
+
if (tree) {
|
|
52
|
+
if (foreign) {
|
|
53
|
+
sourceMemoStats.foreignHits++;
|
|
54
|
+
if (e.context !== context)
|
|
55
|
+
sourceMemoStats.crossLawHits++;
|
|
56
|
+
}
|
|
57
|
+
else
|
|
58
|
+
sourceMemoStats.localHits++;
|
|
59
|
+
return tree;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
},
|
|
64
|
+
put(goal, path, tree) { const id = key(goal, path); entries.delete(id); entries.set(id, { goal, path: new Map(path), tree, context }); if (shared && entries.size > 128)
|
|
65
|
+
entries.delete(entries.keys().next().value); },
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type C } from './machine.js';
|
|
2
|
+
import { type Goal, type Path } from '../kernel/kernel.js';
|
|
3
|
+
export type CountBoundCandidate = {
|
|
4
|
+
index: number;
|
|
5
|
+
bound: C;
|
|
6
|
+
};
|
|
7
|
+
export type CountBoundSelection = {
|
|
8
|
+
indices: number[];
|
|
9
|
+
assumed: number;
|
|
10
|
+
fallback: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function selectCountBounds(base: Goal, candidates: CountBoundCandidate[], until: number, options?: {
|
|
13
|
+
path?: Path;
|
|
14
|
+
queryMs?: number;
|
|
15
|
+
trace?: (event: Record<string, unknown>) => void;
|
|
16
|
+
}): CountBoundSelection | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { clock, usedHyps } from "../kernel/prove.js";
|
|
2
|
+
import { modelSequence } from "../kernel/model-sequence.js";
|
|
3
|
+
import { REFUTED } from "../kernel/cdcl.js";
|
|
4
|
+
// The arithmetic oracle chooses proposals, never facts. In rank order, add
|
|
5
|
+
// candidate bounds until its refutation core names the ones worth deriving.
|
|
6
|
+
export function selectCountBounds(base, candidates, until, options = {}) {
|
|
7
|
+
const path = options.path ?? new Map(), ask = modelSequence(path), started = clock();
|
|
8
|
+
for (let n = candidates.length ? 1 : 0; n <= candidates.length && clock() < until; n++) {
|
|
9
|
+
const goal = { ...base, hyps: [...base.hyps, ...candidates.slice(0, n).map(c => c.bound)] }, q = ask(goal, Math.min(until, clock() + (options.queryMs ?? 200)));
|
|
10
|
+
const used = 'tree' in q ? usedHyps(goal, q.tree, path) : q.why === REFUTED && q.core ? new Set(q.core) : undefined;
|
|
11
|
+
if (used) {
|
|
12
|
+
const indices = candidates.slice(0, n).filter((_, i) => used.has(base.hyps.length + i)).map(c => c.index);
|
|
13
|
+
options.trace?.({ stage: 'count-core-select', pool: candidates.length, assumed: n, indices, ms: Math.round(clock() - started) });
|
|
14
|
+
return { indices, assumed: n, fallback: false };
|
|
15
|
+
}
|
|
16
|
+
if ('tree' in q || q.stuck !== 'sat')
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
if (clock() >= until)
|
|
20
|
+
return undefined;
|
|
21
|
+
const indices = candidates.map(c => c.index);
|
|
22
|
+
options.trace?.({ stage: 'count-core-select', pool: candidates.length, indices, fallback: true, ms: Math.round(clock() - started) });
|
|
23
|
+
return { indices, assumed: indices.length, fallback: true };
|
|
24
|
+
}
|