gdp-wired 0.1.0 → 0.3.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 +86 -35
- package/dist/core/compose.d.ts +38 -0
- package/dist/core/compose.js +245 -0
- package/dist/core/dsl.d.ts +85 -13
- package/dist/core/dsl.js +424 -19
- package/dist/core/machine.d.ts +34 -6
- package/dist/core/machine.js +194 -22
- package/dist/kernel/kernel.d.ts +31 -3
- package/dist/kernel/kernel.js +364 -87
- package/dist/kernel/prove.d.ts +33 -9
- package/dist/kernel/prove.js +298 -24
- package/dist/lean-kernel/emit.d.ts +132 -0
- package/dist/lean-kernel/emit.js +936 -0
- package/dist/lean-kernel/lean-terms.d.ts +5 -0
- package/dist/lean-kernel/lean-terms.js +44 -0
- package/dist/lean-kernel/library.d.ts +1 -0
- package/dist/lean-kernel/library.js +13 -0
- package/package.json +15 -4
package/dist/core/dsl.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type C, type E, type Law, type Machine, type State } from './machine.js';
|
|
2
|
-
import { type Goal, type Loop, type StepLaw, type Tree } from '../kernel/kernel.js';
|
|
1
|
+
import { type C, type E, type Law, type Machine, type Request, type State } from './machine.js';
|
|
2
|
+
import { type Goal, type Liveness, type Loop, 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 {
|
|
@@ -87,7 +87,13 @@ export type MapWrite = {
|
|
|
87
87
|
readonly map: string;
|
|
88
88
|
readonly key: E;
|
|
89
89
|
readonly value: E;
|
|
90
|
+
} | {
|
|
91
|
+
readonly map: string;
|
|
92
|
+
readonly each: string;
|
|
93
|
+
readonly value: E;
|
|
90
94
|
};
|
|
95
|
+
export declare const everyKey: (f: (key: Term) => Cond) => Cond;
|
|
96
|
+
export declare const someKey: (f: (key: Term) => Cond, witness?: TermLike) => Cond;
|
|
91
97
|
export declare class MapRef {
|
|
92
98
|
readonly name: string;
|
|
93
99
|
readonly init: number;
|
|
@@ -95,16 +101,57 @@ export declare class MapRef {
|
|
|
95
101
|
at(key: TermLike): Term;
|
|
96
102
|
set(key: TermLike, value: TermLike): MapWrite;
|
|
97
103
|
bump(key: TermLike, c?: Cond, by?: TermLike): MapWrite;
|
|
104
|
+
each(f: (key: Term) => TermLike): MapWrite;
|
|
105
|
+
has(key: TermLike): Cond;
|
|
106
|
+
subsetOf(other: MapRef): Cond;
|
|
107
|
+
disjointFrom(other: MapRef): Cond;
|
|
108
|
+
sameAs(other: MapRef): Cond;
|
|
109
|
+
within(n: number): Cond;
|
|
110
|
+
sizeBelow(n: number): Term;
|
|
111
|
+
}
|
|
112
|
+
export type ListOp = {
|
|
113
|
+
readonly when: Cond;
|
|
114
|
+
readonly at: (k: Term) => TermLike;
|
|
115
|
+
readonly len: TermLike;
|
|
116
|
+
};
|
|
117
|
+
export declare class ListRef {
|
|
118
|
+
readonly name: string;
|
|
119
|
+
readonly len: Term;
|
|
120
|
+
constructor(name: string, len: Term);
|
|
121
|
+
at(i: TermLike): Term;
|
|
122
|
+
has(x: TermLike): Cond;
|
|
123
|
+
sorted(): Cond;
|
|
124
|
+
push(x: TermLike, when?: Cond): ListOp;
|
|
125
|
+
pop(when?: Cond): ListOp;
|
|
126
|
+
set(i: TermLike, x: TermLike, when?: Cond): ListOp;
|
|
127
|
+
insertAt(i: TermLike, x: TermLike, when?: Cond): ListOp;
|
|
128
|
+
removeAt(i: TermLike, when?: Cond): ListOp;
|
|
129
|
+
apply(...ops: ListOp[]): Record<string, TermLike | MapWrite>;
|
|
130
|
+
within(): Forall;
|
|
131
|
+
increasing(): Forall;
|
|
98
132
|
}
|
|
99
133
|
export type Forall = {
|
|
100
|
-
readonly forall: (key: Term) => Cond;
|
|
134
|
+
readonly forall: (key: Term, ...more: Term[]) => Cond;
|
|
101
135
|
};
|
|
102
|
-
export declare
|
|
136
|
+
export declare function forall(f: (key: Term, key2: Term, key3: Term, key4: Term) => Cond): Forall;
|
|
103
137
|
export type Relation = {
|
|
104
138
|
readonly when: Cond;
|
|
105
139
|
readonly holds: Cond;
|
|
106
140
|
};
|
|
107
141
|
export declare const relation: (holds: Cond, whenever?: Cond) => Relation;
|
|
142
|
+
export declare function nameQuantifiers(m: Machine): Machine;
|
|
143
|
+
export type FnDef = {
|
|
144
|
+
arity: number;
|
|
145
|
+
js: string | ((...args: number[]) => number);
|
|
146
|
+
lean?: string;
|
|
147
|
+
facts?: (f: (...args: TermLike[]) => Term) => Record<string, Cond | Forall>;
|
|
148
|
+
};
|
|
149
|
+
export declare const fn: (arity: number, js: FnDef["js"], opts?: {
|
|
150
|
+
lean?: string;
|
|
151
|
+
facts?: FnDef["facts"];
|
|
152
|
+
}) => FnDef;
|
|
153
|
+
export declare const divBy: (c: number) => FnDef;
|
|
154
|
+
export declare const modBy: (c: number) => FnDef;
|
|
108
155
|
type Kinds = Record<string, Kind<unknown>>;
|
|
109
156
|
type ValuesOf<K extends Kinds> = {
|
|
110
157
|
[n in keyof K]: K[n] extends Kind<infer V> ? V : never;
|
|
@@ -121,6 +168,10 @@ type Spec = {
|
|
|
121
168
|
inputs: [string, Kind<unknown>][];
|
|
122
169
|
state: [string, number | ((p: never) => TermLike)][];
|
|
123
170
|
maps: [string, number][];
|
|
171
|
+
lists?: string[];
|
|
172
|
+
carried?: string[];
|
|
173
|
+
fns?: [string, FnDef][];
|
|
174
|
+
facts?: ((env: never) => Record<string, Cond | Forall>)[];
|
|
124
175
|
flags: ((env: never) => Record<string, Cond>)[];
|
|
125
176
|
step?: (env: never) => Record<string, TermLike | MapWrite | undefined>;
|
|
126
177
|
pre: ((p: never) => Cond)[];
|
|
@@ -148,6 +199,18 @@ export declare class Rule<P extends Obj = {}, I extends Obj = {}, S extends Obj
|
|
|
148
199
|
maps<T extends Record<string, number>>(init: T): Rule<P, I, S, M & {
|
|
149
200
|
[k in keyof T]: MapRef;
|
|
150
201
|
}, F, R, Su, Q>;
|
|
202
|
+
lists<const N extends string>(...names: N[]): Rule<P, I, S & {
|
|
203
|
+
[k in N as `${k}_len`]: Term;
|
|
204
|
+
}, M & {
|
|
205
|
+
[k in N]: ListRef;
|
|
206
|
+
}, F, R, Su, Q>;
|
|
207
|
+
fns<T extends Record<string, FnDef>>(defs: T): Rule<P & {
|
|
208
|
+
[k in keyof T]: (...args: TermLike[]) => Term;
|
|
209
|
+
}, I, S, M, F, R, Su, Q>;
|
|
210
|
+
facts(f: (p: P) => Record<string, Cond | Forall>): Rule<P, I, S, M, F, R, Su, Q>;
|
|
211
|
+
carries<const N extends string>(...names: N[]): Rule<P, I & {
|
|
212
|
+
[k in N]: MapRef;
|
|
213
|
+
}, S, M, F, R, Su, Q>;
|
|
151
214
|
flags<T extends Record<string, Cond>>(f: (env: P & I & S & M & F & Su & Q) => T): Rule<P, I, S, M, F & {
|
|
152
215
|
[k in keyof T]: Cond;
|
|
153
216
|
}, R, Su, Q>;
|
|
@@ -165,7 +228,18 @@ export declare class Rule<P extends Obj = {}, I extends Obj = {}, S extends Obj
|
|
|
165
228
|
relations(f: (env: P & I & Su & Q) => Relation[]): Rule<P, I, S, M, F, R, Su, Q>;
|
|
166
229
|
prune(order: keyof R & string, after: (p: P) => TermLike): Rule<P, I, S, M, F, R, Su, Q>;
|
|
167
230
|
law(name: string, f: (env: P & S & M & Su) => Cond | Forall): Law;
|
|
231
|
+
private lawOf;
|
|
168
232
|
stepLaw(name: string, then: (before: P & I & S & M & F & Su & Q, after: S & M & Su) => Cond | Forall, when?: (before: P & I & S & M & F & Su & Q) => Cond): StepLaw;
|
|
233
|
+
stepsLaw(name: string, k: number, then: (first: P & I & S & M & F & Su & Q, last: S & M & Su, requests: (I & Q)[]) => Cond | Forall, when?: (before: P & I & S & M & F & Su & Q, j: number) => Cond | undefined): StepLaw;
|
|
234
|
+
leadsTo(name: string, spec: {
|
|
235
|
+
from: (env: P & S & M & Su) => Cond;
|
|
236
|
+
to: (env: P & S & M & Su) => Cond;
|
|
237
|
+
rank: (env: P & S & M & Su) => TermLike | TermLike[];
|
|
238
|
+
helpful: ((env: P & S & M & Su) => Record<string, TermLike>) | {
|
|
239
|
+
when?: (env: P & S & M & Su) => Cond;
|
|
240
|
+
request: (env: P & S & M & Su) => Record<string, TermLike>;
|
|
241
|
+
}[];
|
|
242
|
+
}): Liveness;
|
|
169
243
|
decide(name: string, given: (env: P & I) => Cond | Cond[], then: (env: P & I) => Cond): Decision;
|
|
170
244
|
private kindAssumptions;
|
|
171
245
|
private env;
|
|
@@ -174,10 +248,10 @@ export declare class Rule<P extends Obj = {}, I extends Obj = {}, S extends Obj
|
|
|
174
248
|
[k in keyof P]: Raw;
|
|
175
249
|
}): Record<string, number>;
|
|
176
250
|
encodeInput(values: {
|
|
177
|
-
[k in keyof I]: Raw;
|
|
178
|
-
}):
|
|
251
|
+
[k in keyof I]: I[k] extends MapRef ? ReadonlySet<number> | readonly number[] | ReadonlyMap<number, number> : Raw;
|
|
252
|
+
}): Request;
|
|
179
253
|
randomParams(rand: Rand, bound: number): Record<string, number>;
|
|
180
|
-
randomInput(rand: Rand, bound: number):
|
|
254
|
+
randomInput(rand: Rand, bound: number): Request;
|
|
181
255
|
get orderedBy(): string | undefined;
|
|
182
256
|
interpreter(): {
|
|
183
257
|
init: (params: {
|
|
@@ -185,16 +259,12 @@ export declare class Rule<P extends Obj = {}, I extends Obj = {}, S extends Obj
|
|
|
185
259
|
}) => State;
|
|
186
260
|
queries: (params: {
|
|
187
261
|
[x: string]: number;
|
|
188
|
-
}, st: State, input: {
|
|
189
|
-
[x: string]: number;
|
|
190
|
-
}) => {
|
|
262
|
+
}, st: State, input: Request) => {
|
|
191
263
|
[x: string]: number;
|
|
192
264
|
};
|
|
193
265
|
step: (params: {
|
|
194
266
|
[x: string]: number;
|
|
195
|
-
},
|
|
196
|
-
[x: string]: number;
|
|
197
|
-
}) => State;
|
|
267
|
+
}, given: State, input: Request) => State;
|
|
198
268
|
};
|
|
199
269
|
compiled(): {
|
|
200
270
|
init: (params: object) => State & {
|
|
@@ -263,5 +333,7 @@ export type Verdict = {
|
|
|
263
333
|
export declare function proveRule(r: Rule<Obj, Obj, Obj, Obj, Obj, Obj, Obj, Obj>, laws: Law[]): Verdict;
|
|
264
334
|
export declare function proveSteps(r: Rule<Obj, Obj, Obj, Obj, Obj, Obj, Obj, Obj>, laws: Law[], stepLaws: StepLaw[]): Verdict;
|
|
265
335
|
export type { StepLaw };
|
|
336
|
+
export type { Liveness };
|
|
337
|
+
export declare function proveLeadsTo(r: Rule<Obj, Obj, Obj, Obj, Obj, Obj, Obj, Obj>, laws: Law[], l: Liveness): Verdict;
|
|
266
338
|
export declare const proveDecision: (d: Decision) => Verdict;
|
|
267
339
|
export declare const proveLoop: (l: LoopRule<Obj, Obj, Obj>, laws: Law[]) => Verdict;
|