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.
Files changed (133) 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 +445 -38
  7. package/dist/core/calendar.d.ts +29 -0
  8. package/dist/core/calendar.js +82 -0
  9. package/dist/core/check.js +3 -2
  10. package/dist/core/cli.d.ts +4 -0
  11. package/dist/core/cli.js +335 -39
  12. package/dist/core/compose.js +3 -1
  13. package/dist/core/counts.d.ts +5 -2
  14. package/dist/core/counts.js +335 -88
  15. package/dist/core/cycles.js +8 -1
  16. package/dist/core/cyclic.d.ts +1 -0
  17. package/dist/core/cyclic.js +13 -7
  18. package/dist/core/data-synth.d.ts +3 -0
  19. package/dist/core/data-synth.js +252 -0
  20. package/dist/core/data.d.ts +8 -2
  21. package/dist/core/data.js +1113 -172
  22. package/dist/core/discover.js +3 -1
  23. package/dist/core/draft.d.ts +19 -0
  24. package/dist/core/draft.js +53 -0
  25. package/dist/core/dsl.d.ts +39 -3
  26. package/dist/core/dsl.js +250 -31
  27. package/dist/core/effect-prims.js +2 -2
  28. package/dist/core/effect.d.ts +1 -4
  29. package/dist/core/effect.js +1 -15
  30. package/dist/core/ex/reader.exs +17 -1
  31. package/dist/core/exists.d.ts +16 -1
  32. package/dist/core/exists.js +447 -50
  33. package/dist/core/extract-c.d.ts +2 -0
  34. package/dist/core/extract-c.js +185 -31
  35. package/dist/core/extract-check.d.ts +7 -0
  36. package/dist/core/extract-check.js +115 -3
  37. package/dist/core/extract-ex.js +3 -3
  38. package/dist/core/extract-go-check.d.ts +1 -1
  39. package/dist/core/extract-go-check.js +21 -13
  40. package/dist/core/extract-go.d.ts +1 -0
  41. package/dist/core/extract-go.js +58 -9
  42. package/dist/core/extract-ir.d.ts +1 -0
  43. package/dist/core/extract-ir.js +15 -0
  44. package/dist/core/extract-jvm.d.ts +1 -1
  45. package/dist/core/extract-jvm.js +65 -14
  46. package/dist/core/extract-orm.d.ts +12 -0
  47. package/dist/core/extract-orm.js +244 -0
  48. package/dist/core/extract-print.js +23 -1
  49. package/dist/core/extract-py.d.ts +1 -0
  50. package/dist/core/extract-py.js +4 -4
  51. package/dist/core/extract-rb.js +3 -3
  52. package/dist/core/extract-read.d.ts +25 -0
  53. package/dist/core/extract-read.js +60 -5
  54. package/dist/core/extract-rs.js +22 -20
  55. package/dist/core/extract-shapes.js +22 -0
  56. package/dist/core/extract-sol.d.ts +10 -1
  57. package/dist/core/extract-sol.js +89 -30
  58. package/dist/core/extract-step.d.ts +201 -4
  59. package/dist/core/extract-step.js +1514 -111
  60. package/dist/core/extract-swift.js +24 -13
  61. package/dist/core/extract.d.ts +9 -0
  62. package/dist/core/extract.js +88 -7
  63. package/dist/core/fiber-run.d.ts +5 -0
  64. package/dist/core/fiber-run.js +18 -0
  65. package/dist/core/fresh.d.ts +2 -2
  66. package/dist/core/fresh.js +7 -3
  67. package/dist/core/go/reader.go +7 -1
  68. package/dist/core/infer.d.ts +4 -1
  69. package/dist/core/infer.js +1020 -246
  70. package/dist/core/jvm/JavaReader.java +33 -8
  71. package/dist/core/jvm/Jvm.java +20 -1
  72. package/dist/core/jvm/KtReader.java +59 -6
  73. package/dist/core/laws.d.ts +10 -3
  74. package/dist/core/laws.js +193 -14
  75. package/dist/core/machine.d.ts +16 -3
  76. package/dist/core/machine.js +212 -28
  77. package/dist/core/nonterm.js +14 -1
  78. package/dist/core/orm/harness.js +61 -0
  79. package/dist/core/orm-fixtures/schema.prisma +5 -0
  80. package/dist/core/py/harness.py +260 -21
  81. package/dist/core/py/reader.py +278 -39
  82. package/dist/core/rb/reader.rb +52 -5
  83. package/dist/core/reader-fixtures/README.md +28 -0
  84. package/dist/core/reader-fixtures/c-693042.cpp +8 -0
  85. package/dist/core/reader-fixtures/go-685506.go +14 -0
  86. package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
  87. package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
  88. package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
  89. package/dist/core/reader-fixtures/swift-735726.swift +15 -0
  90. package/dist/core/reader-fixtures/swift-735990.swift +15 -0
  91. package/dist/core/reader-fixtures/swift-739158.swift +4 -0
  92. package/dist/core/reader-fixtures/swift-744834.swift +15 -0
  93. package/dist/core/reader-fixtures/swift-746946.swift +31 -0
  94. package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
  95. package/dist/core/relation.d.ts +1 -1
  96. package/dist/core/relation.js +29 -2
  97. package/dist/core/relational.js +4 -2
  98. package/dist/core/rs/src/main.rs +18 -2
  99. package/dist/core/sample-cache.d.ts +8 -0
  100. package/dist/core/sample-cache.js +46 -0
  101. package/dist/core/security.d.ts +38 -0
  102. package/dist/core/security.js +88 -0
  103. package/dist/core/sol/harness.py +63 -7
  104. package/dist/core/sol-concrete.d.ts +23 -0
  105. package/dist/core/sol-concrete.js +195 -0
  106. package/dist/core/solver.js +8 -5
  107. package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
  108. package/dist/core/system.d.ts +62 -1
  109. package/dist/core/system.js +263 -4
  110. package/dist/core/transfer.js +39 -9
  111. package/dist/core/translate.js +39 -10
  112. package/dist/core/watch.js +51 -6
  113. package/dist/interchange/check.js +10 -10
  114. package/dist/interchange/format.d.ts +4 -0
  115. package/dist/interchange/format.js +24 -6
  116. package/dist/kernel/cdcl.d.ts +5 -0
  117. package/dist/kernel/cdcl.js +88 -10
  118. package/dist/kernel/epr.js +141 -29
  119. package/dist/kernel/kernel.d.ts +31 -1
  120. package/dist/kernel/kernel.js +391 -101
  121. package/dist/kernel/model-sequence.d.ts +3 -0
  122. package/dist/kernel/model-sequence.js +34 -0
  123. package/dist/kernel/prove.d.ts +30 -1
  124. package/dist/kernel/prove.js +481 -71
  125. package/dist/kernel/reader.d.ts +3 -0
  126. package/dist/kernel/reader.js +101 -14
  127. package/dist/kernel/share.d.ts +1 -0
  128. package/dist/kernel/share.js +27 -0
  129. package/dist/lean-kernel/emit.d.ts +9 -3
  130. package/dist/lean-kernel/emit.js +200 -66
  131. package/dist/lean-kernel/lean-terms.js +5 -0
  132. package/dist/lean-kernel/library.js +10 -10
  133. package/package.json +7 -2
@@ -14,7 +14,7 @@
14
14
  // value before, shifts of it, the request's values and the state before; each is chosen to satisfy P at every
15
15
  // counterexample so far, per case of the step (the conditions its updates split on: the request's clause, say).
16
16
  // A law under a `forall` key takes witness terms only (a ghost per key would be a map).
17
- import { carriedView, evalC, evalE, interpret, n as k, walk, x as v } from "./machine.js";
17
+ import { carriedView, compileC, evalC, evalE, fastStep, interpret, n as k, walk, x as v } from "./machine.js";
18
18
  import { clock, proveLaw, proveLaws, withDeadline, withinDeadline } from "../kernel/prove.js";
19
19
  import { env } from "./solver.js";
20
20
  import { ghostedMachine, ghostedOk, substC } from "../kernel/kernel.js";
@@ -40,14 +40,16 @@ export function substVarsE(e, s) {
40
40
  switch (e.op) {
41
41
  case 'var': return s[e.name] ?? e;
42
42
  case 'const': return e;
43
- case 'mul': return { ...e, a: substVarsE(e.a, s) };
43
+ case 'mul':
44
+ case 'proj': return { ...e, a: substVarsE(e.a, s) };
44
45
  case 'if': return { op: 'if', c: substVars(e.c, s), then: substVarsE(e.then, s), else: substVarsE(e.else, s) };
45
46
  case 'get': return { ...e, key: substVarsE(e.key, s) };
46
47
  case 'add':
47
48
  case 'sub':
48
49
  case 'min':
49
50
  case 'max':
50
- case 'prod': return { ...e, a: substVarsE(e.a, s), b: substVarsE(e.b, s) };
51
+ case 'prod':
52
+ case 'tup': return { ...e, a: substVarsE(e.a, s), b: substVarsE(e.b, s) };
51
53
  }
52
54
  }
53
55
  export function substVars(c, s) {
@@ -91,7 +93,9 @@ function lin(e, bound) {
91
93
  case 'max':
92
94
  case 'prod':
93
95
  case 'if':
94
- case 'get': return free ? { k: {}, pos: [e], neg: [] } : undefined;
96
+ case 'get':
97
+ case 'tup':
98
+ case 'proj': return free ? { k: {}, pos: [e], neg: [] } : undefined;
95
99
  }
96
100
  }
97
101
  function atomsOf(c, bound, out = []) {
@@ -162,7 +166,12 @@ const atomsOf2 = (c) => (c.op === 'and' || c.op === 'or' ? c.xs.flatMap(atomsOf2
162
166
  // taken as often as any other. Each state's step from the state it was first reached from is kept: `pathTo`.)
163
167
  const pathTo = new WeakMap();
164
168
  export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
169
+ // (past a thousand steps, through the generated JavaScript, fastStep: the interpreter's states, as compile.test.ts holds
170
+ // them; a small machine's few steps cost less than its compiling)
165
171
  const run = interpret(m), start = run.init(p);
172
+ let steps = 0, fast = run.step;
173
+ const step = (p2, st, r) => { if (++steps === 1000)
174
+ fast = fastStep(m) ?? run.step; return fast(p2, st, r); };
166
175
  const subsets = Array.from({ length: 1 << b }, (_, s) => new Map(Array.from({ length: b }, (_, i) => i).filter(i => (s >> i) & 1).map(i => [i, 1])));
167
176
  // (an input the assumption keeps below a few values, an action's, over all of them; the rest below b)
168
177
  const below = (i) => Math.max(b, ...(m.assume ? atomsOf2(m.assume) : []).flatMap(c => (c.op === '<' && c.a.op === 'var' && c.a.name === i && c.b.op === 'const' && c.b.value <= 8 ? [c.b.value] : [])));
@@ -182,7 +191,7 @@ export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
182
191
  break;
183
192
  let next;
184
193
  try {
185
- next = run.step(p, st, r);
194
+ next = step(p, st, r);
186
195
  }
187
196
  catch {
188
197
  continue;
@@ -207,7 +216,7 @@ export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
207
216
  const r = reqs[rnd(reqs.length)];
208
217
  let next;
209
218
  try {
210
- next = run.step(p, st, r);
219
+ next = step(p, st, r);
211
220
  }
212
221
  catch {
213
222
  continue;
@@ -248,12 +257,13 @@ export function ghostOf(m, law) {
248
257
  }
249
258
  // The small instances, the one filter of every candidate (core/counts.ts's laws, the witnesses and ghosts here): each
250
259
  // param 2 and 3, every input and carried set below 3, every state the BFS reaches in 300,000 steps (3,000 at most) and
251
- // the walks past it in a third as many; an instance whose params the machine refuses has no states. Read once a machine.
260
+ // the walks past it in a third as many; an instance whose params the machine refuses has no states. With no params,
261
+ // 2 and 3 denote the same instance, so sample it only once. Read once a machine.
252
262
  const smalls = new WeakMap();
253
263
  export function smallOf(m) {
254
264
  let out = smalls.get(m);
255
265
  if (!out)
256
- smalls.set(m, (out = [2, 3].map(x => { const p = Object.fromEntries(m.params.map(q => [q, x])); try {
266
+ smalls.set(m, (out = (m.params.length ? [2, 3] : [2]).map(x => { const p = Object.fromEntries(m.params.map(q => [q, x])); try {
257
267
  return { p, sts: small(m, p, 3, 3000, 300_000, 100_000) };
258
268
  }
259
269
  catch {
@@ -266,14 +276,18 @@ export function smallOf(m) {
266
276
  // one instance a machine, however many ghosts are asked of it.
267
277
  export function trueSmall(m, laws, ghosted) {
268
278
  const g = ghosted ?? m, run = ghosted && interpret(ghosted);
279
+ const native = Object.values(g.step.maps ?? {}).some(w => !('each' in w) && w.key.op === 'tup');
280
+ let steps = 0, step = run?.step;
269
281
  return smallOf(m).every(({ p, sts }) => {
270
282
  const at = new Map();
271
283
  return sts.every(st => {
272
284
  let s = st;
273
285
  if (run) {
286
+ if (native && ++steps === 1000)
287
+ step = fastStep(g) ?? run.step;
274
288
  const from = pathTo.get(st);
275
289
  try {
276
- s = from ? run.step(p, at.get(from[0]), from[1]) : run.init(p);
290
+ s = from ? step(p, at.get(from[0]), from[1]) : run.init(p);
277
291
  }
278
292
  catch {
279
293
  return false;
@@ -287,14 +301,46 @@ export function trueSmall(m, laws, ghosted) {
287
301
  // A law at a state, its counts the state's, at every key below b.
288
302
  // (a state's view once: a law is read at every state, and every law at each)
289
303
  const views = new WeakMap();
304
+ const sampleTests = new WeakMap();
290
305
  export function holdsAt(m, law, p, st, b) {
291
- const empty = Object.fromEntries((m.inputMaps ?? []).map(c => [c, new Map()]));
292
306
  let view = views.get(st);
293
- if (!view)
307
+ if (!view) {
308
+ const empty = Object.fromEntries((m.inputMaps ?? []).map(c => [c, new Map()]));
294
309
  views.set(st, (view = carriedView(m, st, empty, undefined, p)));
310
+ }
311
+ let tests = sampleTests.get(m);
312
+ if (!tests)
313
+ sampleTests.set(m, (tests = new WeakMap()));
314
+ let test = tests.get(law.holds);
315
+ if (!test)
316
+ tests.set(law.holds, (test = compileC(law.holds, m)));
295
317
  const keys = [law.forall, ...(law.keys ?? [])].filter((x) => !!x);
296
- const go = (env, ks) => (ks.length ? Array.from({ length: b }, (_, x) => x).every(x => go({ ...env, [ks[0]]: x }, ks.slice(1))) : evalC(law.holds, { ...env, ...st.scalars }, view, m));
297
- return go({ ...p }, keys);
318
+ const env = { ...p, ...st.scalars }, fixed = new Set(Object.keys(st.scalars));
319
+ // One environment, not an object/array copy at every tuple prefix. Scalars still
320
+ // shadow binders, as in the interpreter path; restore duplicate binder names.
321
+ for (const name of keys)
322
+ if (!fixed.has(name))
323
+ Object.defineProperty(env, name, { value: env[name], writable: true, enumerable: true, configurable: true });
324
+ const values = keys.length ? Array.from({ length: b }, (_, x) => x) : [];
325
+ const go = (depth) => {
326
+ if (depth === keys.length)
327
+ return test(env, view);
328
+ const name = keys[depth], was = env[name];
329
+ try {
330
+ for (const value of values) {
331
+ if (!fixed.has(name))
332
+ env[name] = value;
333
+ if (!go(depth + 1))
334
+ return false;
335
+ }
336
+ return true;
337
+ }
338
+ finally {
339
+ if (!fixed.has(name))
340
+ env[name] = was;
341
+ }
342
+ };
343
+ return go(0);
298
344
  }
299
345
  // --- evaluating ∃ on a state ----------------------------------------------------------------------------------------
300
346
  // Whether ∃ vars. P holds where env and st give every other value, with a witness: exact when the bound values are one
@@ -314,7 +360,9 @@ const shapeOf = (body, vars) => {
314
360
  byVars.set(id, out);
315
361
  return out;
316
362
  };
317
- export function someHolds(body, vars, env, st, m) {
363
+ // (`quick`: a run's watch, which reads only whether it holds: first 0, then the points without the cells, a witness there
364
+ // one; the verdict and its cap as without)
365
+ export function someHolds(body, vars, env, st, m, quick = false) {
318
366
  const { groups, atoms, linearOnly, reads } = shapeOf(body, vars);
319
367
  const value = (e) => { try {
320
368
  return evalE(e, env, st, m);
@@ -323,12 +371,7 @@ export function someHolds(body, vars, env, st, m) {
323
371
  return undefined;
324
372
  } };
325
373
  // A bound natural read as a map's key: the cells the maps hold, and one past them, are every case a read gives.
326
- const cells = new Set();
327
- if (reads)
328
- for (const c of Object.values(st.maps))
329
- for (const key of c.keys())
330
- cells.add(key);
331
- const points = (g) => {
374
+ const points = (g, cells) => {
332
375
  const ps = new Set([0, 1, ...cells, ...[...cells].map(c => c + 1)]);
333
376
  for (const a of atoms) {
334
377
  const s = a.k[g[0]] ?? 0, s2 = g.length === 2 ? (a.k[g[1]] ?? 0) : 0;
@@ -352,8 +395,7 @@ export function someHolds(body, vars, env, st, m) {
352
395
  catch {
353
396
  return undefined;
354
397
  } };
355
- const lists = groups.map(points);
356
- let tried = 0, unknown = false;
398
+ let tried = 0, unknown = false, lists = [];
357
399
  const go = (i, w) => {
358
400
  if (i === groups.length) {
359
401
  tried++;
@@ -371,6 +413,26 @@ export function someHolds(body, vars, env, st, m) {
371
413
  }
372
414
  return undefined;
373
415
  };
416
+ // (first the points without the cells: P's guard false at a tuple, as at most of a law's, holds at 0 at once; a witness
417
+ // there is one; then every point, as before, its verdict and cap the same)
418
+ const none = new Set();
419
+ if (reads && quick) {
420
+ const w0 = Object.assign({}, ...groups.map(g => at(g, 0)));
421
+ if (test(w0))
422
+ return { holds: true, witness: w0 };
423
+ lists = groups.map(g => points(g, none));
424
+ const near = go(0, {});
425
+ if (near)
426
+ return { holds: true, witness: near };
427
+ }
428
+ const cells = new Set();
429
+ if (reads)
430
+ for (const c of Object.values(st.maps))
431
+ for (const key of c.keys())
432
+ cells.add(key);
433
+ lists = groups.map(g => points(g, cells));
434
+ tried = 0;
435
+ unknown = false;
374
436
  const hit = go(0, {});
375
437
  if (hit)
376
438
  return { holds: true, witness: hit };
@@ -414,7 +476,9 @@ function onlyKeys(e, bound) {
414
476
  case 'max':
415
477
  case 'prod': return onlyKeys(e.a, bound) && onlyKeys(e.b, bound);
416
478
  case 'mul': return onlyKeys(e.a, bound);
417
- case 'if': return false;
479
+ case 'if':
480
+ case 'tup':
481
+ case 'proj': return false;
418
482
  case 'get': return false;
419
483
  }
420
484
  }
@@ -505,6 +569,229 @@ function planOf(m, law) {
505
569
  groups.forEach((g, i) => { starts[i] = [g.map(n => w.ghost[n]?.start ?? k(0))]; steps[i] = [g.map(n => w.ghost[n]?.step ?? v(n))]; });
506
570
  return { law, groups, terms, starts, steps, maps: [], pick: w?.ghost ? { mode: 'ghost', start: groups.map(() => 0), cases: new Map() } : { mode: 'term', at: groups.map(() => 0) }, seen: { term: [], start: [], step: new Map() }, given };
507
571
  }
572
+ // A ghost map (lean-kernel/GhostMap.lean; kernel.ts's Ghosted): for a law about every key with one value ∃x. P, a map W
573
+ // the step keeps, written where a write of the rule sets a cell (its value with the cell's own read at 0 is 1), at that
574
+ // write's key, to a request's value outside the key; the law proven is P with x at W[k] for the law's keys k in the write
575
+ // key's places, beside the ghost's own law: where the written map's cell is set (and the law's guards hold), P at W[k].
576
+ // Every such place and value is a candidate; those false on the small instances' states are never tried
577
+ // (core/counts.ts's), the rest in turn by the kernel's goals.
578
+ // A write's provenance: where map M's cell is set by a write at a key of inputs, a ghost map G at that key holding another
579
+ // input of the request, val, read at that key (G[i·N + p] := r where DbResponseSent[i·N + p] is set); G's own law, where
580
+ // M's cell is set, what the write's guard says of val there, and the cells the same guard sets at keys val is in (T[i·N +
581
+ // n] beside DbRequestSent[i·N + r]), at G's cell. None where the guard says nothing of val.
582
+ const keyedOf = (m) => {
583
+ const keyed = new Set();
584
+ walk([m.step, m.assume ?? null], o => { if (o.op === 'get')
585
+ for (const n of namesOf(o.key))
586
+ keyed.add(n); });
587
+ for (const w2 of Object.values(m.step.maps ?? {}))
588
+ if (!('each' in w2))
589
+ for (const n of namesOf(w2.key))
590
+ keyed.add(n);
591
+ return keyed;
592
+ };
593
+ function provenanceOf(m, mp2, val2, taken, keyed = keyedOf(m)) {
594
+ const w2 = m.step.maps?.[mp2];
595
+ if (!w2 || 'each' in w2)
596
+ return undefined;
597
+ const kv2 = namesOf(w2.key), flags = Object.fromEntries(Object.keys(m.step.flags ?? {}).map(f => [f, { op: 'flag', name: f }]));
598
+ if (!kv2.length || !kv2.every(n => m.inputs.includes(n) && keyed.has(n)) || kv2.includes(val2) || !keyed.has(val2))
599
+ return undefined;
600
+ const setOf = (mp, w) => substC({ op: '<=', a: k(1), b: w.value }, { vars: {}, maps: { [mp]: () => k(0) }, flags });
601
+ const set2 = setOf(mp2, w2);
602
+ const conj = (c, depth = 0) => (c.op === 'and' ? c.xs.flatMap(y => conj(y, depth)) : c.op === 'flag' && depth < 3 && m.step.flags?.[c.name] && m.step.flags[c.name].op !== 'all' ? conj(m.step.flags[c.name], depth + 1) : [c]);
603
+ const lits = [...new Set([...JSON.stringify(w2.value).matchAll(/"op":"flag","name":"([^"]+)"/g)].map(x => x[1]))].flatMap(f => conj({ op: 'flag', name: f }));
604
+ let gname = `${mp2}$g`;
605
+ for (let j = 2; taken.has(gname); j++)
606
+ gname = `${mp2}$g${j}`;
607
+ const ks = kv2.map((_, j) => `g${j}$key`), G = (t) => ({ op: 'get', map: gname, key: t }), K2 = substVarsE(w2.key, Object.fromEntries(kv2.map((n, j) => [n, v(ks[j])])));
608
+ const sub = { [val2]: G(K2), ...Object.fromEntries(kv2.map((n, j) => [n, v(ks[j])])) }, mine = (ns) => ns.includes(val2) && ns.every(n => n === val2 || kv2.includes(n));
609
+ const says = lits.filter(c => c.op !== 'flag' && mine(namesOf(c))).map(c => substVars(c, sub));
610
+ // (the cells the same guard sets beside it)
611
+ for (const [mp3, w3] of Object.entries(m.step.maps ?? {}))
612
+ if (mp3 !== mp2 && !('each' in w3) && mine(namesOf(w3.key)) && key(setOf(mp3, w3)) === key(set2))
613
+ says.push({ op: '<=', a: k(1), b: { op: 'get', map: mp3, key: substVarsE(w3.key, sub) } });
614
+ if (!says.length)
615
+ return undefined;
616
+ if (w2.key.op === 'tup')
617
+ says.push(...(m.assume ? atomsOf2(m.assume) : []).filter(c => mine(namesOf(c))).map(c => substVars(c, sub)));
618
+ const inv = { name: `${gname} where ${mp2} is set`, forall: ks[0], ...(ks.length > 1 ? { keys: ks.slice(1) } : {}), holds: { op: 'or', xs: [{ op: 'not', x: { op: '<=', a: k(1), b: { op: 'get', map: mp2, key: K2 } } }, says.length === 1 ? says[0] : { op: 'and', xs: says }] } };
619
+ return { name: gname, write: { key: w2.key, value: { op: 'if', c: set2, then: v(val2), else: G(w2.key) } }, inv };
620
+ }
621
+ // The writes that set a map's cell from 0: the cell as a term of the request alone and the condition it is set under, a
622
+ // write at one key (its key), or at every key where its value reads `each = τ`, τ over the request alone.
623
+ function settersOf(m, mp) {
624
+ const w = m.step.maps?.[mp];
625
+ if (!w)
626
+ return [];
627
+ const flags = Object.fromEntries(Object.keys(m.step.flags ?? {}).map(f => [f, { op: 'flag', name: f }]));
628
+ const setAt = (val) => substC({ op: '<=', a: k(1), b: val }, { vars: {}, maps: { [mp]: () => k(0) }, flags });
629
+ const reqOnly = (t) => !readsMaps(t) && namesOf(t).length > 0 && namesOf(t).every(n => m.inputs.includes(n));
630
+ if (!('each' in w))
631
+ return reqOnly(w.key) ? [{ at: w.key, set: setAt(w.value) }] : [];
632
+ const ats = new Map();
633
+ walk(w.value, o => { if (o.op === '=')
634
+ for (const [a, b] of [[o.a, o.b], [o.b, o.a]])
635
+ if (a.op === 'var' && a.name === w.each && reqOnly(b))
636
+ ats.set(key(b), b); });
637
+ return [...ats.values()].map(at => ({ at, set: setAt(substVarsE(w.value, { [w.each]: at })) }));
638
+ }
639
+ // The supports a law made plain by binderGhostsOf may need, those the small instances keep: each ghost below the bound the
640
+ // assumption puts on the input it holds (G[k] := n, n < 64: G[k] < 64); each disjunct with its names at their terms,
641
+ // where one or two control facts hold (a scalar at a value, a cell at the law's key of a map written at one input's
642
+ // key): what keeps a witness before the law reads it (no_lost_keys: Owner at Owner$n[k] where Owned[k] before start);
643
+ // and each map empty at every key while a scalar holds a value (no transfer before start).
644
+ function ghostSupports(m, law, c, gm) {
645
+ const L = law.forall, out = [], cmp = (op, a, b) => ({ op, a, b }), lim = (m.assume ? atomsOf2(m.assume) : []);
646
+ for (const [name, w] of Object.entries(c.maps)) {
647
+ const val = w.write.value, i = val.op === 'if' && val.then.op === 'var' ? val.then.name : undefined;
648
+ const bound = lim.find(a => a.op === '<' && a.a.op === 'var' && a.a.name === i && a.b.op === 'const');
649
+ if (bound)
650
+ out.push({ name: `${name} below ${showE(bound.b)}`, forall: L, holds: cmp('<', { op: 'get', map: name, key: v(L) }, bound.b) });
651
+ }
652
+ const sts = smallOf(m).flatMap(q => q.sts), seen = (n) => [...new Set(sts.map(st => st.scalars[n] ?? 0))].slice(0, 3);
653
+ const facts = [...Object.keys(m.state).flatMap(n => seen(n).map(x => cmp('=', v(n), k(x)))),
654
+ ...Object.entries(m.step.maps ?? {}).flatMap(([mp, w]) => ('each' in w || w.key.op !== 'var' ? [] : [0, 1].map(x => cmp('=', { op: 'get', map: mp, key: v(L) }, k(x)))))];
655
+ const ds = (law.holds.op === 'or' ? law.holds.xs : [law.holds]).flatMap(d => (d.op === 'or' ? d.xs : [d])).filter(d => law.some.some(x => namesOf(d).includes(x)));
656
+ const holds = (g, d) => ({ op: 'or', xs: [{ op: 'not', x: g.length === 1 ? g[0] : { op: 'and', xs: g } }, d] });
657
+ for (const d of ds)
658
+ for (const [j, f] of facts.entries())
659
+ for (const g of [[f], ...facts.slice(j + 1).filter(f2 => key(f2.a) !== key(f.a)).map(f2 => [f, f2])])
660
+ out.push({ name: `${showC(holds(g, d)).slice(0, 80)} (${out.length})`, forall: L, holds: holds(g, substC(d, { vars: c.sub, maps: {}, flags: {} })) });
661
+ for (const f of facts.filter(f2 => !readsMaps(f2)))
662
+ for (const mp of Object.keys(m.maps ?? {}))
663
+ out.push({ name: `${mp} empty where ${showC(f)} (${out.length})`, forall: L, holds: holds([f], cmp('=', { op: 'get', map: mp, key: v(L) }, k(0))) });
664
+ return out.filter(l2 => { try {
665
+ return trueSmall(m, [l2], gm);
666
+ }
667
+ catch {
668
+ return false;
669
+ } }).slice(0, 24);
670
+ }
671
+ // Ghost maps for a law about one key with several bound names (a disjunction of ∃s, each name in its own disjuncts): for
672
+ // each name, a write that sets a cell the law reads at a key holding the name: the name the request's value the write's
673
+ // key holds there (Owner[N·k + x] set at N·k + n: x is n), or the cell itself (TransferMsg[z] set at τ: z is τ, the
674
+ // law's key one input of τ and each other a ghost map at it: G[k] := n where the cell is set). Each name a term over the
675
+ // ghosts (kernel.ts's someOfGhostsOk reads them so); every choice of one a name, at most 64.
676
+ function binderGhostsOf(m, law, taken) {
677
+ const L = law.forall, xs = law.some;
678
+ if (law.keys?.length || xs.some(x => x.endsWith('$neg')))
679
+ return [];
680
+ const options = xs.map((x, jx) => {
681
+ const out = [], reads = [];
682
+ walk(law.holds, o => { if (o.op === 'get' && namesOf(o.key).includes(x))
683
+ reads.push({ mp: o.map, at: o.key }); });
684
+ for (const { mp, at: kappa } of reads)
685
+ for (const { at: tau, set } of settersOf(m, mp))
686
+ for (const ki of namesOf(tau)) {
687
+ const ghostOf = (i) => {
688
+ let name = `${mp}$${i}${jx || ''}`;
689
+ for (let j = 2; taken.has(name); j++)
690
+ name = `${mp}$${i}${jx || ''}~${j}`;
691
+ return [name, { start: 0, write: { key: v(ki), value: { op: 'if', c: set, then: v(i), else: { op: 'get', map: name, key: v(ki) } } } }];
692
+ };
693
+ const others = namesOf(tau).filter(i => i !== ki);
694
+ if (kappa.op === 'var' && kappa.name === x) {
695
+ const gs = others.map(i => [i, ghostOf(i)]);
696
+ out.push({ maps: Object.fromEntries(gs.map(([, q]) => q)), term: substVarsE(tau, { [ki]: v(L), ...Object.fromEntries(gs.map(([i, q]) => [i, { op: 'get', map: q[0], key: v(L) }])) }) });
697
+ }
698
+ else
699
+ for (const i of others) {
700
+ if (key(substVarsE(kappa, { [L]: v(ki), [x]: v(i) })) !== key(tau))
701
+ continue;
702
+ const q = ghostOf(i);
703
+ out.push({ maps: { [q[0]]: q[1] }, term: { op: 'get', map: q[0], key: v(L) } });
704
+ }
705
+ }
706
+ return out;
707
+ });
708
+ let combos = [{ maps: {}, sub: {} }];
709
+ xs.forEach((x, j) => { combos = combos.flatMap(c => options[j].map(o => ({ maps: { ...c.maps, ...o.maps }, sub: { ...c.sub, [x]: o.term } }))).slice(0, 64); });
710
+ return combos;
711
+ }
712
+ // A witness's local proof need not instantiate unrelated provenance functions.
713
+ // Keep supports over the target's dependency maps, including reads by their
714
+ // updates and flags. Excluded supports can still prove other
715
+ // members of the final set; no proof/assumption is reused without that check.
716
+ export function witnessSupport(m, laws, law, ghosts = []) {
717
+ const maps = new Set(), flags = new Set();
718
+ const read = (t) => walk(t, o => {
719
+ if (o.op === 'get')
720
+ maps.add(o.map);
721
+ if (o.op === 'flag' && !flags.has(o.name)) {
722
+ flags.add(o.name);
723
+ read(m.step.flags?.[o.name]);
724
+ }
725
+ });
726
+ read(law.holds);
727
+ const plain = ghosts.every(g => !maps.has(g)), ghostSet = new Set(ghosts);
728
+ for (const mp of maps)
729
+ read(m.step.maps?.[mp]);
730
+ return laws.filter(l => {
731
+ if (l === law)
732
+ return true;
733
+ let relevant = true;
734
+ walk(l.holds, o => { if (o.op === 'get' && !maps.has(o.map) && !(plain && ghostSet.has(o.map)))
735
+ relevant = false; });
736
+ return relevant;
737
+ });
738
+ }
739
+ // Candidate closure of row provenance: facts about a write's key, its co-written
740
+ // rows joined at shared inputs, and functional dependencies of each key place.
741
+ // No dependency is presumed to hold: runs discard false ones, the prover checks
742
+ // the remaining simultaneous induction obligations.
743
+ function rowSupports(m) {
744
+ const out = [], seen = new Set();
745
+ const and = (xs) => ({ op: 'and', xs });
746
+ const has = (map, at) => ({ op: '<=', a: k(1), b: { op: 'get', map, key: at } });
747
+ const expand = (c, depth = 0) => c.op === 'and' ? c.xs.flatMap(q => expand(q, depth)) : c.op === 'flag' && depth < 8 && m.step.flags?.[c.name] ? expand(m.step.flags[c.name], depth + 1) : [c];
748
+ const assumptions = m.assume ? expand(m.assume) : [];
749
+ const writes = Object.entries(m.step.maps ?? {}).flatMap(([map, w]) => {
750
+ if ('each' in w || w.key.op !== 'tup')
751
+ return [];
752
+ const names = namesOf(w.key);
753
+ if (!names.length || !names.every(n => m.inputs.includes(n)))
754
+ return [];
755
+ const flags = new Set();
756
+ walk(w.value, o => { if (o.op === 'flag')
757
+ flags.add(o.name); });
758
+ return [{ map, w, names, guards: [...flags].flatMap(name => expand({ op: 'flag', name })), setter: settersOf(m, map)[0]?.set }];
759
+ });
760
+ const emit = (names, pre, post, label) => {
761
+ const ren = Object.fromEntries(names.map((n, i) => [n, v(`row${i}$key`)]));
762
+ const holds = substVars({ op: 'or', xs: [{ op: 'not', x: and(pre) }, post] }, ren);
763
+ // Quantifier order and conjunction order do not distinguish a proposal.
764
+ // Keep the first spelling, rather than burdening later goals with both.
765
+ const id = key([names.slice().sort(), pre.map(key).sort(), post]);
766
+ if (seen.has(id))
767
+ return;
768
+ seen.add(id);
769
+ out.push({ name: `${label} (${out.length})`, forall: `row0$key`, ...(names.length > 1 ? { keys: names.slice(1).map((_, i) => `row${i + 1}$key`) } : {}), holds });
770
+ };
771
+ const usable = (c, names) => c.op !== 'flag' && c.op !== 'all' && namesOf(c).every(n => names.includes(n) || Object.hasOwn(m.state, n) || m.params.includes(n));
772
+ for (const a of writes) {
773
+ for (const c of [...a.guards, ...assumptions].filter(c => usable(c, a.names)))
774
+ emit(a.names, [has(a.map, a.w.key)], c, `${a.map} row guard`);
775
+ const freshRow = a.guards.some(c => c.op === 'all' && JSON.stringify(c).includes(`"map":${JSON.stringify(a.map)}`));
776
+ for (const n of freshRow ? a.names : []) {
777
+ let other = 'other$row';
778
+ while (m.inputs.includes(other) || a.names.includes(other))
779
+ other += '$';
780
+ const bounds = assumptions.filter(c => usable(c, a.names) && !readsMaps(c));
781
+ emit([...a.names, other], [...bounds, ...bounds.map(c => substVars(c, { [n]: v(other) })), has(a.map, a.w.key), has(a.map, substVarsE(a.w.key, { [n]: v(other) }))], { op: '=', a: v(n), b: v(other) }, `${a.map} functional ${n}`);
782
+ }
783
+ for (const b of writes) {
784
+ if (a.map === b.map || !a.setter || key(a.setter) !== key(b.setter) || !a.names.some(n => b.names.includes(n)))
785
+ continue;
786
+ const names = [...new Set([...a.names, ...b.names])];
787
+ if (names.length > 4)
788
+ continue;
789
+ for (const c of a.guards.filter(c => usable(c, names) && readsMaps(c)))
790
+ emit(names, [has(a.map, a.w.key), has(b.map, b.w.key)], c, `${a.map} / ${b.map} joined guard`);
791
+ }
792
+ }
793
+ return out;
794
+ }
508
795
  function mapGhostsOf(m, law, taken) {
509
796
  const x = law.some[0], names = [law.forall, ...(law.keys ?? [])];
510
797
  const xs = law.holds.op === 'or' ? law.holds.xs : [law.holds], P = xs.filter(d => namesOf(d).includes(x)), rest = xs.filter(d => !namesOf(d).includes(x));
@@ -522,14 +809,7 @@ function mapGhostsOf(m, law, taken) {
522
809
  // (each write key's input at a different one of the law's keys)
523
810
  const injections = kv.reduce((acc) => acc.flatMap(a => names.filter(n => !a.includes(n)).map(n => [...a, n])), [[]]);
524
811
  // (a value an action selects, compared with constants alone, is no witness)
525
- const keyed = new Set();
526
- walk([m.step, m.assume ?? null], o => { if (o.op === 'get')
527
- for (const n of namesOf(o.key))
528
- keyed.add(n); });
529
- for (const w2 of Object.values(m.step.maps ?? {}))
530
- if (!('each' in w2))
531
- for (const n of namesOf(w2.key))
532
- keyed.add(n);
812
+ const keyed = keyedOf(m);
533
813
  const action = (i) => !keyed.has(i);
534
814
  const ghost = (val, inner) => {
535
815
  for (const inj of injections) {
@@ -548,31 +828,145 @@ function mapGhostsOf(m, law, taken) {
548
828
  // (a ghost of a ghost, after those: the value another write's ghost holds, read at that write's key in this step's
549
829
  // request: G[i·N + p] := r where DbResponseSent[i·N + p] is set, W[n·N + p] := G[i·N + p] where ResponseSent is.
550
830
  // G's own law: where its write's cell is set, what the write's guard says of r, at G's cell)
551
- for (const [mp2, w2] of Object.entries(m.step.maps ?? {})) {
552
- if (mp2 === mp || 'each' in w2)
831
+ const inner = [];
832
+ for (const mp2 of Object.keys(m.step.maps ?? {})) {
833
+ if (mp2 === mp)
553
834
  continue;
554
- const kv2 = namesOf(w2.key);
555
- if (!kv2.length || !kv2.every(n => m.inputs.includes(n) && keyed.has(n)))
835
+ const w2 = m.step.maps[mp2];
836
+ if ('each' in w2)
556
837
  continue;
557
- const set2 = substC({ op: '<=', a: k(1), b: w2.value }, { vars: {}, maps: { [mp2]: () => k(0) }, flags: Object.fromEntries(Object.keys(m.step.flags ?? {}).map(f => [f, { op: 'flag', name: f }])) });
558
- const conj = (c, depth = 0) => (c.op === 'and' ? c.xs.flatMap(y => conj(y, depth)) : c.op === 'flag' && depth < 3 && m.step.flags?.[c.name] && m.step.flags[c.name].op !== 'all' ? conj(m.step.flags[c.name], depth + 1) : [c]);
559
- const lits = [...new Set([...JSON.stringify(w2.value).matchAll(/"op":"flag","name":"([^"]+)"/g)].map(x => x[1]))].flatMap(f => conj({ op: 'flag', name: f }));
560
- for (const val2 of m.inputs.filter(i => !kv2.includes(i) && !action(i))) {
561
- let gname = `${mp2}$g`;
562
- for (let j = 2; taken.has(gname); j++)
563
- gname = `${mp2}$g${j}`;
564
- const ks = kv2.map((_, j) => `g${j}$key`), G = (t) => ({ op: 'get', map: gname, key: t }), K2 = substVarsE(w2.key, Object.fromEntries(kv2.map((n, j) => [n, v(ks[j])])));
565
- const says = lits.filter(c => c.op !== 'flag' && namesOf(c).includes(val2) && namesOf(c).every(n => n === val2 || kv2.includes(n))).map(c => substVars(c, { [val2]: G(K2), ...Object.fromEntries(kv2.map((n, j) => [n, v(ks[j])])) }));
566
- if (!says.length)
567
- continue;
568
- const inv = { name: `${gname} where ${mp2} is set`, forall: ks[0], ...(ks.length > 1 ? { keys: ks.slice(1) } : {}), holds: { op: 'or', xs: [{ op: 'not', x: { op: '<=', a: k(1), b: { op: 'get', map: mp2, key: K2 } } }, says.length === 1 ? says[0] : { op: 'and', xs: says }] } };
569
- ghost(G(w2.key), { name: gname, write: { key: w2.key, value: { op: 'if', c: set2, then: v(val2), else: G(w2.key) } }, inv });
838
+ // A witness whose writer needs a universal freshness guard has a more
839
+ // expensive support obligation than one selected by positive row reads.
840
+ // On native relations prefer the latter, independently of map order.
841
+ let cost = 0;
842
+ const seen = new Set(), inspect = (t) => walk(t, o => {
843
+ if (o.op === 'all')
844
+ cost++;
845
+ if (o.op === 'flag' && !seen.has(o.name)) {
846
+ seen.add(o.name);
847
+ inspect(m.step.flags?.[o.name]);
848
+ }
849
+ });
850
+ if (w.key.op === 'tup')
851
+ inspect(w2.value);
852
+ for (const val2 of m.inputs) {
853
+ const g = provenanceOf(m, mp2, val2, taken, keyed);
854
+ if (g) {
855
+ if (w.key.op === 'tup')
856
+ inner.push({ g, at: w2.key, cost });
857
+ else
858
+ ghost({ op: 'get', map: g.name, key: w2.key }, g);
859
+ }
570
860
  }
571
861
  }
862
+ for (const { g, at } of inner.sort((a, b) => a.cost - b.cost))
863
+ ghost({ op: 'get', map: g.name, key: at }, g);
572
864
  }
573
865
  return out;
574
866
  }
575
867
  const takenOf = (m) => new Set([...Object.keys(m.maps ?? {}), ...(m.inputMaps ?? []), ...Object.keys(m.fns ?? {})]);
868
+ // The laws about every key with one value ∃x. P made plain by their ghost maps (Skolem functions the step keeps): for
869
+ // each, the first ghost map whose laws hold on the small instances, as proveSome's toMap picks it (the same names), and
870
+ // the law with x at W[k] beside the ghosts' own laws. What the ∀ search takes: a set it proves over the machine with the
871
+ // ghosts, the ghosts the original's (`ok`, kernel.ts's ghostedOk), proves each ∃ law, x at its ghost's cell (GhostMap.lean's
872
+ // forall_some_of_ghostmap); proveSome's ghost maps are the same, for a proof again of the laws as stated.
873
+ // (`ghost`: the ghosts added to a machine the search derives from the rule's (its sums, its divisors), unchecked: `ok`
874
+ // checks them against the original; the laws as proveSome states them, so that the goals the search settled are its again)
875
+ export function skolemOf(m, laws) {
876
+ const taken = takenOf(m), out = [], gs = [];
877
+ const parts = [], one = (m2, q) => ({ orig: m2, vars: {}, maps: { [q.name]: { start: 0, write: q.write } } });
878
+ const ghost = (m2, more = []) => [...parts, ...more].reduce((acc, q) => ghostedMachine(one(acc, q)), m2);
879
+ const plains = {}, witnesses = {}, cands = [];
880
+ const own = (g) => [...(g.inner ? [g.inner] : []), g];
881
+ for (const l of laws) {
882
+ if (!l.some?.length) {
883
+ out.push(l);
884
+ continue;
885
+ }
886
+ if (!l.forall || l.witness)
887
+ return undefined;
888
+ // (the value named apart from the machine's names (proveSome renames it), and no binder inside the law that the ghost's
889
+ // cell, read at the law's keys, would be captured by: else no plain form)
890
+ const binders = new Set();
891
+ walk(l.holds, o => { if (o.op === 'all')
892
+ for (const b of [o.key, ...(o.keys ?? [])])
893
+ binders.add(b); });
894
+ if (l.some.some(x => [...m.params, ...m.inputs, ...Object.keys(m.state)].includes(x)) || [l.forall, ...(l.keys ?? [])].some(x => binders.has(x)))
895
+ return undefined;
896
+ const { some: _s, ...plain } = l;
897
+ void _s;
898
+ // (several bound names (a disjunction of ∃s): each a term over ghost maps, binderGhostsOf's, the first whose plain law
899
+ // holds on the small instances)
900
+ if (l.some.length > 1) {
901
+ const holdsOf = (sub) => substC(l.holds, { vars: sub, maps: {}, flags: {} });
902
+ const c = binderGhostsOf(m, l, taken).find(c2 => { try {
903
+ return trueSmall(m, [{ ...plain, holds: holdsOf(c2.sub) }], ghost(m, Object.entries(c2.maps).map(([name, w]) => ({ name, write: w.write }))));
904
+ }
905
+ catch {
906
+ return false;
907
+ } });
908
+ if (!c)
909
+ return undefined;
910
+ for (const [name, w] of Object.entries(c.maps)) {
911
+ parts.push({ name, write: w.write });
912
+ taken.add(name);
913
+ }
914
+ const pl = { ...plain, holds: holdsOf(c.sub) };
915
+ out.push(pl);
916
+ plains[l.name] = { plain: pl, sub: c.sub };
917
+ witnesses[l.name] = [...l.some.map(x => `${x} = ${showE(c.sub[x])}`), ...Object.entries(c.maps).map(([name, w]) => { const u = w.write; return `${name}[${showE(u.key)}] := ${showE(u.value)}`; })].join(', ');
918
+ cands.push(...ghostSupports(m, l, c, ghost(m)));
919
+ continue;
920
+ }
921
+ const g = mapGhostsOf(m, l, taken).find(c => { try {
922
+ return trueSmall(m, [...(c.inner ? [c.inner.inv] : []), c.inv, { ...l, holds: c.holds, some: undefined }], ghost(m, own(c)));
923
+ }
924
+ catch {
925
+ return false;
926
+ } });
927
+ if (!g)
928
+ return undefined;
929
+ gs.push(g);
930
+ parts.push(...own(g));
931
+ for (const q of own(g))
932
+ taken.add(q.name);
933
+ const pl = { ...plain, holds: g.holds };
934
+ out.push(pl, ...(g.inner ? [g.inner.inv] : []), g.inv);
935
+ plains[l.name] = { plain: pl, sub: { [l.some[0]]: { op: 'get', map: g.name, key: g.at } } };
936
+ witnesses[l.name] = `w = ${g.name}[${showE(g.at)}], ${g.name}[${showE(g.write.key)}] := ${showE(g.write.value)}`;
937
+ }
938
+ // Native relations have independent key components. For a relation read by a
939
+ // witness support, retain the input forgotten by its key as another candidate
940
+ // ghost. In particular, co-written rows then have converse provenance, rather
941
+ // than permitting old orphan rows in induction pre-states. These are proposed
942
+ // laws, filtered on runs and subsequently proved, never admitted assumptions.
943
+ if (gs.some(g => g.inner) && Object.values(m.step.maps ?? {}).some(w => !('each' in w) && w.key.op === 'tup')) {
944
+ cands.push(...rowSupports(m).filter(l => trueSmall(m, [l])));
945
+ const needed = new Set();
946
+ walk(out, o => { if (o.op === 'get')
947
+ needed.add(o.map); });
948
+ for (const mp of needed)
949
+ for (const input of m.inputs) {
950
+ const q = provenanceOf(m, mp, input, taken);
951
+ if (!q || parts.some(p => p.write.value.op === 'if' && q.write.value.op === 'if' && key([p.write.key, p.write.value.c]) === key([q.write.key, q.write.value.c])))
952
+ continue;
953
+ const mm = ghost(m, [q]);
954
+ if (!trueSmall(m, [q.inv], mm))
955
+ continue;
956
+ parts.push(q);
957
+ taken.add(q.name);
958
+ cands.push(q.inv);
959
+ }
960
+ }
961
+ // (each ghost one of the machine it is added to, as kernel.ts's ghostedOk reads it)
962
+ const ok = (m2) => { let at = m2; for (const q of parts) {
963
+ const o = one(at, q);
964
+ if (!ghostedOk(o))
965
+ return false;
966
+ at = ghostedMachine(o);
967
+ } return true; };
968
+ return parts.length ? { ghost: m2 => ghost(m2), laws: out, ok, witnesses, maps: Object.fromEntries(parts.map(q => [q.name, { start: 0, write: q.write }])), plains, cands } : undefined;
969
+ }
576
970
  const firstPicks = new Map();
577
971
  // The machine with a ghost map (kernel.ts's ghostedMachine of Ghosted, whose ghostedOk it must pass).
578
972
  const withMap = (m, g) => {
@@ -775,8 +1169,9 @@ export function proveSome(m, laws, opts = {}) {
775
1169
  }
776
1170
  for (let round = 0;; round++) {
777
1171
  const now = current(), t0 = performance.now(), r = round === 0 && first ? { proven: false, ...first }
778
- // (a ghost map's goals within 2 s: a search asks them with every candidate set, and one without its supports can take minutes)
779
- : p.pick.mode === 'map' ? withDeadline(clock() + 2_000, () => proveLaw(now.machine, now.laws, i)) : proveLaw(now.machine, now.laws, i);
1172
+ // (a ghost map's goals within 2 s: a search asks them with every candidate set, and one without its supports can take
1173
+ // minutes; `mapMs` where the supports are the search's, found over the same map)
1174
+ : p.pick.mode === 'map' ? withDeadline(clock() + (opts.mapMs ?? 2_000), () => proveLaw(now.machine, now.laws, i)) : proveLaw(now.machine, now.laws, i);
780
1175
  if (log)
781
1176
  console.error(`exists: pass ${pass} round ${round} "${p.law.name}" ${p.pick.mode} ${describe(p, cases).slice(0, 160)}: ${r.proven ? 'proven' : `${r.goal} ${r.stuck}`} (${Math.round(performance.now() - t0)} ms)`);
782
1177
  if (r.proven)
@@ -920,6 +1315,8 @@ export function showE(e) {
920
1315
  case 'max': return `${e.op}(${showE(e.a)}, ${showE(e.b)})`;
921
1316
  case 'if': return `(${showC(e.c)} ? ${showE(e.then)} : ${showE(e.else)})`;
922
1317
  case 'get': return `${e.map}[${showE(e.key)}]`;
1318
+ case 'tup': return `⟨${showE(e.a)}, ${showE(e.b)}⟩`;
1319
+ case 'proj': return `${e.k === 0 ? 'fst' : 'snd'}(${showE(e.a)})`;
923
1320
  }
924
1321
  }
925
1322
  export function showC(c) {