gdp-wired 0.43.0 → 0.45.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 (79) hide show
  1. package/README.md +8 -3
  2. package/dist/core/c/reader.js +22 -7
  3. package/dist/core/check.js +3 -2
  4. package/dist/core/cli.d.ts +7 -0
  5. package/dist/core/cli.js +184 -12
  6. package/dist/core/counts.d.ts +1 -1
  7. package/dist/core/counts.js +30 -12
  8. package/dist/core/data.d.ts +6 -1
  9. package/dist/core/data.js +894 -152
  10. package/dist/core/dsl.d.ts +2 -0
  11. package/dist/core/dsl.js +88 -10
  12. package/dist/core/effect-prims.d.ts +60 -0
  13. package/dist/core/effect-prims.js +625 -0
  14. package/dist/core/effect.d.ts +17 -1
  15. package/dist/core/effect.js +108 -4
  16. package/dist/core/ex/harness.exs +2 -0
  17. package/dist/core/ex/reader.exs +17 -1
  18. package/dist/core/exists.d.ts +15 -1
  19. package/dist/core/exists.js +263 -41
  20. package/dist/core/extract-c.d.ts +2 -0
  21. package/dist/core/extract-c.js +22 -13
  22. package/dist/core/extract-check.d.ts +7 -0
  23. package/dist/core/extract-check.js +57 -4
  24. package/dist/core/extract-ex.js +5 -5
  25. package/dist/core/extract-go-check.js +22 -17
  26. package/dist/core/extract-go.d.ts +3 -0
  27. package/dist/core/extract-go.js +24 -9
  28. package/dist/core/extract-jvm.js +68 -16
  29. package/dist/core/extract-print.js +3 -0
  30. package/dist/core/extract-py.js +5 -5
  31. package/dist/core/extract-rb.js +5 -5
  32. package/dist/core/extract-read.d.ts +8 -0
  33. package/dist/core/extract-read.js +55 -0
  34. package/dist/core/extract-rs.js +28 -25
  35. package/dist/core/extract-shapes.js +20 -0
  36. package/dist/core/extract-sol.js +23 -12
  37. package/dist/core/extract-step.d.ts +59 -3
  38. package/dist/core/extract-step.js +334 -64
  39. package/dist/core/extract-swift.js +22 -15
  40. package/dist/core/extract.d.ts +1 -0
  41. package/dist/core/extract.js +27 -2
  42. package/dist/core/fresh.d.ts +2 -2
  43. package/dist/core/fresh.js +7 -3
  44. package/dist/core/go/reader.go +7 -1
  45. package/dist/core/infer.js +113 -40
  46. package/dist/core/jvm/Harness.java +8 -1
  47. package/dist/core/jvm/JavaReader.java +10 -2
  48. package/dist/core/jvm/Jvm.java +18 -2
  49. package/dist/core/jvm/KtReader.java +60 -5
  50. package/dist/core/machine.d.ts +2 -0
  51. package/dist/core/machine.js +32 -6
  52. package/dist/core/py/harness.py +128 -24
  53. package/dist/core/py/reader.py +50 -5
  54. package/dist/core/rb/reader.rb +52 -5
  55. package/dist/core/rs/src/main.rs +10 -0
  56. package/dist/core/sol/Replay.sol +52 -0
  57. package/dist/core/sol/harness.py +511 -0
  58. package/dist/core/solver.js +5 -4
  59. package/dist/core/system.d.ts +62 -1
  60. package/dist/core/system.js +274 -6
  61. package/dist/core/transfer.js +17 -0
  62. package/dist/core/watch.js +1 -1
  63. package/dist/interchange/check.d.ts +18 -1
  64. package/dist/interchange/check.js +19 -12
  65. package/dist/interchange/cli.d.ts +2 -0
  66. package/dist/interchange/cli.js +45 -0
  67. package/dist/interchange/format.d.ts +5 -1
  68. package/dist/interchange/format.js +25 -9
  69. package/dist/kernel/cdcl.js +65 -14
  70. package/dist/kernel/epr.js +35 -5
  71. package/dist/kernel/kernel.d.ts +2 -0
  72. package/dist/kernel/kernel.js +67 -40
  73. package/dist/kernel/prove.d.ts +22 -0
  74. package/dist/kernel/prove.js +156 -7
  75. package/dist/kernel/reader.js +3 -2
  76. package/dist/lean-kernel/emit.d.ts +9 -3
  77. package/dist/lean-kernel/emit.js +170 -29
  78. package/dist/lean-kernel/library.js +1 -1
  79. package/package.json +12 -3
@@ -1,5 +1,8 @@
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_sf_soundA) and a measure part's fold (a
3
+ // fold function's value at a parameter, core/data.ts's Measure): a document is written at the lowest version that holds
4
+ // it (1.0 unless it has one of these), and read at either.
5
+ export const FORMAT = 'gdp-wired-interchange', VERSION = '1.1', VERSIONS = ['1.0', '1.1'];
3
6
  export const KINDS = ['goals', 'laws', 'stepLaws', 'kInduction', 'progress', 'liveness', 'loop', 'recur', 'fold', 'cyclic', 'qgoals', 'qmachine', 'termination'];
4
7
  // Why a value is outside the format: where, and what.
5
8
  export class FormatError extends Error {
@@ -484,12 +487,15 @@ const encRank = (r, at) => (Array.isArray(r) ? r.map((e, i) => encE(e, `${at}[${
484
487
  const decRank = (x, at) => (Array.isArray(x) ? x.map((e, i) => decE(e, `${at}[${i}]`)) : decE(x, at));
485
488
  const encHelpful = (h, at) => clean({ when: h.when && encC(h.when, `${at}.when`), request: pairs(h.request, encE, `${at}.request`) });
486
489
  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`) }); };
490
+ const fairnessOf = (x, at) => (x === 'weak' || x === 'strong' ? x : fail(at, '"weak" or "strong"'));
487
491
  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}]`)) });
492
+ request: l.request && pairs(l.request, encE, `${at}.request`), helpful: l.helpful && l.helpful.map((h, i) => encHelpful(h, `${at}.helpful[${i}]`)),
493
+ fairness: l.fairness && fairnessOf(l.fairness, `${at}.fairness`), levels: l.levels && l.levels.map((n, i) => nat(n, `${at}.levels[${i}]`)) });
489
494
  const decLiveness = (x, at) => {
490
- const o = obj(x, at, ['name', 'from', 'to', 'rank'], ['request', 'helpful']);
495
+ const o = obj(x, at, ['name', 'from', 'to', 'rank'], ['request', 'helpful', 'fairness', 'levels']);
491
496
  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) });
497
+ 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),
498
+ fairness: opt(o, 'fairness', fairnessOf, at), levels: opt(o, 'levels', (y, a) => arr(y, a).map((n, i) => nat(n, `${a}[${i}]`)), at) });
493
499
  };
494
500
  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
501
  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`) });
@@ -556,10 +562,15 @@ const decRecur = (x, cols, at) => {
556
562
  const o = obj(x, at, ['start', 'stem', 'set', 'wit', 'tree']);
557
563
  return { start: record(o.start, nat, `${at}.start`), stem: arr(o.stem, `${at}.stem`).map((t, i) => record(t, nat, `${at}.stem[${i}]`)), set: decC(o.set, `${at}.set`), wit: record(o.wit, decE, `${at}.wit`), tree: decTree(o.tree, cols, `${at}.tree`) };
558
564
  };
559
- const encMeasure = (m, at) => ({ comps: arr(m.comps, `${at}.comps`).map((c, i) => { const q = c; return { coef: arr(q.coef, `${at}.comps[${i}].coef`).map((k, j) => int(k, `${at}.comps[${i}].coef[${j}]`)), c: int(q.c, `${at}.comps[${i}].c`) }; }) });
565
+ const encFoldPart = (f, at) => ({ fn: name(f.fn, `${at}.fn`), of: nat(f.of, `${at}.of`) });
566
+ const encMeasure = (m, at) => ({ comps: arr(m.comps, `${at}.comps`).map((c, i) => { const q = c; return clean({ coef: arr(q.coef, `${at}.comps[${i}].coef`).map((k, j) => int(k, `${at}.comps[${i}].coef[${j}]`)), c: int(q.c, `${at}.comps[${i}].c`), fold: q.fold && encFoldPart(q.fold, `${at}.comps[${i}].fold`) }); }) });
560
567
  const decMeasure = (x, at) => {
561
568
  const o = obj(x, at, ['comps']);
562
- return { comps: arr(o.comps, `${at}.comps`).map((c, i) => { const q = obj(c, `${at}.comps[${i}]`, ['coef', 'c']); return { coef: arr(q.coef, `${at}.comps[${i}].coef`).map((k, j) => int(k, `${at}.comps[${i}].coef[${j}]`)), c: int(q.c, `${at}.comps[${i}].c`) }; }) };
569
+ return { comps: arr(o.comps, `${at}.comps`).map((c, i) => {
570
+ const q = obj(c, `${at}.comps[${i}]`, ['coef', 'c'], ['fold']);
571
+ return clean({ coef: arr(q.coef, `${at}.comps[${i}].coef`).map((k, j) => int(k, `${at}.comps[${i}].coef[${j}]`)), c: int(q.c, `${at}.comps[${i}].c`),
572
+ fold: opt(q, 'fold', (y, a) => { const f = obj(y, a, ['fn', 'of']); return { fn: name(f.fn, `${a}.fn`), of: nat(f.of, `${a}.of`) }; }, `${at}.comps[${i}]`) });
573
+ }) };
563
574
  };
564
575
  // --- documents ---------------------------------------------------------------------------------------------------------------
565
576
  // The fields each kind has, in the order a document is written.
@@ -595,15 +606,20 @@ export function toInterchange(c, meta) {
595
606
  default: return fail('kind', `no kind ${JSON.stringify(c.kind)}`);
596
607
  }
597
608
  })();
598
- return clean({ format: FORMAT, version: VERSION, kind: c.kind, meta, columns: 'terms' in cols && cols.terms.length ? cols.terms : undefined, ...body });
609
+ const v11 = (c.kind === 'liveness' && (c.liveness.fairness !== undefined || c.liveness.levels !== undefined)) || (c.kind === 'termination' && c.measures.some(m => m.comps.some(q => q.fold !== undefined)));
610
+ 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
611
  }
600
612
  // A document read back into the kernel's objects, or a FormatError saying where it leaves the format.
601
613
  export function fromInterchange(doc) {
602
614
  const head = isObj(doc) ? doc : fail('document', 'an object');
603
615
  if (head.format !== FORMAT)
604
616
  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)`);
617
+ if (!VERSIONS.includes(head.version))
618
+ fail('version', `one of ${VERSIONS.join(', ')} (this reader's)`);
619
+ if (head.version === '1.0' && head.kind === 'liveness' && isObj(head.liveness) && ('fairness' in head.liveness || 'levels' in head.liveness))
620
+ fail('liveness', 'no fairness or levels in a 1.0 document (1.1\'s)');
621
+ if (head.version === '1.0' && head.kind === 'termination' && JSON.stringify(head.measures ?? []).includes('"fold"'))
622
+ fail('measures', 'no fold in a 1.0 document (1.1\'s)');
607
623
  const kind = head.kind;
608
624
  if (!KINDS.includes(kind))
609
625
  fail('kind', `one of ${KINDS.join(', ')}`);
@@ -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, late, leafRowsOf, logged, nearOf, openAt, pairedKeys, queryHook, rowsAt, unitAtoms } from "./prove.js";
23
+ import { atPoint, cellPair, 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.
@@ -63,6 +63,12 @@ export const cdclStats = { on: false, runs: 0, proven: 0, conflicts: 0, decision
63
63
  // any value: the trail's atoms, the naturals, the term columns' definitions), as core/infer.ts's join reads it.
64
64
  export const REFUTED = 'refuted, not unfolded';
65
65
  export function growCdcl(goal, root, budget, opts = {}) {
66
+ // (a wide goal's model or refutation: over parts first, prove.ts's growWide)
67
+ if (opts.model && !opts.dag && !opts.clausal && !root.size && wideFor(goal)) {
68
+ const out = growWide(goal, budget, (g, until) => growCdcl(g, root, { nodes: 0, until }, opts));
69
+ if (out)
70
+ return out;
71
+ }
66
72
  const go = () => cdclSession(goal, root, opts).run(budget, opts.wall);
67
73
  return queryHook.on && !queryHook.depth ? logged(opts.model ? 'model' : 'cdcl', goal, go) : go();
68
74
  }
@@ -167,7 +173,8 @@ export function cdclSession(goal, root, opts = {}) {
167
173
  const key = keyOf(lin);
168
174
  if (!vars.has(key)) {
169
175
  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 };
176
+ 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,
177
+ bj: undefined, bjAt: undefined, bsig: undefined, bver: undefined, sj: undefined, sx: undefined, pair: undefined, fs: undefined, aq: undefined, an: undefined };
171
178
  byId.push(x);
172
179
  vals.push(0);
173
180
  rel.push(-1);
@@ -314,8 +321,10 @@ export function cdclSession(goal, root, opts = {}) {
314
321
  if (vals[id])
315
322
  activate(id);
316
323
  };
324
+ // (its stack kept between calls: an assignment of a relevant variable calls it, and an array a call cost every one)
325
+ const todo = [];
317
326
  const activate = (id0) => {
318
- for (const todo = [id0]; todo.length;) {
327
+ for (todo.push(id0); todo.length;) {
319
328
  const id = todo.pop(), own = ownBy[2 * id + (vals[id] === 1 ? 1 : 0)];
320
329
  if (!own)
321
330
  continue;
@@ -356,8 +365,10 @@ export function cdclSession(goal, root, opts = {}) {
356
365
  lowAt = Math.min(lowAt, trail.length);
357
366
  levels.length = l;
358
367
  };
368
+ const undone = [];
359
369
  const undoClausal = (l) => {
360
- const keep = levels[l] ?? trail.length, undone = [];
370
+ const keep = levels[l] ?? trail.length;
371
+ undone.length = 0;
361
372
  while (trail.length > keep) {
362
373
  trail.pop();
363
374
  const x = tv.pop(), q = x.aq;
@@ -532,6 +543,19 @@ export function cdclSession(goal, root, opts = {}) {
532
543
  }
533
544
  return w;
534
545
  };
546
+ // (the point rounded, each name the rows read; undefined where the simplex doesn't know one)
547
+ const roundedOf = (lp, rows) => {
548
+ const w = {};
549
+ for (const r of rows)
550
+ for (const n of namesOf(r.lin))
551
+ if (!(n in w)) {
552
+ const j = lp.indexOf(n);
553
+ if (j === undefined)
554
+ return undefined;
555
+ w[n] = Math.max(0, Math.round(lp.value(j)));
556
+ }
557
+ return w;
558
+ };
535
559
  let qhead = 0;
536
560
  // Unit propagation: a clause whose literals all hold is a conflict (its index); all but one, the last is flipped.
537
561
  const propagateKernel = () => {
@@ -568,13 +592,15 @@ export function cdclSession(goal, root, opts = {}) {
568
592
  // is unit, its other watched pair's variable flipped, or, that pair holding too, a conflict.
569
593
  const propagateClausal = () => {
570
594
  // (each watch a clause and a blocker, a pair of it that, where it doesn't hold, satisfies the clause untouched)
595
+ // (holds and opposed read inline: vals[c >> 1] is 2 − (c & 1) where pair c holds, 1 + (c & 1) where it's opposed)
571
596
  while (qhead < trail.length) {
572
597
  const x = tv[qhead++], code = 2 * x.id + (x.val ? 1 : 0), ws = wl[code];
573
598
  if (!ws)
574
599
  continue;
575
600
  let n = 0;
576
601
  for (let i = 0; i < ws.length;) {
577
- if (opposed(ws[i + 1])) {
602
+ const blocker = ws[i + 1];
603
+ if (vals[blocker >> 1] === 1 + (blocker & 1)) {
578
604
  i += 2;
579
605
  continue;
580
606
  }
@@ -591,15 +617,20 @@ export function cdclSession(goal, root, opts = {}) {
591
617
  c[1] = code;
592
618
  }
593
619
  const o = c[0];
594
- if (opposed(o)) {
620
+ if (vals[o >> 1] === 1 + (o & 1)) {
595
621
  ws[i + 1] = o;
596
622
  i += 2;
597
623
  continue;
598
624
  }
599
625
  let j = 2;
600
- while (j < c.length && holds(c[j]))
626
+ const len = c.length;
627
+ while (j < len) {
628
+ const z = c[j];
629
+ if (vals[z >> 1] !== 2 - (z & 1))
630
+ break;
601
631
  j++;
602
- if (j < c.length) {
632
+ }
633
+ if (j < len) {
603
634
  const z = c[j];
604
635
  c[j] = code;
605
636
  c[1] = z;
@@ -610,7 +641,7 @@ export function cdclSession(goal, root, opts = {}) {
610
641
  continue;
611
642
  }
612
643
  if (!vals[o >> 1]) {
613
- assignVar(byId[o >> 1], !(o & 1), ci);
644
+ assignClausal(byId[o >> 1], !(o & 1), ci);
614
645
  i += 2;
615
646
  continue;
616
647
  }
@@ -694,8 +725,13 @@ export function cdclSession(goal, root, opts = {}) {
694
725
  }, ms => { st.coreMs += ms; });
695
726
  // The clausal mode's conflict analysis: the same resolutions, in one pass down the trail (the clause kept as it is
696
727
  // resolved, its literals at its latest level counted, each step the latest of them on the trail).
728
+ // (whether a variable is in the clause being resolved: its stamp `an` this call's, so the walk down the trail reads
729
+ // each variable once, not the clause's map by its name)
730
+ let anN = 0;
697
731
  const analyzeClausal = (c) => {
698
- const lits = new Map(c.lits);
732
+ const lits = new Map(c.lits), an = ++anN;
733
+ for (const name of lits.keys())
734
+ vars.get(name).an = an;
699
735
  let node = c.node, { top, here } = levelsOf(c), p = trail.length - 1;
700
736
  if (top < level()) {
701
737
  undoTo(top);
@@ -703,9 +739,9 @@ export function cdclSession(goal, root, opts = {}) {
703
739
  p = trail.length - 1;
704
740
  }
705
741
  while (lits.size && !(top > 0 && here === 1)) {
706
- while (p >= 0 && !(lits.has(trail[p]) && vars.get(trail[p]).level === top))
742
+ while (p >= 0 && !(tv[p].an === an && tv[p].level === top))
707
743
  p--;
708
- const name = trail[p], x = vars.get(name);
744
+ const name = trail[p], x = tv[p];
709
745
  if (top > 0 && x.reason === undefined)
710
746
  break;
711
747
  const r = clauses[x.reason];
@@ -715,11 +751,14 @@ export function cdclSession(goal, root, opts = {}) {
715
751
  st.resolved++;
716
752
  node = nodes.length - 1;
717
753
  lits.delete(name);
754
+ x.an = 0;
718
755
  here--;
719
756
  for (const [w, q] of r.lits)
720
757
  if (w !== name && !lits.has(w)) {
758
+ const y = vars.get(w);
721
759
  lits.set(w, q);
722
- if (vars.get(w).level === top)
760
+ y.an = an;
761
+ if (y.level === top)
723
762
  here++;
724
763
  }
725
764
  }
@@ -1073,7 +1112,7 @@ export function cdclSession(goal, root, opts = {}) {
1073
1112
  continue;
1074
1113
  }
1075
1114
  }
1076
- let steps, lpSat = false;
1115
+ let steps, lpSat = false, judged = false;
1077
1116
  let verdict;
1078
1117
  t(() => {
1079
1118
  // The simplex first (warm from the node before): a conflict's rows, refuted exactly, are the leaf. With a case
@@ -1125,6 +1164,16 @@ export function cdclSession(goal, root, opts = {}) {
1125
1164
  st.lpMisses++;
1126
1165
  }
1127
1166
  lpSat = lp.kind === 'sat';
1167
+ // (a wide goal's part, prove.ts's growWide: the simplex's point rounded, where it holds every hypothesis of the part
1168
+ // read as a state, is the part's model, whatever atoms are still open)
1169
+ if (open && lpSat && wideScope.judge) {
1170
+ const w = roundedOf(sx, rowsR);
1171
+ if (w && wideScope.judge(w)) {
1172
+ verdict = { kind: 'sat', witness: w };
1173
+ judged = true;
1174
+ return;
1175
+ }
1176
+ }
1128
1177
  if (steps || (open && lp.kind === 'sat'))
1129
1178
  return;
1130
1179
  // (the clausal mode, every clause satisfied: the simplex's point, where it is integral, is a model)
@@ -1154,6 +1203,8 @@ export function cdclSession(goal, root, opts = {}) {
1154
1203
  steps = fast.steps.map(s => (s.kind === 'input' ? { ...s, index: k[s.index] } : s));
1155
1204
  }
1156
1205
  }, ms => { st.solveMs += ms; });
1206
+ if (judged && verdict?.kind === 'sat')
1207
+ return stuck('sat', 'a model', { witness: verdict.witness });
1157
1208
  if (steps)
1158
1209
  conflict = leafAt(rowsR, steps);
1159
1210
  else {
@@ -16,13 +16,13 @@ const textOfE = (o) => { let s = textsOf.get(o); if (s === undefined)
16
16
  // The patterns of a rule: of each map's reads in the step, the assumption, the flags and the laws (not the kinds' laws,
17
17
  // whose key is a whole key), the one with the most parts. A read keyed by a write-at-every-key's own name is left out.
18
18
  export function patternsOf(m, laws) {
19
- const out = {};
19
+ const out = Object.create(null);
20
20
  const each = new Set(Object.values(m.step.maps ?? {}).flatMap(w => ('each' in w ? [w.each] : [])));
21
21
  const scan = (o) => {
22
22
  if (!o || typeof o !== 'object')
23
23
  return;
24
24
  const x = o;
25
- if (x.op === 'get' && !x.args && !(x.key.op === 'var' && each.has(x.key.name)) && !(m.fns && x.map in m.fns)) {
25
+ if (x.op === 'get' && !x.args && !(x.key.op === 'var' && each.has(x.key.name)) && !(m.fns && Object.hasOwn(m.fns, x.map))) {
26
26
  const t = tupleOf(x.key);
27
27
  if (t && t.coefs.length > (out[x.map]?.length ?? 0))
28
28
  out[x.map] = t.coefs;
@@ -38,6 +38,26 @@ export function patternsOf(m, laws) {
38
38
  for (const l of laws)
39
39
  if (!(l.name.startsWith('every ') && l.name.endsWith('of its kind')))
40
40
  scan(l.holds);
41
+ // (a map read inside another read's key, a Skolem function a ghost map keeps (Sent[W[s]·N + s]): a function of its key
42
+ // too, its reads parts; the step's writes to it are substituted into the goal's reads, so within a goal it is one
43
+ // function)
44
+ const inKey = (o, under) => {
45
+ if (!o || typeof o !== 'object')
46
+ return;
47
+ const x = o;
48
+ if (x.op === 'get' && !x.args && under && !(m.fns && Object.hasOwn(m.fns, x.map)))
49
+ out[x.map] = [0];
50
+ if (x.op === 'get' && !x.args) {
51
+ inKey(x.key, true);
52
+ return;
53
+ }
54
+ for (const y of Object.values(o))
55
+ inKey(y, under);
56
+ };
57
+ inKey(m.step, false);
58
+ inKey(m.assume, false);
59
+ for (const l of laws)
60
+ inKey(l.holds, false);
41
61
  return out;
42
62
  }
43
63
  const T = { k: 'c', b: true }, Fa = { k: 'c', b: false };
@@ -157,6 +177,16 @@ const liftC = (c) => {
157
177
  if (c.op === 'flag')
158
178
  return c;
159
179
  const a = liftE(c.a), b = liftE(c.b);
180
+ // (a comparison whose side holds an if over a map's read, a key a ghost's write is read in (64·W'[k] + k = 64·s + d),
181
+ // as the if of the comparisons of its two sides: c ∧ (a₁ ⋈ b) ∨ ¬c ∧ (a₂ ⋈ b), equal to it; at most three ifs in all,
182
+ // counted before they are distributed, 8 leaves)
183
+ const ifs = (e) => textOfE(e).split('"op":"if"').length - 1, reads = (e) => textOfE(e).includes('"op":"get"');
184
+ const few = (hasIf(a) || hasIf(b)) && ifs(a) + ifs(b) <= 3, ha = few ? hoisted(a) : a, hb = few ? hoisted(b) : b;
185
+ if (few && ((ha.op === 'if' && reads(ha)) || (hb.op === 'if' && reads(hb))) && keysOf(ha) * keysOf(hb) <= 8) {
186
+ const split = (x, y) => (x.op === 'if' ? { op: 'or', xs: [{ op: 'and', xs: [x.c, split(x.then, y)] }, { op: 'and', xs: [{ op: 'not', x: x.c }, split(x.else, y)] }] }
187
+ : y.op === 'if' ? { op: 'or', xs: [{ op: 'and', xs: [y.c, split(x, y.then)] }, { op: 'and', xs: [{ op: 'not', x: y.c }, split(x, y.else)] }] } : { ...c, a: x, b: y });
188
+ return liftC(split(ha, hb));
189
+ }
160
190
  return a === c.a && b === c.b ? c : { ...c, a, b };
161
191
  };
162
192
  const liftedKeys = (c) => { let x = liftMemo.get(c); if (!x)
@@ -1355,7 +1385,7 @@ function encoder(st, patterns) {
1355
1385
  // grouping, as without one)
1356
1386
  const finish = (model, theoryVal) => {
1357
1387
  const val = (l) => model[l] === true;
1358
- const w = {};
1388
+ const w = Object.create(null); // (a name __proto__ kept, constructor read as no value)
1359
1389
  for (const f of gFinsL) {
1360
1390
  let x = 0;
1361
1391
  for (let val2 = 0; val2 <= f.cap; val2++)
@@ -1505,7 +1535,7 @@ function encoder(st, patterns) {
1505
1535
  allMaps.add(x.map);
1506
1536
  const st2 = { scalars: {}, maps: Object.fromEntries([...allMaps].map(mp => [mp, maps.get(mp) ?? new Map()])) };
1507
1537
  const m = { name: goal.name, params: [], inputs: [], state: {}, step: {}, maps: Object.fromEntries([...allMaps].map(mp => [mp, 0])) };
1508
- const env = new Proxy({ ...w }, { get: (t, q) => t[q] ?? 0 });
1538
+ const env = new Proxy({ ...w }, { get: (t, q) => (Object.hasOwn(t, q) ? t[q] : 0) });
1509
1539
  for (const [i, f] of fs.entries()) {
1510
1540
  tick();
1511
1541
  try {
@@ -1527,7 +1557,7 @@ function encoder(st, patterns) {
1527
1557
  }
1528
1558
  // the structure
1529
1559
  const values = [...new Set([...[...parts].map(x => w[x]), ...[...ordVal].filter(([t]) => !t.startsWith('k:') && !t.includes('#')).map(([, x]) => x)].filter((x) => x !== undefined))].sort((a, b) => a - b), elem = new Map(values.map((x, i) => [x, i]));
1530
- const diagram = { elements: values.length, parts: {}, scalars: {}, cells: {}, fns: {} };
1560
+ const diagram = { elements: values.length, parts: Object.create(null), scalars: Object.create(null), cells: Object.create(null), fns: Object.create(null) };
1531
1561
  for (const x of [...parts, ...ordScalars].sort())
1532
1562
  if (w[x] !== undefined)
1533
1563
  diagram.parts[x] = elem.get(w[x]);
@@ -54,6 +54,7 @@ export type Subst = {
54
54
  maps: Record<string, (key: E) => E>;
55
55
  flags: Record<string, C>;
56
56
  };
57
+ export declare const own: <T>(r: Record<string, T>, k: string) => T | undefined;
57
58
  export declare function substE(e: E, s: Subst): E;
58
59
  export declare function substC(c: C, s: Subst): C;
59
60
  export type Instances = Record<string, E[]>;
@@ -356,4 +357,5 @@ export declare const checkGhostedLaws: (g: Ghosted, laws: Law[], proof: {
356
357
  instances: Record<string, Instances>;
357
358
  trees: Record<string, Tree>;
358
359
  }) => boolean;
360
+ export declare function someOfGhostsOk(g: Ghosted, law: Law, plain: Law, sub: Record<string, E>): boolean;
359
361
  export {};