gdp-wired 0.16.0 → 0.18.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.
@@ -0,0 +1,258 @@
1
+ import type { C, E } from './machine.js';
2
+ import { type Fact } from '../kernel/cyclic.js';
3
+ import { type CyclicVerdict, type NodeSpec } from './cyclic.js';
4
+ export declare const self: {
5
+ readonly self: true;
6
+ };
7
+ export declare const natural: "nat";
8
+ export declare const boolean: "bool";
9
+ type FieldSort = 'nat' | 'self';
10
+ export type Sort = 'nat' | 'bool' | Data;
11
+ export type Ctor = {
12
+ name: string;
13
+ fields: {
14
+ name: string;
15
+ sort: FieldSort;
16
+ }[];
17
+ };
18
+ export type X = {
19
+ op: 'var';
20
+ name: string;
21
+ } | {
22
+ op: 'nat';
23
+ value: number;
24
+ } | {
25
+ op: 'add' | 'sub' | 'min' | 'max';
26
+ a: X;
27
+ b: X;
28
+ } | {
29
+ op: 'mul';
30
+ k: number;
31
+ a: X;
32
+ } | {
33
+ op: 'if';
34
+ c: Y;
35
+ then: X;
36
+ else: X;
37
+ } | {
38
+ op: 'call';
39
+ fn: string;
40
+ args: X[];
41
+ } | {
42
+ op: 'ctor';
43
+ data: string;
44
+ ctor: number;
45
+ args: X[];
46
+ } | {
47
+ op: 'match';
48
+ data: string;
49
+ of: X;
50
+ cases: {
51
+ binds: string[];
52
+ body: X;
53
+ }[];
54
+ } | {
55
+ op: 'apply';
56
+ param: string;
57
+ arg: X;
58
+ } | {
59
+ op: 'bool';
60
+ c: Y;
61
+ };
62
+ export type Y = {
63
+ op: '<' | '<=' | '=';
64
+ a: X;
65
+ b: X;
66
+ } | {
67
+ op: 'and' | 'or';
68
+ xs: Y[];
69
+ } | {
70
+ op: 'not';
71
+ x: Y;
72
+ } | {
73
+ op: 'is';
74
+ data: string;
75
+ of: X;
76
+ ctor: number;
77
+ } | {
78
+ op: 'holds';
79
+ x: X;
80
+ };
81
+ export declare class Nat {
82
+ readonly x: X;
83
+ constructor(x: X);
84
+ plus(b: NatLike): Nat;
85
+ minus(b: NatLike): Nat;
86
+ times(k: number): Nat;
87
+ lt(b: NatLike): Bool;
88
+ atMost(b: NatLike): Bool;
89
+ gt(b: NatLike): Bool;
90
+ atLeast(b: NatLike): Bool;
91
+ eq(b: NatLike): Bool;
92
+ ne(b: NatLike): Bool;
93
+ }
94
+ export type NatLike = Nat | number;
95
+ export declare class Bool {
96
+ readonly y: Y;
97
+ constructor(y: Y);
98
+ and(...bs: Bool[]): Bool;
99
+ or(...bs: Bool[]): Bool;
100
+ not(): Bool;
101
+ implies(b: Bool): Bool;
102
+ iff(b: Bool): Bool;
103
+ }
104
+ export declare const yes: Bool;
105
+ export declare const no: Bool;
106
+ export declare class Val {
107
+ readonly data: Data;
108
+ readonly x: X;
109
+ constructor(data: Data, x: X);
110
+ match(cases: Record<string, (fields: Record<string, any>) => Nat | Bool | Val | number>): any;
111
+ is(ctor: string): Bool;
112
+ eq(b: Val): Bool;
113
+ ne(b: Val): Bool;
114
+ }
115
+ export declare const wrap: (s: Sort, x: X) => Nat | Bool | Val;
116
+ export declare function when<T extends Nat | Val | Bool | number>(c: Bool, a: T, b: T): T extends number ? Nat : T;
117
+ export declare class Data {
118
+ readonly name: string;
119
+ readonly ctors: Ctor[];
120
+ constructor(name: string, decl: Record<string, Record<string, typeof self | 'nat' | {
121
+ nat: true;
122
+ }>>);
123
+ index(ctor: string): number;
124
+ get nullary(): number;
125
+ make(ctor: string, ...args: (Val | NatLike)[]): Val;
126
+ }
127
+ type Decl = Record<string, Record<string, unknown>>;
128
+ export declare function data<const D extends Decl>(name: string, decl: D): Data & {
129
+ [c in keyof D]: keyof D[c] extends never ? Val : (...args: (Val | NatLike)[]) => Val;
130
+ };
131
+ export type Fn = {
132
+ name: string;
133
+ params: {
134
+ name: string;
135
+ sort: Sort;
136
+ }[];
137
+ ret: Sort;
138
+ body: () => X;
139
+ decreases?: number;
140
+ paramFns: string[];
141
+ };
142
+ export type Callable = ((...args: (Val | NatLike | Bool)[]) => any) & {
143
+ fn: Fn;
144
+ };
145
+ export declare function define(name: string, params: Record<string, Sort>, ret: Sort, body: (args: Record<string, any>) => Nat | Bool | Val | number): Callable;
146
+ export declare const fnParam: (name: string) => ((x: NatLike) => Nat) & {
147
+ param: string;
148
+ };
149
+ export type DataLaw = {
150
+ name: string;
151
+ vars: {
152
+ name: string;
153
+ sort: Sort;
154
+ }[];
155
+ holds: Y;
156
+ params: string[];
157
+ };
158
+ export declare function law(name: string, vars: Record<string, Sort>, holds: (vs: Record<string, any>) => Bool): DataLaw;
159
+ export type Value = number | {
160
+ c: number;
161
+ f: Value[];
162
+ };
163
+ type Env = Map<string, Value>;
164
+ export declare function evalX(x: X, env: Env, params: Record<string, (n: number) => number>): Value;
165
+ export declare function evalY(y: Y, env: Env, params: Record<string, (n: number) => number>): boolean;
166
+ export declare const showValue: (d: Sort, v: Value) => string;
167
+ type Rand = () => number;
168
+ export declare const rng: (seed: number) => Rand;
169
+ export declare function randomValue(s: Sort, rand: Rand, size: number, natMax?: number): Value;
170
+ export declare const randomFn: (rand: Rand, natMax?: number) => ((n: number) => number);
171
+ export type Sample = {
172
+ env: Env;
173
+ params: Record<string, (n: number) => number>;
174
+ };
175
+ export declare function samples(vars: {
176
+ name: string;
177
+ sort: Sort;
178
+ }[], paramNames: string[], n: number, seed?: number): Sample[];
179
+ export declare const keyOf: (args: E[]) => E;
180
+ export declare const tagMap: (d: string) => string, sizeMap: (d: string) => string;
181
+ export declare const fieldMap: (d: Data, j: number, i: number) => string;
182
+ export declare const ctorMap: (d: Data, j: number) => string;
183
+ export type Program = {
184
+ datas: Data[];
185
+ fns: Fn[];
186
+ params: string[];
187
+ };
188
+ export declare function programOf(laws: DataLaw[], extra?: Fn[]): Program;
189
+ export declare function encX(p: Program, x: X, env: Map<string, E>): E;
190
+ export declare function encY(p: Program, y: Y, env: Map<string, E>): C;
191
+ export type Facts = {
192
+ facts: Fact[];
193
+ at: Map<string, number>;
194
+ arity: Map<string, number>;
195
+ };
196
+ export declare function factsOf(p: Program): Facts;
197
+ export declare function decode(d: Data, n: number): Value;
198
+ export declare function encode(d: Data, v: Value): number;
199
+ export declare function codeValues(p: Program): Record<string, (...xs: number[]) => number>;
200
+ export declare const orderFacts: (p: Program) => Fact[];
201
+ export declare class Model {
202
+ readonly p: Program;
203
+ readonly params: Record<string, (n: number) => number>;
204
+ private ids;
205
+ private vals;
206
+ constructor(p: Program, params: Record<string, (n: number) => number>);
207
+ id(d: Data, v: Value): number;
208
+ value(d: Data, id: number): Value;
209
+ code(s: Sort, v: Value): number;
210
+ decode(s: Sort, n: number): Value;
211
+ private memo;
212
+ read(map: string, key: number): number;
213
+ private terms;
214
+ private readNew;
215
+ evalE(e: E, env: Record<string, number>): number;
216
+ private evalNew;
217
+ evalC(c: C, env: Record<string, number>): boolean;
218
+ }
219
+ export declare const sizeOf: (d: Data, v: Value) => number;
220
+ export declare function unkey(key: number, n: number): number[];
221
+ export type Lemma = {
222
+ law: DataLaw;
223
+ spec?: NodeSpec;
224
+ };
225
+ export type DataVerdict = {
226
+ proven: boolean;
227
+ checked: boolean;
228
+ law: string;
229
+ counterexample?: Record<string, string>;
230
+ proof?: CyclicVerdict;
231
+ lemmas: string[];
232
+ scheme?: string;
233
+ ms: number;
234
+ goal?: string;
235
+ stuck?: string;
236
+ tried: number;
237
+ program?: Program;
238
+ node?: number;
239
+ };
240
+ export type Options = {
241
+ samples?: number;
242
+ depth?: number;
243
+ lemmas?: boolean | DataLaw[];
244
+ ms?: number;
245
+ induction?: boolean;
246
+ seed?: number;
247
+ patience?: number;
248
+ };
249
+ export declare function refute(l: DataLaw, n?: number, seed?: number): Record<string, string> | undefined;
250
+ export declare const attemptMs: {
251
+ ms: number;
252
+ };
253
+ export declare function conjectures(p: Program, l: DataLaw, max?: number, maxSize?: number): DataLaw[];
254
+ export declare const showX: (x: X) => string;
255
+ export declare const showY: (y: Y) => string;
256
+ export declare function proveData(l: DataLaw, opts?: Options): DataVerdict;
257
+ export declare const proveDataToday: (l: DataLaw) => DataVerdict;
258
+ export {};