gdp-wired 0.42.0 → 0.44.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 +14 -3
- package/dist/core/cli.d.ts +8 -1
- package/dist/core/cli.js +271 -30
- package/dist/core/counts.d.ts +8 -1
- package/dist/core/counts.js +171 -302
- package/dist/core/data.js +2 -2
- package/dist/core/dsl.js +26 -30
- package/dist/core/effect-prims.d.ts +60 -0
- package/dist/core/effect-prims.js +625 -0
- package/dist/core/effect-schedule.d.ts +103 -0
- package/dist/core/effect-schedule.js +817 -0
- package/dist/core/effect.d.ts +36 -1
- package/dist/core/effect.js +656 -29
- package/dist/core/ex/harness.exs +2 -0
- package/dist/core/exists.d.ts +5 -0
- package/dist/core/exists.js +98 -34
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +5 -3
- package/dist/core/extract-check.d.ts +2 -0
- package/dist/core/extract-check.js +45 -4
- package/dist/core/extract-ex.js +2 -2
- package/dist/core/extract-go-check.js +4 -6
- package/dist/core/extract-go.d.ts +3 -0
- package/dist/core/extract-go.js +4 -4
- package/dist/core/extract-jvm.js +6 -3
- package/dist/core/extract-print.js +9 -2
- package/dist/core/extract-py.js +2 -2
- package/dist/core/extract-rb.js +2 -2
- package/dist/core/extract-read.js +2 -1
- package/dist/core/extract-rs.js +12 -7
- package/dist/core/extract-sol.js +4 -4
- package/dist/core/extract-step.d.ts +18 -0
- package/dist/core/extract-step.js +135 -31
- package/dist/core/extract-swift.js +3 -3
- 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 +10 -7
- package/dist/core/jvm/Harness.java +8 -1
- package/dist/core/jvm/Jvm.java +1 -1
- package/dist/core/jvm/KtReader.java +3 -0
- package/dist/core/laws.d.ts +4 -0
- package/dist/core/laws.js +176 -9
- package/dist/core/machine.d.ts +3 -0
- package/dist/core/machine.js +17 -3
- package/dist/core/py/harness.py +64 -19
- package/dist/core/py/reader.py +51 -1
- package/dist/core/sol/Replay.sol +52 -0
- package/dist/core/sol/harness.py +508 -0
- package/dist/core/system.d.ts +44 -0
- package/dist/core/system.js +435 -0
- package/dist/interchange/check.d.ts +18 -1
- package/dist/interchange/check.js +9 -2
- package/dist/interchange/cli.d.ts +2 -0
- package/dist/interchange/cli.js +45 -0
- package/dist/interchange/format.d.ts +1 -1
- package/dist/interchange/format.js +15 -7
- package/dist/kernel/cdcl.js +32 -12
- package/dist/kernel/kernel.js +3 -2
- package/dist/kernel/prove.d.ts +1 -0
- package/dist/kernel/prove.js +69 -8
- package/dist/kernel/reader.js +3 -2
- 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 +12 -3
package/dist/core/data.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
// using the others at the fields of their datatypes (mutual induction). Lemmas the law needs are found by the values
|
|
27
27
|
// (theory exploration: equations between terms the random values agree on, then the shapes of a predicate kept), proven
|
|
28
28
|
// the same way at lower levels, and used at the terms of the law they match.
|
|
29
|
-
import { argsKey, atMost as leC, get, n as k, same as eqC, walk, x as ev } from "./machine.js";
|
|
29
|
+
import { argsKey, atMost as leC, get, n as k, same as eqC, walk, x as ev, lcgFloat } from "./machine.js";
|
|
30
30
|
import { substC, substE } from "../kernel/kernel.js";
|
|
31
31
|
import { and as andC, implies, proveCyclic } from "./cyclic.js";
|
|
32
32
|
import { clock, counted, pairedKeys, withDeadline } from "../kernel/prove.js";
|
|
@@ -1160,7 +1160,7 @@ export const showValue = (d, v) => {
|
|
|
1160
1160
|
const c = d.ctors[v.c];
|
|
1161
1161
|
return c.fields.length ? `${c.name}(${c.fields.map((f, i) => showValue(fieldSort(f), v.f[i])).join(', ')})` : c.name;
|
|
1162
1162
|
};
|
|
1163
|
-
export const rng = (seed) => () =>
|
|
1163
|
+
export const rng = (seed) => () => (seed = lcgFloat(seed)) / 2147483648; // (a search's draws: machine.ts's lcgFloat)
|
|
1164
1164
|
// `full`: a value that fills its size (a constructor with a field of the group, unless the size is spent, or at 1 in 8),
|
|
1165
1165
|
// where the plain draw mostly stops at a leaf (a list of length 0 or 1, most often).
|
|
1166
1166
|
export function randomValue(s, rand, size, natMax = 5, full = false) {
|
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,60 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import type { StepLaw } from './dsl.js';
|
|
3
|
+
import { type Law } from './machine.js';
|
|
4
|
+
import { type Setup } from './extract-read.js';
|
|
5
|
+
import type { Extraction } from './extract.js';
|
|
6
|
+
export type Strategy = 'bounded' | 'dropping' | 'sliding' | 'unbounded';
|
|
7
|
+
export type Prim = {
|
|
8
|
+
name: string;
|
|
9
|
+
kind: 'queue';
|
|
10
|
+
strategy: Strategy;
|
|
11
|
+
capacity?: number | string;
|
|
12
|
+
fields: string[];
|
|
13
|
+
} | {
|
|
14
|
+
name: string;
|
|
15
|
+
kind: 'semaphore';
|
|
16
|
+
permits: number | string;
|
|
17
|
+
fields: string[];
|
|
18
|
+
};
|
|
19
|
+
type Api = (e: ts.Expression) => string | undefined;
|
|
20
|
+
export declare const WAITS_FOREVER = "an operation that interrupts its fiber on a shut-down queue (every one on Effect 3, take on Effect 4) is read as a wait that never ends: the fiber takes no step after it, which is what an interrupted one does";
|
|
21
|
+
export declare function rewritePrims(s: Setup, made: {
|
|
22
|
+
fn: ts.FunctionLikeDeclaration;
|
|
23
|
+
params: readonly ts.ParameterDeclaration[];
|
|
24
|
+
}, api: Api, v4: boolean, opts?: {
|
|
25
|
+
params?: boolean;
|
|
26
|
+
}): {
|
|
27
|
+
code: string;
|
|
28
|
+
prims: Prim[];
|
|
29
|
+
notes: string[];
|
|
30
|
+
} | undefined;
|
|
31
|
+
type Mod = Record<string, any>;
|
|
32
|
+
export type Spec = {
|
|
33
|
+
kind: 'queue';
|
|
34
|
+
strategy: Strategy;
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'semaphore';
|
|
37
|
+
};
|
|
38
|
+
export declare function primitiveRule(spec: Spec, effect: Mod, opts?: {
|
|
39
|
+
runs?: number;
|
|
40
|
+
file?: string;
|
|
41
|
+
}): Extraction;
|
|
42
|
+
export declare function primitiveLaws(x: Extraction, spec: Spec): {
|
|
43
|
+
laws: Law[];
|
|
44
|
+
stepLaws: StepLaw[];
|
|
45
|
+
refuted: Law[];
|
|
46
|
+
};
|
|
47
|
+
export declare function primitiveConforms(spec: Spec, effect: Mod, opts?: {
|
|
48
|
+
runs?: number;
|
|
49
|
+
depth?: number;
|
|
50
|
+
seed?: number;
|
|
51
|
+
x?: Extraction;
|
|
52
|
+
file?: string;
|
|
53
|
+
}): Promise<{
|
|
54
|
+
checked: number;
|
|
55
|
+
waited: number;
|
|
56
|
+
blocked: number;
|
|
57
|
+
interrupted: number;
|
|
58
|
+
failure?: string;
|
|
59
|
+
}>;
|
|
60
|
+
export {};
|