gdp-wired 0.26.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.
@@ -12,9 +12,11 @@ export type BmcOptions = {
12
12
  from?: number;
13
13
  depth?: number;
14
14
  progress?: (depth: number, outcome: 'refuted' | 'sat' | 'unknown', ms: number) => void;
15
+ steps?: boolean;
16
+ full?: boolean;
15
17
  };
16
18
  export declare function bmcFits(m: Machine, laws: Law[]): boolean;
17
- export declare const bmcRate = 250;
19
+ export declare const bmcRate = 250, workRate = 250;
18
20
  export declare function bmcGoal(m: Machine, laws: Law[], k: number): {
19
21
  name: string;
20
22
  hyps: C[];
@@ -54,4 +56,5 @@ export type BoundedSearch = {
54
56
  };
55
57
  export declare function boundedSearch(m: Machine, laws: Law[], opts: Omit<BmcOptions, 'ms' | 'wall'> & {
56
58
  forcedMs: number;
59
+ forcedSteps?: number;
57
60
  }): BoundedSearch | undefined;
package/dist/core/bmc.js CHANGED
@@ -19,11 +19,11 @@
19
19
  // that run breaks no law (a read of a pair the relaxation doesn't keep), the goal itself is asked at that depth. A
20
20
  // relaxed goal refuted is the goal refuted.
21
21
  //
22
- // The budget is read off prove.ts's clock inside `counted` (the kernel's work, bmcRate units a millisecond), so the
22
+ // The budget is read off prove.ts's clock inside `counted` (the cost model's work, bmcRate units a millisecond), so the
23
23
  // search is the same on any machine; a wall-clock stop beside it (`wall`) is for callers under a wall-clock limit.
24
24
  import { evalC, evalE, interpret, isArithmetic, loadJs, numbersOf } from "./machine.js";
25
25
  import { stepLawObligations, substC, substE } from "../kernel/kernel.js";
26
- import { clock, counted } from "../kernel/prove.js";
26
+ import { clock, counted, fullRate } from "../kernel/prove.js";
27
27
  import { REFUTED, cdclSession, growCdcl } from "../kernel/cdcl.js";
28
28
  import { allowed } from "./watch.js";
29
29
  import { isF as isFalse, isT as isTrue, simpC, simpE } from "./nonterm.js";
@@ -41,14 +41,15 @@ export function bmcFits(m, laws) {
41
41
  return false;
42
42
  return laws.every(l => !l.forall && !l.some?.length);
43
43
  }
44
- // The counted clock's rate here, units of the kernel's work a millisecond: the median of what Modal's 2-vCPU containers
45
- // did on the k-step goals of CHC-COMP's unsat LIA-Lin tasks, the stage alone (runs/bmc2/only-mine3: 1,215 depths past
46
- // 200 ms, 252 units a ms at the median, 383 at the 90th percentile; 168 at the median before reader.ts kept its clean
47
- // values and the goals were reduced, runs/bmc2/only-base1). The CDCL search counts its rows, which a goal of many atoms
48
- // and few rows a node keeps low, so a caller under a wall-clock limit gives a wall stop too.
49
- export const bmcRate = 250;
44
+ // The counted clock's rate here: the cost model's (kernel/prove.ts's fullWork, about a Modal 2-vCPU container's
45
+ // milliseconds at the median query), which counts what the incremental search does at a node; work.n's rows a node,
46
+ // read whole no more, ran the counted clock about four times past wall time on the unsat tasks' k-step goals. The
47
+ // resumable search (compare/chc/kind.ts's second CPU) reads it, so a slice takes about the wall time it is given;
48
+ // findBoundedRun keeps work.n's (`full` to read the model's), as its callers' budgets were set against it (core/
49
+ // nonterm.ts's bounded runs from a closed set: on that clock s1.t2's recurrent set past the ITS track's 60 s).
50
+ export const bmcRate = fullRate, workRate = 250;
50
51
  // A forced run's share of the budget, and its steps at most (a derivation checkDerivation replays step by step).
51
- const forcedShare = 0.3, forcedSteps = 1_000_000;
52
+ const forcedShare = 0.3, forcedSteps = 1_000_000, forcedRate = 1_000;
52
53
  // GDP_BMC_RELAX=0: no relaxed goal first; GDP_BMC_INC=0: each depth's goal a search of its own (for comparing).
53
54
  const useRelax = env.GDP_BMC_RELAX !== '0', useInc = env.GDP_BMC_INC !== '0', useTidy = env.GDP_BMC_TIDY !== '0';
54
55
  // The goal of depth k: a run of k steps from the start whose last state breaks a law.
@@ -564,16 +565,17 @@ function unrolled(m, laws) {
564
565
  return { next, again, defs };
565
566
  }
566
567
  export function findBoundedRun(m, laws, opts) {
567
- // A forced run first, within forcedShare of the budget (as wall time: it is the compiled rule's, not the kernel's).
568
- const now = performance.now(), end = Math.min(opts.wall ?? Infinity, now + opts.ms);
569
- const out = boundedSearch(m, laws, { ...opts, forcedMs: forcedShare * (end - now) })?.run(opts.ms, opts.wall);
568
+ // A forced run first, within forcedShare of the budget (as wall time: it is the compiled rule's, not the kernel's;
569
+ // with `steps` and no wall stop, in its steps instead).
570
+ const now = performance.now(), end = Math.min(opts.wall ?? Infinity, now + opts.ms), steps = opts.steps && opts.wall === undefined;
571
+ const out = boundedSearch(m, laws, { ...opts, full: opts.full ?? false, forcedMs: steps ? Infinity : forcedShare * (end - now), ...(steps ? { forcedSteps: Math.min(forcedSteps, Math.round(forcedShare * forcedRate * opts.ms)) } : {}) })?.run(opts.ms, opts.wall);
570
572
  return typeof out === 'object' ? out : undefined;
571
573
  }
572
574
  export function boundedSearch(m, laws, opts) {
573
575
  if (!laws.length || !bmcFits(m, laws))
574
576
  return undefined;
575
577
  const last = Math.min(64, opts.depth ?? 64);
576
- const forced = forcedRunner(m, laws, { steps: forcedSteps });
578
+ const forced = forcedRunner(m, laws, { steps: opts.forcedSteps ?? forcedSteps });
577
579
  let forcedLeft = forced === undefined ? 0 : opts.forcedMs, over = false, again = false;
578
580
  let inc, made = false, k = opts.from ?? 1;
579
581
  const run = (ms, wall) => {
@@ -591,7 +593,8 @@ export function boundedSearch(m, laws, opts) {
591
593
  else if (wall !== undefined && performance.now() >= wall)
592
594
  return 'paused';
593
595
  }
594
- return counted(bmcRate, () => {
596
+ const full = opts.full ?? true;
597
+ return counted(full ? bmcRate : workRate, () => {
595
598
  const until = clock() + ms;
596
599
  const late = () => clock() >= until || (wall !== undefined && performance.now() >= wall);
597
600
  if (!made) {
@@ -669,7 +672,7 @@ export function boundedSearch(m, laws, opts) {
669
672
  return done(typeof got === 'string' ? 'over' : got);
670
673
  }
671
674
  return done('over');
672
- });
675
+ }, full);
673
676
  };
674
677
  return { run, depth: () => k };
675
678
  }
@@ -56,7 +56,7 @@
56
56
  import { atMost as le, get, n as k, plus as add, same as eq, walk, x as v } from "./machine.js";
57
57
  import { assumed, boundOf, foldObligations, livenessParts, loopLiveness, loopMachine, loopObligations, obligations, stepLawObligations, substC, substE, witnessesOf } from "../kernel/kernel.js";
58
58
  import { baseHyps, descentGoal, instHyps, mainGoal, premiseGoal, refuseCyclic } from "../kernel/cyclic.js";
59
- 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";
60
60
  import { carry, decide, readsFirst, renamer, translate, tstats } from "./translate.js";
61
61
  import { env } from "./solver.js";
62
62
  const less1 = (a) => ({ op: 'sub', a, b: k(1) });
@@ -952,15 +952,22 @@ export function machineNodes(given, laws, instances, usual, st = tstats()) {
952
952
  }
953
953
  }
954
954
  function translateMade(facts, all, made, st, until) {
955
- for (const x of made) {
956
- const whole = mainGoal(facts, all, all[x.node]);
957
- 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)));
958
- if (!tree)
959
- return { specs: [], why: `${all[x.node].name}: not translated` };
960
- all[x.node] = { ...all[x.node], main: tree };
961
- }
962
- 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
+ });
963
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); };
964
971
  // The terms (not a read, a variable or a constant) of a conclusion that a node's facts read too, largest first; none
965
972
  // inside a product (a product of a term's linear form is no linear form).
966
973
  function shared(facts, a, concl) {
@@ -1183,7 +1190,7 @@ export function allowTranslated(given, laws, inst, p, usual, facts, lawNodes, na
1183
1190
  insts: closeHyps.length ? cl : [], uses: [{ node: lawNodes.length, subst: {}, guard: yes }], carry: true };
1184
1191
  const all = [...lawNodes, terms, allowed], whole = mainGoal(facts, all, terms), until = withinDeadline(clock() + 10_000);
1185
1192
  const ren = renamer({ s: now, cells: Object.fromEntries(mapNames.map(map => [map, { to: `${map}@`, at: t }])) });
1186
- 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))));
1187
1194
  if (!tree)
1188
1195
  return { specs: [], why: `${terms.name}: not translated` };
1189
1196
  return { specs: sliced([{ ...terms, main: tree }, allowed]) };
@@ -13,7 +13,8 @@
13
13
  import { quietly } from "./cyclic.js";
14
14
  import { any, atMost, compileFunction, evalC, evalE, n, plus, prod, same, seeded, times, x } from "./machine.js";
15
15
  import { Unproven, lit, proveFold, proveSteps, recur, recurOf } from "./dsl.js";
16
- import { gcd } from "./solver.js";
16
+ import { gcd, plus as addLin } from "./solver.js";
17
+ import { closedForm as fit, nfold, polyOf } from "./accel.js";
17
18
  const valueOf = (t) => (typeof t === 'number' ? t : t.val);
18
19
  const evalLin = (l, at) => Object.entries(l).reduce((s, [a, c]) => s + c * (a === '1' ? 1 : at[a]), 0);
19
20
  const holds = (c, at) => { const v = evalLin(c.lin, at); return c.rel === '=' ? v === 0 : v <= 0; };
@@ -85,34 +86,72 @@ function linearCands(target, forms, samples, show) {
85
86
  const dedupe = (cs) => [...new Map(cs.map(c => [c.name, c])).values()];
86
87
  // A statement whose coefficients are naturals a term can hold (a fit to values near 2^53 can make one that isn't).
87
88
  const exact = (c) => Object.values(c.lin).every(Number.isSafeInteger);
88
- // A polynomial in x of degree 3 at most, exact over the rationals, as d·f = a·x·x·x + b·x·x + c·x + e with whole
89
- // numbers: fitted to four points (Newton's differences), kept when every sample meets it.
90
- function closedForm(samples, show) {
89
+ // A polynomial in x of degree 2 or 3, exact over the rationals, as d·f = a·x·x·x + b·x·x + c·x + e with whole numbers,
90
+ // from core/accel.ts's closed forms: the recurrence's own where its step is affine in f and a polynomial in x (the
91
+ // engine on f and the powers of x, a triangular system), else the values' (the engine on the numbers: the shortest
92
+ // recurrence they all meet); kept when every sample meets it.
93
+ function closedForm(samples, show, rec) {
91
94
  const at = new Map();
92
95
  for (const s of samples) {
93
96
  if (at.has(s.x) && at.get(s.x) !== s.f)
94
97
  return [];
95
98
  at.set(s.x, s.f);
96
99
  }
97
- if (![0, 1, 2].every(x => at.has(x)))
100
+ const seq = [];
101
+ while (at.has(seq.length))
102
+ seq.push({ 1: at.get(seq.length) });
103
+ const p = (() => {
104
+ const next = rec && powers(rec.next), zero = rec?.zero.op === 'const' ? rec.zero.value : undefined;
105
+ const f = next && zero !== undefined ? nfold({ prev: 1 }, { x: { x: 1, 1: 1 }, xx: { xx: 1, x: 2, 1: 1 }, xxx: { xxx: 1, xx: 3, x: 3, 1: 1 }, prev: next }) : undefined;
106
+ const start = (c) => ({ 1: (c['1'] ?? 0) + (c.prev ?? 0) * zero });
107
+ if (f)
108
+ return { terms: f.terms.map(t => ({ ...t, c: start(t.c) })), den: f.den };
109
+ return seq.length >= 3 ? fit(seq, false) : undefined;
110
+ })();
111
+ const cs = p && polyOf(p);
112
+ if (!cs || cs.length < 3 || cs.length > 4)
98
113
  return [];
99
- const [f0, f1, f2] = [at.get(0), at.get(1), at.get(2)];
100
- const keep = (lin) => {
101
- const g = Object.values(lin).reduce((p, q) => gcd(p, Math.abs(q)), 0);
102
- const c = { name: '', rel: '=', lin: Object.fromEntries(Object.entries(lin).map(([a, k]) => [a, k / g]).filter(([, k]) => k !== 0)) };
103
- c.name = nameOf(c, show, 'f');
104
- return exact(c) && samples.every(s => holds(c, s)) ? [c] : [];
105
- };
106
- // f = a x² + b x + c: c = f0, a = (f2 - 2 f1 + f0) / 2, b = f1 - f0 - a; times 2 to keep whole numbers.
107
- const A = f2 - 2 * f1 + f0, B = 2 * (f1 - f0) - A, C = 2 * f0;
108
- const square = A === 0 ? [] : keep({ f: 2, xx: -A, x: -B, 1: -C });
109
- if (square.length || !at.has(3))
110
- return square;
111
- // f = Δ0 + Δ1·x + Δ2·x(x − 1)/2 + Δ3·x(x − 1)(x − 2)/6, times 6: x³ by Δ3, x² by 3Δ2 − 3Δ3, x by 6Δ1 − 3Δ2 + 2Δ3.
112
- const d1 = f1 - f0, d2 = f2 - 2 * f1 + f0, d3 = at.get(3) - 3 * f2 + 3 * f1 - f0;
113
- if (d3 === 0)
114
- return []; // degree 2 at most: above, or linear (the bounds find it)
115
- return keep({ f: 6, xxx: -d3, xx: -(3 * d2 - 3 * d3), x: -(6 * d1 - 3 * d2 + 2 * d3), 1: -6 * f0 });
114
+ // Σ c_k·C(x, k) / den, times 6·den: C(x, 2)·6 = 3·x·x − 3·x, C(x, 3)·6 = x·x·x − 3·x·x + 2·x
115
+ const [c0, c1, c2, c3] = [0, 1, 2, 3].map(k => cs[k]?.['1'] ?? 0);
116
+ const lin = { f: 6 * p.den, xxx: -c3, xx: -(3 * c2 - 3 * c3), x: -(6 * c1 - 3 * c2 + 2 * c3), 1: -6 * c0 };
117
+ const g = Object.values(lin).reduce((a, b) => gcd(a, Math.abs(b)), 0);
118
+ const c = { name: '', rel: '=', lin: Object.fromEntries(Object.entries(lin).map(([a, k]) => [a, k / g]).filter(([, k]) => k !== 0)) };
119
+ c.name = nameOf(c, show, 'f');
120
+ return exact(c) && samples.every(s => holds(c, s)) ? [c] : [];
121
+ }
122
+ // A step as a form over prev and the powers of x up to x·x·x (x, xx, xxx), or undefined where it isn't one.
123
+ function powers(e) {
124
+ switch (e.op) {
125
+ case 'var': return e.name === 'x' || e.name === 'prev' ? { [e.name]: 1 } : undefined;
126
+ case 'const': return { 1: e.value };
127
+ case 'add': {
128
+ const a = powers(e.a), b = powers(e.b);
129
+ return a && b && addLin(a, b);
130
+ }
131
+ case 'mul': {
132
+ const a = powers(e.a);
133
+ return a && Object.fromEntries(Object.entries(a).map(([k, c]) => [k, c * e.k]));
134
+ }
135
+ case 'prod': {
136
+ const a = powers(e.a), b = powers(e.b);
137
+ if (!a || !b)
138
+ return undefined;
139
+ let o = {};
140
+ for (const [u, c] of Object.entries(a))
141
+ for (const [w, d] of Object.entries(b)) {
142
+ if (u !== '1' && w !== '1' && (u === 'prev' || w === 'prev' || u.length + w.length > 3))
143
+ return undefined;
144
+ const m = u === '1' ? w : w === '1' ? u : 'x'.repeat(u.length + w.length);
145
+ o = addLin(o, { [m]: c * d });
146
+ }
147
+ return o;
148
+ }
149
+ case 'sub':
150
+ case 'min':
151
+ case 'max':
152
+ case 'if':
153
+ case 'get': return undefined;
154
+ }
116
155
  }
117
156
  // The law a goal is of (the kernel names each goal after its law: '<law> @step').
118
157
  const lawOfGoal = (goal) => goal.replace(/ @(start|step|step law|\d+ steps|leaf|node)$/, '');
@@ -145,7 +184,7 @@ function recurSamples(d, args) {
145
184
  return out;
146
185
  }
147
186
  // Lemmas about every x and f(x), and laws between two points, that every value meets.
148
- function recurCands(samples, args) {
187
+ function recurCands(samples, args, rec) {
149
188
  const slopes = new Set();
150
189
  const byArgs = new Map();
151
190
  for (const s of samples) {
@@ -162,7 +201,7 @@ function recurCands(samples, args) {
162
201
  const sorted = [...slopes].sort((a, b) => a - b), picked = [...new Set([...sorted.slice(0, 3), ...sorted.slice(-1)])];
163
202
  const xs = [{}, ...picked.map(s => ({ x: s }))];
164
203
  const forms = xs.flatMap(fx => [fx, ...args.map(a => ({ ...fx, [a]: 1 }))]);
165
- const lemmas = [...linearCands('f', forms, samples, showRecur), ...(args.length ? [] : closedForm(samples, showRecur))];
204
+ const lemmas = [...linearCands('f', forms, samples, showRecur), ...(args.length ? [] : closedForm(samples, showRecur, rec))];
166
205
  const pairs = [];
167
206
  for (const run of byArgs.values())
168
207
  for (const a of run)
@@ -284,7 +323,7 @@ function discoverSearch(r, laws, stepLaws, first) {
284
323
  // fitted exactly) first with it alone: it decides the function, and the bounds beside it, which the closed form
285
324
  // implies only through products, are slow to prove by induction; the rest where the laws aren't proven with it.
286
325
  const cands = new Map(fns.flatMap(([n, d]) => { const src = recurOf(d); if (!src)
287
- return []; const args = [...(src.def.args ?? [])]; return [[n, recurCands(recurSamples(d, args), args)]]; }));
326
+ return []; const args = [...(src.def.args ?? [])]; return [[n, recurCands(recurSamples(d, args), args, d.recur)]]; }));
288
327
  const exact = (c) => c.rel === '=' && ('xx' in c.lin || 'xxx' in c.lin);
289
328
  const makeFns = (closedOnly) => {
290
329
  const out = {};
package/dist/core/dsl.js CHANGED
@@ -19,7 +19,7 @@ import { argsKey, carriedView, compileFunction, divName, divisor, divisorsIn, ev
19
19
  import { allowed, keysOf, requestEnv, watch } from "./watch.js";
20
20
  import { someHolds, substVars } from "./exists.js";
21
21
  import { check, checkRecur, foldObligations, loopObligations } from "../kernel/kernel.js";
22
- import { certLoop, clock, factsFor, grow, proveLaws, proveLiveness, proveStepLaws, usualProof, withDeadline } from "../kernel/prove.js";
22
+ import { certLoop, clock, counted, factsFor, fullRate, grow, proveLaws, proveLiveness, proveStepLaws, usualProof, withDeadline } from "../kernel/prove.js";
23
23
  import { certCyclic, certOn, crossCyclic, cyclicOn, foldNodes, proveCyclic, quietly, recurNodes, translatedProof, uncovered } from "./cyclic.js";
24
24
  import { discover } from "./discover.js";
25
25
  import { inferLaws } from "./infer.js";
@@ -2780,21 +2780,22 @@ function searched(r, laws, stepLaws, v, opts) {
2780
2780
  return refutedVerdict(deeper);
2781
2781
  const until = clock() + (typeof opts.search === 'object' && opts.search.ms !== undefined ? opts.search.ms : 10_000);
2782
2782
  // Bounded runs (core/bmc.ts): a law broken k steps from the start, a model of the kernel's k-step goal, the run taken
2783
- // by the interpreter. The shallow depths first, within a fortieth of the search's budget (at most 250 ms, counted and
2784
- // in wall time); the deeper ones only where the invariant search finds nothing, within the tenth (at most a second)
2785
- // kept from it, so a law the search proves costs no more than the shallow depths.
2783
+ // by the interpreter. The shallow depths first, within a fortieth of the search's budget (at most 250 ms, counted in
2784
+ // the cost model's work: kernel/prove.ts's `counted` with `full`); the deeper ones only where the invariant search
2785
+ // finds nothing, within the tenth (at most a second) kept from it, so a law the search proves costs no more than the
2786
+ // shallow depths.
2786
2787
  const total = until - clock(), tail = Math.min(1000, total / 10);
2787
2788
  let reached = 0;
2788
- const bounded = (ms, from) => findBoundedRun(r.machine, laws, { ms, wall: performance.now() + ms, from, progress: k => { reached = k; } });
2789
+ const bounded = (ms, from) => counted(fullRate, () => findBoundedRun(r.machine, laws, { ms, from, steps: true, progress: k => { reached = k; } }), true);
2789
2790
  const refutedBy = (b) => refutedVerdict({ goal: `${b.law} @step (a run of ${b.depth} steps from the start)`, witness: b.witness, run: { params: b.params, trace: b.trace.map(shownRequest) } });
2790
2791
  const shallow = bounded(Math.min(250, total / 40), 1);
2791
2792
  if (shallow)
2792
2793
  return refutedBy(shallow);
2793
2794
  // k-induction (core/kind.ts): the plain laws as one, over k = 2, 3, ... steps in a row, the rule's kinds assumed;
2794
- // within a twentieth of the budget (at most 500 ms, counted and in wall time).
2795
+ // within a twentieth of the budget (at most 500 ms, counted so too).
2795
2796
  if (!stepLaws.length && laws.every(l => !l.forall && !l.keys?.length && !l.some?.length)) {
2796
2797
  const ms = Math.min(500, total / 20), kinds = withKinds(r, []).filter(k => !laws.some(l => l.name === k.name));
2797
- const kd = proveKInduction(r.machine, kinds, conjunction(laws), { ms, wall: performance.now() + ms });
2798
+ const kd = counted(fullRate, () => proveKInduction(r.machine, kinds, conjunction(laws), { ms }), true);
2798
2799
  if (kd.proven && kd.checked)
2799
2800
  return { proven: true, checked: true, k: kd.k };
2800
2801
  }
@@ -1,5 +1,6 @@
1
1
  type Context = Record<string, unknown>;
2
- import { type Kind, type Rule } from './dsl.js';
2
+ import { Term, type Kind, type Rule } from './dsl.js';
3
+ import { type Rand, type State } from './machine.js';
3
4
  import { type Model, type Var } from './extract-read.js';
4
5
  import * as I from './extract-ir.js';
5
6
  import type { B, N } from './extract-ir.js';
@@ -59,7 +60,17 @@ export type Snap = {
59
60
  maps: Record<string, Cells>;
60
61
  lists?: Record<string, Raw[]>;
61
62
  };
63
+ export declare class Outside extends Error {
64
+ }
65
+ export declare class Refused extends Error {
66
+ }
67
+ export declare const showSnap: (s: Snap) => string;
68
+ export declare const sameSnap: (a: Snap, b: Snap) => string | undefined;
62
69
  export declare const kindOfVar: (v: Var, sorts: Sorts, at?: string) => Kind<unknown>;
70
+ export declare function ruleSnap(r: Rule, m: Model, st: State, sorts: Sorts): Snap;
71
+ export declare function ruleState(base: State, s: Snap, m: Model, sorts: Sorts): State;
72
+ export declare function constantsOf(m: Model): number[];
73
+ export declare function draw(sort: Var['sort'], sorts: Sorts, name: string, rand: Rand, near: number[], bound: number, strs: string[]): Raw;
63
74
  export type CheckOptions = {
64
75
  runs?: number;
65
76
  depth?: number;
@@ -71,8 +82,47 @@ export type CheckOptions = {
71
82
  modules?: Record<string, unknown>;
72
83
  files?: Record<string, string>;
73
84
  };
85
+ type Ev = Model['events'][number];
86
+ export type CodeSide = {
87
+ make: (params: Record<string, Raw>) => {
88
+ ok: true;
89
+ value: unknown;
90
+ } | {
91
+ ok: false;
92
+ error: string;
93
+ };
94
+ at: (snap: Snap, params: Record<string, Raw>) => unknown;
95
+ snapOf: (self: unknown, params: Record<string, Raw>) => Snap;
96
+ call: (self: unknown, e: Ev, args: unknown[]) => {
97
+ ok: true;
98
+ value: unknown;
99
+ } | {
100
+ ok: false;
101
+ error: string;
102
+ };
103
+ reduce?: (snap: Snap, e: Ev, args: unknown[], params: Record<string, Raw>) => {
104
+ refused: string;
105
+ } | {
106
+ snap: Snap;
107
+ } | {
108
+ problem: string;
109
+ };
110
+ args: (inputs: Record<string, Raw>, e: Ev) => unknown[];
111
+ setNow: (n: number) => void;
112
+ init?: (snap: Snap, params: Record<string, Raw>) => string | undefined;
113
+ coverage: () => Coverage;
114
+ input?: (v: Var, x: Raw, rand: Rand) => Raw;
115
+ drawSnap?: (rand: Rand) => Snap;
116
+ normalize?: (s: Snap) => Snap;
117
+ edge?: (s: Snap, raw: Record<string, Raw>) => boolean;
118
+ };
74
119
  export declare function check(code: string, file: string, m: Model, r: Rule, sorts: Sorts, opts?: CheckOptions & {
75
120
  given?: Record<string, 'nat' | 'int'>;
76
121
  }): Evidence;
77
- export declare function evalTerm(t: N | B | I.L, env: Record<string, Raw>): Raw;
122
+ export declare function drive(m: Model, r: Rule, sorts: Sorts, code: CodeSide, opts?: CheckOptions & {
123
+ given?: Record<string, 'nat' | 'int'>;
124
+ }): Evidence;
125
+ export declare function conditionsOf(m: Model): B[];
126
+ export declare function condAt(c: B, env: Record<string, unknown>): ReturnType<Term['lt']>;
127
+ export declare function evalTerm(t: N | B | I.L, env: Record<string, Raw>, cell?: (map: string, key: Raw, field: string) => Raw): Raw;
78
128
  export {};