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
package/dist/core/dsl.js CHANGED
@@ -15,11 +15,11 @@
15
15
  //
16
16
  // A step returns its updates as one object: every right-hand side reads the state before the step, as the kernel and
17
17
  // both runtimes do.
18
- import { carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, withArithmetic } from "./machine.js";
18
+ import { argsKey, carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, seeded, withArithmetic } from "./machine.js";
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";
@@ -1588,8 +1588,6 @@ const flatFns = (defs) => defs.flatMap(([n, d]) => {
1588
1588
  const uses = Object.entries(d.uses ?? {}).map(([u, ud]) => [`${n}.${u}`, ud]);
1589
1589
  return [...flatFns(uses), [n, d, Object.fromEntries(uses.map(([un, ud]) => [un.slice(n.length + 1), fnTerm(un, ud)]))]];
1590
1590
  });
1591
- const pairE = (a, b) => { const s = { op: 'add', a, b }; return { op: 'add', a: { op: 'prod', a: s, b: s }, b }; };
1592
- const argsKey = (args) => args.slice(1).reduce(pairE, args[0]);
1593
1591
  // A function's JavaScript as one function of its key: its arguments unpaired (left-nested, as argsKey pairs them).
1594
1592
  const jsOf = (d) => (typeof d.js === 'string' ? d.js : String(d.js));
1595
1593
  const fnSource = (name, d) => {
@@ -2653,14 +2651,18 @@ const withKinds = (r, laws) => [...r.kindLaws().filter(k => !laws.some(l => l.na
2653
2651
  // knows it only by its facts, which may also bound the params (a recurrence's induction machines take f(x) as a param
2654
2652
  // fx), so params are drawn only where every fact holds: a fact about the params alone exactly, one about every key at
2655
2653
  // each key (or tuple of keys) up to twice the bound. A rule whose function breaks its own facts there gets no run.
2656
- const refuteBudget = { trials: 60, depth: 6, bound: 3, ms: 150 };
2654
+ // The budget is counted, in the runs and requests tried (as core/infer.ts counts its runs), never timed, so a run within
2655
+ // it is found on any machine. (A stop at 150 ms of wall time left a false law to the kernel whenever the first run alone
2656
+ // took that long, a pause on a loaded container: core/pairs.test.ts's two groups, whose 944-hypothesis step goal then ran
2657
+ // out its 944 s, in 7 of 130 runs of the suite's pairs job on Modal.)
2658
+ const refuteBudget = { trials: 60, depth: 6, bound: 3 };
2657
2659
  // A request as a run's trace shows it: each map it carries as an object of its cells.
2658
2660
  const shownRequest = (input) => Object.fromEntries(Object.entries(input).map(([n, x]) => [n, typeof x === 'number' ? x : Object.fromEntries(x)]));
2659
2661
  // The search's own runs, before it looks for what the laws need: deeper and wider, from another seed.
2660
- const deeperBudget = { trials: 600, depth: 24, bound: 8, ms: 1500, seed: 29 };
2662
+ const deeperBudget = { trials: 600, depth: 24, bound: 8, seed: 29 };
2661
2663
  function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
2662
2664
  const m = r.machine;
2663
- const run = interpret(m), rand = seeded(budget.seed ?? 13), until = performance.now() + budget.ms, bound = budget.bound, shown = shownRequest;
2665
+ const run = interpret(m), rand = seeded(budget.seed ?? 13), bound = budget.bound, shown = shownRequest;
2664
2666
  // (Division by a constant is a function too, its facts Euclid's, which its JavaScript meets: not checked.)
2665
2667
  const facts = (m.facts ?? []).filter(f => !isArithmetic(f.name.slice(0, f.name.indexOf(':'))));
2666
2668
  const holds = (f, params) => {
@@ -2680,7 +2682,7 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
2680
2682
  const factsHold = (params) => (alone ??= facts.filter(f => !readsParams(f)).every(f => holds(f, params)))
2681
2683
  && facts.filter(readsParams).every(f => holds(f, params));
2682
2684
  try {
2683
- for (let trial = 0; trial < budget.trials && performance.now() < until; trial++) {
2685
+ for (let trial = 0; trial < budget.trials; trial++) {
2684
2686
  const params = r.randomParams(rand, bound);
2685
2687
  if (m.pre && !evalC(m.pre, params, { scalars: {}, maps: {} }, m) || !factsHold(params))
2686
2688
  continue;
@@ -2712,7 +2714,7 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
2712
2714
  // variable of a kind is drawn as its kind draws (33 yes/nos drawn from 0..7 almost never make a lawful state).
2713
2715
  const steps1 = stepLaws.filter(sl => (sl.steps ?? 1) === 1), given = withKinds(r, laws);
2714
2716
  const wide = Object.keys(m.state).length + m.inputs.length >= 32, lawsHere = wide ? given : [], kinded = wide ? r.kindsOfState() : [];
2715
- for (let trial = 0; !m.history && (steps1.length || lawsHere.length) && trial < budget.trials * 4 && performance.now() < until; trial++) {
2717
+ for (let trial = 0; !m.history && (steps1.length || lawsHere.length) && trial < budget.trials * 4; trial++) {
2716
2718
  const params = r.randomParams(rand, bound);
2717
2719
  if (m.pre && !evalC(m.pre, params, { scalars: {}, maps: {} }, m) || !factsHold(params))
2718
2720
  continue;
@@ -2739,6 +2741,8 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
2739
2741
  }
2740
2742
  return undefined;
2741
2743
  }
2744
+ // The kernel's report as a verdict: its first goal left unproven, with its counterexample and why.
2745
+ export const verdictOf = (out) => ({ proven: out.proven, checked: out.checked, ...(out.failed ? { goal: out.failed.goal, stuck: out.failed.stuck, ...(out.failed.witness ? { witness: out.failed.witness } : {}), ...(out.failed.why ? { why: out.failed.why } : {}) } : {}) });
2742
2746
  const refutedVerdict = (out) => ({ proven: false, checked: false, goal: out.goal, stuck: 'sat', witness: out.witness, ...(out.run ? { run: out.run } : {}) });
2743
2747
  // The divisors some laws read (modBy, divBy), noted on the rule so its machine declares them: a law may come from
2744
2748
  // another instance of the same rule (a factory called twice).
@@ -2753,7 +2757,7 @@ export function proveRule(r, laws, opts = {}) {
2753
2757
  if (refuted)
2754
2758
  return refuted.run ? refutedVerdict(refuted) : searched(r, laws, [], refutedVerdict(refuted), opts);
2755
2759
  const out = proveLaws(r.machine, withKinds(r, laws));
2756
- const v = { proven: out.proven, checked: out.checked, ...(out.failed ? { goal: out.failed.goal, stuck: out.failed.stuck, ...(out.failed.witness ? { witness: out.failed.witness } : {}), ...(out.failed.why ? { why: out.failed.why } : {}) } : {}), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) };
2760
+ const v = { ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) };
2757
2761
  return searched(r, laws, [], v, opts);
2758
2762
  }
2759
2763
  export function proveSteps(r, laws, stepLaws, opts = {}) {
@@ -2762,7 +2766,7 @@ export function proveSteps(r, laws, stepLaws, opts = {}) {
2762
2766
  if (refuted)
2763
2767
  return refutedVerdict(refuted);
2764
2768
  const out = proveStepLaws(r.machine, withKinds(r, laws), stepLaws);
2765
- const v = { proven: out.proven, checked: out.checked, ...(out.failed ? { goal: out.failed.goal, stuck: out.failed.stuck, ...(out.failed.witness ? { witness: out.failed.witness } : {}), ...(out.failed.why ? { why: out.failed.why } : {}) } : {}) };
2769
+ const v = verdictOf(out);
2766
2770
  return searched(r, laws, stepLaws, v, opts);
2767
2771
  }
2768
2772
  // The search, where the prover alone didn't prove the laws and nothing refuted them: the lemmas first where the rule has
@@ -2774,23 +2778,24 @@ function searched(r, laws, stepLaws, v, opts) {
2774
2778
  const deeper = refuteByRuns(r, laws, stepLaws, deeperBudget);
2775
2779
  if (deeper?.run)
2776
2780
  return refutedVerdict(deeper);
2777
- const until = performance.now() + (typeof opts.search === 'object' && opts.search.ms !== undefined ? opts.search.ms : 10_000);
2781
+ const until = clock() + (typeof opts.search === 'object' && opts.search.ms !== undefined ? opts.search.ms : 10_000);
2778
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
2779
- // by the interpreter. The shallow depths first, within a fortieth of the search's budget (at most 250 ms, counted and
2780
- // in wall time); the deeper ones only where the invariant search finds nothing, within the tenth (at most a second)
2781
- // kept from it, so a law the search proves costs no more than the shallow depths.
2782
- const total = until - performance.now(), tail = Math.min(1000, total / 10);
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.
2787
+ const total = until - clock(), tail = Math.min(1000, total / 10);
2783
2788
  let reached = 0;
2784
- 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);
2785
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) } });
2786
2791
  const shallow = bounded(Math.min(250, total / 40), 1);
2787
2792
  if (shallow)
2788
2793
  return refutedBy(shallow);
2789
2794
  // k-induction (core/kind.ts): the plain laws as one, over k = 2, 3, ... steps in a row, the rule's kinds assumed;
2790
- // 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).
2791
2796
  if (!stepLaws.length && laws.every(l => !l.forall && !l.keys?.length && !l.some?.length)) {
2792
2797
  const ms = Math.min(500, total / 20), kinds = withKinds(r, []).filter(k => !laws.some(l => l.name === k.name));
2793
- 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);
2794
2799
  if (kd.proven && kd.checked)
2795
2800
  return { proven: true, checked: true, k: kd.k };
2796
2801
  }
@@ -2805,17 +2810,17 @@ function searched(r, laws, stepLaws, v, opts) {
2805
2810
  }
2806
2811
  // Functions known by their facts alone (not a recurrence): lemmas about them, fitted to their values and proven from
2807
2812
  // the facts as cyclic claims, the laws proven with them as facts.
2808
- if ((typeof opts.search !== 'object' || opts.search.cycles !== false) && fns.some(([, d]) => !recurOf(d)) && rule.machine.facts?.length && until - performance.now() > 500) {
2809
- const c = withDeadline(until, () => cycleLemmas(rule.machine, withKinds(rule, laws), stepLaws, { ms: (until - performance.now()) / 2 }));
2813
+ if ((typeof opts.search !== 'object' || opts.search.cycles !== false) && fns.some(([, d]) => !recurOf(d)) && rule.machine.facts?.length && until - clock() > 500) {
2814
+ const c = withDeadline(until, () => cycleLemmas(rule.machine, withKinds(rule, laws), stepLaws, { ms: (until - clock()) / 2 }));
2810
2815
  if (c.proven && c.checked)
2811
2816
  return { proven: true, checked: true, found: { ...(lemmas ? { lemmas } : {}), facts: c.found.map(f => f.text) } };
2812
2817
  }
2813
- const ms = until - performance.now() - tail;
2818
+ const ms = until - clock() - tail;
2814
2819
  if (ms < 500)
2815
2820
  return v;
2816
2821
  const inf = inferLaws(rule, laws, stepLaws, { ms, ...(rule === r ? { first: v } : {}) });
2817
2822
  if (!(inf.proven && inf.checked)) {
2818
- const deep = bounded(Math.max(0, until - performance.now()), Math.max(1, reached));
2823
+ const deep = bounded(Math.max(0, until - clock()), Math.max(1, reached));
2819
2824
  if (deep)
2820
2825
  return refutedBy(deep);
2821
2826
  return { ...v, why: [v.why, `the search found nothing that proves it in ${Math.round(inf.stats.ms)} ms`].filter(Boolean).join('; ') };
@@ -2834,7 +2839,7 @@ export function proveLeadsTo(r, laws, l, opts = {}) {
2834
2839
  ...(f.found ? { found: { rank: f.found.rank, ...(f.laws?.length ? { laws: f.laws.map((law, i) => ({ law, text: f.found.laws[i] ?? law.name })) } : {}) } } : {}) };
2835
2840
  }
2836
2841
  const out = proveLiveness(r.machine, withKinds(r, laws), l);
2837
- return { proven: out.proven, checked: out.checked, ...(out.failed ? { goal: out.failed.goal, stuck: out.failed.stuck, ...(out.failed.witness ? { witness: out.failed.witness } : {}), ...(out.failed.why ? { why: out.failed.why } : {}) } : {}) };
2842
+ return verdictOf(out);
2838
2843
  }
2839
2844
  // `ms`: the budget (the prover's own per goal, 20 s or a second a hypothesis, where none is given), on the clock the
2840
2845
  // prover reads (the counted one inside a counted search): past it the verdict is unknown.
@@ -2842,7 +2847,6 @@ export const proveDecision = (d, opts = {}) => {
2842
2847
  const go = () => (d.steps ? proveSteps(d.steps.rule, [], [d.steps.law], { search: false }) : goalsVerdict([d.goal]));
2843
2848
  return opts.ms === undefined ? go() : withDeadline(clock() + opts.ms, go);
2844
2849
  };
2845
- const seeded = (seed) => { let x = seed; return k => { x = (x * 1103515245 + 12345) % 2 ** 31; return Math.floor(x / 2 ** 31 * k); }; };
2846
2850
  // A decision's callbacks against its condition, on random params and requests: `given` and `then` each run with every
2847
2851
  // value known, against what the interpreter evaluates of the decision built from them.
2848
2852
  export function crossCheckDecision(d, opts = {}) {
@@ -14,10 +14,9 @@
14
14
  // value before, shifts of it, the request's values and the state before; each is chosen to satisfy P at every
15
15
  // counterexample so far, per case of the step (the conditions its updates split on: the request's clause, say).
16
16
  // A law under a `forall` key takes witness terms only (a ghost per key would be a map).
17
- import { evalC, evalE } from "./machine.js";
18
- import { proveLaw, proveLaws, withinDeadline } from "../kernel/prove.js";
19
- const k = (value) => ({ op: 'const', value });
20
- const v = (name) => ({ op: 'var', name });
17
+ import { evalC, evalE, n as k, walk, x as v } from "./machine.js";
18
+ import { clock, proveLaw, proveLaws, withinDeadline } from "../kernel/prove.js";
19
+ import { env } from "./solver.js";
21
20
  const add = (a, b) => (a.op === 'const' && a.value === 0 ? b : b.op === 'const' && b.value === 0 ? a : { op: 'add', a, b });
22
21
  const sum = (es) => es.reduce((acc, e) => add(acc, e), k(0));
23
22
  const sub = (a, b) => (b.op === 'const' && b.value === 0 ? a : { op: 'sub', a, b });
@@ -286,18 +285,12 @@ const caseAt = (cases, env, st, m) => {
286
285
  };
287
286
  function constantsOf(m) {
288
287
  const out = new Set([1, 2]);
289
- const walk = (t) => {
290
- if (!t || typeof t !== 'object')
291
- return;
292
- const o = t;
288
+ walk(m.step, o => {
293
289
  if (o.op === 'const' && typeof o.value === 'number' && o.value > 0 && o.value <= 64)
294
290
  out.add(o.value);
295
291
  if (o.op === 'mul' && typeof o.k === 'number' && o.k > 1 && o.k <= 64)
296
292
  out.add(o.k);
297
- for (const x of Object.values(o))
298
- (Array.isArray(x) ? x : [x]).forEach(walk);
299
- };
300
- walk(m.step);
293
+ });
301
294
  return [...out].sort((a, b) => a - b).slice(0, 6);
302
295
  }
303
296
  const dedupe = (cs) => [...new Map(cs.map(c => [key(c), c])).values()];
@@ -470,7 +463,7 @@ export function proveSome(m, laws, opts = {}) {
470
463
  return { machine: b.machine, laws: out, ghosts: b.ghosts };
471
464
  };
472
465
  const rounds = opts.rounds ?? 24;
473
- const log = globalThis.process?.env?.GDP_EXISTS_LOG === '1';
466
+ const log = env.GDP_EXISTS_LOG === '1';
474
467
  // Each law's witness until its goals are proven with every law assumed (choose); then the whole set, and where a
475
468
  // later choice broke a law proven before (a witness term is a hypothesis of every law), that law's again.
476
469
  const choose = (i, p, pass, first) => {
@@ -484,7 +477,7 @@ export function proveSome(m, laws, opts = {}) {
484
477
  // A witness given: the kernel proves the law with it, or refuses it here, with its counterexample.
485
478
  if (p.given)
486
479
  return { proven: false, nodes: 0, leaves: 0, checked: false, failed: { goal: r.goal, stuck: r.stuck, ...(r.witness ? { witness: r.witness } : {}), why: `the witness given for "${p.law.name}" does not prove it` } };
487
- if (withinDeadline(Infinity) <= performance.now())
480
+ if (withinDeadline(Infinity) <= clock())
488
481
  return fail(`the deadline passed choosing a witness for "${p.law.name}" (${r.stuck})`);
489
482
  if (round >= rounds)
490
483
  return fail(`no witness found for "${p.law.name}" in ${rounds} rounds (${r.stuck}): name one (exists(kind, f, witness))`);
@@ -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';
@@ -33,7 +34,7 @@ export type Evidence = {
33
34
  ms: number;
34
35
  mismatch?: string;
35
36
  };
36
- export declare function instrument(code: string, file: string, tail?: string): {
37
+ export declare function instrument(code: string, file: string, tail?: string, extra?: [number, string][]): {
37
38
  js: string;
38
39
  arms: Arm[];
39
40
  };
@@ -50,15 +51,26 @@ export type Sandbox = {
50
51
  setNow: (n: number) => void;
51
52
  get: (name: string) => unknown;
52
53
  };
53
- export declare function sandbox(code: string, file: string, expose: string[], modules?: Record<string, unknown>, init?: string, files?: Record<string, string>): Sandbox & {
54
+ export declare function sandbox(code: string, file: string, expose: string[], modules?: Record<string, unknown>, init?: string, files?: Record<string, string>, extra?: [number, string][]): Sandbox & {
54
55
  arms: Arm[];
55
56
  };
56
57
  type Cells = Record<string, Record<string, Raw>>;
57
58
  export type Snap = {
58
59
  leaves: Record<string, Raw>;
59
60
  maps: Record<string, Cells>;
61
+ lists?: Record<string, Raw[]>;
60
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;
61
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;
62
74
  export type CheckOptions = {
63
75
  runs?: number;
64
76
  depth?: number;
@@ -70,8 +82,47 @@ export type CheckOptions = {
70
82
  modules?: Record<string, unknown>;
71
83
  files?: Record<string, string>;
72
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
+ };
73
119
  export declare function check(code: string, file: string, m: Model, r: Rule, sorts: Sorts, opts?: CheckOptions & {
74
120
  given?: Record<string, 'nat' | 'int'>;
75
121
  }): Evidence;
76
- 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;
77
128
  export {};