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,18 +1,69 @@
1
+ // Cyclic proofs found. Untrusted: an instance states the nodes and their uses, kernel/prove.ts grows a tree for every
2
+ // goal, and kernel/cyclic.ts checks the whole. The instances are today's induction rules said as one rule, each a
3
+ // graph of sequents whose back-edges lower a rank:
4
+ // - a recurrence's lemmas (`recur`): f a map read at x, its two equations facts, each lemma a node at rank (0, x)
5
+ // using every lemma at x − 1; each law between two points a node at rank (1, y), using itself at y − 1 and the lemmas
6
+ // (whose rank, (0, ·), is below)
7
+ // - a machine's laws: the run as maps over time, each state variable s read at time t as s@[t], each input as i@[t],
8
+ // each map M at key k as M@[t + k·Ω] (Ω above the run's length T); the start and every step are facts (each at the
9
+ // time it gives, a step only up to T); each
10
+ // law is a node at rank (t), using every law at t − 1 (a law about every key at the keys the machine's proof names)
11
+ // - a fold over trees: the tree as a table of nodes, a node's children numbered below it (any tree can be), each law a
12
+ // node at rank (n) using every law at both children
13
+ // Beyond those, a node may use any node at any terms (nested, mutual, two ranks in order): `proveCyclic` takes the nodes
14
+ // as they are given (examples/cyclic.ts).
15
+ //
16
+ // Translated (machineNodes, recurNodes, foldNodes given the usual proof; core/translate.ts): what the usual route proved,
17
+ // made a cyclic proof from its trees rather than searched. The facts are the instance's as above (Bridge.lean's
18
+ // cycCanon, recFacts, the fold's table); the nodes, in this order:
19
+ // - machines, laws l_0..l_{L-1}: node i < L the law at t, rank (t, 1), hyps the precondition, t <= T, T < Ω (cycMOk's
20
+ // node), facts the start and the step at t and each map's at the keys it reads, uses node L + i (guard 1 <= t) and
21
+ // node 2L + i (guard t <= 0), its tree made (`carry`). Node L + i the law after a step from t − 1, rank (t, 0):
22
+ // hyps the precondition, 1 <= t, t <= T, T < Ω and the request's assumption at t − 1, facts the functions' at the
23
+ // keys the usual proof names, uses the laws at t − 1 at those keys (guard 0 <= 0), its conclusion the law at the
24
+ // state the step gives over the cells at t − 1 (a write's reads at its key read at the key read), its tree the usual
25
+ // step tree. Node 2L + i the law at the start, rank (0, 0): the usual start goal, k# as k, its tree the usual one.
26
+ // Only the facts and uses the usual tree reads are kept.
27
+ // - then each step law s_j (proveStepLaws): node 3L + 2j after its k steps, rank (t, 0), the usual step law's goal over
28
+ // the cells at t − k..t − 1 (hyps the precondition, k <= t, t <= T, T < Ω, the assumption and `when` at each step's
29
+ // time, the state's equations after each step but the last that the usual tree reads; uses the laws at each of those
30
+ // times; the times t − n at once, over a map one step back at a time, t − 1 − 1), and node
31
+ // 3L + 2j + 1 the step law itself, rank (t, 2): hyps the precondition, k <= t, t <= T, T < Ω and `when` at each
32
+ // step's time, its conclusion `then` with plain names at t − k, primed ones at t and a later step's request (i@j) at
33
+ // its time, facts the step at t − k + 1..t (and the maps' at t), its one use node 3L + 2j, its tree made (`carry`).
34
+ // Over several steps a later step reads a map as the usual goal's term over the cells at t − k (its laws there a
35
+ // use only where they read no map), the step law's node reading each cell back to t − k through the maps' steps (its
36
+ // tree carried on its goal sliced first).
37
+ // - a machine with flags that hold at every key is read as its sk machine, the usual goals' closing hypotheses the
38
+ // closing facts at their time (`qflagFacts`); a request allowed (`allowTranslated`) two nodes after the laws'.
39
+ // - a loop's halting (`loopNodes`): its machine's laws and its liveness's step laws as above (kernel.ts's
40
+ // loopObligations); a liveness's certificate is its step laws' proof and its helpful requests' allowed nodes, the
41
+ // claim about runs that never end read from them as from the usual trees (kernel/prove.ts's proveLiveness).
42
+ // - recurrences, lemmas n, laws between b: nodes 0..n+b−1 as above (their trees made), using also node 2n + 2b + i
43
+ // (the lemma at the start, guard x <= 0; a law between at y = x, guard y <= x); nodes n + b.. the lemma (law between)
44
+ // after a step, the usual step goal with x as x − 1, fx as f(x − 1) (y, fy likewise, fx as f(x)); then the start
45
+ // nodes, rank (0, 0, 0) and (1, 0, 0).
46
+ // - folds, laws L: node i the law at a node n, rank (n, 1), using node L + i (guard Kind[n] = 1) and node 2L + i (guard
47
+ // Kind[n] = 0); node L + i from its children, rank (n, 0), hyps n < N, Kind[n] = 1, both children below n and the
48
+ // assumption at n, uses the laws at both children; node 2L + i at a leaf, rank (n, 0).
49
+ //
50
+ // The switches (the environment; a user needs none): GDP_CERT=usual, the usual trees as every certificate (the fallback
51
+ // and the baseline); GDP_CERT_SEARCH=1, a search where a translation fails, within GDP_CERT_MS (10,000 ms); GDP_CYCLIC=1,
52
+ // the cross-check (every proof made again as a cyclic proof, a differing verdict throwing; GDP_CYCLIC_LAX=1 only logs it;
53
+ // GDP_CYCLIC_ROUTE=translate|search|both, its route). Diagnostics: GDP_CYCLIC_LOG=1, the `cyclic: {...}` lines
54
+ // research/cyclic/ratios.ts reads; GDP_CYCLIC_PROF=1, where each proof's time went; GDP_CYCLIC_SLICE=0, every goal grown
55
+ // whole; GDP_CYCLIC_DEBUG=1, each goal grown.
56
+ import { atMost as le, get, n as k, plus as add, same as eq, walk, x as v } from "./machine.js";
1
57
  import { assumed, boundOf, foldObligations, livenessParts, loopLiveness, loopMachine, loopObligations, obligations, stepLawObligations, substC, substE, witnessesOf } from "../kernel/kernel.js";
2
58
  import { baseHyps, descentGoal, instHyps, mainGoal, premiseGoal, refuseCyclic } from "../kernel/cyclic.js";
3
- import { cellProducts, clock, grow, profile, usedHyps, widen, withDeadline, withinDeadline } from "../kernel/prove.js";
59
+ import { cellProducts, clock, counted, fullRate, grow, profile, usedHyps, widen, withDeadline, withinDeadline } from "../kernel/prove.js";
4
60
  import { carry, decide, readsFirst, renamer, translate, tstats } from "./translate.js";
5
- const v = (name) => ({ op: 'var', name });
6
- const k = (value) => ({ op: 'const', value });
7
- const add = (a, b) => ({ op: 'add', a, b });
61
+ import { env } from "./solver.js";
8
62
  const less1 = (a) => ({ op: 'sub', a, b: k(1) });
9
- const get = (map, key) => ({ op: 'get', map, key });
10
- const le = (a, b) => ({ op: '<=', a, b });
11
- const eq = (a, b) => ({ op: '=', a, b });
12
- const and = (...xs) => (xs.length === 1 ? xs[0] : { op: 'and', xs });
13
- const implies = (a, b) => ({ op: 'or', xs: [{ op: 'not', x: a }, b] });
63
+ export const and = (...xs) => (xs.length === 1 ? xs[0] : { op: 'and', xs });
64
+ export const implies = (a, b) => ({ op: 'or', xs: [{ op: 'not', x: a }, b] });
14
65
  const yes = le(k(0), k(0));
15
- const vars = (s) => ({ vars: s, maps: {}, flags: {} });
66
+ export const vars = (s) => ({ vars: s, maps: {}, flags: {} });
16
67
  // A map's cell at time u and key k, in the run's one map over both: u + k·Ω, where Ω is above the run's length T, so
17
68
  // that no two (u, k) with u <= T meet (u < Ω). Linear in u, and two keys' cells differ by (k − k')·Ω.
18
69
  const omega = v('O$');
@@ -21,7 +72,7 @@ export const pair = (u, key) => add(u, { op: 'prod', a: key, b: omega });
21
72
  // GDP_CYCLIC_PROF=1: each comparison's line also has where the cyclic proof's time went, by goal kind (main, premise,
22
73
  // descent, the kernel's check): ms, goals, hypotheses, solver and row ms.
23
74
  export const cyclicProf = {};
24
- const profOn = () => env()?.GDP_CYCLIC_PROF === '1';
75
+ const profOn = () => env.GDP_CYCLIC_PROF === '1';
25
76
  export function timedKind(kind, hyps, f) {
26
77
  if (!profOn())
27
78
  return f();
@@ -50,15 +101,13 @@ export function timedKind(kind, hyps, f) {
50
101
  // A cell by what it may be equal to: a run's map read at time u and any key (two keys the prover may prove equal) is
51
102
  // one, by its map and u; a function's read at any key is one, by the function; a run's other reads are themselves.
52
103
  const cellsIn = (t, out = new Set()) => {
53
- if (t && typeof t === 'object') {
54
- const o = t, map = o.map;
104
+ walk(t, o => {
105
+ const map = o.map;
55
106
  if (o.op === 'get') {
56
107
  const key = o.key;
57
108
  out.add(key.op === 'add' && key.b.op === 'prod' && JSON.stringify(key.b.b) === JSON.stringify(omega) ? `${map}@${JSON.stringify(key.a)}` : map.endsWith('@') ? JSON.stringify(o) : map);
58
109
  }
59
- for (const val of Object.values(o))
60
- cellsIn(val, out);
61
- }
110
+ });
62
111
  return out;
63
112
  };
64
113
  function partsOf(c, guards = [], out = []) {
@@ -149,7 +198,7 @@ finally {
149
198
  cellProducts.on = was;
150
199
  } };
151
200
  let sliceNow = false;
152
- const sliceOn = () => sliceNow && env()?.GDP_CYCLIC_SLICE !== '0';
201
+ const sliceOn = () => sliceNow && env.GDP_CYCLIC_SLICE !== '0';
153
202
  const searched = new Map();
154
203
  export const translatedCache = new Map();
155
204
  // `order`: the order the nodes are grown in, by default those with a weak variant first (a variant that uses a weak node
@@ -168,7 +217,7 @@ export function proveCyclic(facts, specs, order0, grownBefore = searched, st = t
168
217
  if (part) {
169
218
  // (within two seconds: a weaker goal no easier than the whole is left to the whole)
170
219
  const t0 = performance.now(), p = timedKind(`${kind} sliced`, part.hyps.length, () => grow(part, new Map(), { nodes: 0, until: clock() + Math.min(2_000, later ?? 2_000) }));
171
- if (env()?.GDP_CYCLIC_DEBUG)
220
+ if (env.GDP_CYCLIC_DEBUG)
172
221
  console.error(`[cyc] ${g.name}: ${part.hyps.length} hyps${part !== sliced ? ' (opaque)' : ''}, ${'tree' in p ? `${p.nodes} nodes` : p.stuck}, ${Math.round(performance.now() - t0)} ms`);
173
222
  if ('tree' in p)
174
223
  return { tree: p.tree, from: part, used: () => new Set([...usedHyps(part, p.tree)].flatMap(i => part.from[i])) };
@@ -229,7 +278,7 @@ export function proveCyclic(facts, specs, order0, grownBefore = searched, st = t
229
278
  if (part) {
230
279
  const nf = part.from.filter(f => f[0] >= h0 && f[0] < base).length, nu = part.from.filter(f => f[0] >= base && f[0] < last).length;
231
280
  const tree = carry(part, nf, nu, st, clock() + 2_000), wide = tree && timedKind('widen', 0, () => widen(part, g, tree));
232
- if (env()?.GDP_CYCLIC_DEBUG)
281
+ if (env.GDP_CYCLIC_DEBUG)
233
282
  console.error(`[carry] ${n1.name}: ${part.hyps.length} of ${g.hyps.length} hyps, ${tree ? (wide ? 'carried, widened' : 'carried, not widened') : 'not carried'}`);
234
283
  if (wide)
235
284
  return wide;
@@ -266,7 +315,7 @@ export function proveCyclic(facts, specs, order0, grownBefore = searched, st = t
266
315
  if (n2 && (n2.insts.length < n1.insts.length || n2.uses.length < n1.uses.length)) {
267
316
  const g2 = mainGoal(facts, shapes, n2), part = hide(g2);
268
317
  const p = timedKind('main selected', g2.hyps.length, () => withProducts(() => grow(part, new Map(), { nodes: 0, until: clock() + Math.min(2_000, later ?? 2_000) })));
269
- if (env()?.GDP_CYCLIC_DEBUG)
318
+ if (env.GDP_CYCLIC_DEBUG)
270
319
  console.error(`[cyc] ${g.name}: ${g2.hyps.length} of ${g.hyps.length} hyps selected, ${'tree' in p ? `${p.nodes} nodes` : p.stuck}`);
271
320
  const t = 'tree' in p ? own({ tree: p.tree, from: part }, g2) : undefined;
272
321
  if (t && 'tree' in p) {
@@ -306,7 +355,7 @@ export function proveCyclic(facts, specs, order0, grownBefore = searched, st = t
306
355
  const premises = [];
307
356
  for (const [i, c] of m.hyps.entries()) {
308
357
  const t = whole(premiseGoal(facts, n, u, c, i), n.name, mine2);
309
- if ('proven' in t && env()?.GDP_CYCLIC_DEBUG)
358
+ if ('proven' in t && env.GDP_CYCLIC_DEBUG)
310
359
  console.error(`[premise] ${n.name}: use of node ${u.node}, its hypothesis ${i} (${t.stuck}): ${JSON.stringify(substC(c, vars(u.subst)))}`);
311
360
  if ('proven' in t)
312
361
  return t;
@@ -533,13 +582,8 @@ function withReads(facts, specs, nodes = specs) {
533
582
  });
534
583
  if (!simple.length)
535
584
  return specs;
536
- const readsIn = (t, map) => { const out = []; const walk = (x) => { if (x && typeof x === 'object') {
537
- const o = x;
538
- if (o.op === 'get' && o.map === map)
539
- out.push(o.key);
540
- for (const val of Object.values(o))
541
- walk(val);
542
- } }; walk(t); return out; };
585
+ const readsIn = (t, map) => { const out = []; walk(t, o => { if (o.op === 'get' && o.map === map)
586
+ out.push(o.key); }); return out; };
543
587
  return specs.map(n => {
544
588
  const insts = [...n.insts], seen = new Set(insts.map(p => JSON.stringify(p)));
545
589
  for (let round = 0; round < 2; round++) {
@@ -727,12 +771,8 @@ export function machineNodes(given, laws, instances, usual, st = tstats()) {
727
771
  // A function's fact also at its keys with the terms the step gives a state variable (the usual proof reads the state
728
772
  // after the step so) as that variable's cell at t, where it then reads the function where the law at t does: at the
729
773
  // key its own reads are at, not one the prover would have to prove equal to it.
730
- const fnReads = (x) => { const out = []; const walk = (y) => { if (y && typeof y === 'object') {
731
- const o = y;
732
- if (o.op === 'get' && !o.map.endsWith('@'))
733
- out.push(JSON.stringify(o));
734
- Object.values(o).forEach(walk);
735
- } }; walk(x); return out; };
774
+ const fnReads = (x) => { const out = []; walk(x, o => { if (o.op === 'get' && !o.map.endsWith('@'))
775
+ out.push(JSON.stringify(o)); }); return out; };
736
776
  const concl = substC(l.holds, at(t)), reads = new Set(fnReads(concl));
737
777
  const after = (e) => substE(afterStep(substE(e, vars(fresh))), pre);
738
778
  const both = (tuple, make, read) => {
@@ -784,9 +824,7 @@ export function machineNodes(given, laws, instances, usual, st = tstats()) {
784
824
  const wkeys = new Set(mapNames.flatMap(map => { const w = m.step.maps?.[map]; return w && !('each' in w) ? [JSON.stringify(inlineE(w.key))] : []; }));
785
825
  const readsOf = (c) => {
786
826
  const out = [], seen = new Set();
787
- const walk = (x) => {
788
- if (!x || typeof x !== 'object')
789
- return;
827
+ walk(c, x => {
790
828
  const o = x;
791
829
  if (o.op === 'if' && o.c.op === '=' && wkeys.has(JSON.stringify(o.c.b))) {
792
830
  const id = JSON.stringify([o.c.a, o.c.b]);
@@ -795,10 +833,7 @@ export function machineNodes(given, laws, instances, usual, st = tstats()) {
795
833
  out.push({ k: o.c.a, w: o.c.b });
796
834
  }
797
835
  }
798
- for (const val of Object.values(o))
799
- walk(val);
800
- };
801
- walk(c);
836
+ });
802
837
  return out;
803
838
  };
804
839
  for (const [i, l] of laws.entries()) {
@@ -917,15 +952,22 @@ export function machineNodes(given, laws, instances, usual, st = tstats()) {
917
952
  }
918
953
  }
919
954
  function translateMade(facts, all, made, st, until) {
920
- for (const x of made) {
921
- const whole = mainGoal(facts, all, all[x.node]);
922
- const tree = timedKind('translate', 0, () => withProducts(() => decide(whole, x.decide ?? [], wp => readsFirst(whole, x.reads ?? [], x.ren, (p, swaps) => translate(x.g, whole, x.tree, x.ren, st, until, new Map(), p, swaps), st, until, wp), st, until)));
923
- if (!tree)
924
- return { specs: [], why: `${all[x.node].name}: not translated` };
925
- all[x.node] = { ...all[x.node], main: tree };
926
- }
927
- return { specs: sliced(all) };
955
+ return counting(until, end => {
956
+ for (const x of made) {
957
+ const whole = mainGoal(facts, all, all[x.node]);
958
+ const tree = timedKind('translate', 0, () => withProducts(() => decide(whole, x.decide ?? [], wp => readsFirst(whole, x.reads ?? [], x.ren, (p, swaps) => translate(x.g, whole, x.tree, x.ren, st, end, new Map(), p, swaps), st, end, wp), st, end)));
959
+ if (!tree)
960
+ return { specs: [], why: `${all[x.node].name}: not translated` };
961
+ all[x.node] = { ...all[x.node], main: tree };
962
+ }
963
+ return { specs: sliced(all) };
964
+ });
928
965
  }
966
+ // A translation on the cost model's clock (kernel/prove.ts's `counted` with `full`): its budget the time from now to
967
+ // `until`, counted, translate.ts counting each leaf's rows as it reads them, so a large tree's translation stops at its
968
+ // budget on any machine. (On wall time alone it ran past it: the bound was read only where a leaf was grown again, and
969
+ // ledger/tigerbeetle/transfers' 21,108 leaves took 92.7 s, the law then past the real-world corpus's 150 s.)
970
+ const counting = (until, f) => { const ms = Math.max(0, until - clock()); return counted(fullRate, () => f(clock() + ms), true); };
929
971
  // The terms (not a read, a variable or a constant) of a conclusion that a node's facts read too, largest first; none
930
972
  // inside a product (a product of a term's linear form is no linear form).
931
973
  function shared(facts, a, concl) {
@@ -1033,10 +1075,7 @@ export function stepLawNodes(m, laws, steps, facts, lawNodes, time = tBack) {
1033
1075
  function cellsAt(m, facts, x) {
1034
1076
  const mapNames = Object.keys(m.maps ?? {}), t = JSON.stringify(v('t$')), fi = (name) => facts.findIndex(f => f.name === name);
1035
1077
  const out = [], seen = new Set();
1036
- const walk = (y) => {
1037
- if (!y || typeof y !== 'object')
1038
- return;
1039
- const o = y;
1078
+ walk(x, o => {
1040
1079
  if (o.op === 'get' && typeof o.map === 'string' && o.map.endsWith('@') && mapNames.includes(o.map.slice(0, -1))) {
1041
1080
  const key = o.key;
1042
1081
  if (key.op === 'add' && JSON.stringify(key.a) === t && key.b.op === 'prod') {
@@ -1047,10 +1086,7 @@ function cellsAt(m, facts, x) {
1047
1086
  }
1048
1087
  }
1049
1088
  }
1050
- for (const val of Object.values(o))
1051
- walk(val);
1052
- };
1053
- walk(x);
1089
+ });
1054
1090
  return out;
1055
1091
  }
1056
1092
  // Each map cell a node reads at one of `times` (the first the earliest), pushed to `insts`: that map's step there (at a
@@ -1101,10 +1137,7 @@ export function allowNode(m, laws, inst, w, facts, lawNodes, name, extra = []) {
1101
1137
  // Each carried cell the conclusion and the facts given at t read there (a flag's body at its witness, say): 0 (the
1102
1138
  // request carries empty sets).
1103
1139
  const zeros = [], seen = new Set();
1104
- const walk = (x) => {
1105
- if (!x || typeof x !== 'object')
1106
- return;
1107
- const o = x;
1140
+ walk([concl, instHyps(facts, extra)], o => {
1108
1141
  if (o.op === 'get' && typeof o.map === 'string' && o.map.endsWith('@') && carried.includes(o.map.slice(0, -1))) {
1109
1142
  const id = JSON.stringify(o);
1110
1143
  if (!seen.has(id)) {
@@ -1112,10 +1145,7 @@ export function allowNode(m, laws, inst, w, facts, lawNodes, name, extra = []) {
1112
1145
  zeros.push(eq(o, k(0)));
1113
1146
  }
1114
1147
  }
1115
- for (const val of Object.values(o))
1116
- walk(val);
1117
- };
1118
- walk([concl, instHyps(facts, extra)]);
1148
+ });
1119
1149
  const hyps = [...(m.pre ? [m.pre] : []), le(t, T), ...(traced.length ? [{ op: '<', a: T, b: omega }] : []), substC(w, now), ...zeros];
1120
1150
  const uses = laws.flatMap((l, i) => tuplesOf(l).map(ts => ({ node: i, subst: Object.fromEntries(keysOf(l).map((kn, q) => [kn, substE(ts[q], now)])), guard: yes })));
1121
1151
  const insts = [{ fact: fi(`${m.name}: the start`), at: [t] }, { fact: fi(`${m.name}: a step`), at: [t] },
@@ -1160,7 +1190,7 @@ export function allowTranslated(given, laws, inst, p, usual, facts, lawNodes, na
1160
1190
  insts: closeHyps.length ? cl : [], uses: [{ node: lawNodes.length, subst: {}, guard: yes }], carry: true };
1161
1191
  const all = [...lawNodes, terms, allowed], whole = mainGoal(facts, all, terms), until = withinDeadline(clock() + 10_000);
1162
1192
  const ren = renamer({ s: now, cells: Object.fromEntries(mapNames.map(map => [map, { to: `${map}@`, at: t }])) });
1163
- const tree = timedKind('translate', 0, () => withProducts(() => decide(whole, closeFacts.length ? [le(t, T)] : [], wp => translate(g, whole, usual.tree, ren, st, until, new Map(), wp), st, until)));
1193
+ const tree = counting(until, end => timedKind('translate', 0, () => withProducts(() => decide(whole, closeFacts.length ? [le(t, T)] : [], wp => translate(g, whole, usual.tree, ren, st, end, new Map(), wp), st, end))));
1164
1194
  if (!tree)
1165
1195
  return { specs: [], why: `${terms.name}: not translated` };
1166
1196
  return { specs: sliced([{ ...terms, main: tree }, allowed]) };
@@ -1301,12 +1331,11 @@ export function foldNodes(f, laws, usual, st = tstats()) {
1301
1331
  // --- the cyclic route beside the usual one (GDP_CYCLIC=1) -------------------------------------------------------------
1302
1332
  // With GDP_CYCLIC=1, every proof the instances above cover is made again as a cyclic proof, and a verdict that differs
1303
1333
  // throws (GDP_CYCLIC_LAX=1 only prints it, to measure a whole run): the suite run so shows the rules are instances. Each comparison is printed to stderr as a line `cyclic: {...}`.
1304
- const env = () => globalThis.process?.env;
1305
1334
  let quiet = 0;
1306
- export const cyclicOn = () => quiet === 0 && env()?.GDP_CYCLIC === '1';
1335
+ export const cyclicOn = () => quiet === 0 && env.GDP_CYCLIC === '1';
1307
1336
  // The `cyclic: {...}` lines research/cyclic/ratios.ts reads, printed only with GDP_CYCLIC=1 (the cross-check) or
1308
1337
  // GDP_CYCLIC_LOG=1 (modal/run.py sets it): a user's proofs print nothing.
1309
- export const cycLog = (o) => { if (env()?.GDP_CYCLIC === '1' || env()?.GDP_CYCLIC_LOG === '1')
1338
+ export const cycLog = (o) => { if (env.GDP_CYCLIC === '1' || env.GDP_CYCLIC_LOG === '1')
1310
1339
  console.error(`cyclic: ${JSON.stringify(o)}`); };
1311
1340
  // A search's many trial proofs (core/discover.ts, core/infer.ts) aren't compared: what it finds is proven again.
1312
1341
  export const quietly = (f) => { quiet++; try {
@@ -1341,7 +1370,7 @@ export function translatedProof(key, build, st, base) {
1341
1370
  }
1342
1371
  return { verdict: v };
1343
1372
  }
1344
- export const routeOf = () => env()?.GDP_CYCLIC_ROUTE ?? 'translate';
1373
+ export const routeOf = () => env.GDP_CYCLIC_ROUTE ?? 'translate';
1345
1374
  const none = () => ({ proven: false, checked: false, node: '', goal: 'no instance searched', stuck: 'unknown' });
1346
1375
  // The cyclic proof of what the usual route proved: translated, else (`fallback`, or `searched` where nothing is
1347
1376
  // translated) searched, within `until` where it is given; with why the translation wasn't proven.
@@ -1381,7 +1410,7 @@ export function crossCyclic(kind, name, usual, run0, usualMs, translated) {
1381
1410
  search = { searchMs: Math.round(performance.now() - s0), searchCyclic: o.proven && o.checked };
1382
1411
  }
1383
1412
  cycLog({ kind, name, usual, cyclic, ms, ...(usualMs === undefined ? {} : { usualMs: Math.round(usualMs) }), route: how, ...(how !== 'searched' ? st : {}), ...(why ? { fellBack: why } : {}), ...search, ...prof, ...(out.proven ? { nodes: out.proof.nodes.length, ...(out.why ? { why: out.why } : {}) } : { goal: out.goal, stuck: out.stuck }) });
1384
- const lax = env()?.GDP_CYCLIC_LAX === '1';
1413
+ const lax = env.GDP_CYCLIC_LAX === '1';
1385
1414
  if (cyclic !== usual && !lax)
1386
1415
  throw new Error(`cyclic route: ${kind} ${name} is ${cyclic ? 'proven' : 'not proven'} as a cyclic proof, ${usual ? 'proven' : 'not proven'} the usual way${out.proven ? (out.why ? ` (${out.why})` : '') : ` (${out.goal}: ${out.stuck})`}`);
1387
1416
  if (search && search.searchCyclic !== usual && !lax)
@@ -1393,10 +1422,10 @@ export function crossCyclic(kind, name, usual, run0, usualMs, translated) {
1393
1422
  // checks the usual trees and counts the proof uncovered (`why`). With GDP_CERT_SEARCH=1 (off by default: a search costs
1394
1423
  // seconds a proof) a proof the translation doesn't cover is searched first, within GDP_CERT_MS (10 s by default). Each
1395
1424
  // logs a line `cyclic: {..., cert: true}` (cycLog).
1396
- export const certMode = () => env()?.GDP_CERT !== 'usual';
1425
+ export const certMode = () => env.GDP_CERT !== 'usual';
1397
1426
  export const certOn = () => quiet === 0 && certMode();
1398
- export const certSearch = () => env()?.GDP_CERT_SEARCH === '1';
1399
- export const certMs = () => Number(env()?.GDP_CERT_MS ?? 10_000);
1427
+ export const certSearch = () => env.GDP_CERT_SEARCH === '1';
1428
+ export const certMs = () => Number(env.GDP_CERT_MS ?? 10_000);
1400
1429
  // A proof of a kind no cyclic instance covers, or whose cyclic proof wasn't made, counted (`cyclic: {..., uncovered:
1401
1430
  // true, why}`): its certificate the usual trees.
1402
1431
  export const uncovered = (kind, name, why) => cycLog({ kind, name, uncovered: true, why });
@@ -1,4 +1,4 @@
1
- import type { C, E } from './machine.js';
1
+ import { type C, type E } from './machine.js';
2
2
  import { type Fact } from '../kernel/cyclic.js';
3
3
  import { type CyclicVerdict, type NodeSpec } from './cyclic.js';
4
4
  export declare const self: {