gdp-wired 0.22.0 → 0.24.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 (60) hide show
  1. package/README.md +27 -2
  2. package/dist/core/bmc.d.ts +49 -0
  3. package/dist/core/bmc.js +509 -0
  4. package/dist/core/check.d.ts +1 -1
  5. package/dist/core/check.js +19 -6
  6. package/dist/core/cycles.d.ts +38 -0
  7. package/dist/core/cycles.js +531 -43
  8. package/dist/core/data.d.ts +25 -1
  9. package/dist/core/data.js +984 -215
  10. package/dist/core/discover.js +8 -3
  11. package/dist/core/dsl.d.ts +17 -3
  12. package/dist/core/dsl.js +81 -15
  13. package/dist/core/extract-check.d.ts +77 -0
  14. package/dist/core/extract-check.js +785 -0
  15. package/dist/core/extract-ir.d.ts +139 -0
  16. package/dist/core/extract-ir.js +198 -0
  17. package/dist/core/extract-print.d.ts +30 -0
  18. package/dist/core/extract-print.js +426 -0
  19. package/dist/core/extract-read.d.ts +298 -0
  20. package/dist/core/extract-read.js +1298 -0
  21. package/dist/core/extract-shapes.d.ts +13 -0
  22. package/dist/core/extract-shapes.js +993 -0
  23. package/dist/core/extract-xstate.d.ts +34 -0
  24. package/dist/core/extract-xstate.js +320 -0
  25. package/dist/core/extract.d.ts +31 -0
  26. package/dist/core/extract.js +249 -0
  27. package/dist/core/infer.js +518 -5
  28. package/dist/core/kind.d.ts +30 -0
  29. package/dist/core/kind.js +81 -0
  30. package/dist/core/nonterm.d.ts +34 -0
  31. package/dist/core/nonterm.js +610 -0
  32. package/dist/core/q.d.ts +17 -0
  33. package/dist/core/q.js +52 -0
  34. package/dist/core/rationals.d.ts +112 -0
  35. package/dist/core/rationals.js +281 -0
  36. package/dist/core/relation.d.ts +28 -0
  37. package/dist/core/relation.js +483 -0
  38. package/dist/core/solver.d.ts +5 -2
  39. package/dist/core/solver.js +65 -20
  40. package/dist/core/transfer.d.ts +3 -3
  41. package/dist/core/transfer.js +69 -42
  42. package/dist/core/xstate.d.ts +6 -0
  43. package/dist/core/xstate.js +70 -12
  44. package/dist/kernel/cdcl.d.ts +13 -0
  45. package/dist/kernel/cdcl.js +307 -236
  46. package/dist/kernel/kernel.d.ts +106 -0
  47. package/dist/kernel/kernel.js +342 -0
  48. package/dist/kernel/prove.js +14 -3
  49. package/dist/kernel/qprove.d.ts +18 -0
  50. package/dist/kernel/qprove.js +157 -0
  51. package/dist/kernel/reader.d.ts +14 -0
  52. package/dist/kernel/reader.js +102 -14
  53. package/dist/kernel/simplex.d.ts +4 -0
  54. package/dist/kernel/simplex.js +38 -11
  55. package/dist/lean-kernel/emit.d.ts +46 -1
  56. package/dist/lean-kernel/emit.js +125 -16
  57. package/dist/lean-kernel/library.js +4 -1
  58. package/dist/lean-kernel/qlean.d.ts +26 -0
  59. package/dist/lean-kernel/qlean.js +105 -0
  60. package/package.json +16 -3
@@ -80,9 +80,11 @@ function linearCands(target, forms, samples, show) {
80
80
  c.name = nameOf(c, show, target);
81
81
  c.target = target;
82
82
  }
83
- return dedupe(out.filter(c => samples.every(s => holds(c, s))));
83
+ return dedupe(out.filter(c => exact(c) && samples.every(s => holds(c, s))));
84
84
  }
85
85
  const dedupe = (cs) => [...new Map(cs.map(c => [c.name, c])).values()];
86
+ // A statement whose coefficients are naturals a term can hold (a fit to values near 2^53 can make one that isn't).
87
+ const exact = (c) => Object.values(c.lin).every(Number.isSafeInteger);
86
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
87
89
  // numbers: fitted to four points (Newton's differences), kept when every sample meets it.
88
90
  function closedForm(samples, show) {
@@ -99,7 +101,7 @@ function closedForm(samples, show) {
99
101
  const g = Object.values(lin).reduce((p, q) => gcd(p, Math.abs(q)), 0);
100
102
  const c = { name: '', rel: '=', lin: Object.fromEntries(Object.entries(lin).map(([a, k]) => [a, k / g]).filter(([, k]) => k !== 0)) };
101
103
  c.name = nameOf(c, show, 'f');
102
- return samples.every(s => holds(c, s)) ? [c] : [];
104
+ return exact(c) && samples.every(s => holds(c, s)) ? [c] : [];
103
105
  };
104
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.
105
107
  const A = f2 - 2 * f1 + f0, B = 2 * (f1 - f0) - A, C = 2 * f0;
@@ -136,6 +138,9 @@ function recurSamples(d, args) {
136
138
  break;
137
139
  throw e;
138
140
  }
141
+ // (past 2^53 a value isn't exact, and no statement a lemma makes may hold its constants: the run stops there too)
142
+ if (!Number.isSafeInteger(y) || y < 0)
143
+ break;
139
144
  out.push({ x, f: y, xx: x * x, xxx: x * x * x, ...Object.fromEntries(args.map((a, i) => [a, t[i]])) });
140
145
  }
141
146
  return out;
@@ -170,7 +175,7 @@ function recurCands(samples, args) {
170
175
  { name: '', rel: '<=', lin: { f: 1, g: -1 } },
171
176
  { name: '', rel: '<=', lin: { g: 1, f: -1 } },
172
177
  ...(steepest ? [{ name: '', rel: '<=', lin: { g: 1, x: steepest, f: -1, y: -steepest } }] : []),
173
- ].filter(c => pairs.every(p => holds(c, p)));
178
+ ].filter(c => exact(c) && pairs.every(p => holds(c, p)));
174
179
  for (const c of between)
175
180
  c.name = nameOf(c, showRecur, 'g');
176
181
  return { lemmas, between };
@@ -1,5 +1,5 @@
1
1
  import { type C, type E, type Law, type Recurrence, type Machine, type Request, type State } from './machine.js';
2
- import { type Fold, type Goal, type Liveness, type Loop, type StepLaw, type Tree } from '../kernel/kernel.js';
2
+ import { type Fold, type Goal, type Liveness, type Loop, type Recur, type StepLaw, type Tree } from '../kernel/kernel.js';
3
3
  export type TermLike = Term | number;
4
4
  export declare const termOf: (t: TermLike) => E;
5
5
  export declare class Term {
@@ -44,7 +44,8 @@ export declare function when(c: Cond, then: Decimal | number, otherwise: Decimal
44
44
  export declare function when(c: Cond, then: IntLike, otherwise: IntLike): Int;
45
45
  export declare function when<K extends string>(c: Cond, then: Choice<K> | NoInfer<K>, otherwise: Choice<K>): Choice<K>;
46
46
  export declare function when<K extends string>(c: Cond, then: Choice<K>, otherwise: Choice<K> | NoInfer<K>): Choice<K>;
47
- export declare function when(c: Cond, then: Str, otherwise: Str): Str;
47
+ export declare function when(c: Cond, then: Str, otherwise: Str | string): Str;
48
+ export declare function when(c: Cond, then: string, otherwise: Str): Str;
48
49
  export declare function when<V>(c: Cond, then: Maybe<V>, otherwise: Maybe<V>): Maybe<V>;
49
50
  export declare function when(c: Cond, then: Cond, otherwise: Cond): Cond;
50
51
  export declare function when<C extends Cases, T extends string>(c: Cond, then: Variant<C, T>, otherwise: Variant<C, T>): Variant<C, T>;
@@ -236,6 +237,7 @@ export declare class Str {
236
237
  constructor(id: Term, length: Term, bits: ReadonlyMap<string, Term>);
237
238
  get patterns(): string[];
238
239
  choose(c: Cond, other: Str): Str;
240
+ literal(text: string): Str;
239
241
  like(pattern: string): Cond;
240
242
  get isEmpty(): Cond;
241
243
  bit(pattern: string): Term;
@@ -826,6 +828,7 @@ export type Verdict = {
826
828
  };
827
829
  found?: Found;
828
830
  witnesses?: Record<string, string>;
831
+ k?: number;
829
832
  };
830
833
  export type Found = {
831
834
  laws?: {
@@ -857,7 +860,9 @@ export type { Liveness };
857
860
  export declare function proveLeadsTo(r: Rule<Obj, Obj, Obj, Obj, Obj, Obj, Obj, Obj>, laws: Law[], l: Liveness, opts?: {
858
861
  ms?: number;
859
862
  }): Verdict;
860
- export declare const proveDecision: (d: Decision) => Verdict;
863
+ export declare const proveDecision: (d: Decision, opts?: {
864
+ ms?: number;
865
+ }) => Verdict;
861
866
  export declare function crossCheckDecision(d: Decision, opts?: {
862
867
  trials?: number;
863
868
  bound?: number;
@@ -869,6 +874,15 @@ export declare function crossCheckDecision(d: Decision, opts?: {
869
874
  export declare const proveLoop: (l: LoopRule<Obj, Obj, Obj>, laws: Law[], opts?: {
870
875
  ms?: number;
871
876
  }) => Verdict;
877
+ export type NeverEnds = Verdict & {
878
+ recur?: Recur;
879
+ loop?: Loop;
880
+ by?: string;
881
+ };
882
+ export declare function proveNeverEnds<P extends Obj, I extends Obj, S extends Obj>(l: LoopRule<P, I, S>, opts?: {
883
+ ms?: number;
884
+ from?: (p: P) => Cond;
885
+ }): NeverEnds;
872
886
  export type TreeValue<I> = {
873
887
  leaf: I;
874
888
  } | {
package/dist/core/dsl.js CHANGED
@@ -18,12 +18,15 @@
18
18
  import { carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, withArithmetic } from "./machine.js";
19
19
  import { allowed, keysOf, requestEnv, watch } from "./watch.js";
20
20
  import { someHolds, substVars } from "./exists.js";
21
- import { check, foldObligations, loopObligations } from "../kernel/kernel.js";
22
- import { certLoop, factsFor, grow, proveLaws, proveLiveness, proveStepLaws, usualProof, withDeadline } from "../kernel/prove.js";
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";
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";
26
+ import { findBoundedRun } from "./bmc.js";
27
+ import { conjunction, proveKInduction } from "./kind.js";
26
28
  import { cycleLemmas, findLeadsTo, findRank } from "./cycles.js";
29
+ import { findNeverEnds } from "./nonterm.js";
27
30
  // --- terms and conditions -------------------------------------------------------------------------------------------
28
31
  const naturalConst = (v) => {
29
32
  if (!Number.isSafeInteger(v) || v < 0)
@@ -118,6 +121,11 @@ export function when(c, then, otherwise) {
118
121
  return new Choice(when(c, then.n, otherwise.n), then.values);
119
122
  if (then instanceof Str && otherwise instanceof Str)
120
123
  return then.choose(c, otherwise);
124
+ // A string beside a string value is that string: when(claimed, who, '').
125
+ if (then instanceof Str && typeof otherwise === 'string')
126
+ return then.choose(c, then.literal(otherwise));
127
+ if (typeof then === 'string' && otherwise instanceof Str)
128
+ return otherwise.literal(then).choose(c, otherwise);
121
129
  if (then instanceof Maybe && otherwise instanceof Maybe)
122
130
  return new Maybe(when(c, then.present, otherwise.present), when(c, then.inner, otherwise.inner));
123
131
  return pickNumbers(c, then, otherwise);
@@ -698,6 +706,8 @@ export class Str {
698
706
  get patterns() { return [...this.bits.keys()]; }
699
707
  // This string where c holds, else `other` (the patterns both declare).
700
708
  choose(c, other) { return new Str(when(c, this.id, other.id), when(c, this.length, other.length), new Map([...this.bits].filter(([p]) => other.bits.has(p)).map(([p, b]) => [p, when(c, b, other.bits.get(p))]))); }
709
+ // A literal as a string value with this one's patterns (each bit as the literal matches it).
710
+ literal(text) { return new Str(lit(literal(text)), lit(text.length), new Map([...this.bits.keys()].map(p => [p, lit(globMatch(p, text) ? 1 : 0)]))); }
701
711
  // The string matches `pattern`, one the kind declared.
702
712
  like(pattern) {
703
713
  const b = this.bits.get(pattern);
@@ -2639,22 +2649,40 @@ const withKinds = (r, laws) => [...r.kindLaws().filter(k => !laws.some(l => l.na
2639
2649
  // A real run from the start that breaks a law or a step law, from a few random runs (each request drawn by its kinds,
2640
2650
  // those the rule's assumption refuses skipped): a false law is refused at once, with the run, where the symbolic search
2641
2651
  // would have to decide every case of its goal to reach one. Nothing here is trusted; a run it finds is a run the
2642
- // interpreter took. A rule that reads functions is skipped: the kernel knows them only by their facts (a recurrence's
2643
- // induction machine reads the function it proves things about), so a run computing them proves nothing about the goal.
2652
+ // interpreter took. A function the rule reads is computed by its JavaScript, as the runtimes compute it; the kernel
2653
+ // knows it only by its facts, which may also bound the params (a recurrence's induction machines take f(x) as a param
2654
+ // fx), so params are drawn only where every fact holds: a fact about the params alone exactly, one about every key at
2655
+ // each key (or tuple of keys) up to twice the bound. A rule whose function breaks its own facts there gets no run.
2644
2656
  const refuteBudget = { trials: 60, depth: 6, bound: 3, ms: 150 };
2657
+ // A request as a run's trace shows it: each map it carries as an object of its cells.
2658
+ const shownRequest = (input) => Object.fromEntries(Object.entries(input).map(([n, x]) => [n, typeof x === 'number' ? x : Object.fromEntries(x)]));
2645
2659
  // The search's own runs, before it looks for what the laws need: deeper and wider, from another seed.
2646
2660
  const deeperBudget = { trials: 600, depth: 24, bound: 8, ms: 1500, seed: 29 };
2647
2661
  function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
2648
2662
  const m = r.machine;
2649
- // Division by a constant is a function too, but its facts fix its value, so a run computing it is a run of the rule.
2650
- if (Object.keys(m.fns ?? {}).some(f => !isArithmetic(f)) || m.facts?.some(f => !isArithmetic(f.name.slice(0, f.name.indexOf(':')))))
2651
- return undefined;
2652
- const run = interpret(m), rand = seeded(budget.seed ?? 13), until = performance.now() + budget.ms, bound = budget.bound;
2653
- const shown = (input) => Object.fromEntries(Object.entries(input).map(([n, x]) => [n, typeof x === 'number' ? x : Object.fromEntries(x)]));
2663
+ const run = interpret(m), rand = seeded(budget.seed ?? 13), until = performance.now() + budget.ms, bound = budget.bound, shown = shownRequest;
2664
+ // (Division by a constant is a function too, its facts Euclid's, which its JavaScript meets: not checked.)
2665
+ const facts = (m.facts ?? []).filter(f => !isArithmetic(f.name.slice(0, f.name.indexOf(':'))));
2666
+ const holds = (f, params) => {
2667
+ const names = f.forall ? [f.forall, ...(f.keys ?? [])] : [], top = names.length > 1 ? bound : 2 * bound;
2668
+ const at = (env, i) => (i === names.length ? evalC(f.holds, env, { scalars: {}, maps: {} }, m)
2669
+ : Array.from({ length: top + 1 }, (_, key) => key).every(key => at({ ...env, [names[i]]: key }, i + 1)));
2670
+ try {
2671
+ return at(params, 0);
2672
+ }
2673
+ catch {
2674
+ return false;
2675
+ }
2676
+ };
2677
+ // (those that read no param once)
2678
+ const readsParams = (f) => m.params.some(p => JSON.stringify(f.holds).includes(`"name":${JSON.stringify(p)}`));
2679
+ let alone;
2680
+ const factsHold = (params) => (alone ??= facts.filter(f => !readsParams(f)).every(f => holds(f, params)))
2681
+ && facts.filter(readsParams).every(f => holds(f, params));
2654
2682
  try {
2655
2683
  for (let trial = 0; trial < budget.trials && performance.now() < until; trial++) {
2656
2684
  const params = r.randomParams(rand, bound);
2657
- if (m.pre && !evalC(m.pre, params, { scalars: {}, maps: {} }, m))
2685
+ if (m.pre && !evalC(m.pre, params, { scalars: {}, maps: {} }, m) || !factsHold(params))
2658
2686
  continue;
2659
2687
  const watching = [...laws, ...stepLaws].map(w => ({ w, on: watch(m, run, w, params, bound) }));
2660
2688
  let st = run.init(params);
@@ -2686,7 +2714,7 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
2686
2714
  const wide = Object.keys(m.state).length + m.inputs.length >= 32, lawsHere = wide ? given : [], kinded = wide ? r.kindsOfState() : [];
2687
2715
  for (let trial = 0; !m.history && (steps1.length || lawsHere.length) && trial < budget.trials * 4 && performance.now() < until; trial++) {
2688
2716
  const params = r.randomParams(rand, bound);
2689
- if (m.pre && !evalC(m.pre, params, { scalars: {}, maps: {} }, m))
2717
+ if (m.pre && !evalC(m.pre, params, { scalars: {}, maps: {} }, m) || !factsHold(params))
2690
2718
  continue;
2691
2719
  const scalars = Object.fromEntries(Object.keys(m.state).map(n => [n, rand(8)]));
2692
2720
  for (const [n, k] of kinded)
@@ -2719,8 +2747,11 @@ const noting = (r, ...xs) => { const ks = divisorsIn(xs); if (ks.size)
2719
2747
  export function proveRule(r, laws, opts = {}) {
2720
2748
  noting(r, laws);
2721
2749
  const refuted = refuteByRuns(r, laws);
2750
+ // A state the laws allow whose step breaks one, with no run to it (a wide rule's: what the kernel's step goal would end
2751
+ // at), is a counterexample to induction: the laws may still hold, so the search goes on from it, as from the kernel's.
2752
+ // (A step law broken so is refused, proveSteps below: it holds from every state the laws allow, reached or not.)
2722
2753
  if (refuted)
2723
- return refutedVerdict(refuted);
2754
+ return refuted.run ? refutedVerdict(refuted) : searched(r, laws, [], refutedVerdict(refuted), opts);
2724
2755
  const out = proveLaws(r.machine, withKinds(r, laws));
2725
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 } : {}) };
2726
2757
  return searched(r, laws, [], v, opts);
@@ -2744,6 +2775,25 @@ function searched(r, laws, stepLaws, v, opts) {
2744
2775
  if (deeper?.run)
2745
2776
  return refutedVerdict(deeper);
2746
2777
  const until = performance.now() + (typeof opts.search === 'object' && opts.search.ms !== undefined ? opts.search.ms : 10_000);
2778
+ // 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
+ let reached = 0;
2784
+ const bounded = (ms, from) => findBoundedRun(r.machine, laws, { ms, wall: performance.now() + ms, from, progress: k => { reached = k; } });
2785
+ 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
+ const shallow = bounded(Math.min(250, total / 40), 1);
2787
+ if (shallow)
2788
+ return refutedBy(shallow);
2789
+ // 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).
2791
+ if (!stepLaws.length && laws.every(l => !l.forall && !l.keys?.length && !l.some?.length)) {
2792
+ 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 });
2794
+ if (kd.proven && kd.checked)
2795
+ return { proven: true, checked: true, k: kd.k };
2796
+ }
2747
2797
  let rule = r, lemmas;
2748
2798
  const { fns, lists } = r.parts;
2749
2799
  if (lists.length || fns.some(([, d]) => recurOf(d))) {
@@ -2760,12 +2810,16 @@ function searched(r, laws, stepLaws, v, opts) {
2760
2810
  if (c.proven && c.checked)
2761
2811
  return { proven: true, checked: true, found: { ...(lemmas ? { lemmas } : {}), facts: c.found.map(f => f.text) } };
2762
2812
  }
2763
- const ms = until - performance.now();
2813
+ const ms = until - performance.now() - tail;
2764
2814
  if (ms < 500)
2765
2815
  return v;
2766
2816
  const inf = inferLaws(rule, laws, stepLaws, { ms, ...(rule === r ? { first: v } : {}) });
2767
- if (!(inf.proven && inf.checked))
2817
+ if (!(inf.proven && inf.checked)) {
2818
+ const deep = bounded(Math.max(0, until - performance.now()), Math.max(1, reached));
2819
+ if (deep)
2820
+ return refutedBy(deep);
2768
2821
  return { ...v, why: [v.why, `the search found nothing that proves it in ${Math.round(inf.stats.ms)} ms`].filter(Boolean).join('; ') };
2822
+ }
2769
2823
  const { found, stats: _stats, ...verdict } = inf;
2770
2824
  void _stats;
2771
2825
  return { ...verdict, found: { laws: found, ...(lemmas ? { lemmas } : {}) } };
@@ -2782,7 +2836,12 @@ export function proveLeadsTo(r, laws, l, opts = {}) {
2782
2836
  const out = proveLiveness(r.machine, withKinds(r, laws), l);
2783
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 } : {}) } : {}) };
2784
2838
  }
2785
- export const proveDecision = (d) => (d.steps ? proveSteps(d.steps.rule, [], [d.steps.law], { search: false }) : goalsVerdict([d.goal]));
2839
+ // `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
+ // prover reads (the counted one inside a counted search): past it the verdict is unknown.
2841
+ export const proveDecision = (d, opts = {}) => {
2842
+ const go = () => (d.steps ? proveSteps(d.steps.rule, [], [d.steps.law], { search: false }) : goalsVerdict([d.goal]));
2843
+ return opts.ms === undefined ? go() : withDeadline(clock() + opts.ms, go);
2844
+ };
2786
2845
  const seeded = (seed) => { let x = seed; return k => { x = (x * 1103515245 + 12345) % 2 ** 31; return Math.floor(x / 2 ** 31 * k); }; };
2787
2846
  // A decision's callbacks against its condition, on random params and requests: `given` and `then` each run with every
2788
2847
  // value known, against what the interpreter evaluates of the decision built from them.
@@ -2829,6 +2888,13 @@ export const proveLoop = (l, laws, opts = {}) => {
2829
2888
  return { proven: out.proven, checked: out.checked, ...(out.trees ? { trees: out.trees } : {}), ...(out.goal ? { goal: out.goal, stuck: out.stuck } : {}), ...(out.witness ? { witness: out.witness } : {}), ...(out.why ? { why: out.why } : {}),
2830
2889
  ...(out.found ? { found: { rank: out.found.rank, ...(out.laws?.length ? { laws: out.laws.map((law, i) => ({ law, text: out.found.laws[i] ?? law.name })) } : {}) } } : {}) };
2831
2890
  };
2891
+ export function proveNeverEnds(l, opts = {}) {
2892
+ const loop = (opts.from ? l.pre(opts.from) : l).loop;
2893
+ const f = findNeverEnds(loop, { ms: opts.ms ?? 10_000 });
2894
+ if (!f.recur)
2895
+ return { proven: false, checked: false, ...(f.why ? { why: f.why } : {}), loop };
2896
+ return { proven: f.proven, checked: f.checked && checkRecur(loop, f.recur), recur: f.recur, loop, ...(f.by ? { by: f.by } : {}), run: { params: f.recur.start, trace: f.recur.stem } };
2897
+ }
2832
2898
  export class FoldRule {
2833
2899
  spec;
2834
2900
  constructor(spec) {
@@ -0,0 +1,77 @@
1
+ type Context = Record<string, unknown>;
2
+ import { type Kind, type Rule } from './dsl.js';
3
+ import { type Model, type Var } from './extract-read.js';
4
+ import * as I from './extract-ir.js';
5
+ import type { B, N } from './extract-ir.js';
6
+ import type { Sorts } from './extract-print.js';
7
+ type Raw = number | boolean | string;
8
+ export type Arm = {
9
+ label: string;
10
+ where: string;
11
+ pos: number;
12
+ };
13
+ export type Coverage = {
14
+ arms: number;
15
+ hit: number;
16
+ missed: string[];
17
+ };
18
+ export type Evidence = {
19
+ runs: number;
20
+ requests: number;
21
+ fromStates: number;
22
+ probes: {
23
+ conditions: number;
24
+ witnesses: number;
25
+ steps: number;
26
+ };
27
+ refusedBoth: number;
28
+ outside: number;
29
+ edge: number;
30
+ edgeSample?: string;
31
+ compiledAgreed: number;
32
+ coverage: Coverage;
33
+ ms: number;
34
+ mismatch?: string;
35
+ };
36
+ export declare function instrument(code: string, file: string, tail?: string): {
37
+ js: string;
38
+ arms: Arm[];
39
+ };
40
+ export type Sandbox = {
41
+ ctx: Context;
42
+ counts: number[];
43
+ call: (f: string, self: unknown, args: unknown[]) => {
44
+ ok: true;
45
+ value: unknown;
46
+ } | {
47
+ ok: false;
48
+ error: string;
49
+ };
50
+ setNow: (n: number) => void;
51
+ get: (name: string) => unknown;
52
+ };
53
+ export declare function sandbox(code: string, file: string, expose: string[], modules?: Record<string, unknown>, init?: string, files?: Record<string, string>): Sandbox & {
54
+ arms: Arm[];
55
+ };
56
+ type Cells = Record<string, Record<string, Raw>>;
57
+ export type Snap = {
58
+ leaves: Record<string, Raw>;
59
+ maps: Record<string, Cells>;
60
+ };
61
+ export declare const kindOfVar: (v: Var, sorts: Sorts, at?: string) => Kind<unknown>;
62
+ export type CheckOptions = {
63
+ runs?: number;
64
+ depth?: number;
65
+ states?: number;
66
+ seed?: number;
67
+ bound?: number;
68
+ probes?: boolean;
69
+ probeMs?: number;
70
+ modules?: Record<string, unknown>;
71
+ files?: Record<string, string>;
72
+ };
73
+ export declare function check(code: string, file: string, m: Model, r: Rule, sorts: Sorts, opts?: CheckOptions & {
74
+ given?: Record<string, 'nat' | 'int'>;
75
+ }): Evidence;
76
+ export declare function evalTerm(t: N | B | I.L, env: Record<string, Raw>): Raw;
77
+ export {};