gdp-wired 0.41.1 → 0.43.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 +7 -1
- package/dist/core/cli.d.ts +2 -1
- package/dist/core/cli.js +226 -27
- package/dist/core/counts.d.ts +8 -1
- package/dist/core/counts.js +171 -302
- package/dist/core/dsl.js +26 -30
- package/dist/core/effect-schedule.d.ts +103 -0
- package/dist/core/effect-schedule.js +817 -0
- package/dist/core/effect.d.ts +19 -0
- package/dist/core/effect.js +551 -28
- package/dist/core/exists.d.ts +5 -0
- package/dist/core/exists.js +98 -34
- package/dist/core/extract-check.d.ts +1 -0
- package/dist/core/extract-check.js +37 -3
- package/dist/core/extract-print.js +9 -2
- package/dist/core/extract-read.js +2 -1
- package/dist/core/extract-step.d.ts +9 -0
- package/dist/core/extract-step.js +87 -22
- package/dist/core/extract.d.ts +8 -0
- package/dist/core/extract.js +13 -1
- package/dist/core/infer.d.ts +1 -0
- package/dist/core/infer.js +7 -4
- package/dist/core/laws.d.ts +4 -0
- package/dist/core/laws.js +176 -9
- package/dist/core/machine.js +2 -2
- package/dist/core/py/harness.py +13 -6
- package/dist/core/py/reader.py +51 -1
- package/dist/core/system.d.ts +44 -0
- package/dist/core/system.js +426 -0
- package/dist/kernel/cdcl.js +31 -14
- package/dist/kernel/kernel.js +3 -2
- package/dist/kernel/prove.d.ts +1 -0
- package/dist/kernel/prove.js +69 -8
- package/dist/lean-kernel/emit.js +3 -3
- package/dist/lean-kernel/lean-terms.d.ts +1 -0
- package/dist/lean-kernel/lean-terms.js +8 -4
- package/package.json +2 -2
package/dist/core/dsl.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
//
|
|
16
16
|
// A step returns its updates as one object: every right-hand side reads the state before the step, as the kernel and
|
|
17
17
|
// both runtimes do.
|
|
18
|
-
import { searchCounted } from "./counts.js";
|
|
18
|
+
import { candidates, cone, searchCounted } from "./counts.js";
|
|
19
19
|
import { env as knobs } from "./solver.js";
|
|
20
20
|
import { argsKey, machineTerms, carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, seeded, withArithmetic } from "./machine.js";
|
|
21
21
|
import { allowed, keysOf, requestEnv, watch, watchWork } from "./watch.js";
|
|
@@ -891,7 +891,8 @@ function sumOver(map, at, plain) {
|
|
|
891
891
|
export const sumsIn = (ts, more = []) => {
|
|
892
892
|
if (!sumDecls.size)
|
|
893
893
|
return undefined;
|
|
894
|
-
|
|
894
|
+
// (a sum read after the step, primed, is the sum's too)
|
|
895
|
+
const names = new Set([...more, ...[...JSON.stringify(ts).matchAll(/"op":"var","name":"(sum\$[^"]+)"/g)].map(x2 => x2[1].replace(/'$/, ''))].filter(n => sumDecls.has(n)));
|
|
895
896
|
return names.size ? Object.fromEntries([...names].sort().map(n => [n, sumDecls.get(n)])) : undefined;
|
|
896
897
|
};
|
|
897
898
|
// A map from naturals to naturals, every cell starting at `init`. One write per map per step.
|
|
@@ -2933,7 +2934,10 @@ export function proveRule(r, laws, opts = {}) {
|
|
|
2933
2934
|
const c = searchCounted(r.machine, withKinds(r, laws), typeof opts.search === 'object' ? opts.search.ms ?? 60_000 : 60_000);
|
|
2934
2935
|
return { proven: c.proven, checked: c.proven, ...(c.why ? { why: c.why } : {}), found: { laws: c.laws.map(l => ({ text: l.name })) } };
|
|
2935
2936
|
}
|
|
2936
|
-
|
|
2937
|
+
// (with a search budget, the laws as given within it on the wall: a step goal of hundreds of hypotheses has a second
|
|
2938
|
+
// each by its own budget, so the search would never start)
|
|
2939
|
+
const ms = typeof opts.search === 'object' ? opts.search.ms : undefined, given = () => (opts.fast ? proveSetFast : proveLaws)(r.machine, withKinds(r, laws));
|
|
2940
|
+
const out = ms === undefined ? given() : withWall(performance.now() + ms, given);
|
|
2937
2941
|
const v = { ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) };
|
|
2938
2942
|
return searched(r, laws, [], v, opts);
|
|
2939
2943
|
}
|
|
@@ -3094,45 +3098,37 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3094
3098
|
return { ...verdict, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) };
|
|
3095
3099
|
}
|
|
3096
3100
|
// A law with "there exists" about no key, which the join can't take as its goal: its witness core/exists.ts's ghostOf;
|
|
3097
|
-
//
|
|
3098
|
-
//
|
|
3099
|
-
//
|
|
3100
|
-
//
|
|
3101
|
+
// then core/counts.ts's pipeline: the candidates, the engine's template two keys at the bound value's places, framed by
|
|
3102
|
+
// the law's conjuncts that read the value and no map, kept by the cone (each proven from the kept ones and itself), the
|
|
3103
|
+
// kernel's proveLaw their proof; then the laws with those kept. (A law about every key goes the usual way: its ghost
|
|
3104
|
+
// maps' goals ran past the search's wall here, firewall's, and won nothing.)
|
|
3101
3105
|
function someCone(r, laws0, ms) {
|
|
3102
3106
|
const until = clock() + ms, m = r.machine, yes = { op: '<=', a: { op: 'const', value: 0 }, b: { op: 'const', value: 0 } };
|
|
3103
3107
|
const laws = laws0.map(l => (l.some?.length && !l.forall && !l.witness ? { ...l, witness: ghostOf(m, l) } : l));
|
|
3104
3108
|
if (laws.some(l => l.some?.length && !l.forall && !l.witness))
|
|
3105
3109
|
return undefined;
|
|
3106
3110
|
const named = (d, l) => l.some.some(x => JSON.stringify(d).includes(`"name":${JSON.stringify(x)}`));
|
|
3107
|
-
const shape = (l) => (l.some?.length ? shapeOf(l) : l);
|
|
3108
3111
|
// (two keys at the bound value's places, the law's conjuncts that read the value and no map their frame)
|
|
3109
|
-
|
|
3112
|
+
const shapeOf = (l) => {
|
|
3110
3113
|
const x = l.some[0], at = (c, k) => substVars(c, { [x]: { op: 'var', name: k } }), ks = ['k$some', 'k2$some'];
|
|
3111
3114
|
const cs = l.holds.op === 'and' ? l.holds.xs : [l.holds], frame = cs.filter(c => named(c, l) && !JSON.stringify(c).includes('"op":"get"')), rest = cs.filter(c => !frame.includes(c));
|
|
3112
3115
|
return { name: l.name, forall: ks[0], keys: [ks[1]], holds: { op: 'or', xs: [{ op: 'not', x: { op: 'and', xs: ks.flatMap(k => frame.map(c => at(c, k))) } }, ...ks.flatMap(k => rest.map(c => at(c, k))), yes] } };
|
|
3113
|
-
}
|
|
3114
|
-
const
|
|
3115
|
-
const
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
tried.set(c.name, kept.length);
|
|
3122
|
-
// (a cube the kernel refuses to state, one past its key rules, is never kept)
|
|
3123
|
-
let ok = false;
|
|
3124
|
-
try {
|
|
3125
|
-
ok = withDeadline(Math.min(until, clock() + 1000), () => proveLaw(m, [...kept, c], kept.length)).proven;
|
|
3126
|
-
}
|
|
3127
|
-
catch { /* not kept */ }
|
|
3128
|
-
if (ok) {
|
|
3129
|
-
kept.push(c);
|
|
3130
|
-
grew = true;
|
|
3131
|
-
}
|
|
3116
|
+
};
|
|
3117
|
+
const shapes = laws.map(l => (l.some?.length ? shapeOf(l) : l));
|
|
3118
|
+
const set = [...withKinds(r, []), ...candidates(r, m, shapes, shapes, [], ms, until)];
|
|
3119
|
+
// (a cube the kernel refuses to state, one past its key rules, is never kept)
|
|
3120
|
+
const plain = (law, ls, ms2) => {
|
|
3121
|
+
try {
|
|
3122
|
+
const o = withDeadline(Math.min(until, clock() + ms2), () => proveLaw(m, ls, ls.indexOf(law)));
|
|
3123
|
+
return o.proven ? { proof: true } : { stuck: o.stuck };
|
|
3132
3124
|
}
|
|
3133
|
-
|
|
3125
|
+
catch {
|
|
3126
|
+
return { stuck: '' };
|
|
3127
|
+
}
|
|
3128
|
+
};
|
|
3129
|
+
const proven = cone(m, set, plain, until), kept = set.filter(c => proven.has(c.name));
|
|
3134
3130
|
if (knobs.GDP_EXISTS_LOG === '1')
|
|
3135
|
-
console.error(`exists: cone ${kept.length} of ${
|
|
3131
|
+
console.error(`exists: cone ${kept.length} of ${set.length} kept: ${kept.map(l => l.name).join('; ').slice(0, 2000)}`);
|
|
3136
3132
|
if (clock() > until)
|
|
3137
3133
|
return undefined;
|
|
3138
3134
|
const v = verdictOf(proveSome(m, [...laws, ...kept.filter(c => !laws.some(l => l.name === c.name))]));
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { type Cond, type FnDef, type Kind, type Rule, type Term } from './dsl.js';
|
|
3
|
+
import { type Law, type Rand } from './machine.js';
|
|
4
|
+
import { Refusal } from './extract-read.js';
|
|
5
|
+
import type { Name } from './extract.js';
|
|
6
|
+
type Any = any;
|
|
7
|
+
type Env = Record<string, Any>;
|
|
8
|
+
export type Api = (e: ts.Expression) => string | undefined;
|
|
9
|
+
export type ReadCtx = {
|
|
10
|
+
api: Api;
|
|
11
|
+
checker: ts.TypeChecker;
|
|
12
|
+
v4: boolean;
|
|
13
|
+
params: Map<ts.Node, string>;
|
|
14
|
+
sf: ts.SourceFile;
|
|
15
|
+
bound?: Map<ts.Node, Frag>;
|
|
16
|
+
outer?: (at: ts.Node) => never;
|
|
17
|
+
underMin?: boolean;
|
|
18
|
+
};
|
|
19
|
+
type Ctx = {
|
|
20
|
+
attempt: Term;
|
|
21
|
+
elapsed: Term;
|
|
22
|
+
first: Cond;
|
|
23
|
+
};
|
|
24
|
+
type Res = {
|
|
25
|
+
cont: Cond;
|
|
26
|
+
delay: Term;
|
|
27
|
+
out?: Term;
|
|
28
|
+
outDur?: boolean;
|
|
29
|
+
next: Record<string, Any>;
|
|
30
|
+
jittered?: boolean;
|
|
31
|
+
};
|
|
32
|
+
type Frag = {
|
|
33
|
+
step: (env: Env, get: (n: string) => Any, c: Ctx) => Res;
|
|
34
|
+
names: string[];
|
|
35
|
+
jitters?: string[];
|
|
36
|
+
};
|
|
37
|
+
type Init = {
|
|
38
|
+
kind: 'nat' | 'bool';
|
|
39
|
+
init: number | boolean | ((p: Env) => Term);
|
|
40
|
+
};
|
|
41
|
+
declare class Parts {
|
|
42
|
+
params: Map<string, Kind<unknown>>;
|
|
43
|
+
inputs: Map<string, Kind<unknown>>;
|
|
44
|
+
fns: Record<string, FnDef>;
|
|
45
|
+
assume: ((env: Env) => Cond)[];
|
|
46
|
+
state: Map<string, Init>;
|
|
47
|
+
notes: Set<string>;
|
|
48
|
+
jitters: {
|
|
49
|
+
name: string;
|
|
50
|
+
base: string;
|
|
51
|
+
on: string;
|
|
52
|
+
lo: [number, number];
|
|
53
|
+
hi: [number, number];
|
|
54
|
+
}[];
|
|
55
|
+
inputType?: ts.Type;
|
|
56
|
+
inputAt?: ts.Node;
|
|
57
|
+
fields: Map<string, Kind<unknown>>;
|
|
58
|
+
private n;
|
|
59
|
+
fresh(stem: string): string;
|
|
60
|
+
initOf(name: string, env: Env): Any;
|
|
61
|
+
}
|
|
62
|
+
export declare function readSchedule(e: ts.Expression, rc: ReadCtx, parts?: Parts): {
|
|
63
|
+
frag: Frag;
|
|
64
|
+
parts: Parts;
|
|
65
|
+
};
|
|
66
|
+
export type ScheduleRule = {
|
|
67
|
+
rule: Rule;
|
|
68
|
+
notes: string[];
|
|
69
|
+
names: Name[];
|
|
70
|
+
jitters: Parts['jitters'];
|
|
71
|
+
fields: Map<string, Kind<unknown>>;
|
|
72
|
+
params: string[];
|
|
73
|
+
v4: boolean;
|
|
74
|
+
};
|
|
75
|
+
export declare function scheduleRule(frag: Frag, P: Parts, name: string, v4: boolean): ScheduleRule;
|
|
76
|
+
type Decide = (now: number, input: unknown, randoms: number[]) => {
|
|
77
|
+
cont: boolean;
|
|
78
|
+
delay: number;
|
|
79
|
+
};
|
|
80
|
+
export declare function stepper(E: Any, schedule: unknown): Decide;
|
|
81
|
+
export declare function scheduleConforms(s: ScheduleRule, make: (params: Record<string, number>) => unknown, E: Any, opts?: {
|
|
82
|
+
runs?: number;
|
|
83
|
+
depth?: number;
|
|
84
|
+
seed?: number;
|
|
85
|
+
params?: (rand: Rand) => Record<string, number>;
|
|
86
|
+
input?: (rand: Rand) => unknown;
|
|
87
|
+
}): {
|
|
88
|
+
checked: number;
|
|
89
|
+
failure?: string;
|
|
90
|
+
};
|
|
91
|
+
export declare function replaySchedule(s: ScheduleRule, schedule: unknown, E: Any, run: {
|
|
92
|
+
params: Record<string, number>;
|
|
93
|
+
trace: Record<string, unknown>[];
|
|
94
|
+
}): {
|
|
95
|
+
ok: boolean;
|
|
96
|
+
what: string;
|
|
97
|
+
};
|
|
98
|
+
export declare function jitterRun(s: ScheduleRule, law: Law, depth?: number, params?: Record<string, number>): {
|
|
99
|
+
params: Record<string, number>;
|
|
100
|
+
trace: Record<string, unknown>[];
|
|
101
|
+
} | undefined;
|
|
102
|
+
export declare const notSchedule: (at: ts.Node) => Refusal;
|
|
103
|
+
export { Parts };
|