gdp-wired 0.45.0 → 0.47.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 +61 -8
- 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 +423 -31
- package/dist/core/calendar.d.ts +29 -0
- package/dist/core/calendar.js +82 -0
- package/dist/core/cli.d.ts +4 -0
- package/dist/core/cli.js +206 -40
- package/dist/core/compose.js +3 -1
- package/dist/core/counts.d.ts +4 -1
- package/dist/core/counts.js +314 -85
- 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 +2 -1
- package/dist/core/data.js +223 -24
- 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 +37 -3
- package/dist/core/dsl.js +167 -26
- package/dist/core/effect-schema.d.ts +90 -0
- package/dist/core/effect-schema.js +500 -0
- package/dist/core/effect.d.ts +4 -11
- package/dist/core/effect.js +3 -79
- package/dist/core/exists.d.ts +1 -0
- package/dist/core/exists.js +191 -16
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +169 -22
- package/dist/core/extract-check.d.ts +1 -0
- package/dist/core/extract-check.js +97 -6
- package/dist/core/extract-go-check.d.ts +1 -1
- package/dist/core/extract-go-check.js +26 -5
- package/dist/core/extract-go.d.ts +8 -0
- package/dist/core/extract-go.js +67 -6
- 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 +2 -0
- package/dist/core/extract-orm.d.ts +12 -0
- package/dist/core/extract-orm.js +244 -0
- package/dist/core/extract-print.js +20 -1
- package/dist/core/extract-py.d.ts +1 -0
- package/dist/core/extract-py.js +1 -1
- package/dist/core/extract-read.d.ts +26 -1
- package/dist/core/extract-read.js +14 -7
- package/dist/core/extract-rs.js +63 -15
- package/dist/core/extract-shapes.d.ts +1 -0
- package/dist/core/extract-shapes.js +84 -0
- package/dist/core/extract-sol.d.ts +10 -1
- package/dist/core/extract-sol.js +70 -22
- package/dist/core/extract-standalone.d.ts +3 -0
- package/dist/core/extract-standalone.js +221 -0
- package/dist/core/extract-step.d.ts +151 -1
- package/dist/core/extract-step.js +1232 -60
- package/dist/core/extract-swift.js +6 -2
- package/dist/core/extract.d.ts +9 -0
- package/dist/core/extract.js +77 -7
- package/dist/core/fiber-run.d.ts +5 -0
- package/dist/core/fiber-run.js +18 -0
- package/dist/core/infer.d.ts +4 -1
- package/dist/core/infer.js +918 -217
- package/dist/core/jvm/JavaReader.java +23 -6
- package/dist/core/jvm/Jvm.java +3 -0
- package/dist/core/jvm/KtReader.java +6 -5
- package/dist/core/laws.d.ts +10 -3
- package/dist/core/laws.js +226 -23
- package/dist/core/machine.d.ts +15 -1
- package/dist/core/machine.js +187 -15
- 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 +183 -10
- package/dist/core/py/reader.py +234 -40
- 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/Cargo.toml +1 -1
- package/dist/core/rs/src/main.rs +466 -11
- 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 +57 -4
- package/dist/core/sol-concrete.d.ts +23 -0
- package/dist/core/sol-concrete.js +195 -0
- package/dist/core/solver.js +3 -1
- package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
- package/dist/core/system.js +1 -1
- package/dist/core/transfer.js +22 -9
- package/dist/core/translate.js +39 -10
- package/dist/core/watch.js +50 -5
- package/dist/interchange/format.js +11 -1
- package/dist/kernel/cdcl.d.ts +5 -0
- package/dist/kernel/cdcl.js +56 -9
- package/dist/kernel/epr.js +108 -26
- package/dist/kernel/kernel.d.ts +29 -1
- package/dist/kernel/kernel.js +325 -62
- package/dist/kernel/model-sequence.d.ts +3 -0
- package/dist/kernel/model-sequence.js +34 -0
- package/dist/kernel/prove.d.ts +10 -3
- package/dist/kernel/prove.js +332 -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.js +30 -37
- package/dist/lean-kernel/lean-terms.js +5 -0
- package/dist/lean-kernel/library.js +10 -10
- package/package.json +6 -1
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)
|
|
@@ -65,16 +65,23 @@ const and = (xs) => { const ys = xs.filter(x => !(x.k === 'c' && x.b)); return y
|
|
|
65
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 }; };
|
|
66
66
|
const not = (x) => (x.k === 'c' ? { k: 'c', b: !x.b } : x.k === 'not' ? x.x : { k: 'not', x });
|
|
67
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)`.
|
|
68
|
-
let fnMaps = new Set();
|
|
68
|
+
let fnMaps = new Set(), fnSignature = '';
|
|
69
69
|
const partName = (e) => e.op === 'var' ? e.name
|
|
70
70
|
: e.op === 'get' && fnMaps.has(e.map) && !e.args ? (n => (n === undefined ? undefined : `${e.map}(${n})`))(partName(e.key)) : undefined;
|
|
71
71
|
// A key Σ c·x + d as its terms; undefined where it reads anything but parts under constant factors.
|
|
72
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)
|
|
73
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;
|
|
74
74
|
const tupleMemo = new WeakMap();
|
|
75
|
-
function tupleOf(e) { let
|
|
76
|
-
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; }
|
|
77
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
|
+
}
|
|
78
85
|
const ts = [], d = { c: 0 };
|
|
79
86
|
if (!linTerms(e, 1, ts, d) || d.c !== 0 || !ts.length)
|
|
80
87
|
return undefined;
|
|
@@ -89,6 +96,9 @@ const sameCoefs = (a, b) => a.length === b.length && a.every((c, i) => c === b[i
|
|
|
89
96
|
// (a probe's hook: each decision with its goal, ms and outcome)
|
|
90
97
|
export const decideHook = {};
|
|
91
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; };
|
|
92
102
|
export function decide(goal, patterns, opts = {}) {
|
|
93
103
|
if (!decideHook.on)
|
|
94
104
|
return decide1(goal, patterns, opts);
|
|
@@ -97,8 +107,11 @@ export function decide(goal, patterns, opts = {}) {
|
|
|
97
107
|
return d;
|
|
98
108
|
}
|
|
99
109
|
function decide1(goal0, patterns, opts = {}) {
|
|
110
|
+
const previous = fnMaps, previousSignature = fnSignature;
|
|
100
111
|
fnMaps = new Set(Object.entries(patterns).filter(([, c]) => c.length === 1 && c[0] === 0).map(([f]) => f));
|
|
101
|
-
|
|
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;
|
|
102
115
|
// (a model whose order leaves no room between two near constants: again with the constants between them, below)
|
|
103
116
|
// (a model the read-back breaks: once more without the other goals' theory lemmas, whose history chose that model)
|
|
104
117
|
try {
|
|
@@ -111,7 +124,8 @@ function decide1(goal0, patterns, opts = {}) {
|
|
|
111
124
|
throw e;
|
|
112
125
|
}
|
|
113
126
|
finally {
|
|
114
|
-
fnMaps =
|
|
127
|
+
fnMaps = previous;
|
|
128
|
+
fnSignature = previousSignature;
|
|
115
129
|
}
|
|
116
130
|
}
|
|
117
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
|
|
@@ -127,12 +141,46 @@ const hasIf = (o) => {
|
|
|
127
141
|
ifMemo.set(o, (b = o.op === 'if' || Object.values(o).some(hasIf)));
|
|
128
142
|
return b;
|
|
129
143
|
};
|
|
130
|
-
const
|
|
131
|
-
|
|
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') {
|
|
132
180
|
const a = hoisted(e.a), b = hoisted(e.b);
|
|
133
|
-
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 };
|
|
134
182
|
}
|
|
135
|
-
if (e.op === 'mul') {
|
|
183
|
+
if (e.op === 'mul' || e.op === 'proj') {
|
|
136
184
|
const a = hoisted(e.a);
|
|
137
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 };
|
|
138
186
|
}
|
|
@@ -180,8 +228,17 @@ const liftC = (c) => {
|
|
|
180
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),
|
|
181
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,
|
|
182
230
|
// counted before they are distributed, 8 leaves)
|
|
183
|
-
const
|
|
184
|
-
const
|
|
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;
|
|
185
242
|
if (few && ((ha.op === 'if' && reads(ha)) || (hb.op === 'if' && reads(hb))) && keysOf(ha) * keysOf(hb) <= 8) {
|
|
186
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)] }] }
|
|
187
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 });
|
|
@@ -287,9 +344,9 @@ const compInfo = (c) => {
|
|
|
287
344
|
(k(e.then), k(e.else)); };
|
|
288
345
|
k(c.a);
|
|
289
346
|
k(c.b);
|
|
290
|
-
compMemo.set(c, (x = { ts, top: Math.max(1, ...consts)
|
|
347
|
+
compMemo.set(c, (x = { ts, top: Math.max(1, ...consts) }));
|
|
291
348
|
}
|
|
292
|
-
return x;
|
|
349
|
+
return { ...x, ta: tupleOf(c.a), tb: tupleOf(c.b) };
|
|
293
350
|
};
|
|
294
351
|
function stateOf(fs, patterns, tick) {
|
|
295
352
|
const fits = (map, key) => { const t = tupleOf(key), p = patterns[map]; return t && p && sameCoefs(t.coefs, p) ? t : undefined; };
|
|
@@ -1081,11 +1138,7 @@ function encoder(st, patterns) {
|
|
|
1081
1138
|
if (theory.length && !opts.fresh)
|
|
1082
1139
|
seedLemmas();
|
|
1083
1140
|
// EPR-shaped: no comparison the abstraction can't read (a counter's arithmetic, a sum, a product) in any hypothesis
|
|
1084
|
-
|
|
1085
|
-
const loose = [...gOpq].filter(x => { const o = opqs.get(x); return o.foreign && !o.tied; }).length;
|
|
1086
|
-
if (loose)
|
|
1087
|
-
return { unknown: `${loose} comparisons outside the EPR shape` };
|
|
1088
|
-
}
|
|
1141
|
+
const loose = opts.exact ? [...gOpq].filter(x => { const o = opqs.get(x); return o.foreign && !o.tied; }) : [];
|
|
1089
1142
|
// --- the search, the goal's hypotheses assumed
|
|
1090
1143
|
if (opts.late?.())
|
|
1091
1144
|
return { unknown: 'past the deadline' };
|
|
@@ -1353,7 +1406,7 @@ function encoder(st, patterns) {
|
|
|
1353
1406
|
return exact();
|
|
1354
1407
|
};
|
|
1355
1408
|
const outcome = (o) => (typeof o === 'string' ? { unknown: o } : o === undefined ? { unknown: 'the conflict budget ran out, or the deadline' }
|
|
1356
|
-
: !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 });
|
|
1357
1410
|
// the goal's own terms, for the read-back: its finite variables, cells (of its maps' patterns, and at keys of the
|
|
1358
1411
|
// wrong sort), ordered cells and functions' parts
|
|
1359
1412
|
const gFinsL = finsList.filter(f => gFins.has(f)), cellsOf = new Map(), odd = [];
|
|
@@ -1409,6 +1462,7 @@ function encoder(st, patterns) {
|
|
|
1409
1462
|
const tight = new Set(succList.filter(x => val(x.s)).map(x => `${groupOf.get(x.lo)}>${groupOf.get(x.hi)}`));
|
|
1410
1463
|
const tied = (i) => tight.has(`${i}>${i + 1}`);
|
|
1411
1464
|
let prev = -1, far = 0;
|
|
1465
|
+
const tupled = Object.values(patterns).some(c => c.length > 1 && c[0] === 0);
|
|
1412
1466
|
for (const [gi, g] of groups.entries()) {
|
|
1413
1467
|
const c = constOf(g);
|
|
1414
1468
|
if (Number.isNaN(c))
|
|
@@ -1421,7 +1475,8 @@ function encoder(st, patterns) {
|
|
|
1421
1475
|
break;
|
|
1422
1476
|
}
|
|
1423
1477
|
}
|
|
1424
|
-
|
|
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);
|
|
1425
1480
|
if (c === undefined && next !== Infinity && x % 2 === 0 && x + 1 < next)
|
|
1426
1481
|
x++;
|
|
1427
1482
|
if (c === undefined && gi > 0 && tied(gi - 1))
|
|
@@ -1466,7 +1521,19 @@ function encoder(st, patterns) {
|
|
|
1466
1521
|
odd2.push(o);
|
|
1467
1522
|
}
|
|
1468
1523
|
// every read of the goal, at its key's value under w: the abstraction's value where it has one, else 0
|
|
1469
|
-
|
|
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))
|
|
1470
1537
|
return undefined; let s = d.c; for (const [x, c] of ts) {
|
|
1471
1538
|
if (w[x] === undefined)
|
|
1472
1539
|
return undefined;
|
|
@@ -1514,7 +1581,13 @@ function encoder(st, patterns) {
|
|
|
1514
1581
|
[...reads].reverse().forEach(fnOdd);
|
|
1515
1582
|
for (const [mp, cs] of cells2)
|
|
1516
1583
|
for (const c of cs) {
|
|
1517
|
-
|
|
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
|
+
}
|
|
1518
1591
|
if (!maps.has(mp))
|
|
1519
1592
|
maps.set(mp, new Map());
|
|
1520
1593
|
maps.get(mp).set(key, cellVal.get(c.id));
|
|
@@ -1551,8 +1624,17 @@ function encoder(st, patterns) {
|
|
|
1551
1624
|
const witness = { ...w };
|
|
1552
1625
|
for (const x of reads) {
|
|
1553
1626
|
tick();
|
|
1554
|
-
const
|
|
1555
|
-
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)
|
|
1556
1638
|
witness[`${x.map}[${canon(l)}]`] = st2.maps[x.map]?.get(kv) ?? 0;
|
|
1557
1639
|
}
|
|
1558
1640
|
// the structure
|
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 = {
|
|
@@ -68,6 +83,16 @@ export declare const witnessesOf: (f: string, q: Extract<C, {
|
|
|
68
83
|
export declare const crossFree: (c: C, keys: string[]) => C;
|
|
69
84
|
export declare const assumed: (laws: Law[], instances: Instances) => C[];
|
|
70
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;
|
|
71
96
|
export declare const keyTerm: (e: E, key: string) => boolean;
|
|
72
97
|
export declare const plainKey: (t: E | C, key: string) => boolean;
|
|
73
98
|
export declare function historyMachine(m: Machine): {
|
|
@@ -320,17 +345,20 @@ export type CountDecl = {
|
|
|
320
345
|
key: string;
|
|
321
346
|
below: E;
|
|
322
347
|
body: E;
|
|
348
|
+
lo?: string;
|
|
349
|
+
base?: number;
|
|
323
350
|
};
|
|
324
351
|
export type MapRead = [string, string, E];
|
|
325
352
|
export type CountCert = {
|
|
326
353
|
reads: MapRead[];
|
|
327
354
|
insts: CountInst[];
|
|
328
355
|
tree: Tree;
|
|
356
|
+
picks?: [string, E[]][];
|
|
329
357
|
};
|
|
330
358
|
export declare const postName: (map: string) => string;
|
|
331
359
|
export declare const stateCounts: (m: Machine) => string[];
|
|
332
360
|
export declare function checkMC(hyps: C[], ds: CountDecl[], k: CountCert): boolean;
|
|
333
|
-
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;
|
|
334
362
|
export declare function countedObligations(m: Machine, laws: Law[], instances?: Record<string, Instances>, only?: number): {
|
|
335
363
|
goal: Goal;
|
|
336
364
|
decls: CountDecl[];
|