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
@@ -0,0 +1,81 @@
1
+ import { checkKInduction, historyMachine, kInductionStart, kInductionSteps, stepLawObligations } from "../kernel/kernel.js";
2
+ import { clock, counted, grow, proveLaws } from "../kernel/prove.js";
3
+ import { REFUTED, growCdcl } from "../kernel/cdcl.js";
4
+ import { quietly } from "./cyclic.js";
5
+ // Machines whose k-step goals need no instances: no map a law or fact reads at keys, no flag that holds at every key.
6
+ export const kindFits = (m, laws, law) => {
7
+ const plain = m.history ? historyMachine(m).machine : m;
8
+ return !Object.values(plain.step.flags ?? {}).some(c => c.op === 'all') && !plain.inputMaps?.length && [...laws, law, ...(plain.facts ?? [])].every(l => !l.forall && !l.keys?.length && !l.some?.length);
9
+ };
10
+ // The laws as one: their conjunction, named by them.
11
+ export const conjunction = (laws) => (laws.length === 1 ? laws[0] : { name: laws.map(l => l.name).join(' and '), holds: { op: 'and', xs: laws.map(l => l.holds) } });
12
+ export function proveKInduction(m, laws, law, opts) {
13
+ const depths = [];
14
+ if (!kindFits(m, laws, law))
15
+ return { proven: false, checked: false, depths, why: 'a law or fact about every key, a flag at every key, or a carried map' };
16
+ return counted(opts.rate ?? 200, () => {
17
+ const until = clock() + opts.ms, over = () => clock() > until || (opts.wall !== undefined && performance.now() > opts.wall);
18
+ // A goal's tree: CDCL's, unfolded (prove.ts's grow keeps CDCL off a goal over k steps, for the size of the tree its
19
+ // cuts would make smaller; but here the plain search's cases multiply with every step), else the plain search's.
20
+ const treeOf = (g) => {
21
+ const c = growCdcl(g, new Map(), { nodes: 0, until }, opts.wall !== undefined ? { wall: opts.wall } : {});
22
+ if ('tree' in c || c.stuck === 'sat' || over())
23
+ return c;
24
+ return grow(g, new Map(), { nodes: 0, until });
25
+ };
26
+ const trees = {}, assumed = laws;
27
+ // The laws it assumes (their usual proof: no cyclic certificate is made for it here, checkKInduction reads the usual
28
+ // trees) and the start goal: once, after the first step goal refuted (a step goal is decided over them as
29
+ // hypotheses; only a certificate needs their proof).
30
+ let base;
31
+ const prepared = () => {
32
+ if (base)
33
+ return undefined;
34
+ base = quietly(() => proveLaws(m, laws));
35
+ if (!base.proven || !base.checked || !base.proof)
36
+ return 'the laws it assumes are not proven';
37
+ const start = kInductionStart(m, { law, k: 1 }, {}), s0 = treeOf(start);
38
+ if (!('tree' in s0))
39
+ return `${start.name}: ${s0.stuck}`;
40
+ trees[start.name] = s0.tree;
41
+ return undefined;
42
+ };
43
+ for (let k = Math.max(1, opts.from ?? 2); k <= Math.min(64, opts.to ?? 64) && !over(); k++) {
44
+ const t0 = clock(), kl = { law, k }, steps = kInductionSteps(m, kl), last = steps.at(-1);
45
+ const goal = stepLawObligations(m, assumed, {}, last)[0];
46
+ const decided = growCdcl(goal, new Map(), { nodes: 0, until }, { model: true, ...(opts.wall !== undefined ? { wall: opts.wall } : {}) });
47
+ if (!('tree' in decided) && decided.why !== REFUTED) {
48
+ depths.push([k, decided.stuck[0], Math.round(clock() - t0)]);
49
+ if (decided.stuck === 'sat')
50
+ continue;
51
+ return { proven: false, checked: false, depths, why: `${goal.name}: unknown` };
52
+ }
53
+ const why = prepared();
54
+ if (why) {
55
+ depths.push([k, 'r', Math.round(clock() - t0)]);
56
+ return { proven: false, checked: false, depths, why };
57
+ }
58
+ const st = treeOf(goal);
59
+ if (!('tree' in st)) {
60
+ depths.push([k, 't', Math.round(clock() - t0)]);
61
+ return { proven: false, checked: false, depths, why: `${goal.name}: refuted, but no tree within the budget` };
62
+ }
63
+ depths.push([k, 'r', Math.round(clock() - t0)]);
64
+ trees[goal.name] = st.tree;
65
+ // The base, from the start: each depth below k (grown once, whatever k).
66
+ for (const sl of steps.slice(0, -1)) {
67
+ const g = stepLawObligations(m, assumed, {}, sl)[0];
68
+ if (trees[g.name])
69
+ continue;
70
+ const b = treeOf(g);
71
+ if (!('tree' in b))
72
+ return { proven: false, checked: false, depths, why: `${g.name}: ${b.stuck === 'sat' ? 'a run from the start breaks it' : 'unknown'}` };
73
+ trees[g.name] = b.tree;
74
+ }
75
+ const proof = { laws: base.proof, instances: {}, trees };
76
+ const checked = checkKInduction(m, assumed, kl, proof);
77
+ return { proven: true, checked, k, kl, proof, laws: assumed, depths };
78
+ }
79
+ return { proven: false, checked: false, depths, why: 'no k within the budget' };
80
+ });
81
+ }
@@ -0,0 +1,34 @@
1
+ import type { C, E } from './machine.js';
2
+ import { type Loop, type Recur } from '../kernel/kernel.js';
3
+ export type NeverEndsOptions = {
4
+ ms?: number;
5
+ seed?: number;
6
+ maxTurns?: number;
7
+ lassos?: boolean;
8
+ counted?: number;
9
+ };
10
+ export type NeverEndsVerdict = {
11
+ proven: boolean;
12
+ checked: boolean;
13
+ recur?: Recur;
14
+ by?: 'lasso' | 'policy lasso' | 'recurrent set';
15
+ why?: string;
16
+ lasso?: {
17
+ params: Record<string, number>;
18
+ stem: Record<string, number>[];
19
+ cycle: Record<string, number>[];
20
+ };
21
+ stats: {
22
+ runs: number;
23
+ turns: number;
24
+ policies: number;
25
+ rounds: number;
26
+ ms: number;
27
+ lassoTried: number;
28
+ goalSize: number;
29
+ };
30
+ };
31
+ export declare const simpE: (e: E) => E;
32
+ export declare const simpC: (c: C) => C;
33
+ export declare function goalSize(x: unknown): number;
34
+ export declare function findNeverEnds(l: Loop, opts?: NeverEndsOptions): NeverEndsVerdict;