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,139 @@
1
+ export type N = {
2
+ op: 'var';
3
+ name: string;
4
+ } | {
5
+ op: 'const';
6
+ v: number;
7
+ } | {
8
+ op: 'add' | 'sub' | 'min' | 'max' | 'mul';
9
+ a: N;
10
+ b: N;
11
+ } | {
12
+ op: 'neg';
13
+ a: N;
14
+ } | {
15
+ op: 'mulk';
16
+ k: number;
17
+ a: N;
18
+ } | {
19
+ op: 'divk' | 'modk';
20
+ k: number;
21
+ a: N;
22
+ } | {
23
+ op: 'ite';
24
+ c: B;
25
+ a: N;
26
+ b: N;
27
+ } | {
28
+ op: 'cell';
29
+ map: string;
30
+ key: K;
31
+ field: string;
32
+ };
33
+ export type B = {
34
+ op: 'const';
35
+ v: boolean;
36
+ } | {
37
+ op: 'var';
38
+ name: string;
39
+ } | {
40
+ op: 'cmp';
41
+ rel: '<' | '<=' | '=';
42
+ a: N;
43
+ b: N;
44
+ } | {
45
+ op: 'and' | 'or';
46
+ xs: B[];
47
+ } | {
48
+ op: 'not';
49
+ x: B;
50
+ } | {
51
+ op: 'ite';
52
+ c: B;
53
+ a: B;
54
+ b: B;
55
+ } | {
56
+ op: 'is';
57
+ l: L;
58
+ value: string;
59
+ } | {
60
+ op: 'leq';
61
+ a: L;
62
+ b: L;
63
+ } | {
64
+ op: 'keq';
65
+ a: K;
66
+ b: K;
67
+ } | {
68
+ op: 'cell';
69
+ map: string;
70
+ key: K;
71
+ field: string;
72
+ };
73
+ export type L = {
74
+ op: 'var';
75
+ name: string;
76
+ values: string[];
77
+ } | {
78
+ op: 'lit';
79
+ value: string;
80
+ values: string[];
81
+ } | {
82
+ op: 'ite';
83
+ c: B;
84
+ a: L;
85
+ b: L;
86
+ } | {
87
+ op: 'cell';
88
+ map: string;
89
+ key: K;
90
+ field: string;
91
+ values: string[];
92
+ };
93
+ export type K = {
94
+ op: 'num';
95
+ e: N;
96
+ } | {
97
+ op: 'svar';
98
+ name: string;
99
+ } | {
100
+ op: 'slit';
101
+ value: string;
102
+ } | {
103
+ op: 'kite';
104
+ c: B;
105
+ a: K;
106
+ b: K;
107
+ };
108
+ export declare const keyOf: (x: object) => string;
109
+ export declare const same: (a: object, b: object) => boolean;
110
+ export declare const num: (v: number) => N;
111
+ export declare const nvar: (name: string) => N;
112
+ export declare const add: (a: N, b: N) => N;
113
+ export declare const sub: (a: N, b: N) => N;
114
+ export declare const neg: (a: N) => N;
115
+ export declare const mulk: (k: number, a: N) => N;
116
+ export declare const mul: (a: N, b: N) => N;
117
+ export declare const nmin: (a: N, b: N) => N;
118
+ export declare const nmax: (a: N, b: N) => N;
119
+ export declare const divk: (k: number, a: N) => N;
120
+ export declare const modk: (k: number, a: N) => N;
121
+ export declare const nite: (c: B, a: N, b: N) => N;
122
+ export declare const T: B;
123
+ export declare const F: B;
124
+ export declare const bvar: (name: string) => B;
125
+ export declare const cmp: (rel: "<" | "<=" | "=", a: N, b: N) => B;
126
+ export declare const and: (...xs: B[]) => B;
127
+ export declare const or: (...xs: B[]) => B;
128
+ export declare const not: (x: B) => B;
129
+ export declare const bite: (c: B, a: B, b: B) => B;
130
+ export declare const llit: (value: string, values: string[]) => L;
131
+ export declare const lite: (c: B, a: L, b: L) => L;
132
+ export declare const is: (l: L, value: string) => B;
133
+ export declare const leq: (a: L, b: L) => B;
134
+ export declare const kite: (c: B, a: K, b: K) => K;
135
+ export declare const keq: (a: K, b: K) => B;
136
+ export declare function varsOf(x: N | B | L | K, out?: Set<string>, maps?: Set<string>): {
137
+ vars: Set<string>;
138
+ maps: Set<string>;
139
+ };
@@ -0,0 +1,198 @@
1
+ // Structural keys (memoized: the same object is compared many times while paths merge).
2
+ const keys = new WeakMap();
3
+ export const keyOf = (x) => {
4
+ let k = keys.get(x);
5
+ if (k === undefined) {
6
+ k = JSON.stringify(x);
7
+ keys.set(x, k);
8
+ }
9
+ return k;
10
+ };
11
+ export const same = (a, b) => a === b || keyOf(a) === keyOf(b);
12
+ // --- numbers --------------------------------------------------------------------------------------------------------
13
+ export const num = (v) => ({ op: 'const', v });
14
+ export const nvar = (name) => ({ op: 'var', name });
15
+ const isC = (e) => e.op === 'const';
16
+ export const add = (a, b) => (isC(a) && isC(b) ? num(a.v + b.v) : isC(a) && a.v === 0 ? b : isC(b) && b.v === 0 ? a : { op: 'add', a, b });
17
+ export const sub = (a, b) => (isC(a) && isC(b) ? num(a.v - b.v) : isC(b) && b.v === 0 ? a : same(a, b) ? num(0) : { op: 'sub', a, b });
18
+ export const neg = (a) => (isC(a) ? num(-a.v) : a.op === 'neg' ? a.a : { op: 'neg', a });
19
+ export const mulk = (k, a) => (k === 0 ? num(0) : k === 1 ? a : isC(a) ? num(k * a.v) : { op: 'mulk', k, a });
20
+ export const mul = (a, b) => (isC(a) ? mulk(a.v, b) : isC(b) ? mulk(b.v, a) : { op: 'mul', a, b });
21
+ export const nmin = (a, b) => (isC(a) && isC(b) ? num(Math.min(a.v, b.v)) : same(a, b) ? a : { op: 'min', a, b });
22
+ export const nmax = (a, b) => (isC(a) && isC(b) ? num(Math.max(a.v, b.v)) : same(a, b) ? a : { op: 'max', a, b });
23
+ export const divk = (k, a) => (k === 1 ? a : isC(a) ? num(Math.floor(a.v / k)) : { op: 'divk', k, a });
24
+ export const modk = (k, a) => (k === 1 ? num(0) : isC(a) && a.v >= 0 ? num(a.v % k) : { op: 'modk', k, a });
25
+ export const nite = (c, a, b) => (c.op === 'const' ? (c.v ? a : b) : same(a, b) ? a : c.op === 'not' ? nite(c.x, b, a) : { op: 'ite', c, a, b });
26
+ // --- conditions -----------------------------------------------------------------------------------------------------
27
+ export const T = { op: 'const', v: true };
28
+ export const F = { op: 'const', v: false };
29
+ export const bvar = (name) => ({ op: 'var', name });
30
+ export const cmp = (rel, a, b) => {
31
+ if (isC(a) && isC(b))
32
+ return rel === '<' ? (a.v < b.v ? T : F) : rel === '<=' ? (a.v <= b.v ? T : F) : a.v === b.v ? T : F;
33
+ if (same(a, b))
34
+ return rel === '<' ? F : T;
35
+ return { op: 'cmp', rel, a, b };
36
+ };
37
+ export const and = (...xs) => {
38
+ const out = [];
39
+ for (const x of xs.flatMap(x => (x.op === 'and' ? x.xs : [x]))) {
40
+ if (x.op === 'const') {
41
+ if (!x.v)
42
+ return F;
43
+ continue;
44
+ }
45
+ if (out.some(y => same(x, y)))
46
+ continue;
47
+ if (out.some(y => (y.op === 'not' && same(y.x, x)) || (x.op === 'not' && same(x.x, y))))
48
+ return F;
49
+ out.push(x);
50
+ }
51
+ // A choice is one value at a time: two values contradict, and one implies it is none of the others.
52
+ const iss = out.filter((x) => x.op === 'is');
53
+ if (iss.some(a => iss.some(b => b.value !== a.value && same(a.l, b.l))))
54
+ return F;
55
+ const kept = out.filter(x => !(x.op === 'not' && x.x.op === 'is' && iss.some(a => same(a.l, x.x.l) && a.value !== x.x.value)));
56
+ return kept.length === 0 ? T : kept.length === 1 ? kept[0] : { op: 'and', xs: kept };
57
+ };
58
+ export const or = (...xs) => {
59
+ const out = [];
60
+ for (const x of xs.flatMap(x => (x.op === 'or' ? x.xs : [x]))) {
61
+ if (x.op === 'const') {
62
+ if (x.v)
63
+ return T;
64
+ continue;
65
+ }
66
+ if (out.some(y => same(x, y)))
67
+ continue;
68
+ if (out.some(y => (y.op === 'not' && same(y.x, x)) || (x.op === 'not' && same(x.x, y))))
69
+ return T;
70
+ out.push(x);
71
+ }
72
+ // Absorption: a ∨ (¬a ∧ b) is a ∨ b.
73
+ for (let i = 0; i < out.length; i++) {
74
+ const d = out[i];
75
+ if (d.op !== 'and')
76
+ continue;
77
+ const parts = d.xs.filter(x => !out.some((y, j) => j !== i && x.op === 'not' && same(x.x, y)));
78
+ if (parts.length !== d.xs.length) {
79
+ out[i] = and(...parts);
80
+ return or(...out);
81
+ }
82
+ }
83
+ // A choice is one of its values: all of them together always hold.
84
+ const iss = out.filter((x) => x.op === 'is' && x.l.op === 'var');
85
+ for (const a of iss) {
86
+ const l = a.l;
87
+ if (l.values.every(v => iss.some(b => b.value === v && same(b.l, l))))
88
+ return T;
89
+ }
90
+ return out.length === 0 ? F : out.length === 1 ? out[0] : { op: 'or', xs: out };
91
+ };
92
+ export const not = (x) => (x.op === 'const' ? (x.v ? F : T) : x.op === 'not' ? x.x : { op: 'not', x });
93
+ export const bite = (c, a, b) => {
94
+ if (c.op === 'const')
95
+ return c.v ? a : b;
96
+ if (same(a, b))
97
+ return a;
98
+ if (a.op === 'const' && b.op === 'const')
99
+ return a.v ? c : not(c);
100
+ // A branch that is the condition, or its negation: c ? a : ¬c is a ∨ ¬c, c ? a : c is c ∧ a, and so on.
101
+ if (same(b, not(c)))
102
+ return or(not(c), a);
103
+ if (same(b, c))
104
+ return and(c, a);
105
+ if (same(a, c))
106
+ return or(c, b);
107
+ if (same(a, not(c)))
108
+ return and(not(c), b);
109
+ if (a.op === 'const')
110
+ return a.v ? or(c, b) : and(not(c), b);
111
+ if (b.op === 'const')
112
+ return b.v ? or(not(c), a) : and(c, a);
113
+ return { op: 'ite', c, a, b };
114
+ };
115
+ // --- choices and keys -----------------------------------------------------------------------------------------------
116
+ export const llit = (value, values) => ({ op: 'lit', value, values });
117
+ export const lite = (c, a, b) => (c.op === 'const' ? (c.v ? a : b) : same(a, b) ? a : c.op === 'not' ? lite(c.x, b, a) : { op: 'ite', c, a, b });
118
+ export const is = (l, value) => {
119
+ if (l.op === 'lit')
120
+ return l.value === value ? T : F;
121
+ if (l.op === 'ite')
122
+ return bite(l.c, is(l.a, value), is(l.b, value));
123
+ return { op: 'is', l, value };
124
+ };
125
+ export const leq = (a, b) => (a.op === 'lit' ? is(b, a.value) : b.op === 'lit' ? is(a, b.value) : same(a, b) ? T : { op: 'leq', a, b });
126
+ export const kite = (c, a, b) => (c.op === 'const' ? (c.v ? a : b) : same(a, b) ? a : { op: 'kite', c, a, b });
127
+ export const keq = (a, b) => {
128
+ if (same(a, b))
129
+ return T;
130
+ if (a.op === 'kite')
131
+ return bite(a.c, keq(a.a, b), keq(a.b, b));
132
+ if (b.op === 'kite')
133
+ return bite(b.c, keq(a, b.a), keq(a, b.b));
134
+ if (a.op === 'num' && b.op === 'num')
135
+ return cmp('=', a.e, b.e);
136
+ if (a.op === 'slit' && b.op === 'slit')
137
+ return a.value === b.value ? T : F;
138
+ if (a.op === 'num' || b.op === 'num')
139
+ return F;
140
+ return { op: 'keq', a, b };
141
+ };
142
+ // The variables a term reads, and the maps.
143
+ export function varsOf(x, out = new Set(), maps = new Set()) {
144
+ const go = (y) => {
145
+ switch (y.op) {
146
+ case 'var':
147
+ case 'svar':
148
+ out.add(y.name);
149
+ return;
150
+ case 'const':
151
+ case 'lit':
152
+ case 'slit': return;
153
+ case 'num': return go(y.e);
154
+ case 'add':
155
+ case 'sub':
156
+ case 'min':
157
+ case 'max':
158
+ case 'mul':
159
+ go(y.a);
160
+ go(y.b);
161
+ return;
162
+ case 'neg':
163
+ case 'mulk':
164
+ case 'divk':
165
+ case 'modk':
166
+ go(y.a);
167
+ return;
168
+ case 'ite':
169
+ case 'kite':
170
+ go(y.c);
171
+ go(y.a);
172
+ go(y.b);
173
+ return;
174
+ case 'cell':
175
+ maps.add(y.map);
176
+ go(y.key);
177
+ return;
178
+ case 'cmp':
179
+ case 'leq':
180
+ case 'keq':
181
+ go(y.a);
182
+ go(y.b);
183
+ return;
184
+ case 'and':
185
+ case 'or':
186
+ y.xs.forEach(go);
187
+ return;
188
+ case 'not':
189
+ go(y.x);
190
+ return;
191
+ case 'is':
192
+ go(y.l);
193
+ return;
194
+ }
195
+ };
196
+ go(x);
197
+ return { vars: out, maps };
198
+ }
@@ -0,0 +1,30 @@
1
+ import type { B, K, L, N } from './extract-ir.js';
2
+ import type { MapDecl, Model, Term, Var } from './extract-read.js';
3
+ export type Sorts = Map<string, 'nat' | 'int'>;
4
+ type Ctx = {
5
+ m: Model;
6
+ sorts: Sorts;
7
+ atoms: B[];
8
+ };
9
+ export declare function nonneg(e: N, ctx: Ctx): boolean;
10
+ export declare const decided: (c: B, ctx: Ctx) => boolean | undefined;
11
+ export declare function natOK(e: N, ctx: Ctx): boolean;
12
+ export declare function sortsOf(m: Model, given?: Record<string, 'nat' | 'int'>): {
13
+ sorts: Sorts;
14
+ notes: string[];
15
+ };
16
+ export type Printer = {
17
+ sorts: Sorts;
18
+ m: Model;
19
+ hoisted: Map<string, string>;
20
+ choiceVars: Map<string, string>;
21
+ };
22
+ export declare const pnum: (e: N, P: Printer, ctx: Ctx, recv?: boolean) => string;
23
+ export declare function pb(c: B, P: Printer, ctx: Ctx): string;
24
+ export declare function pl(l: L, P: Printer, ctx: Ctx, bare?: boolean): string;
25
+ export declare function pk(k: K, P: Printer, ctx: Ctx): string;
26
+ export declare function pterm(t: Term, P: Printer, ctx: Ctx, target?: string): string;
27
+ export declare const kindOf: (v: Var, sorts: Sorts, at?: string) => string;
28
+ export declare const mapKind: (d: MapDecl, sorts: Sorts) => string;
29
+ export declare const mapEmpty: (d: MapDecl) => string;
30
+ export type { Ctx };