gdp-wired 0.25.0 → 0.27.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 (52) hide show
  1. package/README.md +14 -9
  2. package/dist/core/accel.d.ts +20 -1
  3. package/dist/core/accel.js +797 -220
  4. package/dist/core/bmc.d.ts +12 -1
  5. package/dist/core/bmc.js +275 -106
  6. package/dist/core/cycles.d.ts +2 -3
  7. package/dist/core/cycles.js +35 -131
  8. package/dist/core/cyclic.d.ts +4 -1
  9. package/dist/core/cyclic.js +103 -74
  10. package/dist/core/data.d.ts +1 -1
  11. package/dist/core/data.js +89 -118
  12. package/dist/core/discover.js +65 -27
  13. package/dist/core/dsl.d.ts +3 -2
  14. package/dist/core/dsl.js +29 -25
  15. package/dist/core/exists.js +7 -14
  16. package/dist/core/extract-check.d.ts +55 -4
  17. package/dist/core/extract-check.js +248 -122
  18. package/dist/core/extract-print.d.ts +1 -0
  19. package/dist/core/extract-print.js +26 -3
  20. package/dist/core/extract-read.d.ts +98 -4
  21. package/dist/core/extract-read.js +306 -43
  22. package/dist/core/extract-shapes.d.ts +14 -0
  23. package/dist/core/extract-shapes.js +609 -79
  24. package/dist/core/extract-xstate.d.ts +5 -1
  25. package/dist/core/extract-xstate.js +618 -184
  26. package/dist/core/extract.d.ts +1 -0
  27. package/dist/core/extract.js +81 -30
  28. package/dist/core/infer.d.ts +1 -0
  29. package/dist/core/infer.js +126 -64
  30. package/dist/core/machine.d.ts +6 -0
  31. package/dist/core/machine.js +35 -4
  32. package/dist/core/nonterm.d.ts +5 -1
  33. package/dist/core/nonterm.js +133 -45
  34. package/dist/core/q.d.ts +1 -0
  35. package/dist/core/q.js +2 -2
  36. package/dist/core/relation.d.ts +1 -0
  37. package/dist/core/relation.js +20 -36
  38. package/dist/core/solver.d.ts +33 -0
  39. package/dist/core/solver.js +84 -30
  40. package/dist/core/transfer.js +22 -13
  41. package/dist/core/translate.d.ts +1 -1
  42. package/dist/core/translate.js +88 -65
  43. package/dist/core/xstate.d.ts +6 -1
  44. package/dist/core/xstate.js +336 -55
  45. package/dist/kernel/cdcl.js +212 -79
  46. package/dist/kernel/prove.d.ts +36 -5
  47. package/dist/kernel/prove.js +212 -104
  48. package/dist/kernel/reader.d.ts +75 -5
  49. package/dist/kernel/reader.js +533 -76
  50. package/dist/kernel/simplex.d.ts +27 -2
  51. package/dist/kernel/simplex.js +160 -14
  52. package/package.json +3 -2
@@ -1,22 +1,16 @@
1
- import { compileFunction, evalC as evalMC, evalE as evalME, fnValue, interpret, pairedArgs } from "./machine.js";
1
+ import { argsKey, atMost as le, compileFunction, evalC as evalMC, evalE as evalME, fnValue, get, interpret, minus as sub, n as k, pairedArgs, plus as add, same as eqC, seeded, walk, x as v } from "./machine.js";
2
2
  import { check, livenessHelpful, livenessParts, loopLiveness, loopMachine, loopObligations, substC, substE } from "../kernel/kernel.js";
3
3
  import { checkCyclic, factsAvoid, lexLt } from "../kernel/cyclic.js";
4
- import { proveCyclic } from "./cyclic.js";
5
- import { refuteFast, solve, work } from "./solver.js";
4
+ import { and, proveCyclic, vars as vs } from "./cyclic.js";
5
+ import { canon, env, gcd, konst, pivot, plus, ratioRow, refuteFast, solve, subst, times, vars, work } from "./solver.js";
6
6
  import { clock, grow, proveLaws, proveLiveness, proveStepLaws, withDeadline } from "../kernel/prove.js";
7
7
  import { inferLaws } from "./infer.js";
8
- import { generators, houdini, relationOf } from "./relation.js";
8
+ import { bgcd } from "./q.js";
9
+ import { generators, houdini, relationOf, tightBounds } from "./relation.js";
9
10
  // --- terms ----------------------------------------------------------------------------------------------------------
10
- const v = (name) => ({ op: 'var', name }), k = (value) => ({ op: 'const', value });
11
- const add = (a, b) => ({ op: 'add', a, b }), sub = (a, b) => ({ op: 'sub', a, b });
12
- const get = (map, key) => ({ op: 'get', map, key });
13
- const le = (a, b) => ({ op: '<=', a, b }), eqC = (a, b) => ({ op: '=', a, b });
14
- const and = (...xs) => (xs.length === 1 ? xs[0] : { op: 'and', xs });
15
11
  const yes = le(k(0), k(0));
16
- const vs = (s) => ({ vars: s, maps: {}, flags: {} });
17
12
  const id = (t) => JSON.stringify(t);
18
- export const pairE = (a, b) => { const s = add(a, b); return add({ op: 'prod', a: s, b: s }, b); };
19
- export const argsKey = (args) => args.slice(1).reduce(pairE, args[0]);
13
+ export { argsKey };
20
14
  // Σ coef·x + c as a term over the naturals: the negative part subtracted (truncated, as the kernel reads sub).
21
15
  export const linE = (coef, c) => {
22
16
  const pos = [], neg = [];
@@ -62,19 +56,6 @@ export const showC = (c) => {
62
56
  case 'all': return `∀${c.key}. ${showC(c.c)}`;
63
57
  }
64
58
  };
65
- const walk = (t, f) => {
66
- if (Array.isArray(t)) {
67
- for (const x of t)
68
- walk(x, f);
69
- return;
70
- }
71
- if (!t || typeof t !== 'object')
72
- return;
73
- const o = t;
74
- f(o);
75
- for (const x of Object.values(o))
76
- walk(x, f);
77
- };
78
59
  const readsOf = (t) => { const out = []; walk(t, o => { if (o.op === 'get')
79
60
  out.push(o); }); return out; };
80
61
  const varsOf = (t) => { const out = new Set(); walk(t, o => { if (o.op === 'var')
@@ -382,11 +363,6 @@ const rankRow = (n, nodes, s, name, scale = 1) => {
382
363
  out = plus(out, { [name(n, j)]: scale * s[x] });
383
364
  return out;
384
365
  };
385
- const plus = (a, b) => { const o = { ...a }; for (const [x, c] of Object.entries(b)) {
386
- o[x] = (o[x] ?? 0) + c;
387
- if (!o[x])
388
- delete o[x];
389
- } return o; };
390
366
  const valueAt = (l, w) => Object.entries(l).reduce((s, [x, c]) => s + c * (x === '1' ? 1 : w[x] ?? 0), 0);
391
367
  // An integer solution of every row (lin <= 0) of `must` and `pool`, the pool's rows added as they are violated. Its
392
368
  // unknowns are bounded, the coefficients first to naturals (a rank with no subtraction, which no truncation bends), then
@@ -429,10 +405,6 @@ function lp(must, pool, until, scale = 1, signs = [true, false], whole = false)
429
405
  }
430
406
  return undefined;
431
407
  }
432
- const bgcd = (a, b) => { if (a < 0n)
433
- a = -a; if (b < 0n)
434
- b = -b; while (b)
435
- [a, b] = [b, a % b]; return a; };
436
408
  const q = (n, d = 1n) => { if (d < 0n)
437
409
  (n = -n, d = -d); const g = bgcd(n, d) || 1n; return g === 1n ? { n, d } : { n: n / g, d: d / g }; };
438
410
  const Q0 = q(0n);
@@ -522,7 +494,7 @@ const nearFraction = (x, most = 10_000) => {
522
494
  }
523
495
  return [h1, k1];
524
496
  };
525
- const lpTrace = !!globalThis.process?.env?.LP_TRACE;
497
+ const lpTrace = !!env.LP_TRACE;
526
498
  function floatSolve(rows, until, equil = true, again = true) {
527
499
  const xs = [...new Set(rows.flatMap(l => Object.keys(l)).filter(x => x !== '1'))].sort(), n = xs.length, m = rows.length;
528
500
  const cols = 2 * n + 2 * m, T = [], basis = [], eps = 1e-9;
@@ -583,37 +555,11 @@ function floatSolve(rows, until, equil = true, again = true) {
583
555
  }
584
556
  if (enter < 0)
585
557
  return true;
586
- let leave = -1, best = Infinity;
587
- for (let r = 0; r < T.length; r++) {
588
- const a = T[r][enter];
589
- if (a > eps) {
590
- const ratio = T[r][cols] / a;
591
- if (ratio < best - eps || (Math.abs(ratio - best) <= eps && basis[r] < basis[leave])) {
592
- best = ratio;
593
- leave = r;
594
- }
595
- }
596
- }
558
+ const [leave, best] = ratioRow(T, basis, enter, cols, eps);
597
559
  if (leave < 0)
598
560
  return false;
599
561
  stalled = best <= eps ? stalled + 1 : 0;
600
- const p = T[leave], pv = p[enter];
601
- for (let j = 0; j <= cols; j++)
602
- p[j] /= pv;
603
- for (let r = 0; r < T.length; r++)
604
- if (r !== leave) {
605
- const f = T[r][enter];
606
- if (f !== 0) {
607
- const row = T[r];
608
- for (let j = 0; j <= cols; j++)
609
- row[j] -= f * p[j];
610
- }
611
- }
612
- const f = z[enter];
613
- if (f !== 0)
614
- for (let j = 0; j <= cols; j++)
615
- z[j] -= f * p[j];
616
- basis[leave] = enter;
562
+ pivot(T, z, basis, leave, enter, cols);
617
563
  }
618
564
  return false;
619
565
  };
@@ -638,19 +584,7 @@ function floatSolve(rows, until, equil = true, again = true) {
638
584
  basis.splice(i, 1);
639
585
  continue;
640
586
  }
641
- const p = T[i], pv = p[j];
642
- for (let c = 0; c <= cols; c++)
643
- p[c] /= pv;
644
- for (let r = 0; r < T.length; r++)
645
- if (r !== i) {
646
- const f = T[r][j];
647
- if (f !== 0) {
648
- const row = T[r];
649
- for (let c = 0; c <= cols; c++)
650
- row[c] -= f * p[c];
651
- }
652
- }
653
- basis[i] = j;
587
+ pivot(T, undefined, basis, i, j, cols);
654
588
  }
655
589
  if (!run(j => (j < 2 * n ? 1 : 0), j => !art(j)))
656
590
  return undefined;
@@ -826,7 +760,7 @@ function lexRanks(idx, nodes, samples, edges, name, until, onEdges = false, weak
826
760
  let sum = {};
827
761
  const strict = (l) => valueAt(l, sum) < 0;
828
762
  // One try per pattern of signs (which unknowns an edge raises and lowers): edges alike drop alike, mostly.
829
- const tried = new Set(), sign = (l) => id(Object.keys(l).filter(x => x !== '1').sort().map(x => `${x}${Math.sign(l[x])}`));
763
+ const tried = new Set(), sign = (l) => id(vars(l).sort().map(x => `${x}${Math.sign(l[x])}`));
830
764
  for (const l of left) {
831
765
  if (strict(l) || clock() > until || tried.has(sign(l)) || tried.size > 40)
832
766
  continue;
@@ -850,7 +784,6 @@ function lexRanks(idx, nodes, samples, edges, name, until, onEdges = false, weak
850
784
  }
851
785
  return { comps, left: left.length };
852
786
  }
853
- const gcd = (a, b) => (b === 0 ? a : gcd(b, a % b));
854
787
  // The same over named naturals and the edges of runs alone (core/data.ts: a recursive function's calls, each from its
855
788
  // parameters' sizes to its arguments'): each component's coefficient per variable and its constant. Several nodes (a
856
789
  // ring of functions calling each other, each its own names; `nodes`), each its own coefficients and constant per
@@ -1106,7 +1039,7 @@ function beside(cx, facts, nodes, big, until, analog) {
1106
1039
  }
1107
1040
  return [...new Map(out.map(n => [n.name, n])).values()];
1108
1041
  }
1109
- const trace = !!globalThis.process?.env?.CYCLES_TRACE;
1042
+ const trace = !!env.CYCLES_TRACE;
1110
1043
  const nodeOf = (c, level, given) => ({ name: c.name, hyps: c.hyps ?? [], concl: c.concl, vars: varsOf([c.hyps ?? [], c.concl]), level, given });
1111
1044
  // The facts at the terms a claim's goal reads (and at those the facts read, `depth` times over): what the search gives
1112
1045
  // each node, for a caller building nodes of its own (research/frontier's today, the builders' shape).
@@ -1197,15 +1130,6 @@ export function findCycles(facts, claims, opts = {}) {
1197
1130
  }
1198
1131
  return last;
1199
1132
  }
1200
- const plusL = (a, b, f = 1) => { const o = { ...a }; for (const x in b) {
1201
- o[x] = (o[x] ?? 0) + f * b[x];
1202
- if (!o[x])
1203
- delete o[x];
1204
- } return o; };
1205
- const konstL = (c) => (c ? { 1: c } : {});
1206
- const scaleL = (a, f) => { const o = {}; if (f)
1207
- for (const x in a)
1208
- o[x] = a[x] * f; return o; };
1209
1133
  // A form over the relation's names as the kernel's term (an integer's coefficient on its two parts), read truncated.
1210
1134
  const termOf = (rel, f) => {
1211
1135
  const coef = {};
@@ -1307,18 +1231,18 @@ function relationRank(l, rel, until, extra = [], inv) {
1307
1231
  // (each row once; one that reads no unknown and holds, along a name the template doesn't read, left out)
1308
1232
  const out = new Map();
1309
1233
  for (const r of [
1310
- ...p.gens.vertices.map(g => plusL(scaleL(h(env(g), tOf(g)), -1), { 1: c * tOf(g) })),
1311
- ...p.gens.rays.map(g => scaleL(h(env(g), 0), -1)),
1312
- ...p.gens.lines.flatMap(g => [h(env(g), 0), scaleL(h(env(g), 0), -1)]),
1234
+ ...p.gens.vertices.map(g => plus(times(h(env(g), tOf(g)), -1), { 1: c * tOf(g) })),
1235
+ ...p.gens.rays.map(g => times(h(env(g), 0), -1)),
1236
+ ...p.gens.lines.flatMap(g => [h(env(g), 0), times(h(env(g), 0), -1)]),
1313
1237
  ])
1314
1238
  if (Object.keys(r).some(x => x !== '1') || (r['1'] ?? 0) > 0)
1315
- out.set(id(Object.keys(r).sort().map(x => [x, r[x]])), r);
1239
+ out.set(canon(r), r);
1316
1240
  return [...out.values()];
1317
1241
  };
1318
- const delta = (tp, j, p) => (x, t) => plusL(fAt(tp, j, p.from, x, t), fAt(tp, j, p.to, postAt(p, x, t), t), -1);
1242
+ const delta = (tp, j, p) => (x, t) => plus(fAt(tp, j, p.from, x, t), fAt(tp, j, p.to, postAt(p, x, t), t), -1);
1319
1243
  const strictRows = (tp, p) => [
1320
1244
  ...holds(p, delta(tp, 0, p), 1),
1321
- ...Array.from({ length: tp.depth - 1 }, (_, j) => holds(p, (x, t) => plusL(delta(tp, j + 1, p)(x, t), fAt(tp, j, p.from, x, t)), 1)).flat(),
1245
+ ...Array.from({ length: tp.depth - 1 }, (_, j) => holds(p, (x, t) => plus(delta(tp, j + 1, p)(x, t), fAt(tp, j, p.from, x, t)), 1)).flat(),
1322
1246
  ...holds(p, (x, t) => fAt(tp, tp.depth - 1, p.from, x, t), tp.depth === 1 ? 1 : 0),
1323
1247
  ];
1324
1248
  const weakRows = (tp, p) => Array.from({ length: tp.depth }, (_, j) => holds(p, delta(tp, j, p), 0)).flat();
@@ -1393,7 +1317,7 @@ function relationRank(l, rel, until, extra = [], inv) {
1393
1317
  if (a)
1394
1318
  f[x] = a;
1395
1319
  }
1396
- return plusL(f, { 1: (tp.depth === 1 ? 0 : 1) + (w[unknown(tp, j, n, 1)] ?? 0) });
1320
+ return plus(f, { 1: (tp.depth === 1 ? 0 : 1) + (w[unknown(tp, j, n, 1)] ?? 0) });
1397
1321
  }));
1398
1322
  sizes.push(tp.depth);
1399
1323
  left = left.filter(p => !strict.includes(p));
@@ -1408,14 +1332,12 @@ function relationRank(l, rel, until, extra = [], inv) {
1408
1332
  // (if atom then f else g). With invariants (`inv`), each node's own first, by Houdini over every path of the relation
1409
1333
  // split the same way: disjunctive invariants (x ≤ −1 where x ≥ 1 fails, after x := 1 or x := −1), each a law
1410
1334
  // (pc = ℓ ∧ the signs → atom) the kernel proves inductive with the rest.
1411
- const after1 = (p, a) => { let o = {}; for (const [x, c] of Object.entries(a))
1412
- o = plusL(o, x !== '1' && p.post[x] ? scaleL(p.post[x], c) : { [x]: c }); return o; };
1413
- const side = (a, yes) => (yes ? a : plusL({ 1: 1 }, a, -1));
1335
+ const side = (a, yes) => (yes ? a : plus({ 1: 1 }, a, -1));
1414
1336
  const regionLaws = [], regionTexts = [];
1415
1337
  const regions = (c, paths) => {
1416
1338
  const seen = new Set(), guards = [], deltas = [];
1417
1339
  const add = (r, to) => {
1418
- const key = [id(Object.keys(r).sort().map(x => [x, r[x]])), id(Object.keys(side(r, false)).sort().map(x => [x, side(r, false)[x]]))].sort().join();
1340
+ const key = [canon(r), id(Object.keys(side(r, false)).sort().map(x => [x, side(r, false)[x]]))].sort().join();
1419
1341
  if (!seen.has(key)) {
1420
1342
  seen.add(key);
1421
1343
  to.push(r);
@@ -1426,9 +1348,9 @@ function relationRank(l, rel, until, extra = [], inv) {
1426
1348
  add(r, guards);
1427
1349
  for (const p of paths)
1428
1350
  for (const [x, f] of Object.entries(p.post)) {
1429
- const d = plusL(f, { [x]: 1 }, -1);
1351
+ const d = plus(f, { [x]: 1 }, -1);
1430
1352
  if (Object.keys(d).some(y => y !== '1') && Object.keys(d).every(y => y === '1' || every.includes(y)))
1431
- add(plusL({ 1: 1 }, d, -1), deltas); // d ≥ 1, over live names
1353
+ add(plus({ 1: 1 }, d, -1), deltas); // d ≥ 1, over live names
1432
1354
  }
1433
1355
  guards.sort((a, b) => Object.keys(b).length - Object.keys(a).length);
1434
1356
  // (the signs of what paths add first: fewer, and each a direction of progress; then the guards' atoms)
@@ -1450,7 +1372,7 @@ function relationRank(l, rel, until, extra = [], inv) {
1450
1372
  for (const n of values.keys())
1451
1373
  for (let b = 0; b < 1 << K; b++)
1452
1374
  nodeLoc.push(n);
1453
- const sides = (p, bits, after) => as.map((a, i) => side(after ? after1(p, a) : a, ((bits >> i) & 1) === 0));
1375
+ const sides = (p, bits, after) => as.map((a, i) => side(after ? subst(a, p.post) : a, ((bits >> i) & 1) === 0));
1454
1376
  // (undefined where a path's generators aren't found, past their cap or the time: a path left out is no path ranked)
1455
1377
  const splitOf = (ps, extra = () => []) => {
1456
1378
  const out = [];
@@ -1459,7 +1381,7 @@ function relationRank(l, rel, until, extra = [], inv) {
1459
1381
  for (let b2 = 0; b2 < 1 << K; b2++) {
1460
1382
  const rows = [...p.rows, ...sides(p, b1, false), ...sides(p, b2, true), ...extra(node(p.from, b1))];
1461
1383
  // (over the path's names and any an atom reads beside them: a name missing would drop its coefficient)
1462
- const ns = rows.some(r => Object.keys(r).some(x => x !== '1' && !p.gens.names.includes(x))) ? [...new Set([...p.gens.names, ...rows.flatMap(r => Object.keys(r).filter(x => x !== '1'))])].sort() : p.gens.names;
1384
+ const ns = rows.some(r => Object.keys(r).some(x => x !== '1' && !p.gens.names.includes(x))) ? [...new Set([...p.gens.names, ...rows.flatMap(r => vars(r))])].sort() : p.gens.names;
1463
1385
  const gens = generators(rows, ns, rel.nats, 600, mine);
1464
1386
  if (!gens)
1465
1387
  return undefined;
@@ -1541,7 +1463,7 @@ function relationRank(l, rel, until, extra = [], inv) {
1541
1463
  }
1542
1464
  // per location, its component's parts in order (0 past them), the heights first where paths join components
1543
1465
  const width = Math.max(0, ...parts.map(p => p?.length ?? 0));
1544
- const columns = [...(gpaths.some(p => comp[p.from] !== comp[p.to]) ? [values.map((_, n) => termOf(rel, konstL(heightOf(comp[n]))))] : []),
1466
+ const columns = [...(gpaths.some(p => comp[p.from] !== comp[p.to]) ? [values.map((_, n) => termOf(rel, konst(heightOf(comp[n]))))] : []),
1545
1467
  ...Array.from({ length: width }, (_, j) => values.map((_, n) => parts[comp[n]]?.[j]?.[n] ?? k(0)))];
1546
1468
  const rank = columns.map(terms => {
1547
1469
  let e = terms.at(-1) ?? k(0);
@@ -1553,7 +1475,7 @@ function relationRank(l, rel, until, extra = [], inv) {
1553
1475
  if (!rank.length)
1554
1476
  rank.push(k(0));
1555
1477
  const linear = [...new Set(comp)].every(c => lins[c] || !parts[c]);
1556
- const forms = linear ? [...(gpaths.some(p => comp[p.from] !== comp[p.to]) ? [values.map((_, n) => konstL(heightOf(comp[n])))] : []),
1478
+ const forms = linear ? [...(gpaths.some(p => comp[p.from] !== comp[p.to]) ? [values.map((_, n) => konst(heightOf(comp[n])))] : []),
1557
1479
  ...Array.from({ length: width }, (_, j) => values.map((_, n) => lins[comp[n]]?.[j]?.[n] ?? {}))] : undefined;
1558
1480
  return { rank, text: `(${rank.map(showE).join(', ')})`, blocks: sizes, laws: regionLaws, texts: regionTexts, ...(forms ? { forms } : {}) };
1559
1481
  }
@@ -1590,7 +1512,7 @@ export function rankWithInvariants(l, laws, until) {
1590
1512
  const consts = new Set([0, 1, -1]);
1591
1513
  for (const p of rel.paths)
1592
1514
  for (const r of p.rows) {
1593
- const c = r['1'] ?? 0, xs = Object.keys(r).filter(x => x !== '1');
1515
+ const c = r['1'] ?? 0, xs = vars(r);
1594
1516
  if (Math.abs(c) <= 1_000_000)
1595
1517
  for (const d of xs.length === 1 ? [c / Math.abs(r[xs[0]])] : [c])
1596
1518
  if (Number.isInteger(d)) {
@@ -1603,10 +1525,10 @@ export function rankWithInvariants(l, laws, until) {
1603
1525
  }
1604
1526
  }
1605
1527
  const K = [...consts].sort((a, b) => Math.abs(a) - Math.abs(b) || a - b).slice(0, 24);
1606
- const atoms = [...new Map(rel.paths.flatMap(p => p.rows).filter(r => Object.keys(r).filter(x => x !== '1').length > 1 && Object.keys(r).every(x => x === '1' || names.has(x))).map(r => [id(Object.keys(r).sort().map(x => [x, r[x]])), r])).values()];
1528
+ const atoms = [...new Map(rel.paths.flatMap(p => p.rows).filter(r => vars(r).length > 1 && Object.keys(r).every(x => x === '1' || names.has(x))).map(r => [canon(r), r])).values()];
1607
1529
  // per location, over the names live there: their bounds at the constants, then (a second try) the paths' atoms too
1608
1530
  // (and 1 ≤ 0: the location unreachable, where every path into it leaves from states the rest rule out)
1609
- const bounds = values.map((_, n) => [{ 1: 1 }, ...at[n].flatMap(x => K.flatMap((c) => [plusL({ [x]: 1 }, konstL(-c)), plusL({ [x]: -1 }, konstL(c))]))]);
1531
+ const bounds = values.map((_, n) => [{ 1: 1 }, ...at[n].flatMap(x => K.flatMap((c) => [plus({ [x]: 1 }, konst(-c)), plus({ [x]: -1 }, konst(c))]))]);
1610
1532
  // and what a path's assignments leave where it goes: x := y + c with y kept, x − y = c there (KoAT2's 2 + X₄ = X₁)
1611
1533
  const copies = values.map(() => []);
1612
1534
  for (const [i, p] of rel.paths.entries())
@@ -1616,7 +1538,7 @@ export function rankWithInvariants(l, laws, until) {
1616
1538
  continue;
1617
1539
  const y = ys[0], kept = p.post[y] ? id(p.post[y]) === id({ [y]: 1 }) : true;
1618
1540
  if (kept)
1619
- copies[toOf(i)].push(plusL({ [x]: 1, [y]: -1 }, konstL(-(f['1'] ?? 0))), plusL({ [x]: -1, [y]: 1 }, konstL(f['1'] ?? 0)));
1541
+ copies[toOf(i)].push(plus({ [x]: 1, [y]: -1 }, konst(-(f['1'] ?? 0))), plus({ [x]: -1, [y]: 1 }, konst(f['1'] ?? 0)));
1620
1542
  }
1621
1543
  const withAtoms = values.map((_, n) => [...bounds[n], ...atoms.filter(a => Object.keys(a).every(x => x === '1' || at[n].includes(x))), ...copies[n].filter(a => Object.keys(a).every(x => x === '1' || at[n].includes(x)))]);
1622
1544
  // the starts: random params (the precondition's), the state they begin in
@@ -1645,25 +1567,8 @@ export function rankWithInvariants(l, laws, until) {
1645
1567
  }
1646
1568
  return { laws: out, texts };
1647
1569
  };
1648
- // of the bounds on one name each way, the tightest (the others follow from it: the same set)
1649
- const tightest = (hs) => {
1650
- // (a location no run reaches: 1 ≤ 0 alone)
1651
- const never = hs.find(c => Object.keys(c).every(x => x === '1') && (c['1'] ?? 0) > 0);
1652
- if (never)
1653
- return [never];
1654
- const best = new Map(), rest = [];
1655
- for (const c of hs) {
1656
- const xs = Object.keys(c).filter(x => x !== '1');
1657
- if (xs.length !== 1) {
1658
- rest.push(c);
1659
- continue;
1660
- }
1661
- const x = xs[0], key = `${x}${Math.sign(c[x])}`, b = (c['1'] ?? 0) / Math.abs(c[x]), was = best.get(key);
1662
- if (!was || b > (was['1'] ?? 0) / Math.abs(was[x]))
1663
- best.set(key, c);
1664
- }
1665
- return [...best.values(), ...rest];
1666
- };
1570
+ // of the bounds on one name each way, the tightest (the same set); a location no run reaches: 1 ≤ 0 alone
1571
+ const tightest = (hs) => { const never = hs.find(c => Object.keys(c).every(x => x === '1') && (c['1'] ?? 0) > 0); return never ? [never] : tightBounds(hs); };
1667
1572
  let H = [], found = { why: 'no invariant' };
1668
1573
  const t1 = clock();
1669
1574
  for (const [i, cands] of [bounds, withAtoms].entries()) {
@@ -1716,7 +1621,6 @@ export function rankWithInvariants(l, laws, until) {
1716
1621
  const at0 = asLaws(H);
1717
1622
  return { rank: found.rank, text: found.text, laws: [...at0.laws, ...found.laws], texts: [...at0.texts, ...found.texts] };
1718
1623
  }
1719
- const seeded = (seed) => { let x = seed; return (n) => { x = (x * 1103515245 + 12345) % 2 ** 31; return Math.floor(x / 2 ** 31 * n); }; };
1720
1624
  const goalsProven = (goals) => {
1721
1625
  const trees = {};
1722
1626
  for (const g of goals) {
@@ -1950,10 +1854,10 @@ export function findLeadsTo(m, laws, l, sample, opts = {}) {
1950
1854
  const trivial = [...(strong.size ? [] : [[zero]]), ...Object.keys(m.state).filter(x => keeps(x) && lowers(x)).slice(0, 4).map(name => [{ op: 'var', name }])];
1951
1855
  const rankText = (rank) => `(${rank.map(showE).join(', ')})`;
1952
1856
  for (const [i, rank] of trivial.entries()) {
1953
- const ms = until - performance.now();
1857
+ const ms = until - clock();
1954
1858
  if (ms < 200)
1955
1859
  break;
1956
- const v = withDeadline(performance.now() + ms * (i === 0 && !strong.size ? 0.5 : 0.25), () => proveLiveness(m, laws, { ...l, rank }));
1860
+ const v = withDeadline(clock() + ms * (i === 0 && !strong.size ? 0.5 : 0.25), () => proveLiveness(m, laws, { ...l, rank }));
1957
1861
  if (v.proven && v.checked)
1958
1862
  return { proven: true, checked: true, rank, laws: [], found: { rank: rankText(rank), laws: [] } };
1959
1863
  tried.set(id(rank), v);
@@ -1,4 +1,4 @@
1
- import type { C, E, Law, Machine } from './machine.js';
1
+ import { type C, type E, type Law, type Machine } from './machine.js';
2
2
  import type { Fold, Goal, Instances, Loop, StepLaw, Subst, Tree } from '../kernel/kernel.js';
3
3
  import { type CNode, type Cyclic, type Fact, type Use } from '../kernel/cyclic.js';
4
4
  import { type TStats } from './translate.js';
@@ -23,6 +23,9 @@ export type CyclicVerdict = {
23
23
  goal: string;
24
24
  stuck: string;
25
25
  };
26
+ export declare const and: (...xs: C[]) => C;
27
+ export declare const implies: (a: C, b: C) => C;
28
+ export declare const vars: (s: Record<string, E>) => Subst;
26
29
  export declare const pair: (u: E, key: E) => E;
27
30
  export declare const cyclicProf: Record<string, {
28
31
  ms: number;