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.
Files changed (126) hide show
  1. package/README.md +61 -8
  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 +4 -0
  10. package/dist/core/cli.js +206 -40
  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-schema.d.ts +90 -0
  27. package/dist/core/effect-schema.js +500 -0
  28. package/dist/core/effect.d.ts +4 -11
  29. package/dist/core/effect.js +3 -79
  30. package/dist/core/exists.d.ts +1 -0
  31. package/dist/core/exists.js +191 -16
  32. package/dist/core/extract-c.d.ts +2 -0
  33. package/dist/core/extract-c.js +169 -22
  34. package/dist/core/extract-check.d.ts +1 -0
  35. package/dist/core/extract-check.js +97 -6
  36. package/dist/core/extract-go-check.d.ts +1 -1
  37. package/dist/core/extract-go-check.js +26 -5
  38. package/dist/core/extract-go.d.ts +8 -0
  39. package/dist/core/extract-go.js +67 -6
  40. package/dist/core/extract-ir.d.ts +1 -0
  41. package/dist/core/extract-ir.js +15 -0
  42. package/dist/core/extract-jvm.d.ts +1 -1
  43. package/dist/core/extract-jvm.js +2 -0
  44. package/dist/core/extract-orm.d.ts +12 -0
  45. package/dist/core/extract-orm.js +244 -0
  46. package/dist/core/extract-print.js +20 -1
  47. package/dist/core/extract-py.d.ts +1 -0
  48. package/dist/core/extract-py.js +1 -1
  49. package/dist/core/extract-read.d.ts +26 -1
  50. package/dist/core/extract-read.js +14 -7
  51. package/dist/core/extract-rs.js +63 -15
  52. package/dist/core/extract-shapes.d.ts +1 -0
  53. package/dist/core/extract-shapes.js +84 -0
  54. package/dist/core/extract-sol.d.ts +10 -1
  55. package/dist/core/extract-sol.js +70 -22
  56. package/dist/core/extract-standalone.d.ts +3 -0
  57. package/dist/core/extract-standalone.js +221 -0
  58. package/dist/core/extract-step.d.ts +151 -1
  59. package/dist/core/extract-step.js +1232 -60
  60. package/dist/core/extract-swift.js +6 -2
  61. package/dist/core/extract.d.ts +9 -0
  62. package/dist/core/extract.js +77 -7
  63. package/dist/core/fiber-run.d.ts +5 -0
  64. package/dist/core/fiber-run.js +18 -0
  65. package/dist/core/infer.d.ts +4 -1
  66. package/dist/core/infer.js +918 -217
  67. package/dist/core/jvm/JavaReader.java +23 -6
  68. package/dist/core/jvm/Jvm.java +3 -0
  69. package/dist/core/jvm/KtReader.java +6 -5
  70. package/dist/core/laws.d.ts +10 -3
  71. package/dist/core/laws.js +226 -23
  72. package/dist/core/machine.d.ts +15 -1
  73. package/dist/core/machine.js +187 -15
  74. package/dist/core/nonterm.js +14 -1
  75. package/dist/core/orm/harness.js +61 -0
  76. package/dist/core/orm-fixtures/schema.prisma +5 -0
  77. package/dist/core/py/harness.py +183 -10
  78. package/dist/core/py/reader.py +234 -40
  79. package/dist/core/reader-fixtures/README.md +28 -0
  80. package/dist/core/reader-fixtures/c-693042.cpp +8 -0
  81. package/dist/core/reader-fixtures/go-685506.go +14 -0
  82. package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
  83. package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
  84. package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
  85. package/dist/core/reader-fixtures/swift-735726.swift +15 -0
  86. package/dist/core/reader-fixtures/swift-735990.swift +15 -0
  87. package/dist/core/reader-fixtures/swift-739158.swift +4 -0
  88. package/dist/core/reader-fixtures/swift-744834.swift +15 -0
  89. package/dist/core/reader-fixtures/swift-746946.swift +31 -0
  90. package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
  91. package/dist/core/relation.d.ts +1 -1
  92. package/dist/core/relation.js +29 -2
  93. package/dist/core/relational.js +4 -2
  94. package/dist/core/rs/Cargo.toml +1 -1
  95. package/dist/core/rs/src/main.rs +466 -11
  96. package/dist/core/sample-cache.d.ts +8 -0
  97. package/dist/core/sample-cache.js +46 -0
  98. package/dist/core/security.d.ts +38 -0
  99. package/dist/core/security.js +88 -0
  100. package/dist/core/sol/harness.py +57 -4
  101. package/dist/core/sol-concrete.d.ts +23 -0
  102. package/dist/core/sol-concrete.js +195 -0
  103. package/dist/core/solver.js +3 -1
  104. package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
  105. package/dist/core/system.js +1 -1
  106. package/dist/core/transfer.js +22 -9
  107. package/dist/core/translate.js +39 -10
  108. package/dist/core/watch.js +50 -5
  109. package/dist/interchange/format.js +11 -1
  110. package/dist/kernel/cdcl.d.ts +5 -0
  111. package/dist/kernel/cdcl.js +56 -9
  112. package/dist/kernel/epr.js +108 -26
  113. package/dist/kernel/kernel.d.ts +29 -1
  114. package/dist/kernel/kernel.js +325 -62
  115. package/dist/kernel/model-sequence.d.ts +3 -0
  116. package/dist/kernel/model-sequence.js +34 -0
  117. package/dist/kernel/prove.d.ts +10 -3
  118. package/dist/kernel/prove.js +332 -71
  119. package/dist/kernel/reader.d.ts +3 -0
  120. package/dist/kernel/reader.js +101 -14
  121. package/dist/kernel/share.d.ts +1 -0
  122. package/dist/kernel/share.js +27 -0
  123. package/dist/lean-kernel/emit.js +30 -37
  124. package/dist/lean-kernel/lean-terms.js +5 -0
  125. package/dist/lean-kernel/library.js +10 -10
  126. package/package.json +6 -1
@@ -123,7 +123,7 @@ function isBridge(y, f, op) {
123
123
  const callsOf = (t) => { const out = []; walk(t, o => { if (o.op === 'call')
124
124
  out.push(o.fn); }); return out; };
125
125
  export function transferPlan(l) {
126
- const p = programOf([l]), bridges = new Map();
126
+ const p = programOf([l], [], false), bridges = new Map();
127
127
  for (const f of p.fns) {
128
128
  const op = builtinOf(f);
129
129
  if (op && !isBridge(l.holds, f, op))
@@ -233,7 +233,7 @@ const freshName = (base) => { let n = base; for (let i = 2; fnNamed(n); i++)
233
233
  function build(l, bridged, unfold) {
234
234
  // Copied: a function that calls a bridged one, or (unfolding) one that isn't recursive, or a copied one; a function
235
235
  // that isn't recursive is unfolded where it is called instead.
236
- const p0 = programOf([l]), reach = new Set(), unfolded = (n) => unfold && !taken(fnOf(n));
236
+ const p0 = programOf([l], [], false), reach = new Set(), unfolded = (n) => unfold && !taken(fnOf(n));
237
237
  for (let changed = true; changed;) {
238
238
  changed = false;
239
239
  for (const f of p0.fns)
@@ -307,7 +307,7 @@ function build(l, bridged, unfold) {
307
307
  return undefined;
308
308
  const v = (name) => ({ op: 'var', name });
309
309
  // Only the copies the law said through them reaches (each with those its copy calls).
310
- const p1 = programOf([lstar]), back = new Map([...copies].map(([a, b]) => [b, a]));
310
+ const p1 = programOf([lstar], [], false), back = new Map([...copies].map(([a, b]) => [b, a]));
311
311
  const bridges = [...bridged].map(([f, op]) => {
312
312
  const fn = fnOf(f), vs = fn.params.map(q => q.name);
313
313
  return { fn, op, law: { name: `${f} is ${op.name}`, vars: fn.params.map(q => ({ name: q.name, sort: q.sort })), holds: { op: '=', a: { op: 'call', fn: f, args: vs.map(v) }, b: op.x(vs.map(v)) }, params: [] } };
@@ -316,7 +316,7 @@ function build(l, bridged, unfold) {
316
316
  const fn = fnOf(back.get(c.name)), vs = fn.params.map(q => q.name), params = [...new Set(fn.paramFns)];
317
317
  return { fn, law: { name: `${fn.name} is ${c.name}`, vars: fn.params.map(q => ({ name: q.name, sort: q.sort })), holds: { op: '=', a: { op: 'call', fn: fn.name, args: vs.map(v) }, b: { op: 'call', fn: c.name, args: vs.map(v) } }, params } };
318
318
  });
319
- const p = programOf([l, lstar, ...bridges.map(b => b.law), ...equivs.map(e => e.law)]);
319
+ const p = programOf([l, lstar, ...bridges.map(b => b.law), ...equivs.map(e => e.law)], [], false);
320
320
  return { p, lstar, bridges, equivs, copies, unfolded: unfold };
321
321
  }
322
322
  // --- the proof ---------------------------------------------------------------------------------------------------------
@@ -345,15 +345,24 @@ export function proveThrough(l, plan, opts, until) {
345
345
  if (!b)
346
346
  return undefined;
347
347
  // One chain of nodes: each bridge (by the search), each copy's law (its node made, or by the search), in order.
348
- const fs = factsOf(b.p), chain = [], nodes = [], nodeOf = new Map();
348
+ let fs = factsOf(b.p);
349
+ const chain = [], nodes = [], nodeOf = new Map();
350
+ // Search may invent ordinary observer definitions. Its facts append to the context's,
351
+ // preserving the indices of the chain; carry that vocabulary into the final verification.
352
+ const extend = (r) => { if (r.out && r.facts && r.verdict.program) {
353
+ fs = r.facts;
354
+ b.p = r.verdict.program;
355
+ } };
349
356
  const add = (pr) => { chain.push(pr); nodes.splice(0, nodes.length, ...pr.nodes); nodeOf.set(pr.law.name, nodes.findIndex(n => n.name === pr.spec.name)); };
350
357
  const ctx = () => ({ p: b.p, fs, base: [...chain], level: chain.length ? top(chain.at(-1)) : 0 });
351
358
  const lost = [];
352
359
  for (const x of b.bridges) {
353
360
  const r = searchIn(x.law, opts, Math.min(until, clock() + 6000 * (opts.patience ?? 1)), ctx());
354
361
  tried += r.verdict.tried;
355
- if (r.out)
362
+ if (r.out) {
363
+ extend(r);
356
364
  add(r.out);
365
+ }
357
366
  else
358
367
  lost.push(x.fn.name);
359
368
  }
@@ -375,6 +384,7 @@ export function proveThrough(l, plan, opts, until) {
375
384
  tried += r.verdict.tried;
376
385
  if (!r.out)
377
386
  return undefined;
387
+ extend(r);
378
388
  add(r.out);
379
389
  }
380
390
  // (through the bridges and unfolded: half the time left, the other half through the unfolding alone, the functions
@@ -388,6 +398,7 @@ export function proveThrough(l, plan, opts, until) {
388
398
  }
389
399
  if (!r.out)
390
400
  return { ...r.verdict, proven: false, checked: false, law: l.name, counterexample: undefined, tried };
401
+ extend(r);
391
402
  // The nodes: the chain's, then the law's said through them, then the law's own.
392
403
  const specs = [...nodes], names = new Set(specs.map(n => n.name)), off = specs.length;
393
404
  for (const n of r.out.nodes) {
@@ -405,7 +416,7 @@ export function proveThrough(l, plan, opts, until) {
405
416
  const v = verify(fs, specs, Math.max(until, clock() + 3000));
406
417
  if (!v.proven || !v.checked)
407
418
  return undefined;
408
- const through = [...b.bridges.map(x => `${x.fn.name} is ${x.op.name}`), ...b.equivs.map(x => x.law.name), ...(b.unfolded ? [`unfolded: ${programOf([l]).fns.filter(f => !taken(f)).map(f => f.name).join(', ')}`] : [])];
419
+ const through = [...b.bridges.map(x => `${x.fn.name} is ${x.op.name}`), ...b.equivs.map(x => x.law.name), ...(b.unfolded ? [`unfolded: ${programOf([l], [], false).fns.filter(f => !taken(f)).map(f => f.name).join(', ')}`] : [])];
409
420
  return { law: l.name, proven: true, checked: true, proof: v, lemmas: [...b.bridges.map(x => x.law.name), ...b.equivs.map(x => x.law.name), ...r.verdict.lemmas], scheme: `${r.verdict.scheme ?? 'no induction'}, through the law ${b.lstar.name}`, tried, program: b.p, node: specs.length - 1, ms: Math.round(performance.now() - t0), through };
410
421
  }
411
422
  }
@@ -472,11 +483,13 @@ function walker(b, fs, nodeOf, own) {
472
483
  case 'sub':
473
484
  case 'min':
474
485
  case 'max':
475
- case 'prod': {
486
+ case 'prod':
487
+ case 'tup': {
476
488
  const o = c;
477
489
  return walkE(a.a, o.a) && walkE(a.b, o.b);
478
490
  }
479
- case 'mul': {
491
+ case 'mul':
492
+ case 'proj': {
480
493
  const o = c;
481
494
  return a.k === o.k && walkE(a.a, o.a);
482
495
  }
@@ -13,12 +13,20 @@ import { walk } from "./machine.js";
13
13
  import { add, costs, env, refuteFast, scale, solve } from "./solver.js";
14
14
  import { checkRefutation } from "./check.js";
15
15
  import { canon, canonFlip, columnTerm, factorsOf, isCell, isMonomial, leafConstraints, leafConstraintsReusing, linear, substE, truth, withProducts } from "../kernel/kernel.js";
16
- import { cellProducts, clock, grow, leafRowsOf, parseKey, withinDeadline } from "../kernel/prove.js";
16
+ import { cellProducts, grow, late, leafRowsOf, parseKey, withinDeadline } from "../kernel/prove.js";
17
17
  import { Reader, times } from "../kernel/reader.js";
18
18
  const omega = 'O$';
19
19
  const debugOn = () => !!env.GDP_CYCLIC_DEBUG;
20
20
  // A cell's key, from its name (`M[key]`, the key's canonical text, whose names may be cells themselves).
21
- const keyOf = (cell) => parseKey(cell.slice(cell.indexOf('[') + 1, -1));
21
+ const keyOf = (cell) => {
22
+ const text = cell.slice(cell.indexOf('[') + 1, -1);
23
+ // The time encoding below is scalar. A tuple cell is not a linear key: parsing its
24
+ // separators as coefficients made NaN rows, on which elimination's gcd never ends.
25
+ if (text.startsWith('⟨'))
26
+ return undefined;
27
+ const key = parseKey(text);
28
+ return Object.values(key).every(Number.isFinite) ? key : undefined;
29
+ };
22
30
  export function renamer(r) {
23
31
  const terms = new Map(), memo = new WeakMap(), cells = r.cells ?? {};
24
32
  const col = (name, wp) => {
@@ -51,7 +59,7 @@ export function renamer(r) {
51
59
  return out;
52
60
  }
53
61
  if (isCell(name)) {
54
- const map = name.slice(0, name.indexOf('[')), key = lin(keyOf(name), wp);
62
+ const map = name.slice(0, name.indexOf('[')), original = keyOf(name), key = original && lin(original, wp);
55
63
  if (!key)
56
64
  return undefined;
57
65
  const to = cells[map];
@@ -148,12 +156,14 @@ function regrow(whole, wp, until) {
148
156
  export function translate(part, whole, tree, ren0, st, until0, pp = new Map(), wp = new Map(), swaps = []) {
149
157
  // (within the deadline it runs in too: a certificate's translation, core/cyclic.ts's translateMs)
150
158
  const until = withinDeadline(until0);
159
+ if (late(until))
160
+ return undefined;
151
161
  const ren = swaps.length ? (lin, p) => {
152
162
  const out = {};
153
163
  for (const key in lin) {
154
164
  let to = key;
155
165
  if (isCell(key)) {
156
- const kt = canon(keyOf(key)), sw = swaps.find(x => x[0] === kt);
166
+ const k = keyOf(key), sw = k && swaps.find(x => x[0] === canon(k));
157
167
  if (sw)
158
168
  to = `${key.slice(0, key.indexOf('['))}[${sw[1]}]`;
159
169
  }
@@ -174,7 +184,7 @@ export function translate(part, whole, tree, ren0, st, until0, pp = new Map(), w
174
184
  return yes && no ? { split: wl, yes, no } : undefined;
175
185
  }
176
186
  // (past its budget, no translation: each leaf reads the two goals' rows whole, counted, so a large tree's stops there)
177
- if (clock() > until)
187
+ if (late(until))
178
188
  return undefined;
179
189
  // (the usual leaf's rows as its search kept them, where it did: kernel/prove.ts's leafRowsOf; else read again)
180
190
  const kept = !tree.products && !tree.squares ? leafRowsOf.get(tree) : undefined;
@@ -198,7 +208,10 @@ export function translate(part, whole, tree, ren0, st, until0, pp = new Map(), w
198
208
  const a = ren({ [pair[0]]: 1 }, wp), b = ren({ [pair[1]]: 1 }, wp), [ca] = Object.keys(a ?? {}), [cb] = Object.keys(b ?? {});
199
209
  if (!ca || !cb || !isCell(ca) || !isCell(cb))
200
210
  continue;
201
- const d = add(keyOf(ca), scale(keyOf(cb), -1)), q0 = {};
211
+ const ak = keyOf(ca), bk = keyOf(cb);
212
+ if (!ak || !bk)
213
+ continue;
214
+ const d = add(ak, scale(bk, -1)), q0 = {};
202
215
  if (!Object.keys(d).length || Object.keys(d).some(key => key === '1' || !factorsOf(key).includes(omega)))
203
216
  continue;
204
217
  for (const key of Object.keys(d)) {
@@ -252,6 +265,8 @@ export function translate(part, whole, tree, ren0, st, until0, pp = new Map(), w
252
265
  return close(whole, wp, st, until);
253
266
  }
254
267
  export function readsFirst(whole, reads, ren, inner, st, until, wp = new Map(), swaps = []) {
268
+ if (late(withinDeadline(until)))
269
+ return undefined;
255
270
  if (!reads.length)
256
271
  return inner(wp, swaps);
257
272
  const [r, ...rest] = reads, ku = linear(r.k, new Map()), wu = linear(r.w, new Map()), kl = ku && ren(ku, wp), wl = wu && ren(wu, wp);
@@ -281,6 +296,8 @@ export function readsFirst(whole, reads, ren, inner, st, until, wp = new Map(),
281
296
  // A path where l >= 1 (two cells' keys apart by l = q·Ω) while q <= 0 is a row: refuted by q·Ω <= 0, the product of
282
297
  // that row and Ω >= 0.
283
298
  function apart(whole, wp, l, q, st, until) {
299
+ if (late(withinDeadline(until)))
300
+ return undefined;
284
301
  const rows = rowsAt(whole, wp), find = (x) => { const c = canon(x); return rows.findIndex(r => canon(r.lin) === c); };
285
302
  const iq = find(q), io = find({ [omega]: -1 }), ia = find(add({ 1: 1 }, scale(l, -1)));
286
303
  if (iq >= 0 && io >= 0 && ia >= 0) {
@@ -317,6 +334,8 @@ function atomsOf(c, wp) {
317
334
  // A tree for `whole` that first decides each condition true (a guard, the antecedent of a use's implication), each
318
335
  // other side grown on the goal (the node's hypotheses refute it), then `inner` at the path where all hold.
319
336
  export function decide(whole, conds, inner, st, until, wp = new Map()) {
337
+ if (late(withinDeadline(until)))
338
+ return undefined;
320
339
  for (const [i, c] of conds.entries()) {
321
340
  if (truth(c, wp) === true)
322
341
  continue;
@@ -376,7 +395,10 @@ function cellAtom(g, wp) {
376
395
  for (const q of names.slice(i + 1)) {
377
396
  if (p.slice(0, p.indexOf('[')) !== q.slice(0, q.indexOf('[')))
378
397
  continue;
379
- const d = add(keyOf(p), scale(keyOf(q), -1));
398
+ const pk = keyOf(p), qk = keyOf(q);
399
+ if (!pk || !qk)
400
+ continue;
401
+ const d = add(pk, scale(qk, -1));
380
402
  if (Object.keys(d).some(key => key !== '1' && isMonomial(key)))
381
403
  continue;
382
404
  const column = Object.keys(d).some(key => key.includes('⟦'));
@@ -444,7 +466,10 @@ function omegaPair(g, wp) {
444
466
  for (const q of names.slice(i + 1)) {
445
467
  if (p.slice(0, p.indexOf('[')) !== q.slice(0, q.indexOf('[')))
446
468
  continue;
447
- const d = add(keyOf(p), scale(keyOf(q), -1)), q0 = {};
469
+ const pk = keyOf(p), qk = keyOf(q);
470
+ if (!pk || !qk)
471
+ continue;
472
+ const d = add(pk, scale(qk, -1)), q0 = {};
448
473
  if (!Object.keys(d).length || Object.keys(d).some(key => key === '1' || !factorsOf(key).includes(omega)))
449
474
  continue;
450
475
  for (const key of Object.keys(d)) {
@@ -471,11 +496,13 @@ function omegaPair(g, wp) {
471
496
  // A case of `g` closed: refuted by its rows, else an open choice, two reads of a function or two cells over time split
472
497
  // (each then equal), else the goal grown at the path.
473
498
  export function close(g, wp, st, until) {
499
+ if (late(withinDeadline(until)))
500
+ return undefined;
474
501
  const l = leafAt(g, wp, true, st);
475
502
  if (l)
476
503
  return l;
477
504
  const pick = choiceAtom(g, wp) ?? cellAtom(g, wp), om = pick ? undefined : omegaPair(g, wp), next = pick ?? om?.l;
478
- if (next && clock() < until) {
505
+ if (next && !late(withinDeadline(until))) {
479
506
  st.splits++;
480
507
  const id = canon(next), y = close(g, new Map(wp).set(id, { lin: next, holds: true }), st, until);
481
508
  const no = new Map(wp).set(id, { lin: next, holds: false }), n = y && (om?.q ? apart(g, no, next, om.q, st, until) : close(g, no, st, until));
@@ -496,6 +523,8 @@ export function close(g, wp, st, until) {
496
523
  // `nUses`: the uses' hypotheses, just before the conclusion refuted (mainGoal's order).
497
524
  export function carry(g, nFacts, nUses, st, until0) {
498
525
  const until = withinDeadline(until0);
526
+ if (late(until))
527
+ return undefined;
499
528
  const last = g.hyps.length - 1, uses = g.hyps.slice(last - nUses, last), facts = g.hyps.slice(last - nUses - nFacts, last - nUses);
500
529
  const law = g.hyps[last].x;
501
530
  const parts = uses.map(u => (u.op === 'or' && u.xs.length === 2 && u.xs[0].op === 'not' ? { guard: u.xs[0].x, concl: u.xs[1] } : { guard: undefined, concl: u }));
@@ -541,7 +570,7 @@ export function carry(g, nFacts, nUses, st, until0) {
541
570
  };
542
571
  const leafOf = (wp, solveIt) => leafAt(g, wp, solveIt, st), final = (wp) => close(g, wp, st, until);
543
572
  const node = (wp, guardsDone) => {
544
- if (clock() > until)
573
+ if (late(until))
545
574
  return undefined;
546
575
  // A hypothesis false at the path: the law at t holds there, or a law it is carried from (its guard true) fails.
547
576
  if (truth(law, wp) === true || parts.some(p => (p.guard === undefined || truth(p.guard, wp) === true) && truth(p.concl, wp) === false))
@@ -7,7 +7,7 @@
7
7
  // at every k steps in a row the run takes: each step's `when` read with the state it starts from, its request, queries
8
8
  // and flags; `then` with the state before the first step (plain names), the first request and its flags, the j-th
9
9
  // request as input@j, and the state and maps after the last step (primed names).
10
- import { carriedView, evalC, numbersOf, walk } from "./machine.js";
10
+ import { carriedView, evalC, evalE, numbersOf, walk } from "./machine.js";
11
11
  import { someHolds } from "./exists.js";
12
12
  export const isStepLaw = (w) => 'then' in w;
13
13
  // A request's environment: the params, its inputs and queries, and the step's flags decided (as ?name).
@@ -77,6 +77,43 @@ function keysPer(c, names) {
77
77
  return [...vals];
78
78
  });
79
79
  }
80
+ // A key no map reads, scaled and compared linearly with what the run holds (c·k ⋈ t, c >= 16: a time's week,
81
+ // core/calendar.ts), is read
82
+ // where that comparison turns too: ⌊t/c⌋ and the keys beside it, each later key 0 while it is solved. Untrusted: more
83
+ // keys read is only more of the law checked.
84
+ function turns(c, names) {
85
+ const atoms = [];
86
+ walk(c, o => {
87
+ if (o.op !== '<' && o.op !== '<=' && o.op !== '=')
88
+ return;
89
+ // (a key scaled past the small keys a run reads, k·x with k at least 16: its turn is far from 0 to bound + 1)
90
+ const t = JSON.stringify(o), reads = new Set(names.filter(x => [...t.matchAll(new RegExp(`"op":"mul","k":(\\d+),"a":\\{"op":"var","name":${JSON.stringify(x).replace(/[$]/g, '\\$&')}\\}`, 'g'))].some(m => Number(m[1]) >= 16)));
91
+ if (reads.size)
92
+ atoms.push({ a: o.a, b: o.b, reads });
93
+ });
94
+ return (i, env, st, m) => {
95
+ const x = names[i], out = new Set(), saved = names.slice(i).map(y => env[y]);
96
+ for (let j = i + 1; j < names.length; j++)
97
+ env[names[j]] = 0;
98
+ for (const at of atoms) {
99
+ if (!at.reads.has(x))
100
+ continue;
101
+ try {
102
+ const f = (v) => { env[x] = v; return evalE(at.a, env, st, m) - evalE(at.b, env, st, m); };
103
+ const f0 = f(0), slope = f(1) - f0;
104
+ if (slope) {
105
+ const k = Math.floor(-f0 / slope);
106
+ for (const v of [k - 1, k, k + 1])
107
+ if (v >= 0 && Number.isSafeInteger(v))
108
+ out.add(v);
109
+ }
110
+ }
111
+ catch { /* (a value the run doesn't hold: no turn) */ }
112
+ }
113
+ names.slice(i).forEach((y, j) => { env[y] = saved[j]; });
114
+ return [...out];
115
+ };
116
+ }
80
117
  // The tuples every watch has read a law at (core/dsl.ts's refuteByRuns counts its budget in them).
81
118
  export const watchWork = { n: 0 };
82
119
  // Watches one law or step law along one run: `start` with the state at the start, `step` after each step the run takes
@@ -84,13 +121,21 @@ export const watchWork = { n: 0 };
84
121
  export function watch(m, run, w, params, bound) {
85
122
  // At every tuple of the keys (each name's own: keysPer), one key per name, in one environment set in place.
86
123
  const names = w.forall ? [w.forall, ...(w.keys ?? [])] : [], per = keysPer(isStepLaw(w) ? w.then : w.holds, names);
87
- const atKeys = (keys, env, f) => {
124
+ // (the keys no map reads, also where a comparison of theirs turns)
125
+ const mapRead = new Set();
126
+ walk(isStepLaw(w) ? w.then : w.holds, o => { if (o.op === 'get')
127
+ for (const x of names)
128
+ if (JSON.stringify(o.key).includes(`"name":${JSON.stringify(x)}`))
129
+ mapRead.add(x); });
130
+ const turn = names.some(x => !mapRead.has(x)) ? turns(isStepLaw(w) ? w.then : w.holds, names) : undefined;
131
+ const atKeys = (keys, env, f, st, mm) => {
88
132
  const go = (i) => {
89
133
  if (i === names.length) {
90
134
  watchWork.n++;
91
135
  return f(env);
92
136
  }
93
- for (const key of keys[i]) {
137
+ const more = turn && st && mm && !mapRead.has(names[i]) ? turn(i, env, st, mm).filter(k => !keys[i].includes(k)) : [];
138
+ for (const key of more.length ? [...keys[i], ...more] : keys[i]) {
94
139
  env[names[i]] = key;
95
140
  if (!go(i + 1))
96
141
  return false;
@@ -103,7 +148,7 @@ export function watch(m, run, w, params, bound) {
103
148
  // A law with "there exists" (core/exists.ts): broken only where no value can be a witness, as far as that is decided
104
149
  // (one natural or integer read linearly); undecided, it is kept.
105
150
  const at = (env, st) => (w.some?.length ? someHolds(w.holds, w.some, { ...env }, st, m, true)?.holds ?? true : evalC(w.holds, env, st, m));
106
- const holds = (st) => atKeys(per(bound, st, () => keysOf(bound, st)), { ...params }, env => at(env, st));
151
+ const holds = (st) => atKeys(per(bound, st, () => keysOf(bound, st)), { ...params }, env => at(env, st), st, m);
107
152
  return { start: holds, step: (_before, _input, after) => holds(after) };
108
153
  }
109
154
  const k = w.steps ?? 1, whens = w.when === undefined ? [] : Array.isArray(w.when) ? w.when : [w.when];
@@ -132,7 +177,7 @@ export function watch(m, run, w, params, bound) {
132
177
  maps: { ...first.maps, ...Object.fromEntries(Object.entries(after.maps).map(([n, cells]) => [`${n}'`, cells])) },
133
178
  defaults: { ...first.defaults, ...Object.fromEntries(Object.entries(after.defaults ?? {}).map(([n, d]) => [`${n}'`, d])) },
134
179
  };
135
- return atKeys(per(bound, both, () => keysOf(bound, first, after)), { ...env }, e => evalC(w.then, e, both, primedMaps));
180
+ return atKeys(per(bound, both, () => keysOf(bound, first, after)), { ...env }, e => evalC(w.then, e, both, primedMaps), both, primedMaps);
136
181
  },
137
182
  };
138
183
  }
@@ -70,6 +70,8 @@ export function encE(e, at = 'term') {
70
70
  case 'mul': return { op: e.op, k: nat(e.k, `${at}.k`), a: encE(e.a, `${at}.a`) };
71
71
  case 'if': return { op: e.op, c: encC(e.c, `${at}.c`), then: encE(e.then, `${at}.then`), else: encE(e.else, `${at}.else`) };
72
72
  case 'get': return { op: e.op, map: name(e.map, `${at}.map`), key: encE(e.key, `${at}.key`) };
73
+ case 'tup':
74
+ case 'proj': return fail(at, 'tuple terms are not supported by interchange 1.1');
73
75
  default: return fail(at, `no term op ${JSON.stringify(e.op)}`);
74
76
  }
75
77
  }
@@ -100,6 +102,8 @@ export function decE(x, at = 'term') {
100
102
  case 'get':
101
103
  obj(o, at, ['op', 'map', 'key']);
102
104
  return { op: 'get', map: name(o.map, `${at}.map`), key: decE(o.key, `${at}.key`) };
105
+ case 'tup':
106
+ case 'proj': return fail(at, 'tuple terms are not supported by interchange 1.1');
103
107
  default: return fail(at, `no term op ${JSON.stringify(o.op ?? null)}`);
104
108
  }
105
109
  }
@@ -267,6 +271,9 @@ function encAtom(key, cols, at) {
267
271
  return { mono: factorsOf(key).map((f, i) => encAtom(f, cols, `${at}.mono[${i}]`)) };
268
272
  if (isCell(key)) {
269
273
  const map = key.slice(0, key.indexOf('[')), inner = key.slice(key.indexOf('[') + 1, -1);
274
+ // Version 1.1 has one linear key, not the native tuple's list of linear parts.
275
+ if (inner.startsWith('⟨'))
276
+ fail(at, 'tuple-keyed cells are not supported by interchange 1.1');
270
277
  // (a cell's name is the kernel's canon of its key: written back from the key read, it must be the same text)
271
278
  const lin = parseKey(inner);
272
279
  if (canon(lin) !== inner)
@@ -297,7 +304,10 @@ function decAtom(x, cols, at) {
297
304
  return [...fs].sort().join('*');
298
305
  }
299
306
  obj(o, at, ['cell', 'key']);
300
- return `${name(o.cell, `${at}.cell`)}[${canon(decLin(o.key, cols, `${at}.key`))}]`;
307
+ const key = canon(decLin(o.key, cols, `${at}.key`));
308
+ if (key.startsWith('⟨'))
309
+ fail(at, 'tuple-keyed cells are not supported by interchange 1.1');
310
+ return `${name(o.cell, `${at}.cell`)}[${key}]`;
301
311
  }
302
312
  export function encLin(lin, cols, at = 'row') {
303
313
  if (!isObj(lin))
@@ -49,6 +49,10 @@ export declare const cdclStats: {
49
49
  lpLoad: number;
50
50
  nodes: number;
51
51
  boundRounds: number;
52
+ fmLeafMs: number;
53
+ fmOpenMs: number;
54
+ fastMs: number;
55
+ missMs: number;
52
56
  };
53
57
  export declare const REFUTED = "refuted, not unfolded";
54
58
  export type Refuted = Outcome & {
@@ -64,6 +68,7 @@ export type CdclOptions = {
64
68
  clausal?: boolean;
65
69
  sideOf?: (hyp: number) => number;
66
70
  quiet?: (name: string) => boolean;
71
+ point?: boolean;
67
72
  };
68
73
  export declare function growCdcl(goal: Goal, root: Path, budget: {
69
74
  nodes: number;
@@ -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')