gdp-wired 0.44.0 → 0.46.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 +58 -7
- package/dist/core/bitsets.d.ts +2 -0
- package/dist/core/bitsets.js +23 -0
- package/dist/core/bmc.js +6 -2
- package/dist/core/c/reader.d.ts +9 -1
- package/dist/core/c/reader.js +445 -38
- package/dist/core/calendar.d.ts +29 -0
- package/dist/core/calendar.js +82 -0
- package/dist/core/check.js +3 -2
- package/dist/core/cli.d.ts +4 -0
- package/dist/core/cli.js +335 -39
- package/dist/core/compose.js +3 -1
- package/dist/core/counts.d.ts +5 -2
- package/dist/core/counts.js +335 -88
- package/dist/core/cycles.js +8 -1
- package/dist/core/cyclic.d.ts +1 -0
- package/dist/core/cyclic.js +13 -7
- package/dist/core/data-synth.d.ts +3 -0
- package/dist/core/data-synth.js +252 -0
- package/dist/core/data.d.ts +8 -2
- package/dist/core/data.js +1113 -172
- package/dist/core/discover.js +3 -1
- package/dist/core/draft.d.ts +19 -0
- package/dist/core/draft.js +53 -0
- package/dist/core/dsl.d.ts +39 -3
- package/dist/core/dsl.js +250 -31
- package/dist/core/effect-prims.js +2 -2
- package/dist/core/effect.d.ts +1 -4
- package/dist/core/effect.js +1 -15
- package/dist/core/ex/reader.exs +17 -1
- package/dist/core/exists.d.ts +16 -1
- package/dist/core/exists.js +447 -50
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +185 -31
- package/dist/core/extract-check.d.ts +7 -0
- package/dist/core/extract-check.js +115 -3
- package/dist/core/extract-ex.js +3 -3
- package/dist/core/extract-go-check.d.ts +1 -1
- package/dist/core/extract-go-check.js +21 -13
- package/dist/core/extract-go.d.ts +1 -0
- package/dist/core/extract-go.js +58 -9
- package/dist/core/extract-ir.d.ts +1 -0
- package/dist/core/extract-ir.js +15 -0
- package/dist/core/extract-jvm.d.ts +1 -1
- package/dist/core/extract-jvm.js +65 -14
- package/dist/core/extract-orm.d.ts +12 -0
- package/dist/core/extract-orm.js +244 -0
- package/dist/core/extract-print.js +23 -1
- package/dist/core/extract-py.d.ts +1 -0
- package/dist/core/extract-py.js +4 -4
- package/dist/core/extract-rb.js +3 -3
- package/dist/core/extract-read.d.ts +25 -0
- package/dist/core/extract-read.js +60 -5
- package/dist/core/extract-rs.js +22 -20
- package/dist/core/extract-shapes.js +22 -0
- package/dist/core/extract-sol.d.ts +10 -1
- package/dist/core/extract-sol.js +89 -30
- package/dist/core/extract-step.d.ts +201 -4
- package/dist/core/extract-step.js +1514 -111
- package/dist/core/extract-swift.js +24 -13
- package/dist/core/extract.d.ts +9 -0
- package/dist/core/extract.js +88 -7
- package/dist/core/fiber-run.d.ts +5 -0
- package/dist/core/fiber-run.js +18 -0
- package/dist/core/fresh.d.ts +2 -2
- package/dist/core/fresh.js +7 -3
- package/dist/core/go/reader.go +7 -1
- package/dist/core/infer.d.ts +4 -1
- package/dist/core/infer.js +1020 -246
- package/dist/core/jvm/JavaReader.java +33 -8
- package/dist/core/jvm/Jvm.java +20 -1
- package/dist/core/jvm/KtReader.java +59 -6
- package/dist/core/laws.d.ts +10 -3
- package/dist/core/laws.js +193 -14
- package/dist/core/machine.d.ts +16 -3
- package/dist/core/machine.js +212 -28
- package/dist/core/nonterm.js +14 -1
- package/dist/core/orm/harness.js +61 -0
- package/dist/core/orm-fixtures/schema.prisma +5 -0
- package/dist/core/py/harness.py +260 -21
- package/dist/core/py/reader.py +278 -39
- package/dist/core/rb/reader.rb +52 -5
- package/dist/core/reader-fixtures/README.md +28 -0
- package/dist/core/reader-fixtures/c-693042.cpp +8 -0
- package/dist/core/reader-fixtures/go-685506.go +14 -0
- package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
- package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
- package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
- package/dist/core/reader-fixtures/swift-735726.swift +15 -0
- package/dist/core/reader-fixtures/swift-735990.swift +15 -0
- package/dist/core/reader-fixtures/swift-739158.swift +4 -0
- package/dist/core/reader-fixtures/swift-744834.swift +15 -0
- package/dist/core/reader-fixtures/swift-746946.swift +31 -0
- package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
- package/dist/core/relation.d.ts +1 -1
- package/dist/core/relation.js +29 -2
- package/dist/core/relational.js +4 -2
- package/dist/core/rs/src/main.rs +18 -2
- package/dist/core/sample-cache.d.ts +8 -0
- package/dist/core/sample-cache.js +46 -0
- package/dist/core/security.d.ts +38 -0
- package/dist/core/security.js +88 -0
- package/dist/core/sol/harness.py +63 -7
- package/dist/core/sol-concrete.d.ts +23 -0
- package/dist/core/sol-concrete.js +195 -0
- package/dist/core/solver.js +8 -5
- package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
- package/dist/core/system.d.ts +62 -1
- package/dist/core/system.js +263 -4
- package/dist/core/transfer.js +39 -9
- package/dist/core/translate.js +39 -10
- package/dist/core/watch.js +51 -6
- package/dist/interchange/check.js +10 -10
- package/dist/interchange/format.d.ts +4 -0
- package/dist/interchange/format.js +24 -6
- package/dist/kernel/cdcl.d.ts +5 -0
- package/dist/kernel/cdcl.js +88 -10
- package/dist/kernel/epr.js +141 -29
- package/dist/kernel/kernel.d.ts +31 -1
- package/dist/kernel/kernel.js +391 -101
- package/dist/kernel/model-sequence.d.ts +3 -0
- package/dist/kernel/model-sequence.js +34 -0
- package/dist/kernel/prove.d.ts +30 -1
- package/dist/kernel/prove.js +481 -71
- package/dist/kernel/reader.d.ts +3 -0
- package/dist/kernel/reader.js +101 -14
- package/dist/kernel/share.d.ts +1 -0
- package/dist/kernel/share.js +27 -0
- package/dist/lean-kernel/emit.d.ts +9 -3
- package/dist/lean-kernel/emit.js +200 -66
- package/dist/lean-kernel/lean-terms.js +5 -0
- package/dist/lean-kernel/library.js +10 -10
- package/package.json +7 -2
package/dist/kernel/epr.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// capped above every constant they meet, so unsat here is unsat there. It answers unsat with its core (the hypotheses
|
|
6
6
|
// its refutation read: prove.ts proves the goal over those and widens the tree to the whole, which kernel.ts checks), or
|
|
7
7
|
// a model read back as the kernel's witness and judged on every hypothesis, or nothing.
|
|
8
|
-
import { evalC } from "../core/machine.js";
|
|
9
|
-
import { canon, linear } from "./kernel.js";
|
|
8
|
+
import { cpair, evalC, tupleParts } from "../core/machine.js";
|
|
9
|
+
import { canon, linear, projected, projectedC } from "./kernel.js";
|
|
10
10
|
import { env, konst, plus, solve, times, v as tv } from "../core/solver.js";
|
|
11
11
|
import { Simplex } from "./simplex.js";
|
|
12
12
|
// (a term's text, once per object: the decision asks it of the same terms many times)
|
|
@@ -16,13 +16,13 @@ const textOfE = (o) => { let s = textsOf.get(o); if (s === undefined)
|
|
|
16
16
|
// The patterns of a rule: of each map's reads in the step, the assumption, the flags and the laws (not the kinds' laws,
|
|
17
17
|
// whose key is a whole key), the one with the most parts. A read keyed by a write-at-every-key's own name is left out.
|
|
18
18
|
export function patternsOf(m, laws) {
|
|
19
|
-
const out =
|
|
19
|
+
const out = Object.create(null);
|
|
20
20
|
const each = new Set(Object.values(m.step.maps ?? {}).flatMap(w => ('each' in w ? [w.each] : [])));
|
|
21
21
|
const scan = (o) => {
|
|
22
22
|
if (!o || typeof o !== 'object')
|
|
23
23
|
return;
|
|
24
24
|
const x = o;
|
|
25
|
-
if (x.op === 'get' && !x.args && !(x.key.op === 'var' && each.has(x.key.name)) && !(m.fns &&
|
|
25
|
+
if (x.op === 'get' && !x.args && !(x.key.op === 'var' && each.has(x.key.name)) && !(m.fns && Object.hasOwn(m.fns, x.map))) {
|
|
26
26
|
const t = tupleOf(x.key);
|
|
27
27
|
if (t && t.coefs.length > (out[x.map]?.length ?? 0))
|
|
28
28
|
out[x.map] = t.coefs;
|
|
@@ -38,6 +38,26 @@ export function patternsOf(m, laws) {
|
|
|
38
38
|
for (const l of laws)
|
|
39
39
|
if (!(l.name.startsWith('every ') && l.name.endsWith('of its kind')))
|
|
40
40
|
scan(l.holds);
|
|
41
|
+
// (a map read inside another read's key, a Skolem function a ghost map keeps (Sent[W[s]·N + s]): a function of its key
|
|
42
|
+
// too, its reads parts; the step's writes to it are substituted into the goal's reads, so within a goal it is one
|
|
43
|
+
// function)
|
|
44
|
+
const inKey = (o, under) => {
|
|
45
|
+
if (!o || typeof o !== 'object')
|
|
46
|
+
return;
|
|
47
|
+
const x = o;
|
|
48
|
+
if (x.op === 'get' && !x.args && under && !(m.fns && Object.hasOwn(m.fns, x.map)))
|
|
49
|
+
out[x.map] = [0];
|
|
50
|
+
if (x.op === 'get' && !x.args) {
|
|
51
|
+
inKey(x.key, true);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
for (const y of Object.values(o))
|
|
55
|
+
inKey(y, under);
|
|
56
|
+
};
|
|
57
|
+
inKey(m.step, false);
|
|
58
|
+
inKey(m.assume, false);
|
|
59
|
+
for (const l of laws)
|
|
60
|
+
inKey(l.holds, false);
|
|
41
61
|
return out;
|
|
42
62
|
}
|
|
43
63
|
const T = { k: 'c', b: true }, Fa = { k: 'c', b: false };
|
|
@@ -45,16 +65,23 @@ const and = (xs) => { const ys = xs.filter(x => !(x.k === 'c' && x.b)); return y
|
|
|
45
65
|
const or = (xs) => { const ys = xs.filter(x => !(x.k === 'c' && !x.b)); return ys.some(x => x.k === 'c' && x.b) ? T : ys.length === 0 ? Fa : ys.length === 1 ? ys[0] : { k: 'or', xs: ys }; };
|
|
46
66
|
const not = (x) => (x.k === 'c' ? { k: 'c', b: !x.b } : x.k === 'not' ? x.x : { k: 'not', x });
|
|
47
67
|
// The functions of one key of the goal being decided (patterns [0]): a read f(x) of one at a part is a part, `f(x)`.
|
|
48
|
-
let fnMaps = new Set();
|
|
68
|
+
let fnMaps = new Set(), fnSignature = '';
|
|
49
69
|
const partName = (e) => e.op === 'var' ? e.name
|
|
50
70
|
: e.op === 'get' && fnMaps.has(e.map) && !e.args ? (n => (n === undefined ? undefined : `${e.map}(${n})`))(partName(e.key)) : undefined;
|
|
51
71
|
// A key Σ c·x + d as its terms; undefined where it reads anything but parts under constant factors.
|
|
52
72
|
const linTerms = (e, k, out, d) => e.op === 'var' || e.op === 'get' ? (n => n !== undefined && (out.push([n, k]), true))(partName(e)) : e.op === 'const' ? ((d.c += k * e.value), true)
|
|
53
73
|
: e.op === 'mul' ? linTerms(e.a, k * e.k, out, d) : e.op === 'add' ? linTerms(e.a, k, out, d) && linTerms(e.b, k, out, d) : false;
|
|
54
74
|
const tupleMemo = new WeakMap();
|
|
55
|
-
function tupleOf(e) { let
|
|
56
|
-
tupleMemo.set(e, (
|
|
75
|
+
function tupleOf(e) { let memo = tupleMemo.get(e); if (!memo)
|
|
76
|
+
tupleMemo.set(e, (memo = new Map())); let t = memo.get(fnSignature); if (t === undefined)
|
|
77
|
+
memo.set(fnSignature, (t = tupleOf0(e) ?? null)); return t ?? undefined; }
|
|
57
78
|
function tupleOf0(e) {
|
|
79
|
+
// A tuple key (core/machine.ts's tup): its parts, each a name, compared part by part; its pattern n zeros (no radix
|
|
80
|
+
// pattern has a 0), no part bounded (the pairing is a bijection: equal keys, equal parts).
|
|
81
|
+
if (e.op === 'tup') {
|
|
82
|
+
const ps = tupleParts(e).map(partName);
|
|
83
|
+
return ps.every(p => p !== undefined) ? { coefs: ps.map(() => 0), parts: ps, bounds: ps.map(() => undefined) } : undefined;
|
|
84
|
+
}
|
|
58
85
|
const ts = [], d = { c: 0 };
|
|
59
86
|
if (!linTerms(e, 1, ts, d) || d.c !== 0 || !ts.length)
|
|
60
87
|
return undefined;
|
|
@@ -69,6 +96,9 @@ const sameCoefs = (a, b) => a.length === b.length && a.every((c, i) => c === b[i
|
|
|
69
96
|
// (a probe's hook: each decision with its goal, ms and outcome)
|
|
70
97
|
export const decideHook = {};
|
|
71
98
|
let lastShaped;
|
|
99
|
+
const projectedMemo = new WeakMap();
|
|
100
|
+
const projectedOf = (g) => { let o = projectedMemo.get(g); if (!o)
|
|
101
|
+
projectedMemo.set(g, (o = { ...g, hyps: g.hyps.map(projectedC) })); return o; };
|
|
72
102
|
export function decide(goal, patterns, opts = {}) {
|
|
73
103
|
if (!decideHook.on)
|
|
74
104
|
return decide1(goal, patterns, opts);
|
|
@@ -77,8 +107,11 @@ export function decide(goal, patterns, opts = {}) {
|
|
|
77
107
|
return d;
|
|
78
108
|
}
|
|
79
109
|
function decide1(goal0, patterns, opts = {}) {
|
|
110
|
+
const previous = fnMaps, previousSignature = fnSignature;
|
|
80
111
|
fnMaps = new Set(Object.entries(patterns).filter(([, c]) => c.length === 1 && c[0] === 0).map(([f]) => f));
|
|
81
|
-
|
|
112
|
+
fnSignature = JSON.stringify([...fnMaps].sort());
|
|
113
|
+
// (a tuple's part read back, proj(tup(a, b)), as the part: the kernel's linear reads it so)
|
|
114
|
+
const goal = JSON.stringify(goal0.hyps).includes('"op":"proj"') ? projectedOf(goal0) : goal0;
|
|
82
115
|
// (a model whose order leaves no room between two near constants: again with the constants between them, below)
|
|
83
116
|
// (a model the read-back breaks: once more without the other goals' theory lemmas, whose history chose that model)
|
|
84
117
|
try {
|
|
@@ -91,7 +124,8 @@ function decide1(goal0, patterns, opts = {}) {
|
|
|
91
124
|
throw e;
|
|
92
125
|
}
|
|
93
126
|
finally {
|
|
94
|
-
fnMaps =
|
|
127
|
+
fnMaps = previous;
|
|
128
|
+
fnSignature = previousSignature;
|
|
95
129
|
}
|
|
96
130
|
}
|
|
97
131
|
// A read at a key that holds an if (a write at every key read at a ghost's key, M'[c ? w : y]) as the if of the reads at
|
|
@@ -107,12 +141,46 @@ const hasIf = (o) => {
|
|
|
107
141
|
ifMemo.set(o, (b = o.op === 'if' || Object.values(o).some(hasIf)));
|
|
108
142
|
return b;
|
|
109
143
|
};
|
|
110
|
-
const
|
|
111
|
-
|
|
144
|
+
const underMemo = new WeakMap();
|
|
145
|
+
const underGuard = (e, guard, yes) => {
|
|
146
|
+
if (!hasIf(e))
|
|
147
|
+
return e;
|
|
148
|
+
const id = textOfE(guard), key = `${yes}:${id}`, memo = underMemo.get(e) ?? new Map();
|
|
149
|
+
if (!underMemo.has(e))
|
|
150
|
+
underMemo.set(e, memo);
|
|
151
|
+
const was = memo.get(key);
|
|
152
|
+
if (was)
|
|
153
|
+
return was;
|
|
154
|
+
const visit = (o) => {
|
|
155
|
+
if (!o || typeof o !== 'object' || !hasIf(o))
|
|
156
|
+
return o;
|
|
157
|
+
if (Array.isArray(o)) {
|
|
158
|
+
const xs = o.map(visit);
|
|
159
|
+
return xs.every((x, i) => x === o[i]) ? o : xs;
|
|
160
|
+
}
|
|
161
|
+
const t = o;
|
|
162
|
+
if (t.op === 'if' && textOfE(t.c) === id)
|
|
163
|
+
return visit(yes ? t.then : t.else);
|
|
164
|
+
let changed = false;
|
|
165
|
+
const entries = Object.entries(o).map(([k, v]) => { const next = visit(v); if (next !== v)
|
|
166
|
+
changed = true; return [k, next]; });
|
|
167
|
+
return changed ? Object.fromEntries(entries) : o;
|
|
168
|
+
};
|
|
169
|
+
const out = visit(e);
|
|
170
|
+
memo.set(key, out);
|
|
171
|
+
return out;
|
|
172
|
+
};
|
|
173
|
+
const hoistMemo = new WeakMap();
|
|
174
|
+
const hoisted = (e) => { const was = hoistMemo.get(e); if (was)
|
|
175
|
+
return was; const out = hoisted0(e); hoistMemo.set(e, out); return out; };
|
|
176
|
+
const hoisted0 = (e) => {
|
|
177
|
+
if (e.op === 'if')
|
|
178
|
+
return { ...e, then: hoisted(underGuard(e.then, e.c, true)), else: hoisted(underGuard(e.else, e.c, false)) };
|
|
179
|
+
if (e.op === 'add' || e.op === 'tup') {
|
|
112
180
|
const a = hoisted(e.a), b = hoisted(e.b);
|
|
113
|
-
return a.op === 'if' ? { op: 'if', c: a.c, then: hoisted({ ...e, a: a.then, b }), else: hoisted({ ...e, a: a.else, b }) } : b.op === 'if' ? { op: 'if', c: b.c, then: hoisted({ ...e, a, b: b.then }), else: hoisted({ ...e, a, b: b.else }) } : a === e.a && b === e.b ? e : { ...e, a, b };
|
|
181
|
+
return a.op === 'if' ? { op: 'if', c: a.c, then: hoisted({ ...e, a: a.then, b: underGuard(b, a.c, true) }), else: hoisted({ ...e, a: a.else, b: underGuard(b, a.c, false) }) } : b.op === 'if' ? { op: 'if', c: b.c, then: hoisted({ ...e, a: underGuard(a, b.c, true), b: b.then }), else: hoisted({ ...e, a: underGuard(a, b.c, false), b: b.else }) } : a === e.a && b === e.b ? e : { ...e, a, b };
|
|
114
182
|
}
|
|
115
|
-
if (e.op === 'mul') {
|
|
183
|
+
if (e.op === 'mul' || e.op === 'proj') {
|
|
116
184
|
const a = hoisted(e.a);
|
|
117
185
|
return a.op === 'if' ? { op: 'if', c: a.c, then: hoisted({ ...e, a: a.then }), else: hoisted({ ...e, a: a.else }) } : a === e.a ? e : { ...e, a };
|
|
118
186
|
}
|
|
@@ -157,6 +225,25 @@ const liftC = (c) => {
|
|
|
157
225
|
if (c.op === 'flag')
|
|
158
226
|
return c;
|
|
159
227
|
const a = liftE(c.a), b = liftE(c.b);
|
|
228
|
+
// (a comparison whose side holds an if over a map's read, a key a ghost's write is read in (64·W'[k] + k = 64·s + d),
|
|
229
|
+
// as the if of the comparisons of its two sides: c ∧ (a₁ ⋈ b) ∨ ¬c ∧ (a₂ ⋈ b), equal to it; at most three ifs in all,
|
|
230
|
+
// counted before they are distributed, 8 leaves)
|
|
231
|
+
const guards = new Set(), seen = new WeakSet();
|
|
232
|
+
const countGuards = (o) => { if (!o || typeof o !== 'object' || seen.has(o) || guards.size > 3)
|
|
233
|
+
return; seen.add(o); const t = o; if (t.op === 'if')
|
|
234
|
+
guards.add(textOfE(t.c)); for (const v of Object.values(o))
|
|
235
|
+
countGuards(v); };
|
|
236
|
+
if (hasIf(a))
|
|
237
|
+
countGuards(a);
|
|
238
|
+
if (hasIf(b))
|
|
239
|
+
countGuards(b);
|
|
240
|
+
const reads = (e) => textOfE(e).includes('"op":"get"');
|
|
241
|
+
const few = guards.size > 0 && guards.size <= 3, ha = few ? hoisted(a) : a, hb = few ? hoisted(b) : b;
|
|
242
|
+
if (few && ((ha.op === 'if' && reads(ha)) || (hb.op === 'if' && reads(hb))) && keysOf(ha) * keysOf(hb) <= 8) {
|
|
243
|
+
const split = (x, y) => (x.op === 'if' ? { op: 'or', xs: [{ op: 'and', xs: [x.c, split(x.then, y)] }, { op: 'and', xs: [{ op: 'not', x: x.c }, split(x.else, y)] }] }
|
|
244
|
+
: y.op === 'if' ? { op: 'or', xs: [{ op: 'and', xs: [y.c, split(x, y.then)] }, { op: 'and', xs: [{ op: 'not', x: y.c }, split(x, y.else)] }] } : { ...c, a: x, b: y });
|
|
245
|
+
return liftC(split(ha, hb));
|
|
246
|
+
}
|
|
160
247
|
return a === c.a && b === c.b ? c : { ...c, a, b };
|
|
161
248
|
};
|
|
162
249
|
const liftedKeys = (c) => { let x = liftMemo.get(c); if (!x)
|
|
@@ -257,9 +344,9 @@ const compInfo = (c) => {
|
|
|
257
344
|
(k(e.then), k(e.else)); };
|
|
258
345
|
k(c.a);
|
|
259
346
|
k(c.b);
|
|
260
|
-
compMemo.set(c, (x = { ts, top: Math.max(1, ...consts)
|
|
347
|
+
compMemo.set(c, (x = { ts, top: Math.max(1, ...consts) }));
|
|
261
348
|
}
|
|
262
|
-
return x;
|
|
349
|
+
return { ...x, ta: tupleOf(c.a), tb: tupleOf(c.b) };
|
|
263
350
|
};
|
|
264
351
|
function stateOf(fs, patterns, tick) {
|
|
265
352
|
const fits = (map, key) => { const t = tupleOf(key), p = patterns[map]; return t && p && sameCoefs(t.coefs, p) ? t : undefined; };
|
|
@@ -1051,11 +1138,7 @@ function encoder(st, patterns) {
|
|
|
1051
1138
|
if (theory.length && !opts.fresh)
|
|
1052
1139
|
seedLemmas();
|
|
1053
1140
|
// EPR-shaped: no comparison the abstraction can't read (a counter's arithmetic, a sum, a product) in any hypothesis
|
|
1054
|
-
|
|
1055
|
-
const loose = [...gOpq].filter(x => { const o = opqs.get(x); return o.foreign && !o.tied; }).length;
|
|
1056
|
-
if (loose)
|
|
1057
|
-
return { unknown: `${loose} comparisons outside the EPR shape` };
|
|
1058
|
-
}
|
|
1141
|
+
const loose = opts.exact ? [...gOpq].filter(x => { const o = opqs.get(x); return o.foreign && !o.tied; }) : [];
|
|
1059
1142
|
// --- the search, the goal's hypotheses assumed
|
|
1060
1143
|
if (opts.late?.())
|
|
1061
1144
|
return { unknown: 'past the deadline' };
|
|
@@ -1323,7 +1406,7 @@ function encoder(st, patterns) {
|
|
|
1323
1406
|
return exact();
|
|
1324
1407
|
};
|
|
1325
1408
|
const outcome = (o) => (typeof o === 'string' ? { unknown: o } : o === undefined ? { unknown: 'the conflict budget ran out, or the deadline' }
|
|
1326
|
-
: !o.sat ? { sat: false, core: [...new Set([...o.core].flatMap(g => (index.has(g) ? [index.get(g)] : [])))].sort((a, b) => a - b) } : { model: o.model });
|
|
1409
|
+
: !o.sat ? { sat: false, core: [...new Set([...o.core].flatMap(g => (index.has(g) ? [index.get(g)] : [])))].sort((a, b) => a - b) } : loose.length ? { unknown: `${loose.length} comparisons outside the EPR shape` } : { model: o.model });
|
|
1327
1410
|
// the goal's own terms, for the read-back: its finite variables, cells (of its maps' patterns, and at keys of the
|
|
1328
1411
|
// wrong sort), ordered cells and functions' parts
|
|
1329
1412
|
const gFinsL = finsList.filter(f => gFins.has(f)), cellsOf = new Map(), odd = [];
|
|
@@ -1355,7 +1438,7 @@ function encoder(st, patterns) {
|
|
|
1355
1438
|
// grouping, as without one)
|
|
1356
1439
|
const finish = (model, theoryVal) => {
|
|
1357
1440
|
const val = (l) => model[l] === true;
|
|
1358
|
-
const w =
|
|
1441
|
+
const w = Object.create(null); // (a name __proto__ kept, constructor read as no value)
|
|
1359
1442
|
for (const f of gFinsL) {
|
|
1360
1443
|
let x = 0;
|
|
1361
1444
|
for (let val2 = 0; val2 <= f.cap; val2++)
|
|
@@ -1379,6 +1462,7 @@ function encoder(st, patterns) {
|
|
|
1379
1462
|
const tight = new Set(succList.filter(x => val(x.s)).map(x => `${groupOf.get(x.lo)}>${groupOf.get(x.hi)}`));
|
|
1380
1463
|
const tied = (i) => tight.has(`${i}>${i + 1}`);
|
|
1381
1464
|
let prev = -1, far = 0;
|
|
1465
|
+
const tupled = Object.values(patterns).some(c => c.length > 1 && c[0] === 0);
|
|
1382
1466
|
for (const [gi, g] of groups.entries()) {
|
|
1383
1467
|
const c = constOf(g);
|
|
1384
1468
|
if (Number.isNaN(c))
|
|
@@ -1391,7 +1475,8 @@ function encoder(st, patterns) {
|
|
|
1391
1475
|
break;
|
|
1392
1476
|
}
|
|
1393
1477
|
}
|
|
1394
|
-
|
|
1478
|
+
// (a goal with tuple keys spaces its far values less: a tuple of them is their pairing, which must stay exact)
|
|
1479
|
+
let x = c ?? (next === Infinity && prev > 0 ? (tupled ? 64 : 1 << 24) * ++far + (tupled ? 7 : 997) * far + prev + 13 : prev + 1);
|
|
1395
1480
|
if (c === undefined && next !== Infinity && x % 2 === 0 && x + 1 < next)
|
|
1396
1481
|
x++;
|
|
1397
1482
|
if (c === undefined && gi > 0 && tied(gi - 1))
|
|
@@ -1436,7 +1521,19 @@ function encoder(st, patterns) {
|
|
|
1436
1521
|
odd2.push(o);
|
|
1437
1522
|
}
|
|
1438
1523
|
// every read of the goal, at its key's value under w: the abstraction's value where it has one, else 0
|
|
1439
|
-
|
|
1524
|
+
// (a tuple key's value its parts' pairing; a part read back from a tuple, the part)
|
|
1525
|
+
const keyVal = (e) => { if (e.op === 'tup') {
|
|
1526
|
+
const ps = tupleParts(e).map(keyVal);
|
|
1527
|
+
if (ps.some(x => x === undefined))
|
|
1528
|
+
return undefined;
|
|
1529
|
+
try {
|
|
1530
|
+
return ps.slice(0, -1).reduceRight((b, a) => cpair(a, b), ps.at(-1));
|
|
1531
|
+
}
|
|
1532
|
+
catch {
|
|
1533
|
+
return undefined;
|
|
1534
|
+
}
|
|
1535
|
+
} return keyVal0(e); };
|
|
1536
|
+
const keyVal0 = (e) => { const ts = [], d = { c: 0 }; if (!linTerms(e, 1, ts, d))
|
|
1440
1537
|
return undefined; let s = d.c; for (const [x, c] of ts) {
|
|
1441
1538
|
if (w[x] === undefined)
|
|
1442
1539
|
return undefined;
|
|
@@ -1484,7 +1581,13 @@ function encoder(st, patterns) {
|
|
|
1484
1581
|
[...reads].reverse().forEach(fnOdd);
|
|
1485
1582
|
for (const [mp, cs] of cells2)
|
|
1486
1583
|
for (const c of cs) {
|
|
1487
|
-
|
|
1584
|
+
let key;
|
|
1585
|
+
try {
|
|
1586
|
+
key = patterns[mp][0] === 0 ? c.parts.slice(0, -1).reduceRight((b, p) => cpair(w[p], b), w[c.parts.at(-1)]) : c.parts.reduce((s, p, i) => s + w[p] * (patterns[mp][i] ?? 1), 0);
|
|
1587
|
+
}
|
|
1588
|
+
catch {
|
|
1589
|
+
return { unknown: 'a tuple key of the model past 2^53' };
|
|
1590
|
+
}
|
|
1488
1591
|
if (!maps.has(mp))
|
|
1489
1592
|
maps.set(mp, new Map());
|
|
1490
1593
|
maps.get(mp).set(key, cellVal.get(c.id));
|
|
@@ -1505,7 +1608,7 @@ function encoder(st, patterns) {
|
|
|
1505
1608
|
allMaps.add(x.map);
|
|
1506
1609
|
const st2 = { scalars: {}, maps: Object.fromEntries([...allMaps].map(mp => [mp, maps.get(mp) ?? new Map()])) };
|
|
1507
1610
|
const m = { name: goal.name, params: [], inputs: [], state: {}, step: {}, maps: Object.fromEntries([...allMaps].map(mp => [mp, 0])) };
|
|
1508
|
-
const env = new Proxy({ ...w }, { get: (t, q) => t[q]
|
|
1611
|
+
const env = new Proxy({ ...w }, { get: (t, q) => (Object.hasOwn(t, q) ? t[q] : 0) });
|
|
1509
1612
|
for (const [i, f] of fs.entries()) {
|
|
1510
1613
|
tick();
|
|
1511
1614
|
try {
|
|
@@ -1521,13 +1624,22 @@ function encoder(st, patterns) {
|
|
|
1521
1624
|
const witness = { ...w };
|
|
1522
1625
|
for (const x of reads) {
|
|
1523
1626
|
tick();
|
|
1524
|
-
const
|
|
1525
|
-
if (
|
|
1627
|
+
const key = x.key.op === 'tup' || x.key.op === 'proj' ? projected(x.key) : x.key, kv = keyVal(key);
|
|
1628
|
+
if (kv === undefined)
|
|
1629
|
+
continue;
|
|
1630
|
+
if (key.op === 'tup') {
|
|
1631
|
+
const cell = linear({ op: 'get', map: x.map, key }, new Map());
|
|
1632
|
+
if (cell)
|
|
1633
|
+
witness[Object.keys(cell)[0]] = st2.maps[x.map]?.get(kv) ?? 0;
|
|
1634
|
+
continue;
|
|
1635
|
+
}
|
|
1636
|
+
const l = linear(key, new Map());
|
|
1637
|
+
if (l)
|
|
1526
1638
|
witness[`${x.map}[${canon(l)}]`] = st2.maps[x.map]?.get(kv) ?? 0;
|
|
1527
1639
|
}
|
|
1528
1640
|
// the structure
|
|
1529
1641
|
const values = [...new Set([...[...parts].map(x => w[x]), ...[...ordVal].filter(([t]) => !t.startsWith('k:') && !t.includes('#')).map(([, x]) => x)].filter((x) => x !== undefined))].sort((a, b) => a - b), elem = new Map(values.map((x, i) => [x, i]));
|
|
1530
|
-
const diagram = { elements: values.length, parts:
|
|
1642
|
+
const diagram = { elements: values.length, parts: Object.create(null), scalars: Object.create(null), cells: Object.create(null), fns: Object.create(null) };
|
|
1531
1643
|
for (const x of [...parts, ...ordScalars].sort())
|
|
1532
1644
|
if (w[x] !== undefined)
|
|
1533
1645
|
diagram.parts[x] = elem.get(w[x]);
|
package/dist/kernel/kernel.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { C, E, Law, Machine, MapUpdate } from '../core/machine.js';
|
|
2
2
|
import { type Constraint, type Lin, type Step } from '../core/solver.js';
|
|
3
3
|
export declare function unreachable(value: never): never;
|
|
4
|
+
export declare const tuple: (parts: E[]) => E;
|
|
5
|
+
export declare const tupleParts: (e: E) => E[];
|
|
6
|
+
export declare const part: (key: E, i: number, n: number) => E;
|
|
4
7
|
export type Tree = {
|
|
5
8
|
split: Lin;
|
|
6
9
|
yes: Tree;
|
|
@@ -22,6 +25,7 @@ export declare const canon: (lin: Lin) => string;
|
|
|
22
25
|
export declare const canonFlip: (lin: Lin) => string;
|
|
23
26
|
export declare const atomOf: (lin: Lin, holds: boolean) => Constraint;
|
|
24
27
|
export declare function linear(e: E, path: Path): Lin | undefined;
|
|
28
|
+
export declare const plainMap: (name: string) => boolean;
|
|
25
29
|
export declare const termColumn: (e: E) => string;
|
|
26
30
|
export declare const columnTerm: (name: string) => E | undefined;
|
|
27
31
|
export declare function decided(e: E, path: Path): boolean;
|
|
@@ -30,6 +34,12 @@ export declare function factorsOf(name: string): string[];
|
|
|
30
34
|
export declare const isMonomial: (name: string) => boolean;
|
|
31
35
|
export declare const isCell: (name: string) => boolean;
|
|
32
36
|
export declare function truth(c: C, path: Path): boolean | undefined;
|
|
37
|
+
export declare function tupleAnd(c: Extract<C, {
|
|
38
|
+
a: E;
|
|
39
|
+
}>): C | undefined;
|
|
40
|
+
export declare function tupleEq(c: Extract<C, {
|
|
41
|
+
a: E;
|
|
42
|
+
}>): [C, C] | undefined;
|
|
33
43
|
export declare function facts(c: C, path: Path, positive?: boolean): Lin[];
|
|
34
44
|
export declare function leafConstraints(goal: Goal, path: Path): Constraint[];
|
|
35
45
|
export declare function leafConstraintsReusing(goal: Goal, path: Path): Constraint[];
|
|
@@ -47,6 +57,11 @@ export type Seen<T> = {
|
|
|
47
57
|
size?: number;
|
|
48
58
|
};
|
|
49
59
|
export declare function reusing<T>(seen: Seen<T>, path: Path, f: (path: Path) => T): T;
|
|
60
|
+
export declare function cellParts(cell: string): {
|
|
61
|
+
map: string;
|
|
62
|
+
key?: Lin;
|
|
63
|
+
keys?: Lin[];
|
|
64
|
+
};
|
|
50
65
|
export declare function withProducts(rows: Constraint[], pairs: [number, number][], squares?: Lin[]): Constraint[];
|
|
51
66
|
export declare function check(goal: Goal, tree: Tree, path?: Path): boolean;
|
|
52
67
|
export type Subst = {
|
|
@@ -54,6 +69,7 @@ export type Subst = {
|
|
|
54
69
|
maps: Record<string, (key: E) => E>;
|
|
55
70
|
flags: Record<string, C>;
|
|
56
71
|
};
|
|
72
|
+
export declare const own: <T>(r: Record<string, T>, k: string) => T | undefined;
|
|
57
73
|
export declare function substE(e: E, s: Subst): E;
|
|
58
74
|
export declare function substC(c: C, s: Subst): C;
|
|
59
75
|
export type Instances = Record<string, E[]>;
|
|
@@ -67,6 +83,16 @@ export declare const witnessesOf: (f: string, q: Extract<C, {
|
|
|
67
83
|
export declare const crossFree: (c: C, keys: string[]) => C;
|
|
68
84
|
export declare const assumed: (laws: Law[], instances: Instances) => C[];
|
|
69
85
|
export declare function scope(m: Machine, laws?: Law[]): void;
|
|
86
|
+
export declare function mapArities(m: Machine, laws?: Law[]): Record<string, number>;
|
|
87
|
+
export declare function eachParts(w: {
|
|
88
|
+
each: string;
|
|
89
|
+
value: E;
|
|
90
|
+
}, n: number): {
|
|
91
|
+
names: string[];
|
|
92
|
+
value: E;
|
|
93
|
+
};
|
|
94
|
+
export declare function projected(e: E): E;
|
|
95
|
+
export declare const projectedC: (c: C) => C;
|
|
70
96
|
export declare const keyTerm: (e: E, key: string) => boolean;
|
|
71
97
|
export declare const plainKey: (t: E | C, key: string) => boolean;
|
|
72
98
|
export declare function historyMachine(m: Machine): {
|
|
@@ -319,17 +345,20 @@ export type CountDecl = {
|
|
|
319
345
|
key: string;
|
|
320
346
|
below: E;
|
|
321
347
|
body: E;
|
|
348
|
+
lo?: string;
|
|
349
|
+
base?: number;
|
|
322
350
|
};
|
|
323
351
|
export type MapRead = [string, string, E];
|
|
324
352
|
export type CountCert = {
|
|
325
353
|
reads: MapRead[];
|
|
326
354
|
insts: CountInst[];
|
|
327
355
|
tree: Tree;
|
|
356
|
+
picks?: [string, E[]][];
|
|
328
357
|
};
|
|
329
358
|
export declare const postName: (map: string) => string;
|
|
330
359
|
export declare const stateCounts: (m: Machine) => string[];
|
|
331
360
|
export declare function checkMC(hyps: C[], ds: CountDecl[], k: CountCert): boolean;
|
|
332
|
-
export declare function mcGoal(hyps: C[], ds: CountDecl[], k: Pick<CountCert, 'reads' | 'insts'>): Goal | undefined;
|
|
361
|
+
export declare function mcGoal(hyps: C[], ds: CountDecl[], k: Pick<CountCert, 'reads' | 'insts' | 'picks'>): Goal | undefined;
|
|
333
362
|
export declare function countedObligations(m: Machine, laws: Law[], instances?: Record<string, Instances>, only?: number): {
|
|
334
363
|
goal: Goal;
|
|
335
364
|
decls: CountDecl[];
|
|
@@ -356,4 +385,5 @@ export declare const checkGhostedLaws: (g: Ghosted, laws: Law[], proof: {
|
|
|
356
385
|
instances: Record<string, Instances>;
|
|
357
386
|
trees: Record<string, Tree>;
|
|
358
387
|
}) => boolean;
|
|
388
|
+
export declare function someOfGhostsOk(g: Ghosted, law: Law, plain: Law, sub: Record<string, E>): boolean;
|
|
359
389
|
export {};
|