gdp-wired 0.45.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.
Files changed (120) hide show
  1. package/README.md +58 -7
  2. package/dist/core/bitsets.d.ts +2 -0
  3. package/dist/core/bitsets.js +23 -0
  4. package/dist/core/bmc.js +6 -2
  5. package/dist/core/c/reader.d.ts +9 -1
  6. package/dist/core/c/reader.js +423 -31
  7. package/dist/core/calendar.d.ts +29 -0
  8. package/dist/core/calendar.js +82 -0
  9. package/dist/core/cli.d.ts +3 -0
  10. package/dist/core/cli.js +204 -38
  11. package/dist/core/compose.js +3 -1
  12. package/dist/core/counts.d.ts +4 -1
  13. package/dist/core/counts.js +314 -85
  14. package/dist/core/cycles.js +8 -1
  15. package/dist/core/cyclic.d.ts +1 -0
  16. package/dist/core/cyclic.js +13 -7
  17. package/dist/core/data-synth.d.ts +3 -0
  18. package/dist/core/data-synth.js +252 -0
  19. package/dist/core/data.d.ts +2 -1
  20. package/dist/core/data.js +223 -24
  21. package/dist/core/discover.js +3 -1
  22. package/dist/core/draft.d.ts +19 -0
  23. package/dist/core/draft.js +53 -0
  24. package/dist/core/dsl.d.ts +37 -3
  25. package/dist/core/dsl.js +167 -26
  26. package/dist/core/effect.d.ts +1 -4
  27. package/dist/core/effect.js +1 -15
  28. package/dist/core/exists.d.ts +1 -0
  29. package/dist/core/exists.js +191 -16
  30. package/dist/core/extract-c.d.ts +2 -0
  31. package/dist/core/extract-c.js +169 -22
  32. package/dist/core/extract-check.d.ts +1 -0
  33. package/dist/core/extract-check.js +66 -0
  34. package/dist/core/extract-go-check.d.ts +1 -1
  35. package/dist/core/extract-go-check.js +2 -1
  36. package/dist/core/extract-go.d.ts +1 -0
  37. package/dist/core/extract-go.js +38 -4
  38. package/dist/core/extract-ir.d.ts +1 -0
  39. package/dist/core/extract-ir.js +15 -0
  40. package/dist/core/extract-jvm.d.ts +1 -1
  41. package/dist/core/extract-jvm.js +2 -0
  42. package/dist/core/extract-orm.d.ts +12 -0
  43. package/dist/core/extract-orm.js +244 -0
  44. package/dist/core/extract-print.js +20 -1
  45. package/dist/core/extract-py.d.ts +1 -0
  46. package/dist/core/extract-py.js +1 -1
  47. package/dist/core/extract-read.d.ts +17 -0
  48. package/dist/core/extract-read.js +5 -5
  49. package/dist/core/extract-rs.js +5 -1
  50. package/dist/core/extract-shapes.js +2 -0
  51. package/dist/core/extract-sol.d.ts +10 -1
  52. package/dist/core/extract-sol.js +70 -22
  53. package/dist/core/extract-step.d.ts +151 -1
  54. package/dist/core/extract-step.js +1232 -60
  55. package/dist/core/extract-swift.js +6 -2
  56. package/dist/core/extract.d.ts +8 -0
  57. package/dist/core/extract.js +61 -5
  58. package/dist/core/fiber-run.d.ts +5 -0
  59. package/dist/core/fiber-run.js +18 -0
  60. package/dist/core/infer.d.ts +4 -1
  61. package/dist/core/infer.js +918 -217
  62. package/dist/core/jvm/JavaReader.java +23 -6
  63. package/dist/core/jvm/Jvm.java +3 -0
  64. package/dist/core/jvm/KtReader.java +6 -5
  65. package/dist/core/laws.d.ts +10 -3
  66. package/dist/core/laws.js +193 -14
  67. package/dist/core/machine.d.ts +15 -1
  68. package/dist/core/machine.js +187 -15
  69. package/dist/core/nonterm.js +14 -1
  70. package/dist/core/orm/harness.js +61 -0
  71. package/dist/core/orm-fixtures/schema.prisma +5 -0
  72. package/dist/core/py/harness.py +183 -10
  73. package/dist/core/py/reader.py +234 -40
  74. package/dist/core/reader-fixtures/README.md +28 -0
  75. package/dist/core/reader-fixtures/c-693042.cpp +8 -0
  76. package/dist/core/reader-fixtures/go-685506.go +14 -0
  77. package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
  78. package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
  79. package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
  80. package/dist/core/reader-fixtures/swift-735726.swift +15 -0
  81. package/dist/core/reader-fixtures/swift-735990.swift +15 -0
  82. package/dist/core/reader-fixtures/swift-739158.swift +4 -0
  83. package/dist/core/reader-fixtures/swift-744834.swift +15 -0
  84. package/dist/core/reader-fixtures/swift-746946.swift +31 -0
  85. package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
  86. package/dist/core/relation.d.ts +1 -1
  87. package/dist/core/relation.js +29 -2
  88. package/dist/core/relational.js +4 -2
  89. package/dist/core/rs/src/main.rs +8 -2
  90. package/dist/core/sample-cache.d.ts +8 -0
  91. package/dist/core/sample-cache.js +46 -0
  92. package/dist/core/security.d.ts +38 -0
  93. package/dist/core/security.js +88 -0
  94. package/dist/core/sol/harness.py +57 -4
  95. package/dist/core/sol-concrete.d.ts +23 -0
  96. package/dist/core/sol-concrete.js +195 -0
  97. package/dist/core/solver.js +3 -1
  98. package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
  99. package/dist/core/system.js +1 -1
  100. package/dist/core/transfer.js +22 -9
  101. package/dist/core/translate.js +39 -10
  102. package/dist/core/watch.js +50 -5
  103. package/dist/interchange/format.js +11 -1
  104. package/dist/kernel/cdcl.d.ts +5 -0
  105. package/dist/kernel/cdcl.js +56 -9
  106. package/dist/kernel/epr.js +108 -26
  107. package/dist/kernel/kernel.d.ts +29 -1
  108. package/dist/kernel/kernel.js +325 -62
  109. package/dist/kernel/model-sequence.d.ts +3 -0
  110. package/dist/kernel/model-sequence.js +34 -0
  111. package/dist/kernel/prove.d.ts +10 -3
  112. package/dist/kernel/prove.js +332 -71
  113. package/dist/kernel/reader.d.ts +3 -0
  114. package/dist/kernel/reader.js +101 -14
  115. package/dist/kernel/share.d.ts +1 -0
  116. package/dist/kernel/share.js +27 -0
  117. package/dist/lean-kernel/emit.js +30 -37
  118. package/dist/lean-kernel/lean-terms.js +5 -0
  119. package/dist/lean-kernel/library.js +10 -10
  120. package/package.json +6 -1
@@ -20,7 +20,7 @@
20
20
  import { costs, env, refuteFast, solve, work } from "../core/solver.js";
21
21
  import { checkRefutation } from "../core/check.js";
22
22
  import { atomOf, canon, canonFlip, isMonomial, leafConstraints } from "./kernel.js";
23
- import { atPoint, cellPair, growWide, late, leafRowsOf, logged, nearOf, openAt, pairedKeys, queryHook, rowsAt, unitAtoms, wideFor, wideScope } from "./prove.js";
23
+ import { atPoint, cellPair, tupleCellPairs, growWide, late, leafRowsOf, logged, nearOf, openAt, pairedKeys, queryHook, rowsAt, unitAtoms, wideFor, wideScope } from "./prove.js";
24
24
  import { Clausal, Reader, namesOf } from "./reader.js";
25
25
  import { Simplex } from "./simplex.js";
26
26
  // A derivation's own inputs: the rows it reads, in order, and the steps renumbered to them.
@@ -52,9 +52,10 @@ const keyOf = (lin) => {
52
52
  };
53
53
  // GDP_CDCL_LP=0: each node solved by elimination alone (no simplex); GDP_CDCL_FILL (8): the simplex's tableau begun
54
54
  // again past this many entries a row the node reads (research/step's comparisons).
55
+ const pointLeaf = env.GDP_CDCL_POINT !== '0';
55
56
  const lpFill = Number(env.GDP_CDCL_FILL ?? 8), lpGrow = Number(env.GDP_CDCL_GROW ?? 4), lpBase = Number(env.GDP_CDCL_BASE ?? 500), lpGreedy = Number(env.GDP_CDCL_GREEDY ?? 200), useLp = env.GDP_CDCL_LP !== '0', verify = env.GDP_CDCL_VERIFY === '1';
56
57
  // Counters research/step reads (times only while `on`).
57
- export const cdclStats = { on: false, runs: 0, proven: 0, conflicts: 0, decisions: 0, solveMs: 0, rowsMs: 0, coreMs: 0, unfoldMs: 0, leaves: 0, resolved: 0, coreSize: 0, pathSize: 0, lpMisses: 0, resolved2: 0, unfoldWhy: '', orderMs: 0, boundMs: 0, openMisses: 0, lpMs: 0, lpUnknown: 0, fmCalls: 0, pivots: 0, lpRebuilds: 0, lpRows: 0, lpNnz: 0, lpVars: 0, lpLoad: 0, nodes: 0, boundRounds: 0 };
58
+ export const cdclStats = { on: false, runs: 0, proven: 0, conflicts: 0, decisions: 0, solveMs: 0, rowsMs: 0, coreMs: 0, unfoldMs: 0, leaves: 0, resolved: 0, coreSize: 0, pathSize: 0, lpMisses: 0, resolved2: 0, unfoldWhy: '', orderMs: 0, boundMs: 0, openMisses: 0, lpMs: 0, lpUnknown: 0, fmCalls: 0, pivots: 0, lpRebuilds: 0, lpRows: 0, lpNnz: 0, lpVars: 0, lpLoad: 0, nodes: 0, boundRounds: 0, fmLeafMs: 0, fmOpenMs: 0, fastMs: 0, missMs: 0 };
58
59
  // `opts.model`: only whether the goal has a model is wanted (core/bmc.ts): a refutation isn't unfolded into a tree, its
59
60
  // outcome `unknown` with `why` REFUTED; each decision's phase is the simplex's point's (phaseAtPoint; in the tree search too
60
61
  // where prove.ts's `atPoint` is on); past `opts.wall` (wall time) the search stops as past its budget.
@@ -214,10 +215,20 @@ export function cdclSession(goal, root, opts = {}) {
214
215
  for (let j = i + 1; j < ns.length; j++) {
215
216
  let r = row.get(ns[j]);
216
217
  if (!r) {
217
- const pair = cellPair(ns[i], ns[j]);
218
- row.set(ns[j], (r = { d: pair.d, neg: pair.neg, mono: Object.keys(pair.d).some(isMonomial) }));
218
+ // (two tuple cells: a pair for each part, each split on as a plain key's difference is)
219
+ const parts = tupleCellPairs(ns[i], ns[j]);
220
+ if (parts)
221
+ r = parts.map(([d, neg]) => ({ d: d, neg: neg, mono: false }));
222
+ else {
223
+ const pair = cellPair(ns[i], ns[j]);
224
+ r = { d: pair.d, neg: pair.neg, mono: Object.keys(pair.d).some(isMonomial) };
225
+ }
226
+ row.set(ns[j], r);
219
227
  }
220
- flat.push(r);
228
+ if (Array.isArray(r))
229
+ flat.push(...r);
230
+ else
231
+ flat.push(r);
221
232
  }
222
233
  }
223
234
  }
@@ -543,6 +554,19 @@ export function cdclSession(goal, root, opts = {}) {
543
554
  }
544
555
  return w;
545
556
  };
557
+ // (the point as it is, each name the rows read; undefined where the simplex doesn't know one)
558
+ const roundless = (lp, rows) => {
559
+ const w = {};
560
+ for (const r of rows)
561
+ for (const n of namesOf(r.lin))
562
+ if (!(n in w)) {
563
+ const j = lp.indexOf(n);
564
+ if (j === undefined)
565
+ return undefined;
566
+ w[n] = lp.value(j);
567
+ }
568
+ return w;
569
+ };
546
570
  // (the point rounded, each name the rows read; undefined where the simplex doesn't know one)
547
571
  const roundedOf = (lp, rows) => {
548
572
  const w = {};
@@ -991,7 +1015,7 @@ export function cdclSession(goal, root, opts = {}) {
991
1015
  if (verify && !clausal) {
992
1016
  const mine = new Set(rowsR.map(r => canon(r.lin))), theirs = new Set(leafConstraints(goal, pathOf()).map(r => canon(r.lin)));
993
1017
  if (mine.size !== theirs.size || [...mine].some(x => !theirs.has(x)))
994
- throw new Error(`reader.ts's rows differ from kernel.ts's at a node of ${goal.name}`);
1018
+ throw new Error(`reader.ts's rows differ from kernel.ts's at a node of ${goal.name}: reader's alone ${[...mine].filter(x => !theirs.has(x)).slice(0, 4).join(' ; ')}; kernel's alone ${[...theirs].filter(x => !mine.has(x)).slice(0, 4).join(' ; ')}; path ${[...pathOf()].map(([k2, a]) => `${a.holds ? '' : '¬'}${k2}`).join(' ; ')}`);
995
1019
  }
996
1020
  work.n += 1 + full.length;
997
1021
  costs.cdclNodes++;
@@ -1157,7 +1181,9 @@ export function cdclSession(goal, root, opts = {}) {
1157
1181
  st.lpUnknown++;
1158
1182
  }
1159
1183
  if (lp.kind === 'conflict') {
1160
- const support = lp.rows.sort((x, y) => x - y), out = solve(support.map(i => full[i]));
1184
+ const tm = timing ? performance.now() : 0, support = lp.rows.sort((x, y) => x - y), out = solve(support.map(i => full[i]));
1185
+ if (timing)
1186
+ st.missMs += performance.now() - tm;
1161
1187
  if (out.kind === 'refuted')
1162
1188
  steps = out.steps.map(s => (s.kind === 'input' ? { ...s, index: support[s.index] } : s));
1163
1189
  else
@@ -1177,26 +1203,47 @@ export function cdclSession(goal, root, opts = {}) {
1177
1203
  if (steps || (open && lp.kind === 'sat'))
1178
1204
  return;
1179
1205
  // (the clausal mode, every clause satisfied: the simplex's point, where it is integral, is a model)
1180
- if (clausal && !open && lpSat) {
1206
+ // (`point`, a model's search over the kernel's reading (GDP_CDCL_POINT=0: not): a leaf whose rows the simplex's
1207
+ // point meets at integers is met, and at one whose point is not integral a fractional name of it is split on
1208
+ // (branch and bound) where one is not split on yet, not the exact elimination over every row; the counted
1209
+ // search's (its leaves' elimination took 228 of paxos-hand's 600 s); the others' models stay the elimination's)
1210
+ const byPoint = pointLeaf && !!opts.point && !!opts.model;
1211
+ if ((clausal || byPoint) && !open && lpSat) {
1181
1212
  const w = pointOf(sx, rowsR);
1182
1213
  if (w) {
1183
1214
  verdict = { kind: 'sat', witness: w };
1184
1215
  return;
1185
1216
  }
1186
1217
  }
1218
+ if (byPoint && !clausal && !open && lpSat) {
1219
+ const point = roundless(sx, rowsR);
1220
+ if (point && Object.entries(point).some(([x0, value]) => Math.abs(value - Math.round(value)) >= 1e-9 && !isMonomial(x0) && !decidedLin(Math.floor(value) === 0 ? { [x0]: 1 } : { [x0]: 1, 1: -Math.floor(value) }))) {
1221
+ verdict = { kind: 'unknown', point };
1222
+ return;
1223
+ }
1224
+ }
1187
1225
  }
1188
1226
  st.fmCalls++;
1189
- const rows = plain();
1227
+ const rows = plain(), tf = timing ? performance.now() : 0;
1190
1228
  if (open && rows.length > 60) {
1191
1229
  const fast = refuteFast(rows);
1192
1230
  if (fast?.kind === 'refuted')
1193
1231
  steps = fast.steps.map(s => (s.kind === 'input' ? { ...s, index: at(s.index) } : s));
1194
1232
  }
1233
+ const tf2 = timing ? performance.now() : 0;
1234
+ if (timing)
1235
+ st.fastMs += tf2 - tf;
1195
1236
  if (!steps) {
1196
1237
  verdict = open && rows.length > 60 ? solve(rows, 2 * rows.length) : solve(rows);
1197
1238
  if (verdict.kind === 'refuted')
1198
1239
  steps = verdict.steps.map(s => (s.kind === 'input' ? { ...s, index: at(s.index) } : s));
1199
1240
  }
1241
+ if (timing) {
1242
+ if (open)
1243
+ st.fmOpenMs += performance.now() - tf2;
1244
+ else
1245
+ st.fmLeafMs += performance.now() - tf2;
1246
+ }
1200
1247
  if (!steps && open && !columns && full.length > rows.length) {
1201
1248
  const k = korder(), fast = refuteFast(k.map(i => full[i]));
1202
1249
  if (fast?.kind === 'refuted')
@@ -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 t = tupleMemo.get(e); if (t === undefined)
76
- tupleMemo.set(e, (t = tupleOf0(e) ?? null)); return t ?? undefined; }
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
- const goal = goal0;
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 = new Set();
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 hoisted = (e) => {
131
- if (e.op === 'add') {
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 ifs = (e) => textOfE(e).split('"op":"if"').length - 1, reads = (e) => textOfE(e).includes('"op":"get"');
184
- const few = (hasIf(a) || hasIf(b)) && ifs(a) + ifs(b) <= 3, ha = few ? hoisted(a) : a, hb = few ? hoisted(b) : b;
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), ta: tupleOf(c.a), tb: tupleOf(c.b) }));
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
- if (opts.exact) {
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
- let x = c ?? (next === Infinity && prev > 0 ? (1 << 24) * ++far + 997 * far + prev + 13 : prev + 1);
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
- const keyVal = (e) => { const ts = [], d = { c: 0 }; if (!linTerms(e, 1, ts, d))
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
- const key = c.parts.reduce((s, p, i) => s + w[p] * (patterns[mp][i] ?? 1), 0);
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 l = linear(x.key, new Map()), kv = keyVal(x.key);
1555
- if (l && kv !== undefined)
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
@@ -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[];