gdp-wired 0.42.0 → 0.44.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 (66) hide show
  1. package/README.md +14 -3
  2. package/dist/core/cli.d.ts +8 -1
  3. package/dist/core/cli.js +271 -30
  4. package/dist/core/counts.d.ts +8 -1
  5. package/dist/core/counts.js +171 -302
  6. package/dist/core/data.js +2 -2
  7. package/dist/core/dsl.js +26 -30
  8. package/dist/core/effect-prims.d.ts +60 -0
  9. package/dist/core/effect-prims.js +625 -0
  10. package/dist/core/effect-schedule.d.ts +103 -0
  11. package/dist/core/effect-schedule.js +817 -0
  12. package/dist/core/effect.d.ts +36 -1
  13. package/dist/core/effect.js +656 -29
  14. package/dist/core/ex/harness.exs +2 -0
  15. package/dist/core/exists.d.ts +5 -0
  16. package/dist/core/exists.js +98 -34
  17. package/dist/core/extract-c.d.ts +2 -0
  18. package/dist/core/extract-c.js +5 -3
  19. package/dist/core/extract-check.d.ts +2 -0
  20. package/dist/core/extract-check.js +45 -4
  21. package/dist/core/extract-ex.js +2 -2
  22. package/dist/core/extract-go-check.js +4 -6
  23. package/dist/core/extract-go.d.ts +3 -0
  24. package/dist/core/extract-go.js +4 -4
  25. package/dist/core/extract-jvm.js +6 -3
  26. package/dist/core/extract-print.js +9 -2
  27. package/dist/core/extract-py.js +2 -2
  28. package/dist/core/extract-rb.js +2 -2
  29. package/dist/core/extract-read.js +2 -1
  30. package/dist/core/extract-rs.js +12 -7
  31. package/dist/core/extract-sol.js +4 -4
  32. package/dist/core/extract-step.d.ts +18 -0
  33. package/dist/core/extract-step.js +135 -31
  34. package/dist/core/extract-swift.js +3 -3
  35. package/dist/core/extract.d.ts +8 -0
  36. package/dist/core/extract.js +13 -1
  37. package/dist/core/infer.d.ts +1 -0
  38. package/dist/core/infer.js +10 -7
  39. package/dist/core/jvm/Harness.java +8 -1
  40. package/dist/core/jvm/Jvm.java +1 -1
  41. package/dist/core/jvm/KtReader.java +3 -0
  42. package/dist/core/laws.d.ts +4 -0
  43. package/dist/core/laws.js +176 -9
  44. package/dist/core/machine.d.ts +3 -0
  45. package/dist/core/machine.js +17 -3
  46. package/dist/core/py/harness.py +64 -19
  47. package/dist/core/py/reader.py +51 -1
  48. package/dist/core/sol/Replay.sol +52 -0
  49. package/dist/core/sol/harness.py +508 -0
  50. package/dist/core/system.d.ts +44 -0
  51. package/dist/core/system.js +435 -0
  52. package/dist/interchange/check.d.ts +18 -1
  53. package/dist/interchange/check.js +9 -2
  54. package/dist/interchange/cli.d.ts +2 -0
  55. package/dist/interchange/cli.js +45 -0
  56. package/dist/interchange/format.d.ts +1 -1
  57. package/dist/interchange/format.js +15 -7
  58. package/dist/kernel/cdcl.js +32 -12
  59. package/dist/kernel/kernel.js +3 -2
  60. package/dist/kernel/prove.d.ts +1 -0
  61. package/dist/kernel/prove.js +69 -8
  62. package/dist/kernel/reader.js +3 -2
  63. package/dist/lean-kernel/emit.js +3 -3
  64. package/dist/lean-kernel/lean-terms.d.ts +1 -0
  65. package/dist/lean-kernel/lean-terms.js +8 -4
  66. package/package.json +12 -3
@@ -1,5 +1,7 @@
1
1
  import { canon, columnTerm, factorsOf, isCell, isMonomial, termColumn } from "../kernel/kernel.js";
2
- export const FORMAT = 'gdp-wired-interchange', VERSION = '1.0';
2
+ // 1.1 adds a liveness's fairness and levels (strong fairness, Live.lean's sleads_sound): a document is written at the
3
+ // lowest version that holds it (1.0 unless a liveness is strong or has levels), and read at either.
4
+ export const FORMAT = 'gdp-wired-interchange', VERSION = '1.1', VERSIONS = ['1.0', '1.1'];
3
5
  export const KINDS = ['goals', 'laws', 'stepLaws', 'kInduction', 'progress', 'liveness', 'loop', 'recur', 'fold', 'cyclic', 'qgoals', 'qmachine', 'termination'];
4
6
  // Why a value is outside the format: where, and what.
5
7
  export class FormatError extends Error {
@@ -484,12 +486,15 @@ const encRank = (r, at) => (Array.isArray(r) ? r.map((e, i) => encE(e, `${at}[${
484
486
  const decRank = (x, at) => (Array.isArray(x) ? x.map((e, i) => decE(e, `${at}[${i}]`)) : decE(x, at));
485
487
  const encHelpful = (h, at) => clean({ when: h.when && encC(h.when, `${at}.when`), request: pairs(h.request, encE, `${at}.request`) });
486
488
  const decHelpful = (x, at) => { const o = obj(x, at, ['request'], ['when']); return clean({ when: opt(o, 'when', decC, at), request: record(o.request, decE, `${at}.request`) }); };
489
+ const fairnessOf = (x, at) => (x === 'weak' || x === 'strong' ? x : fail(at, '"weak" or "strong"'));
487
490
  const encLiveness = (l, at) => clean({ name: str(l.name, `${at}.name`), from: encC(l.from, `${at}.from`), to: encC(l.to, `${at}.to`), rank: encRank(l.rank, `${at}.rank`),
488
- request: l.request && pairs(l.request, encE, `${at}.request`), helpful: l.helpful && l.helpful.map((h, i) => encHelpful(h, `${at}.helpful[${i}]`)) });
491
+ request: l.request && pairs(l.request, encE, `${at}.request`), helpful: l.helpful && l.helpful.map((h, i) => encHelpful(h, `${at}.helpful[${i}]`)),
492
+ fairness: l.fairness && fairnessOf(l.fairness, `${at}.fairness`), levels: l.levels && l.levels.map((n, i) => nat(n, `${at}.levels[${i}]`)) });
489
493
  const decLiveness = (x, at) => {
490
- const o = obj(x, at, ['name', 'from', 'to', 'rank'], ['request', 'helpful']);
494
+ const o = obj(x, at, ['name', 'from', 'to', 'rank'], ['request', 'helpful', 'fairness', 'levels']);
491
495
  return clean({ name: str(o.name, `${at}.name`), from: decC(o.from, `${at}.from`), to: decC(o.to, `${at}.to`), rank: decRank(o.rank, `${at}.rank`),
492
- request: opt(o, 'request', (y, a) => record(y, decE, a), at), helpful: opt(o, 'helpful', (y, a) => arr(y, a).map((h, i) => decHelpful(h, `${a}[${i}]`)), at) });
496
+ request: opt(o, 'request', (y, a) => record(y, decE, a), at), helpful: opt(o, 'helpful', (y, a) => arr(y, a).map((h, i) => decHelpful(h, `${a}[${i}]`)), at),
497
+ fairness: opt(o, 'fairness', fairnessOf, at), levels: opt(o, 'levels', (y, a) => arr(y, a).map((n, i) => nat(n, `${a}[${i}]`)), at) });
493
498
  };
494
499
  const encLoop = (l, at) => clean({ name: str(l.name, `${at}.name`), params: strs(l.params, `${at}.params`), inputs: strs(l.inputs, `${at}.inputs`), state: pairs(l.state, encE, `${at}.state`),
495
500
  while: encC(l.while, `${at}.while`), body: pairs(l.body, encE, `${at}.body`), pre: l.pre && encC(l.pre, `${at}.pre`), assume: l.assume && encC(l.assume, `${at}.assume`) });
@@ -595,15 +600,18 @@ export function toInterchange(c, meta) {
595
600
  default: return fail('kind', `no kind ${JSON.stringify(c.kind)}`);
596
601
  }
597
602
  })();
598
- return clean({ format: FORMAT, version: VERSION, kind: c.kind, meta, columns: 'terms' in cols && cols.terms.length ? cols.terms : undefined, ...body });
603
+ const v11 = c.kind === 'liveness' && (c.liveness.fairness !== undefined || c.liveness.levels !== undefined);
604
+ return clean({ format: FORMAT, version: v11 ? '1.1' : '1.0', kind: c.kind, meta, columns: 'terms' in cols && cols.terms.length ? cols.terms : undefined, ...body });
599
605
  }
600
606
  // A document read back into the kernel's objects, or a FormatError saying where it leaves the format.
601
607
  export function fromInterchange(doc) {
602
608
  const head = isObj(doc) ? doc : fail('document', 'an object');
603
609
  if (head.format !== FORMAT)
604
610
  fail('format', `${JSON.stringify(FORMAT)}`);
605
- if (head.version !== VERSION)
606
- fail('version', `${VERSION} (this reader's; a 1.0 reader reads 1.0 alone)`);
611
+ if (!VERSIONS.includes(head.version))
612
+ fail('version', `one of ${VERSIONS.join(', ')} (this reader's)`);
613
+ if (head.version === '1.0' && head.kind === 'liveness' && isObj(head.liveness) && ('fairness' in head.liveness || 'levels' in head.liveness))
614
+ fail('liveness', 'no fairness or levels in a 1.0 document (1.1\'s)');
607
615
  const kind = head.kind;
608
616
  if (!KINDS.includes(kind))
609
617
  fail('kind', `one of ${KINDS.join(', ')}`);
@@ -167,7 +167,8 @@ export function cdclSession(goal, root, opts = {}) {
167
167
  const key = keyOf(lin);
168
168
  if (!vars.has(key)) {
169
169
  const flip = key !== canon(lin), stored = flip ? atomOf(lin, false).lin : lin, terms = Object.entries(stored).filter(([x0]) => x0 !== '1');
170
- const x = { name: key, lin: stored, terms, col: terms.some(([x0]) => x0.startsWith('⟦')), id: byId.length, level: -1, at: -1, act: 0, phase: !flip };
170
+ const x = { name: key, lin: stored, terms, col: terms.some(([x0]) => x0.startsWith('⟦')), quiet: undefined, id: byId.length, hp: undefined, cond: undefined, val: undefined, level: -1, reason: undefined, at: -1, act: 0, phase: !flip,
171
+ bj: undefined, bjAt: undefined, bsig: undefined, bver: undefined, sj: undefined, sx: undefined, pair: undefined, fs: undefined, aq: undefined, an: undefined };
171
172
  byId.push(x);
172
173
  vals.push(0);
173
174
  rel.push(-1);
@@ -314,8 +315,10 @@ export function cdclSession(goal, root, opts = {}) {
314
315
  if (vals[id])
315
316
  activate(id);
316
317
  };
318
+ // (its stack kept between calls: an assignment of a relevant variable calls it, and an array a call cost every one)
319
+ const todo = [];
317
320
  const activate = (id0) => {
318
- for (const todo = [id0]; todo.length;) {
321
+ for (todo.push(id0); todo.length;) {
319
322
  const id = todo.pop(), own = ownBy[2 * id + (vals[id] === 1 ? 1 : 0)];
320
323
  if (!own)
321
324
  continue;
@@ -356,8 +359,10 @@ export function cdclSession(goal, root, opts = {}) {
356
359
  lowAt = Math.min(lowAt, trail.length);
357
360
  levels.length = l;
358
361
  };
362
+ const undone = [];
359
363
  const undoClausal = (l) => {
360
- const keep = levels[l] ?? trail.length, undone = [];
364
+ const keep = levels[l] ?? trail.length;
365
+ undone.length = 0;
361
366
  while (trail.length > keep) {
362
367
  trail.pop();
363
368
  const x = tv.pop(), q = x.aq;
@@ -568,13 +573,15 @@ export function cdclSession(goal, root, opts = {}) {
568
573
  // is unit, its other watched pair's variable flipped, or, that pair holding too, a conflict.
569
574
  const propagateClausal = () => {
570
575
  // (each watch a clause and a blocker, a pair of it that, where it doesn't hold, satisfies the clause untouched)
576
+ // (holds and opposed read inline: vals[c >> 1] is 2 − (c & 1) where pair c holds, 1 + (c & 1) where it's opposed)
571
577
  while (qhead < trail.length) {
572
578
  const x = tv[qhead++], code = 2 * x.id + (x.val ? 1 : 0), ws = wl[code];
573
579
  if (!ws)
574
580
  continue;
575
581
  let n = 0;
576
582
  for (let i = 0; i < ws.length;) {
577
- if (opposed(ws[i + 1])) {
583
+ const blocker = ws[i + 1];
584
+ if (vals[blocker >> 1] === 1 + (blocker & 1)) {
578
585
  i += 2;
579
586
  continue;
580
587
  }
@@ -591,15 +598,20 @@ export function cdclSession(goal, root, opts = {}) {
591
598
  c[1] = code;
592
599
  }
593
600
  const o = c[0];
594
- if (opposed(o)) {
601
+ if (vals[o >> 1] === 1 + (o & 1)) {
595
602
  ws[i + 1] = o;
596
603
  i += 2;
597
604
  continue;
598
605
  }
599
606
  let j = 2;
600
- while (j < c.length && holds(c[j]))
607
+ const len = c.length;
608
+ while (j < len) {
609
+ const z = c[j];
610
+ if (vals[z >> 1] !== 2 - (z & 1))
611
+ break;
601
612
  j++;
602
- if (j < c.length) {
613
+ }
614
+ if (j < len) {
603
615
  const z = c[j];
604
616
  c[j] = code;
605
617
  c[1] = z;
@@ -610,7 +622,7 @@ export function cdclSession(goal, root, opts = {}) {
610
622
  continue;
611
623
  }
612
624
  if (!vals[o >> 1]) {
613
- assignVar(byId[o >> 1], !(o & 1), ci);
625
+ assignClausal(byId[o >> 1], !(o & 1), ci);
614
626
  i += 2;
615
627
  continue;
616
628
  }
@@ -694,8 +706,13 @@ export function cdclSession(goal, root, opts = {}) {
694
706
  }, ms => { st.coreMs += ms; });
695
707
  // The clausal mode's conflict analysis: the same resolutions, in one pass down the trail (the clause kept as it is
696
708
  // resolved, its literals at its latest level counted, each step the latest of them on the trail).
709
+ // (whether a variable is in the clause being resolved: its stamp `an` this call's, so the walk down the trail reads
710
+ // each variable once, not the clause's map by its name)
711
+ let anN = 0;
697
712
  const analyzeClausal = (c) => {
698
- const lits = new Map(c.lits);
713
+ const lits = new Map(c.lits), an = ++anN;
714
+ for (const name of lits.keys())
715
+ vars.get(name).an = an;
699
716
  let node = c.node, { top, here } = levelsOf(c), p = trail.length - 1;
700
717
  if (top < level()) {
701
718
  undoTo(top);
@@ -703,9 +720,9 @@ export function cdclSession(goal, root, opts = {}) {
703
720
  p = trail.length - 1;
704
721
  }
705
722
  while (lits.size && !(top > 0 && here === 1)) {
706
- while (p >= 0 && !(lits.has(trail[p]) && vars.get(trail[p]).level === top))
723
+ while (p >= 0 && !(tv[p].an === an && tv[p].level === top))
707
724
  p--;
708
- const name = trail[p], x = vars.get(name);
725
+ const name = trail[p], x = tv[p];
709
726
  if (top > 0 && x.reason === undefined)
710
727
  break;
711
728
  const r = clauses[x.reason];
@@ -715,11 +732,14 @@ export function cdclSession(goal, root, opts = {}) {
715
732
  st.resolved++;
716
733
  node = nodes.length - 1;
717
734
  lits.delete(name);
735
+ x.an = 0;
718
736
  here--;
719
737
  for (const [w, q] of r.lits)
720
738
  if (w !== name && !lits.has(w)) {
739
+ const y = vars.get(w);
721
740
  lits.set(w, q);
722
- if (vars.get(w).level === top)
741
+ y.an = an;
742
+ if (y.level === top)
723
743
  here++;
724
744
  }
725
745
  }
@@ -830,7 +830,8 @@ export function scope(m, laws = []) {
830
830
  plainName(what, key);
831
831
  if ([...names, ...readable, ...flags].includes(key))
832
832
  throw new Error(`${what}: the key ${key} is already a name of ${m.name}`);
833
- keyOnly(what, t, key, fns);
833
+ // (a count map, like a function, has a value at every key, not cells a runtime can list: read at no key term)
834
+ keyOnly(what, t, key, [...fns, ...counts]);
834
835
  };
835
836
  inScope(`${m.name}'s start`, Object.values(m.state), m.params);
836
837
  flags.forEach((f, i) => {
@@ -898,7 +899,7 @@ export function scope(m, laws = []) {
898
899
  inScope(`fact ${fact.name}`, [fact.holds], [...m.params, ...keysOf(fact)], fns);
899
900
  }
900
901
  // A key bound in t is read in key terms only: the key, or the key plus or less a term that doesn't read it (k + e, e + k,
901
- // k ∸ e), each a map's key (no function's: a function's values don't stop where a map's cells do) or a side of a
902
+ // k ∸ e), each a map's key (no function's or count's: their values don't stop where a map's cells do) or a side of a
902
903
  // comparison whose other side doesn't read the key. Then t is constant between finitely many keys (the runtimes'
903
904
  // breakpoints: each map's cells and each compared value, shifted by the offsets), so a runtime decides it on those.
904
905
  const readsKey = (t, key) => JSON.stringify(t).includes(`"op":"var","name":${JSON.stringify(key)}`);
@@ -56,6 +56,7 @@ export declare const fullWork: () => number;
56
56
  export declare const withWork: <T>(cap: number, f: () => T) => T;
57
57
  export declare const pastWall: () => boolean;
58
58
  export declare function withWall<T>(end: number, f: () => T): T;
59
+ export declare const wallAt: () => number;
59
60
  export declare const late: (until: number) => boolean;
60
61
  export declare const withinDeadline: (until: number) => number;
61
62
  export declare function withDeadline<T>(until: number, f: () => T): T;
@@ -305,6 +305,10 @@ export function withWall(end, f) {
305
305
  wallEnd = outer;
306
306
  }
307
307
  }
308
+ // Past the wall or the deadline in force: a goal grown now is left unknown at once.
309
+ const ranOut = () => pastWall() || withinDeadline(Infinity) <= clock();
310
+ // (the wall's end in force, Infinity where none: a search inside that stops itself there)
311
+ export const wallAt = () => wallEnd;
308
312
  export const late = (until) => clock() > until || (workCap !== Infinity && fullWork() > workCap) || pastWall();
309
313
  // A budget's end, within the deadline (a translation's own bound, core/cyclic.ts's, kept by the export's GDP_CERT_MS).
310
314
  export const withinDeadline = (until) => Math.min(until, deadline);
@@ -1458,18 +1462,60 @@ const withReads = (laws, inst, keys, focus, byMap, fns = []) => {
1458
1462
  return { ...inst, ...Object.fromEntries(laws.filter(l => l.forall).map(l => {
1459
1463
  const had = inst[l.name] ?? [];
1460
1464
  if (l.keys?.length) {
1461
- const n = l.keys.length + 1, out = new Map(), sorted = byMap ? keySorted(l, byMap, fns) : undefined;
1465
+ const n = l.keys.length + 1, out = new Map();
1462
1466
  for (let i = 0; i + n <= had.length; i += n)
1463
1467
  out.set(JSON.stringify(had.slice(i, i + n)), had.slice(i, i + n));
1464
- for (const tuple of [...related(keys, focus, n, sorted, most), ...matched(l, keys, most)])
1465
- if (!sorted || sorted(tuple))
1468
+ // (a key the law's hypothesis fixes by an equation, x + c = t: the tuples of the others, x at t ∸ c in each)
1469
+ const { law: lr, back } = fixedOut(l), m2 = lr.keys?.length ?? 0, sorted = byMap ? keySorted(lr, byMap, fns) : undefined;
1470
+ const tuples = m2 ? [...related(keys, focus, m2 + 1, sorted, most), ...matched(lr, keys, most)] : related(keys, focus, 1, sorted, most);
1471
+ for (const t0 of tuples)
1472
+ if (!sorted || sorted(t0)) {
1473
+ const tuple = back(t0);
1466
1474
  out.set(JSON.stringify(tuple), tuple);
1475
+ }
1467
1476
  return [l.name, [...out.values()].flat()];
1468
1477
  }
1469
1478
  const seen = new Set(had.map(e => JSON.stringify(e)));
1470
1479
  return [l.name, [...had, ...keys.filter(e => { const id = JSON.stringify(e); return seen.has(id) ? false : (seen.add(id), true); })]];
1471
1480
  })) };
1472
1481
  };
1482
+ // A law's keys that its hypothesis fixes by an equation (x + c = t, or t = x, t reading no fixed key): the law without
1483
+ // them (each read at t ∸ c, c ≤ t a further hypothesis: the same law over the naturals), and `back`, a tuple of its keys
1484
+ // made a tuple of the law's (each fixed key at its t). A law with five keys of which two a cell fixes (Table[a·N + k] =
1485
+ // v + 1) has its instances over three. Untrusted: it chooses instances only.
1486
+ const fixedMemo = new WeakMap();
1487
+ function fixedOut(l) {
1488
+ let out = fixedMemo.get(l);
1489
+ if (!out)
1490
+ fixedMemo.set(l, (out = fixedOut0(l)));
1491
+ return out;
1492
+ }
1493
+ function fixedOut0(l) {
1494
+ const all = [l.forall, ...(l.keys ?? [])], same = { law: l, back: (t) => t };
1495
+ const hyps = l.holds.op === 'or' ? l.holds.xs.flatMap(d => (d.op === 'not' ? (d.x.op === 'and' ? d.x.xs : [d.x]) : [])) : [];
1496
+ const named = (e, x) => JSON.stringify(e).includes(`"name":${JSON.stringify(x)}`);
1497
+ const offset = (e) => (e.op === 'var' && all.includes(e.name) ? [e.name, 0] : e.op === 'add' && e.a.op === 'var' && all.includes(e.a.name) && e.b.op === 'const' ? [e.a.name, e.b.value] : undefined);
1498
+ const fixed = new Map();
1499
+ for (const h of hyps) {
1500
+ if (h.op !== '=')
1501
+ continue;
1502
+ for (const [x, t] of [[h.a, h.b], [h.b, h.a]]) {
1503
+ const o = offset(x);
1504
+ if (!o || o[0] === l.forall || fixed.has(o[0]) || named(t, o[0]) || [...fixed.keys()].some(f => named(t, f)) || [...fixed.values()].some(f => named(f.t, o[0])))
1505
+ continue;
1506
+ fixed.set(o[0], { t, c: o[1] });
1507
+ break;
1508
+ }
1509
+ }
1510
+ if (!fixed.size)
1511
+ return same;
1512
+ const at = (x) => { const { t, c } = fixed.get(x); return c ? { op: 'sub', a: t, b: { op: 'const', value: c } } : t; };
1513
+ const sub0 = { vars: Object.fromEntries([...fixed.keys()].map(x => [x, at(x)])), maps: {}, flags: {} };
1514
+ const guards = [...fixed.values()].flatMap(({ t, c }) => (c ? [{ op: '<=', a: { op: 'const', value: c }, b: t }] : []));
1515
+ const kept = all.filter(x => !fixed.has(x)), holds = substC(guards.length ? { op: 'or', xs: [{ op: 'not', x: { op: 'and', xs: guards } }, l.holds] } : l.holds, sub0);
1516
+ const law = { ...l, holds, keys: kept.slice(1) };
1517
+ return { law, back: t => { const s2 = { vars: Object.fromEntries(kept.map((x, i) => [x, t[i]])), maps: {}, flags: {} }; return all.map(x => (fixed.has(x) ? substE(at(x), s2) : t[kept.indexOf(x)])); } };
1518
+ }
1473
1519
  // A tuple of the key's sort: each of a law's keys read at a map (M[x], M[x·N + y]) takes only the terms its read matches
1474
1520
  // against the keys the goals read that map at (the key's sort, as the goal holds it: Link[c1·N + s] against
1475
1521
  // Link[a·N + b] gives c1 a and s b); a key no read binds, or a read no goal key matches, takes any. A function's
@@ -2185,8 +2231,21 @@ export function proveLaw(m, laws, i) {
2185
2231
  function proveOne(m, laws, i) {
2186
2232
  const law = laws[i], pm = plainOf(m), inst = lawInstances(m, laws, i);
2187
2233
  const few = triggered(pm, laws, inst, i2 => obligations(m, laws, { [law.name]: i2 }, i), law.forall ? [`${law.forall}#`] : []);
2188
- if (!sameInstances(few, inst) && obligations(m, laws, { [law.name]: few }, i).every(goal => 'tree' in grow(goal)))
2189
- return { proven: true };
2234
+ if (!sameInstances(few, inst)) {
2235
+ let proven = true;
2236
+ for (const goal of obligations(m, laws, { [law.name]: few }, i)) {
2237
+ const o = grow(goal);
2238
+ if ('tree' in o)
2239
+ continue;
2240
+ proven = false;
2241
+ // (a goal that ran out past the deadline: the next instances can't be tried, and it is the verdict's goal)
2242
+ if (o.stuck === 'unknown' && ranOut())
2243
+ return { proven: false, goal: goal.name, stuck: 'unknown' };
2244
+ break;
2245
+ }
2246
+ if (proven)
2247
+ return { proven: true };
2248
+ }
2190
2249
  // (a model breaking a law at a tuple of the goal's keys: those added, the law asked again)
2191
2250
  const { result: a } = withModels(m, laws, inst, i2 => obligations(m, laws, { [law.name]: i2 }, i), growAll, grownModel, grownSettled);
2192
2251
  return a.out ? { proven: false, goal: a.goal.name, stuck: a.out.stuck, ...(a.out.witness ? { witness: a.out.witness } : {}), ...(a.out.diagram ? { diagram: a.out.diagram } : {}) } : { proven: true };
@@ -2482,15 +2541,17 @@ function thinned(m, laws, instances) {
2482
2541
  const trees = {}, fulls = { ...instances };
2483
2542
  let nodes = 0, leaves = 0;
2484
2543
  for (const [i, law] of laws.entries()) {
2485
- const full = instances[law.name];
2486
- const few = triggered(plainOf(m), laws, full, inst => obligations(m, laws, { ...instances, [law.name]: inst }, i), law.forall ? [`${law.forall}#`] : []);
2544
+ const full = instances[law.name], focus = law.forall ? [`${law.forall}#`] : [];
2545
+ const few = triggered(plainOf(m), laws, full, inst => obligations(m, laws, { ...instances, [law.name]: inst }, i), focus);
2487
2546
  // (thinned instances first, then the full ones; each asked again at the tuples its models ask for)
2488
2547
  for (const inst of sameInstances(few, full) ? [full] : [few, full]) {
2489
2548
  const { result: a, inst: at } = withModels(m, laws, inst, i2 => obligations(m, laws, { ...instances, [law.name]: i2 }, i), growAll, grownModel, grownSettled);
2490
2549
  instances[law.name] = at;
2491
2550
  if (inst === full)
2492
2551
  fulls[law.name] = at;
2493
- if (a.out && inst !== full)
2552
+ // (one that ran out past the wall: the next instances can't be tried, and the goal that ran out is the verdict's, not
2553
+ // the next one's first goal)
2554
+ if (a.out && inst !== full && !(a.out.stuck === 'unknown' && ranOut()))
2494
2555
  continue;
2495
2556
  if (a.out)
2496
2557
  return stuckAt(a.goal, a.out, nodes, leaves);
@@ -388,9 +388,10 @@ export class Reader {
388
388
  out.push({ lin: row.lin, w: join(row.w, closed.w), label: '' });
389
389
  // (the last open part's own value is a read: open while it is)
390
390
  const last = this.truth(open[0]);
391
- // (and the facts are kept only while the part's own value is: its reason is theirs, though not their rows')
391
+ // (and the facts are kept only while the part's own value is: its reason is theirs, though not their rows'; and
392
+ // while the closed parts' are: one closed through an open term column opens when the column's choice is decided)
392
393
  const x = both(both(closed, r), last);
393
- return { w: x.w, pos: x.pos, fin: r.fin && last.t !== undefined && last.fin };
394
+ return { w: x.w, pos: x.pos, fin: x.fin && last.t !== undefined };
394
395
  }
395
396
  case '<':
396
397
  case '<=':
@@ -3,7 +3,7 @@ import { add, k, scale, sub } from "../core/solver.js";
3
3
  import { countedGoal, countedObligations, countHyps, mcGoal, postName, boundOf, caseGoals, check, checkRecur, checkRecurCases, coverGoal, recurGoal, canon, decided, factorsOf, isCell, isMonomial, columnTerm, stateName, termColumn, truth, historyMachine, sumMachine, sumCovers, sumParts, foldObligations, kInductionStart, kInductionSteps, leafConstraints, loopLiveness, loopMachine, linear, livenessHelpful, livenessParts, livenessLevels, livenessRanks, strongly, loopObligations, trueC, obligations, progressObligations, stepLawObligations, substC, witnessesOf, withProducts } from "../kernel/kernel.js";
4
4
  import { chooseLevels, clock, grow, minimal, proveBuilt, proveLaws, proveSetFast, proveStepLaws, withDeadline } from "../kernel/prove.js";
5
5
  import { refinement, refinementSides } from "../core/compose.js";
6
- import { leanSurface, leanTerms } from "./lean-terms.js";
6
+ import { exactNat, leanSurface, leanTerms } from "./lean-terms.js";
7
7
  import { descentGoal, mainGoal, premiseGoal } from "../kernel/cyclic.js";
8
8
  import { allowNode, certMs, closingInsts, reqTS, withWitness, foldNodes, certMode, quietly, uncoveredWhy, hasQuantified, kWhens, machineNodes, proveCyclic, routeOf, searchedStepNodes, skMachine, stepLawNodes, tBack, tSub } from "../core/cyclic.js";
9
9
  import { leanLibrary } from "./library.js";
@@ -908,7 +908,7 @@ export function mmachineToLean(id, m, laws, opts = {}) {
908
908
  const ix = (name) => vars.indexOf(name);
909
909
  const lit = (mm) => `⟨⟨${list(mm.inputs.map(name => String(ix(name))))},
910
910
  ${list(Object.entries(mm.state).map(([name, e]) => `(${ix(name)}, ${any0.e(e)})`))},
911
- ${list(Object.entries(mm.maps ?? {}).map(([name, c2]) => `(${mapNames.indexOf(name)}, ${c2})`))},
911
+ ${list(Object.entries(mm.maps ?? {}).map(([name, c2]) => `(${mapNames.indexOf(name)}, ${exactNat(c2)})`))},
912
912
  ${list(Object.entries(mm.step.state ?? {}).map(([name, e]) => `(${ix(name)}, ${any0.e(e)})`))},
913
913
  ${list(Object.entries(mm.step.maps ?? {}).map(([name, w]) => { const pw = pointWrite(w, 'Lean (for now)'); return `(${mapNames.indexOf(name)}, ${any0.e(pw.key)}, ${any0.e(pw.value)})`; }))},
914
914
  ${mm.pre ? any0.c(mm.pre) : TRUE},
@@ -1004,7 +1004,7 @@ export function machineLit(mm, t, ix, mx) {
1004
1004
  const fl = flagsOfM(mm), fs = Object.entries(mm.step.flags ?? {}), ws = Object.entries(mm.step.maps ?? {});
1005
1005
  return `⟨⟨⟨${list(mm.inputs.map(name => String(ix(name))))},
1006
1006
  ${list(Object.entries(mm.state).map(([name, e2]) => `(${ix(name)}, ${e(e2)})`))},
1007
- ${list(Object.entries(mm.maps ?? {}).map(([name, c2]) => `(${mx(name)}, ${c2})`))},
1007
+ ${list(Object.entries(mm.maps ?? {}).map(([name, c2]) => `(${mx(name)}, ${exactNat(c2)})`))},
1008
1008
  ${list(Object.entries(mm.step.state ?? {}).map(([name, e2]) => `(${ix(name)}, ${e(e2)})`))},
1009
1009
  ${list(ws.flatMap(([name, w]) => ('each' in w ? [] : [`(${mx(name)}, ${e(w.key)}, ${e(w.value)})`])))},
1010
1010
  ${mm.pre ? c(mm.pre) : TRUE},
@@ -1,4 +1,5 @@
1
1
  import { type C, type E } from '../core/machine.js';
2
+ export declare const exactNat: (x: number) => string;
2
3
  export declare function leanTerms(vars: readonly string[], maps: readonly string[], where: string): {
3
4
  e: (t: E) => string;
4
5
  c: (t: C) => string;
@@ -3,6 +3,10 @@
3
3
  // numbered by their place in `vars` and `maps`; a flag is the variable ?flag read as `= 1` (Progress.lean inlines it).
4
4
  // A name with no number fails here, never as a malformed index in the Lean text.
5
5
  import { unreachable } from "../core/machine.js";
6
+ // A number as Lean reads it: the exact integer JavaScript holds. (Past 2^53 a JavaScript number prints as the shortest
7
+ // decimal that reads back to it, 10^18 + 128 as 1000000000000000100: Lean would read another number than the kernel and
8
+ // the runtimes do. terra's review of gen/laneQ.)
9
+ export const exactNat = (x) => (Number.isSafeInteger(x) ? String(x) : BigInt(x).toString());
6
10
  export function leanTerms(vars, maps, where) {
7
11
  const ix = (name) => { const j = vars.indexOf(name); if (j < 0)
8
12
  throw new Error(`${where}: no variable for ${name}`); return j; };
@@ -11,8 +15,8 @@ export function leanTerms(vars, maps, where) {
11
15
  const e = (t) => {
12
16
  switch (t.op) {
13
17
  case 'var': return `.var ${ix(t.name)}`;
14
- case 'const': return `.const ${t.value}`;
15
- case 'mul': return `.mul ${t.k} (${e(t.a)})`;
18
+ case 'const': return `.const ${exactNat(t.value)}`;
19
+ case 'mul': return `.mul ${exactNat(t.k)} (${e(t.a)})`;
16
20
  case 'add':
17
21
  case 'sub':
18
22
  case 'min':
@@ -50,8 +54,8 @@ export function leanSurface(names, where, get) {
50
54
  const e = (t) => {
51
55
  switch (t.op) {
52
56
  case 'var': return name(t.name);
53
- case 'const': return String(t.value);
54
- case 'mul': return `(${t.k} * ${e(t.a)})`;
57
+ case 'const': return exactNat(t.value);
58
+ case 'mul': return `(${exactNat(t.k)} * ${e(t.a)})`;
55
59
  case 'add': return `(${e(t.a)} + ${e(t.b)})`;
56
60
  case 'sub': return `(${e(t.a)} - ${e(t.b)})`;
57
61
  case 'prod': return `(${e(t.a)} * ${e(t.b)})`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gdp-wired",
3
- "version": "0.42.0",
3
+ "version": "0.44.0",
4
4
  "description": "An automatic prover for stateful rules (budgets, caps, windows, workflows, policies): laws proven with no proof to write, checked again in Lean, counterexamples found on the GPU, the rule shipped as code",
5
5
  "keywords": [
6
6
  "verification",
@@ -140,6 +140,10 @@
140
140
  "types": "./dist/core/extract-go.d.ts",
141
141
  "default": "./dist/core/extract-go.js"
142
142
  },
143
+ "./extract-sol": {
144
+ "types": "./dist/core/extract-sol.d.ts",
145
+ "default": "./dist/core/extract-sol.js"
146
+ },
143
147
  "./cli": {
144
148
  "types": "./dist/core/cli.d.ts",
145
149
  "default": "./dist/core/cli.js"
@@ -152,10 +156,15 @@
152
156
  "types": "./dist/core/relational.d.ts",
153
157
  "default": "./dist/core/relational.js"
154
158
  },
159
+ "./interchange": {
160
+ "types": "./dist/interchange/check.d.ts",
161
+ "default": "./dist/interchange/check.js"
162
+ },
155
163
  "./package.json": "./package.json"
156
164
  },
157
165
  "bin": {
158
- "gdp-wired": "dist/core/cli.js"
166
+ "gdp-wired": "dist/core/cli.js",
167
+ "gdp-wired-check": "dist/interchange/cli.js"
159
168
  },
160
169
  "files": [
161
170
  "dist",
@@ -185,7 +194,7 @@
185
194
  "prepublishOnly": "bun scripts/build.ts",
186
195
  "smoke": "sh scripts/smoke.sh",
187
196
  "bar": "bun gates/bar.ts",
188
- "test": "bun scripts/gen-lean-library.ts --check && cd core && bun test exports.test.ts cli.test.ts solver.test.ts dsl.test.ts sums.test.ts arith.test.ts conformance.test.ts compose.test.ts relational.test.ts quantifiers.test.ts functions.test.ts keyterms.test.ts lists.test.ts liveness.test.ts sizes.test.ts values.test.ts rationals.test.ts builders.test.ts gdp.test.ts datatypes.test.ts lemmas.test.ts discover.test.ts infer.test.ts cyclic.test.ts cycles.test.ts nonterm.test.ts data.test.ts hypothesis.test.ts seqs.test.ts abstract.test.ts search.test.ts invoices.test.ts folds.test.ts trees.test.ts pairs.test.ts chart.test.ts xstate.test.ts extract.test.ts effect.test.ts && cd ../kernel && bun test tamper.test.ts refusals.test.ts steplaw.test.ts sets.test.ts cdcl.test.ts && cd ../examples && bun test examples.test.ts && cd .. && bun examples/readme.ts && bun examples/guide.ts && bun examples/composition.ts && bun examples/sets.ts && bun examples/quantifiers.ts && bun examples/functions.ts && bun examples/datatypes.ts && bun examples/lemmas.ts && bun examples/discover.ts && bun examples/invoices.ts && bun examples/folds.ts && bun examples/trees.ts && bun examples/pairs.ts && bun examples/groups.ts && bun examples/charts.ts && bun examples/xstate.ts && bun examples/effect.ts && bun examples/infer.ts && bun examples/arith.ts && bun examples/cyclic.ts && bun examples/cycles.ts && bun examples/data.ts && bun examples/abstract.ts && bun test compare/tip/translate.test.ts && bun examples/scopes.ts && bun examples/lists.ts && bun examples/sizes.ts && bun examples/liveness.ts && bun examples/sums.ts && bun examples/nonterm.ts && bun examples/rationals.ts && bun examples/budget.ts && bun examples/gdp.ts && bun examples/steps.ts && bun examples/jev-fabric/run.ts"
197
+ "test": "bun scripts/gen-lean-library.ts --check && cd core && bun test exports.test.ts cli.test.ts solver.test.ts rand.test.ts dsl.test.ts sums.test.ts arith.test.ts conformance.test.ts compose.test.ts relational.test.ts quantifiers.test.ts functions.test.ts keyterms.test.ts lists.test.ts liveness.test.ts sizes.test.ts values.test.ts rationals.test.ts builders.test.ts gdp.test.ts datatypes.test.ts lemmas.test.ts discover.test.ts infer.test.ts cyclic.test.ts cycles.test.ts nonterm.test.ts data.test.ts hypothesis.test.ts seqs.test.ts abstract.test.ts search.test.ts invoices.test.ts folds.test.ts trees.test.ts pairs.test.ts chart.test.ts xstate.test.ts extract.test.ts effect.test.ts effect-schedule.test.ts effect-stm.test.ts effect-queue.test.ts && cd ../kernel && bun test tamper.test.ts refusals.test.ts steplaw.test.ts sets.test.ts cdcl.test.ts && cd ../examples && bun test examples.test.ts && cd .. && bun examples/readme.ts && bun examples/guide.ts && bun examples/composition.ts && bun examples/sets.ts && bun examples/quantifiers.ts && bun examples/functions.ts && bun examples/datatypes.ts && bun examples/lemmas.ts && bun examples/discover.ts && bun examples/invoices.ts && bun examples/folds.ts && bun examples/trees.ts && bun examples/pairs.ts && bun examples/groups.ts && bun examples/charts.ts && bun examples/xstate.ts && bun examples/effect.ts && bun examples/effect-retry.ts && bun examples/effect-stm.ts && bun examples/effect-queue.ts && bun examples/infer.ts && bun examples/arith.ts && bun examples/cyclic.ts && bun examples/cycles.ts && bun examples/data.ts && bun examples/abstract.ts && bun test compare/tip/translate.test.ts && bun examples/scopes.ts && bun examples/lists.ts && bun examples/sizes.ts && bun examples/liveness.ts && bun examples/sums.ts && bun examples/nonterm.ts && bun examples/rationals.ts && bun examples/budget.ts && bun examples/gdp.ts && bun examples/steps.ts && bun examples/jev-fabric/run.ts"
189
198
  },
190
199
  "devDependencies": {
191
200
  "@gdp-ts/core": "0.1.0",