gdp-wired 0.3.0 → 0.5.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.
- package/README.md +109 -113
- package/dist/core/dsl.d.ts +210 -9
- package/dist/core/dsl.js +799 -78
- package/dist/core/watch.d.ts +14 -0
- package/dist/core/watch.js +78 -0
- package/dist/kernel/kernel.d.ts +7 -0
- package/dist/kernel/kernel.js +121 -11
- package/dist/kernel/prove.d.ts +3 -0
- package/dist/kernel/prove.js +190 -51
- package/dist/lean-kernel/emit.d.ts +2 -10
- package/dist/lean-kernel/emit.js +164 -201
- package/dist/lean-kernel/library.js +5 -5
- package/package.json +2 -2
package/dist/core/dsl.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ export type TermLike = Term | number;
|
|
|
4
4
|
export declare const termOf: (t: TermLike) => E;
|
|
5
5
|
export declare class Term {
|
|
6
6
|
readonly e: E;
|
|
7
|
-
|
|
7
|
+
readonly val?: number | undefined;
|
|
8
|
+
constructor(e: E, val?: number | undefined);
|
|
8
9
|
plus(b: TermLike): Term;
|
|
9
10
|
minus(b: TermLike): Term;
|
|
10
11
|
times(k: number): Term;
|
|
@@ -18,7 +19,8 @@ export declare class Term {
|
|
|
18
19
|
}
|
|
19
20
|
export declare class Cond {
|
|
20
21
|
readonly c: C;
|
|
21
|
-
|
|
22
|
+
readonly ok?: boolean | undefined;
|
|
23
|
+
constructor(c: C, ok?: boolean | undefined);
|
|
22
24
|
and(...xs: Cond[]): Cond;
|
|
23
25
|
or(...xs: Cond[]): Cond;
|
|
24
26
|
not(): Cond;
|
|
@@ -33,19 +35,79 @@ export declare const any: (...cs: Cond[]) => Cond;
|
|
|
33
35
|
export declare const not: (c: Cond) => Cond;
|
|
34
36
|
export declare const min: (a: TermLike, b: TermLike) => Term;
|
|
35
37
|
export declare const max: (a: TermLike, b: TermLike) => Term;
|
|
36
|
-
export declare
|
|
38
|
+
export declare function when(c: Cond, then: TermLike, otherwise: TermLike): Term;
|
|
39
|
+
export declare function when(c: Cond, then: Decimal, otherwise: Decimal | number): Decimal;
|
|
40
|
+
export declare function when(c: Cond, then: Decimal | number, otherwise: Decimal): Decimal;
|
|
41
|
+
export declare function when(c: Cond, then: IntLike, otherwise: IntLike): Int;
|
|
42
|
+
export declare function when<K extends string>(c: Cond, then: Choice<K>, otherwise: Choice<K>): Choice<K>;
|
|
43
|
+
export declare function when(c: Cond, then: Str, otherwise: Str): Str;
|
|
44
|
+
export declare function when<V>(c: Cond, then: Maybe<V>, otherwise: Maybe<V>): Maybe<V>;
|
|
45
|
+
export declare function when(c: Cond, then: Cond, otherwise: Cond): Cond;
|
|
37
46
|
export declare const choose: (c: Cond, then: Cond, otherwise: Cond) => Cond;
|
|
38
47
|
export declare const count: (c: Cond) => Term;
|
|
39
48
|
export declare const sum: (first: TermLike, ...rest: TermLike[]) => Term;
|
|
40
49
|
type Rand = (k: number) => number;
|
|
41
50
|
type Raw = number | boolean | string | null | undefined;
|
|
51
|
+
export type At = string | ((name: string) => string);
|
|
52
|
+
export type Init<V> = {
|
|
53
|
+
readonly kind: Kind<V>;
|
|
54
|
+
readonly init: Raw | ((p: never) => unknown);
|
|
55
|
+
};
|
|
42
56
|
export declare abstract class Kind<V> {
|
|
43
57
|
readonly _value: V;
|
|
44
58
|
abstract vars(name: string): string[];
|
|
45
59
|
abstract assume(name: string): Cond[];
|
|
46
|
-
abstract value(name: string,
|
|
60
|
+
abstract value(name: string, at?: At): V;
|
|
47
61
|
abstract encode(name: string, raw: Raw): Record<string, number>;
|
|
48
62
|
abstract random(name: string, rand: Rand, bound: number): Record<string, number>;
|
|
63
|
+
abstract store(name: string, value: unknown): Record<string, TermLike>;
|
|
64
|
+
abstract decode(name: string, vars: Record<string, number>): Raw;
|
|
65
|
+
abstract empty(): Raw;
|
|
66
|
+
sample(_rand: Rand, _bound: number): Raw;
|
|
67
|
+
from(init: Raw | ((p: never) => unknown)): Init<V>;
|
|
68
|
+
}
|
|
69
|
+
export type IntLike = Int | Term | number;
|
|
70
|
+
export declare class Int {
|
|
71
|
+
readonly pos: Term;
|
|
72
|
+
readonly neg: Term;
|
|
73
|
+
constructor(pos: Term, neg: Term);
|
|
74
|
+
static of(x: IntLike): Int;
|
|
75
|
+
plus(b: IntLike): Int;
|
|
76
|
+
minus(b: IntLike): Int;
|
|
77
|
+
negate(): Int;
|
|
78
|
+
times(k: number): Int;
|
|
79
|
+
lt(b: IntLike): Cond;
|
|
80
|
+
atMost(b: IntLike): Cond;
|
|
81
|
+
gt(b: IntLike): Cond;
|
|
82
|
+
atLeast(b: IntLike): Cond;
|
|
83
|
+
eq(b: IntLike): Cond;
|
|
84
|
+
ne(b: IntLike): Cond;
|
|
85
|
+
min(b: IntLike): Int;
|
|
86
|
+
max(b: IntLike): Int;
|
|
87
|
+
get isNegative(): Cond;
|
|
88
|
+
get abs(): Term;
|
|
89
|
+
get clamped(): Term;
|
|
90
|
+
}
|
|
91
|
+
export type DecimalLike = Decimal | IntLike;
|
|
92
|
+
export declare class Decimal {
|
|
93
|
+
readonly int: Int;
|
|
94
|
+
readonly places: number;
|
|
95
|
+
constructor(int: Int, places: number);
|
|
96
|
+
lift(b: DecimalLike): Int;
|
|
97
|
+
private with;
|
|
98
|
+
plus(b: DecimalLike): Decimal;
|
|
99
|
+
minus(b: DecimalLike): Decimal;
|
|
100
|
+
negate(): Decimal;
|
|
101
|
+
times(k: number): Decimal;
|
|
102
|
+
lt(b: DecimalLike): Cond;
|
|
103
|
+
atMost(b: DecimalLike): Cond;
|
|
104
|
+
gt(b: DecimalLike): Cond;
|
|
105
|
+
atLeast(b: DecimalLike): Cond;
|
|
106
|
+
eq(b: DecimalLike): Cond;
|
|
107
|
+
ne(b: DecimalLike): Cond;
|
|
108
|
+
min(b: DecimalLike): Decimal;
|
|
109
|
+
max(b: DecimalLike): Decimal;
|
|
110
|
+
get isNegative(): Cond;
|
|
49
111
|
}
|
|
50
112
|
export declare const nat: Kind<Term>;
|
|
51
113
|
export declare const upTo: (maxValue: number) => Kind<Term>;
|
|
@@ -68,8 +130,8 @@ export declare class Choice<K extends string> {
|
|
|
68
130
|
}
|
|
69
131
|
export declare const oneOf: <const K extends string>(...values: K[]) => Kind<Choice<K>>;
|
|
70
132
|
export declare class Maybe<V> {
|
|
71
|
-
|
|
72
|
-
|
|
133
|
+
readonly present: Term;
|
|
134
|
+
readonly inner: V;
|
|
73
135
|
constructor(present: Term, inner: V);
|
|
74
136
|
get isSome(): Cond;
|
|
75
137
|
get isNone(): Cond;
|
|
@@ -83,20 +145,52 @@ export declare class Maybe<V> {
|
|
|
83
145
|
}): Term;
|
|
84
146
|
}
|
|
85
147
|
export declare const maybe: <V>(of: Kind<V>) => Kind<Maybe<V>>;
|
|
148
|
+
export declare const intern: ((text: string) => number) & {
|
|
149
|
+
load(entries: [string, number][]): void;
|
|
150
|
+
};
|
|
151
|
+
export declare const interned: () => [string, number][];
|
|
152
|
+
export declare const globMatch: (pattern: string, text: string) => boolean;
|
|
153
|
+
export declare class Str {
|
|
154
|
+
readonly id: Term;
|
|
155
|
+
readonly length: Term;
|
|
156
|
+
private readonly bits;
|
|
157
|
+
constructor(id: Term, length: Term, bits: ReadonlyMap<string, Term>);
|
|
158
|
+
get patterns(): string[];
|
|
159
|
+
choose(c: Cond, other: Str): Str;
|
|
160
|
+
like(pattern: string): Cond;
|
|
161
|
+
get isEmpty(): Cond;
|
|
162
|
+
bit(pattern: string): Term;
|
|
163
|
+
eq(b: Str | string): Cond;
|
|
164
|
+
ne(b: Str | string): Cond;
|
|
165
|
+
}
|
|
166
|
+
export declare const str: (opts?: {
|
|
167
|
+
like?: readonly string[];
|
|
168
|
+
maxLength?: number;
|
|
169
|
+
}) => Kind<Str>;
|
|
170
|
+
export declare const int: Kind<Int>;
|
|
171
|
+
export declare const decimal: (places: number) => Kind<Decimal>;
|
|
86
172
|
export type MapWrite = {
|
|
87
173
|
readonly map: string;
|
|
88
174
|
readonly key: E;
|
|
89
175
|
readonly value: E;
|
|
176
|
+
readonly concrete?: {
|
|
177
|
+
key?: number;
|
|
178
|
+
value?: number;
|
|
179
|
+
};
|
|
90
180
|
} | {
|
|
91
181
|
readonly map: string;
|
|
92
182
|
readonly each: string;
|
|
93
183
|
readonly value: E;
|
|
184
|
+
readonly concrete?: {
|
|
185
|
+
at: (key: Term) => TermLike;
|
|
186
|
+
};
|
|
94
187
|
};
|
|
95
188
|
export declare const everyKey: (f: (key: Term) => Cond) => Cond;
|
|
96
189
|
export declare const someKey: (f: (key: Term) => Cond, witness?: TermLike) => Cond;
|
|
97
190
|
export declare class MapRef {
|
|
98
191
|
readonly name: string;
|
|
99
192
|
readonly init: number;
|
|
193
|
+
private readonly cells;
|
|
100
194
|
constructor(name: string, init: number);
|
|
101
195
|
at(key: TermLike): Term;
|
|
102
196
|
set(key: TermLike, value: TermLike): MapWrite;
|
|
@@ -117,6 +211,7 @@ export type ListOp = {
|
|
|
117
211
|
export declare class ListRef {
|
|
118
212
|
readonly name: string;
|
|
119
213
|
readonly len: Term;
|
|
214
|
+
private readonly cells;
|
|
120
215
|
constructor(name: string, len: Term);
|
|
121
216
|
at(i: TermLike): Term;
|
|
122
217
|
has(x: TermLike): Cond;
|
|
@@ -157,8 +252,9 @@ type ValuesOf<K extends Kinds> = {
|
|
|
157
252
|
[n in keyof K]: K[n] extends Kind<infer V> ? V : never;
|
|
158
253
|
};
|
|
159
254
|
type Obj = object;
|
|
255
|
+
type Writes<V> = V extends Decimal ? DecimalLike | string : V extends Int ? IntLike : V extends Cond ? Cond | boolean : V extends Choice<infer K> ? Choice<K> | K : V extends Maybe<infer W> ? Maybe<W> | Writes<W> | null : V extends Str ? Str | string : TermLike;
|
|
160
256
|
type Update<S extends Obj, M extends Obj> = Partial<{
|
|
161
|
-
[k in keyof S]:
|
|
257
|
+
[k in keyof S]: Writes<S[k]>;
|
|
162
258
|
} & {
|
|
163
259
|
[k in keyof M]: MapWrite;
|
|
164
260
|
}>;
|
|
@@ -169,6 +265,7 @@ type Spec = {
|
|
|
169
265
|
state: [string, number | ((p: never) => TermLike)][];
|
|
170
266
|
maps: [string, number][];
|
|
171
267
|
lists?: string[];
|
|
268
|
+
kinded?: [string, Kind<unknown>][];
|
|
172
269
|
carried?: string[];
|
|
173
270
|
fns?: [string, FnDef][];
|
|
174
271
|
facts?: ((env: never) => Record<string, Cond | Forall>)[];
|
|
@@ -193,12 +290,18 @@ export declare class Rule<P extends Obj = {}, I extends Obj = {}, S extends Obj
|
|
|
193
290
|
get name(): string;
|
|
194
291
|
params<K extends Kinds>(kinds: K): Rule<P & ValuesOf<K>, I, S, M, F, R, Su, Q>;
|
|
195
292
|
inputs<K extends Kinds>(kinds: K): Rule<P, I & ValuesOf<K>, S, M, F, R, Su, Q>;
|
|
196
|
-
state<T extends Record<string, number | ((p: P) => TermLike)
|
|
197
|
-
[k in keyof T]: Term;
|
|
293
|
+
state<T extends Record<string, number | ((p: P) => TermLike) | Init<unknown>>>(init: T): Rule<P, I, S & {
|
|
294
|
+
[k in keyof T]: T[k] extends Init<infer V> ? V : Term;
|
|
198
295
|
}, M, F, R, Su, Q>;
|
|
199
296
|
maps<T extends Record<string, number>>(init: T): Rule<P, I, S, M & {
|
|
200
297
|
[k in keyof T]: MapRef;
|
|
201
298
|
}, F, R, Su, Q>;
|
|
299
|
+
ints<T extends Record<string, number | ((p: P) => IntLike)>>(init: T): Rule<P, I, S & {
|
|
300
|
+
[k in keyof T]: Int;
|
|
301
|
+
}, M, F, R, Su, Q>;
|
|
302
|
+
decimals<T extends Record<string, number | string | ((p: P) => DecimalLike)>>(places: number, init: T): Rule<P, I, S & {
|
|
303
|
+
[k in keyof T]: Decimal;
|
|
304
|
+
}, M, F, R, Su, Q>;
|
|
202
305
|
lists<const N extends string>(...names: N[]): Rule<P, I, S & {
|
|
203
306
|
[k in N as `${k}_len`]: Term;
|
|
204
307
|
}, M & {
|
|
@@ -241,9 +344,42 @@ export declare class Rule<P extends Obj = {}, I extends Obj = {}, S extends Obj
|
|
|
241
344
|
}[];
|
|
242
345
|
}): Liveness;
|
|
243
346
|
decide(name: string, given: (env: P & I) => Cond | Cond[], then: (env: P & I) => Cond): Decision;
|
|
347
|
+
relate(name: string, given: (a: P & I, b: P & I) => Cond | Cond[], then: (a: P & I, b: P & I) => Cond): Decision;
|
|
244
348
|
private kindAssumptions;
|
|
349
|
+
private afterEnv;
|
|
245
350
|
private env;
|
|
351
|
+
private names;
|
|
352
|
+
private whatIs;
|
|
353
|
+
private distinct;
|
|
246
354
|
get machine(): Machine;
|
|
355
|
+
crossCheck(laws: Law[], stepLaws?: StepLaw[], opts?: {
|
|
356
|
+
trials?: number;
|
|
357
|
+
depth?: number;
|
|
358
|
+
bound?: number;
|
|
359
|
+
rand?: Rand;
|
|
360
|
+
}): {
|
|
361
|
+
checked: number;
|
|
362
|
+
failure?: string;
|
|
363
|
+
};
|
|
364
|
+
private verdict;
|
|
365
|
+
private crossStep;
|
|
366
|
+
compare<St extends Record<string, number>>(reference: {
|
|
367
|
+
init: (params: {
|
|
368
|
+
[k in keyof P]: Raw;
|
|
369
|
+
}) => St;
|
|
370
|
+
step: (params: {
|
|
371
|
+
[k in keyof P]: Raw;
|
|
372
|
+
}, st: St, request: {
|
|
373
|
+
[k in keyof I]: Raw;
|
|
374
|
+
}) => St;
|
|
375
|
+
}, opts?: Draws<{
|
|
376
|
+
[k in keyof I]: Raw;
|
|
377
|
+
}> & {
|
|
378
|
+
params?: (rand: Rand) => {
|
|
379
|
+
[k in keyof P]: Raw;
|
|
380
|
+
};
|
|
381
|
+
depth?: number;
|
|
382
|
+
}): Agreement;
|
|
247
383
|
encodeParams(values: {
|
|
248
384
|
[k in keyof P]: Raw;
|
|
249
385
|
}): Record<string, number>;
|
|
@@ -252,6 +388,7 @@ export declare class Rule<P extends Obj = {}, I extends Obj = {}, S extends Obj
|
|
|
252
388
|
}): Request;
|
|
253
389
|
randomParams(rand: Rand, bound: number): Record<string, number>;
|
|
254
390
|
randomInput(rand: Rand, bound: number): Request;
|
|
391
|
+
decode(st: State): Record<string, Raw>;
|
|
255
392
|
get orderedBy(): string | undefined;
|
|
256
393
|
interpreter(): {
|
|
257
394
|
init: (params: {
|
|
@@ -288,6 +425,61 @@ export type Decision = {
|
|
|
288
425
|
then: C;
|
|
289
426
|
goal: Goal;
|
|
290
427
|
};
|
|
428
|
+
type Result<T> = {
|
|
429
|
+
[k in keyof T]: T[k] extends Cond ? Cond : T[k] extends Decimal ? Decimal : T[k] extends Int ? Int : T[k] extends Choice<infer K> ? Choice<K> : T[k] extends Str ? Str : Term;
|
|
430
|
+
};
|
|
431
|
+
type Value<T> = {
|
|
432
|
+
[k in keyof T]: T[k] extends Cond ? boolean : T[k] extends Choice<infer K> ? K : T[k] extends Str ? string : number;
|
|
433
|
+
};
|
|
434
|
+
type Field = Term | Cond | Int | Decimal | Choice<string> | Str;
|
|
435
|
+
export declare class Fun<P extends Obj = {}, I extends Obj = {}, O extends Obj = {}> {
|
|
436
|
+
private readonly r;
|
|
437
|
+
private readonly out?;
|
|
438
|
+
constructor(r: Rule<P, I>, out?: ((env: never) => Record<string, TermLike | Field>) | undefined);
|
|
439
|
+
get name(): string;
|
|
440
|
+
params<K extends Kinds>(kinds: K): Fun<P & ValuesOf<K>, I, O>;
|
|
441
|
+
inputs<K extends Kinds>(kinds: K): Fun<P, I & ValuesOf<K>, O>;
|
|
442
|
+
fns<T extends Record<string, FnDef>>(defs: T): Fun<P & {
|
|
443
|
+
[k in keyof T]: (...args: TermLike[]) => Term;
|
|
444
|
+
}, I, O>;
|
|
445
|
+
facts(f: (p: P) => Record<string, Cond | Forall>): Fun<P, I, O>;
|
|
446
|
+
pre(f: (p: P) => Cond): Fun<P, I, O>;
|
|
447
|
+
assume(f: (env: P & I) => Cond): Fun<P, I, O>;
|
|
448
|
+
returns<T extends Record<string, TermLike | Field>>(f: (env: P & I) => T): Fun<P, I, Result<T>>;
|
|
449
|
+
private result;
|
|
450
|
+
law(name: string, given: (env: P & I, out: O) => Cond | Cond[], then: (out: O, env: P & I) => Cond): Decision;
|
|
451
|
+
relate(name: string, given: (a: P & I, b: P & I) => Cond | Cond[], then: (outA: O, outB: O, a: P & I, b: P & I) => Cond): Decision;
|
|
452
|
+
compare(reference: (values: {
|
|
453
|
+
[k in keyof I]: Raw;
|
|
454
|
+
}, params: {
|
|
455
|
+
[k in keyof P]: Raw;
|
|
456
|
+
}) => Partial<Value<O>>, opts?: Draws<{
|
|
457
|
+
[k in keyof I]: Raw;
|
|
458
|
+
}> & {
|
|
459
|
+
params?: {
|
|
460
|
+
[k in keyof P]: Raw;
|
|
461
|
+
};
|
|
462
|
+
}): Agreement;
|
|
463
|
+
get rule(): Rule<P, I>;
|
|
464
|
+
private compiledRule?;
|
|
465
|
+
run(values: {
|
|
466
|
+
[k in keyof I]: Raw;
|
|
467
|
+
}, params?: {
|
|
468
|
+
[k in keyof P]?: Raw;
|
|
469
|
+
}): Value<O>;
|
|
470
|
+
}
|
|
471
|
+
export declare const fun: (name: string) => Fun;
|
|
472
|
+
export type Agreement = {
|
|
473
|
+
checked: number;
|
|
474
|
+
failure?: string;
|
|
475
|
+
};
|
|
476
|
+
type Draws<T> = {
|
|
477
|
+
trials?: number;
|
|
478
|
+
bound?: number;
|
|
479
|
+
rand?: Rand;
|
|
480
|
+
edges?: T[];
|
|
481
|
+
draw?: (rand: Rand) => T;
|
|
482
|
+
};
|
|
291
483
|
export declare class LoopRule<P extends Obj = {}, I extends Obj = {}, S extends Obj = {}> {
|
|
292
484
|
private readonly spec;
|
|
293
485
|
constructor(spec: {
|
|
@@ -328,6 +520,7 @@ export type Verdict = {
|
|
|
328
520
|
stuck?: string;
|
|
329
521
|
goal?: string;
|
|
330
522
|
witness?: Record<string, number>;
|
|
523
|
+
why?: string;
|
|
331
524
|
trees?: Record<string, Tree>;
|
|
332
525
|
};
|
|
333
526
|
export declare function proveRule(r: Rule<Obj, Obj, Obj, Obj, Obj, Obj, Obj, Obj>, laws: Law[]): Verdict;
|
|
@@ -336,4 +529,12 @@ export type { StepLaw };
|
|
|
336
529
|
export type { Liveness };
|
|
337
530
|
export declare function proveLeadsTo(r: Rule<Obj, Obj, Obj, Obj, Obj, Obj, Obj, Obj>, laws: Law[], l: Liveness): Verdict;
|
|
338
531
|
export declare const proveDecision: (d: Decision) => Verdict;
|
|
532
|
+
export declare function crossCheckDecision(d: Decision, opts?: {
|
|
533
|
+
trials?: number;
|
|
534
|
+
bound?: number;
|
|
535
|
+
rand?: Rand;
|
|
536
|
+
}): {
|
|
537
|
+
checked: number;
|
|
538
|
+
failure?: string;
|
|
539
|
+
};
|
|
339
540
|
export declare const proveLoop: (l: LoopRule<Obj, Obj, Obj>, laws: Law[]) => Verdict;
|