gdp-wired 0.30.0 → 0.31.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 +12 -2
- package/dist/core/chart.d.ts +2 -2
- package/dist/core/chart.js +1 -1
- package/dist/core/cyclic.d.ts +3 -2
- package/dist/core/cyclic.js +12 -5
- package/dist/core/data.d.ts +5 -0
- package/dist/core/data.js +66 -10
- package/dist/core/discover.js +1 -0
- package/dist/core/dsl.d.ts +8 -0
- package/dist/core/dsl.js +42 -14
- package/dist/core/effect.d.ts +47 -0
- package/dist/core/effect.js +481 -0
- package/dist/core/extract-check.js +4 -4
- package/dist/core/extract-print.js +2 -2
- package/dist/core/extract-read.d.ts +22 -7
- package/dist/core/extract-read.js +95 -17
- package/dist/core/extract-shapes.d.ts +20 -2
- package/dist/core/extract-shapes.js +37 -23
- package/dist/core/extract-xstate.js +2 -5
- package/dist/core/extract.js +5 -6
- package/dist/core/infer.js +439 -120
- package/dist/core/machine.js +13 -4
- package/dist/core/nonterm.js +30 -2
- package/dist/core/transfer.js +27 -4
- package/dist/core/translate.d.ts +2 -2
- package/dist/core/translate.js +6 -3
- package/dist/core/watch.d.ts +5 -1
- package/dist/core/watch.js +65 -9
- package/dist/kernel/cdcl.js +4 -3
- package/dist/kernel/kernel.d.ts +2 -2
- package/dist/kernel/kernel.js +13 -7
- package/dist/kernel/prove.d.ts +14 -0
- package/dist/kernel/prove.js +256 -46
- package/dist/lean-kernel/emit.d.ts +1 -0
- package/dist/lean-kernel/emit.js +12 -5
- package/dist/lean-kernel/library.js +1 -1
- package/package.json +12 -2
package/dist/core/machine.js
CHANGED
|
@@ -298,14 +298,23 @@ export function evalC(c, env, st, m) {
|
|
|
298
298
|
// same value, which need not be the default), and past it the value is the new default.
|
|
299
299
|
function writeEvery(w, env, st, m) {
|
|
300
300
|
if (!plainKey(w.value, w.each)) {
|
|
301
|
-
const
|
|
301
|
+
const ks = breakKeys(breaksOf(w.value, w.each), env, st, m), top = ks.at(-1);
|
|
302
302
|
if (top > 1_000_000)
|
|
303
303
|
throw new RangeError(`a write at every key reads its key in arithmetic past a million keys (${top})`);
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
304
|
+
// (each breakpoint on its own, and each stretch between two at one key of it: no read moves and no comparison turns
|
|
305
|
+
// inside one, so it holds one value; most stretches hold the default, and a stretch that doesn't is filled)
|
|
306
|
+
const at = (key) => evalE(w.value, { ...env, [w.each]: key }, st, m);
|
|
307
|
+
const fallback = at(top), cells = new Map();
|
|
308
|
+
for (let i = 0; i + 1 < ks.length; i++) {
|
|
309
|
+
const key = ks[i], v = at(key);
|
|
307
310
|
if (v !== fallback)
|
|
308
311
|
cells.set(key, v);
|
|
312
|
+
if (ks[i + 1] > key + 1) {
|
|
313
|
+
const u = at(key + 1);
|
|
314
|
+
if (u !== fallback)
|
|
315
|
+
for (let k2 = key + 1; k2 < ks[i + 1]; k2++)
|
|
316
|
+
cells.set(k2, u);
|
|
317
|
+
}
|
|
309
318
|
}
|
|
310
319
|
return { cells, default: fallback };
|
|
311
320
|
}
|
package/dist/core/nonterm.js
CHANGED
|
@@ -66,6 +66,34 @@ function simpE0(e) {
|
|
|
66
66
|
case 'get': return { op: 'get', map: e.map, key: simpE(e.key) };
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
+
// An and's (an or's) parts simplified, its nested and-s (or-s) walked in place, each part once (x ∧ x is x): the parts
|
|
70
|
+
// of each nested one simplified and flattened in turn, in order, the same object kept at its first place. A part shared
|
|
71
|
+
// along a DAG (an interpolant's: binary and-s and or-s whose parts recur) is read once, not once per path to it.
|
|
72
|
+
function partsOf(c) {
|
|
73
|
+
const out = [], seen = new Set();
|
|
74
|
+
const put = (y) => { if (!seen.has(y)) {
|
|
75
|
+
seen.add(y);
|
|
76
|
+
out.push(y);
|
|
77
|
+
} };
|
|
78
|
+
for (const todo = [...c.xs].reverse(); todo.length;) {
|
|
79
|
+
const x = todo.pop();
|
|
80
|
+
if (seen.has(x))
|
|
81
|
+
continue;
|
|
82
|
+
seen.add(x);
|
|
83
|
+
if (x.op === c.op && !simpMemo.has(x)) {
|
|
84
|
+
for (let i = x.xs.length - 1; i >= 0; i--)
|
|
85
|
+
todo.push(x.xs[i]);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const y = simpC(x);
|
|
89
|
+
if (y.op === c.op)
|
|
90
|
+
for (const z of y.xs)
|
|
91
|
+
put(z);
|
|
92
|
+
else
|
|
93
|
+
put(y);
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
69
97
|
function simpC0(c) {
|
|
70
98
|
switch (c.op) {
|
|
71
99
|
case '<=':
|
|
@@ -76,8 +104,8 @@ function simpC0(c) {
|
|
|
76
104
|
return (c.op === '<=' ? a.value <= b.value : c.op === '<' ? a.value < b.value : a.value === b.value) ? T : F;
|
|
77
105
|
return { op: c.op, a, b };
|
|
78
106
|
}
|
|
79
|
-
case 'and': return and(c
|
|
80
|
-
case 'or': return or(c
|
|
107
|
+
case 'and': return and(partsOf(c));
|
|
108
|
+
case 'or': return or(partsOf(c));
|
|
81
109
|
case 'not': {
|
|
82
110
|
const x = simpC(c.x);
|
|
83
111
|
return isT(x) ? F : isF(x) ? T : { op: 'not', x };
|
package/dist/core/transfer.js
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
// copies below (each again, down to the recursive functions), so the induction is chosen on what the law means. A
|
|
6
6
|
// law that grows past eight times its size so (definitions unfolded into each other's arguments) isn't unfolded.
|
|
7
7
|
// - Bridges: a recursive function of one or two naturals that computes a built-in (+, ∸, min, max, ≤, <, =, ≥, >, ≠,
|
|
8
|
-
// x + 1, x ∸ 1, 2·x, x = 0) at every argument up to 6 (12 for one) is a candidate,
|
|
9
|
-
//
|
|
10
|
-
// bridge
|
|
8
|
+
// x + 1, x ∸ 1, 2·x, x = 0) at every argument up to 6 (12 for one) is a candidate, as is a recursive Bool function of
|
|
9
|
+
// two values of one datatype that is their equality or its negation at 160 pairs of random values (half of them a
|
|
10
|
+
// value and itself: a Horn system's `diseq` predicates, compare/chc-adt), unless its bridge law (the function is the
|
|
11
|
+
// built-in, at every argument) is the law itself; the bridge law is proven by the search first, and only a bridge
|
|
12
|
+
// proven is used.
|
|
11
13
|
// - Copies: a recursive function that calls a bridged one, one unfolded, or a copied one is copied with the built-in,
|
|
12
14
|
// the body or the copy in its place, and its copy law (it is its copy at every argument) proven: one node made from
|
|
13
15
|
// the two bodies walked together (its recursive calls by the node's own induction, at its recursion's uses), or,
|
|
@@ -19,7 +21,7 @@
|
|
|
19
21
|
// and the same call at the arguments said another way. Its goal is equalities; nothing is assumed.
|
|
20
22
|
// The bridges and the copies' laws are nodes like any lemma's, at levels below the law's.
|
|
21
23
|
import { n as k, walk } from "./machine.js";
|
|
22
|
-
import { Bool, Integer, Nat, Val, argsOf, bindName, define, encX, encY, evalX, factsOf, fnNamed, programOf, rankWidth, schemesOf, searchIn } from "./data.js";
|
|
24
|
+
import { Bool, Integer, Nat, Val, argsOf, bindName, define, encX, encY, evalX, factsOf, fnNamed, programOf, randomValue, rankWidth, rng, schemesOf, searchIn } from "./data.js";
|
|
23
25
|
import { proveCyclic } from "./cyclic.js";
|
|
24
26
|
import { clock, pairedKeys, withDeadline } from "../kernel/prove.js";
|
|
25
27
|
import { substE } from "../kernel/kernel.js";
|
|
@@ -57,6 +59,8 @@ const taken = (f) => recursive(f) || f.measure !== undefined;
|
|
|
57
59
|
// The built-in a recursive function of naturals (structural, or well-founded: its termination proven) computes at every
|
|
58
60
|
// argument up to 6 (one argument: up to 12; three: up to 5; four: up to 3), if one.
|
|
59
61
|
function builtinOf(f) {
|
|
62
|
+
if (taken(f) && !f.paramFns.length && f.ret === 'bool' && f.params.length === 2 && typeof f.params[0].sort === 'object' && f.params[0].sort === f.params[1].sort && !f.params[0].sort.abstract)
|
|
63
|
+
return equalityOf(f);
|
|
60
64
|
if (!taken(f) || f.paramFns.length || !(f.ret === 'nat' || f.ret === 'bool') || !f.params.every(q => q.sort === 'nat'))
|
|
61
65
|
return undefined;
|
|
62
66
|
const n = f.params.length;
|
|
@@ -89,6 +93,25 @@ function builtinOf(f) {
|
|
|
89
93
|
const op = linear(cs, c0);
|
|
90
94
|
return agrees(op) ? op : undefined;
|
|
91
95
|
}
|
|
96
|
+
// = or ≠, if f (a Bool function of two values of one datatype) is it at 160 pairs of random values, half of them a value
|
|
97
|
+
// and itself.
|
|
98
|
+
function equalityOf(f) {
|
|
99
|
+
const rand = rng(3), s = f.params[0].sort, args = [{ op: 'var', name: '$p' }, { op: 'var', name: '$q' }];
|
|
100
|
+
let eq = true, ne = true;
|
|
101
|
+
for (let i = 0; i < 160 && (eq || ne); i++) {
|
|
102
|
+
const a = randomValue(s, rand, 1 + (i % 6)), b = i % 2 ? a : randomValue(s, rand, 1 + (i % 6)), same = JSON.stringify(a) === JSON.stringify(b);
|
|
103
|
+
let v;
|
|
104
|
+
try {
|
|
105
|
+
v = evalX({ op: 'call', fn: f.name, args }, new Map([['$p', a], ['$q', b]]), {});
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
eq &&= v === +same;
|
|
111
|
+
ne &&= v === +!same;
|
|
112
|
+
}
|
|
113
|
+
return eq ? OPS.find(o => o.name === '=') : ne ? OPS.find(o => o.name === '≠') : undefined;
|
|
114
|
+
}
|
|
92
115
|
// Whether `y` is f's bridge law: f at distinct variables equal (either side) to the built-in at them.
|
|
93
116
|
function isBridge(y, f, op) {
|
|
94
117
|
if (y.op !== '=')
|
package/dist/core/translate.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type TStats = {
|
|
|
19
19
|
cached: number;
|
|
20
20
|
};
|
|
21
21
|
export declare const tstats: () => TStats;
|
|
22
|
-
export declare function translate(part: Goal, whole: Goal, tree: Tree, ren0: Renamer, st: TStats,
|
|
22
|
+
export declare function translate(part: Goal, whole: Goal, tree: Tree, ren0: Renamer, st: TStats, until0: number, pp?: Path, wp?: Path, swaps?: [string, string][]): Tree | undefined;
|
|
23
23
|
export type Reads = {
|
|
24
24
|
k: E;
|
|
25
25
|
w: E;
|
|
@@ -27,4 +27,4 @@ export type Reads = {
|
|
|
27
27
|
export declare function readsFirst(whole: Goal, reads: Reads, ren: Renamer, inner: (wp: Path, swaps: [string, string][]) => Tree | undefined, st: TStats, until: number, wp?: Path, swaps?: [string, string][]): Tree | undefined;
|
|
28
28
|
export declare function decide(whole: Goal, conds: C[], inner: (wp: Path) => Tree | undefined, st: TStats, until: number, wp?: Path): Tree | undefined;
|
|
29
29
|
export declare function close(g: Goal, wp: Path, st: TStats, until: number): Tree | undefined;
|
|
30
|
-
export declare function carry(g: Goal, nFacts: number, nUses: number, st: TStats,
|
|
30
|
+
export declare function carry(g: Goal, nFacts: number, nUses: number, st: TStats, until0: number): Tree | undefined;
|
package/dist/core/translate.js
CHANGED
|
@@ -13,7 +13,7 @@ import { walk } from "./machine.js";
|
|
|
13
13
|
import { add, costs, env, refuteFast, scale, solve } from "./solver.js";
|
|
14
14
|
import { checkRefutation } from "./check.js";
|
|
15
15
|
import { canon, canonFlip, columnTerm, factorsOf, isCell, isMonomial, leafConstraints, leafConstraintsReusing, linear, substE, truth, withProducts } from "../kernel/kernel.js";
|
|
16
|
-
import { cellProducts, clock, grow, leafRowsOf, parseKey } from "../kernel/prove.js";
|
|
16
|
+
import { cellProducts, clock, grow, leafRowsOf, parseKey, withinDeadline } from "../kernel/prove.js";
|
|
17
17
|
import { Reader, times } from "../kernel/reader.js";
|
|
18
18
|
const omega = 'O$';
|
|
19
19
|
const debugOn = () => !!env.GDP_CYCLIC_DEBUG;
|
|
@@ -145,7 +145,9 @@ function regrow(whole, wp, until) {
|
|
|
145
145
|
// key W equal to a key K the node's conclusion reads its map at, that conclusion reads at K what the usual one reads at
|
|
146
146
|
// W (a write's reads at its key read at the key read, as the step's facts have them), so the usual cells at W are read
|
|
147
147
|
// as the cells at K (`readsFirst` decides the two equal or apart first).
|
|
148
|
-
export function translate(part, whole, tree, ren0, st,
|
|
148
|
+
export function translate(part, whole, tree, ren0, st, until0, pp = new Map(), wp = new Map(), swaps = []) {
|
|
149
|
+
// (within the deadline it runs in too: a certificate's translation, core/cyclic.ts's translateMs)
|
|
150
|
+
const until = withinDeadline(until0);
|
|
149
151
|
const ren = swaps.length ? (lin, p) => {
|
|
150
152
|
const out = {};
|
|
151
153
|
for (const key in lin) {
|
|
@@ -492,7 +494,8 @@ export function close(g, wp, st, until) {
|
|
|
492
494
|
// one where both are decided by whichever of the two hypotheses is then false. A case none of that refutes is grown on
|
|
493
495
|
// the goal at its path.
|
|
494
496
|
// `nUses`: the uses' hypotheses, just before the conclusion refuted (mainGoal's order).
|
|
495
|
-
export function carry(g, nFacts, nUses, st,
|
|
497
|
+
export function carry(g, nFacts, nUses, st, until0) {
|
|
498
|
+
const until = withinDeadline(until0);
|
|
496
499
|
const last = g.hyps.length - 1, uses = g.hyps.slice(last - nUses, last), facts = g.hyps.slice(last - nUses - nFacts, last - nUses);
|
|
497
500
|
const law = g.hyps[last].x;
|
|
498
501
|
const parts = uses.map(u => (u.op === 'or' && u.xs.length === 2 && u.xs[0].op === 'not' ? { guard: u.xs[0].x, concl: u.xs[1] } : { guard: undefined, concl: u }));
|
package/dist/core/watch.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Law, type Machine, type Request, type State, type interpret } from './machine.js';
|
|
1
|
+
import { type E, type Law, type Machine, type Request, type State, type interpret } from './machine.js';
|
|
2
2
|
import type { StepLaw } from '../kernel/kernel.js';
|
|
3
3
|
export type Watched = Law | StepLaw;
|
|
4
4
|
export declare const isStepLaw: (w: Watched) => w is StepLaw;
|
|
@@ -7,6 +7,10 @@ type Env = Record<string, number>;
|
|
|
7
7
|
export declare function requestEnv(m: Machine, run: Runtime, params: Env, st: State, input: Request): Env;
|
|
8
8
|
export declare const allowed: (m: Machine, run: Runtime, params: Env, st: State, input: Request) => boolean;
|
|
9
9
|
export declare const keysOf: (bound: number, ...states: State[]) => number[];
|
|
10
|
+
export declare const linKey: (e: E, ok: (v: string) => boolean, k: number, out: Map<string, number>) => boolean;
|
|
11
|
+
export declare const watchWork: {
|
|
12
|
+
n: number;
|
|
13
|
+
};
|
|
10
14
|
export declare function watch(m: Machine, run: Runtime, w: Watched, params: Env, bound: number): {
|
|
11
15
|
start: (st: State) => boolean;
|
|
12
16
|
step: (_before: State, _input: Request, after: State) => boolean;
|
package/dist/core/watch.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// at every k steps in a row the run takes: each step's `when` read with the state it starts from, its request, queries
|
|
8
8
|
// and flags; `then` with the state before the first step (plain names), the first request and its flags, the j-th
|
|
9
9
|
// request as input@j, and the state and maps after the last step (primed names).
|
|
10
|
-
import { carriedView, evalC, numbersOf } from "./machine.js";
|
|
10
|
+
import { carriedView, evalC, numbersOf, walk } from "./machine.js";
|
|
11
11
|
import { someHolds } from "./exists.js";
|
|
12
12
|
export const isStepLaw = (w) => 'then' in w;
|
|
13
13
|
// A request's environment: the params, its inputs and queries, and the step's flags decided (as ?name).
|
|
@@ -34,20 +34,76 @@ export const keysOf = (bound, ...states) => {
|
|
|
34
34
|
keys.add(key);
|
|
35
35
|
return [...keys];
|
|
36
36
|
};
|
|
37
|
+
// A key c·x + … + d as its coefficients by name ('1': d), where each name `ok` takes (core/infer.ts's pairings too).
|
|
38
|
+
export const linKey = (e, ok, k, out) => (e.op === 'const' ? (out.set('1', (out.get('1') ?? 0) + k * e.value), true) : e.op === 'var' ? ok(e.name) && (out.set(e.name, (out.get(e.name) ?? 0) + k), true) : e.op === 'add' ? linKey(e.a, ok, k, out) && linKey(e.b, ok, k, out) : e.op === 'mul' ? linKey(e.a, ok, k * e.k, out) : false);
|
|
39
|
+
// The keys each of a law's names is read at: a name keyed in a map's reads (M[x], M[k·N + j], M[k·N² + j·N + i]) only
|
|
40
|
+
// linearly takes, of each key the map holds, its digit there (the key in mixed radix by the coefficients), and 0 to
|
|
41
|
+
// bound + 1; a name keyed otherwise, or nowhere, every key (keysOf). A composed key is no value of its parts, and a law
|
|
42
|
+
// about n names was read at (keys)^n tuples a step. Untrusted: where a run checks a law.
|
|
43
|
+
function keysPer(c, names) {
|
|
44
|
+
const reads = new Map(), wide = new Set();
|
|
45
|
+
walk(c, o => {
|
|
46
|
+
if (o.op !== 'get')
|
|
47
|
+
return;
|
|
48
|
+
const l = new Map(), key = JSON.stringify(o.key);
|
|
49
|
+
if (linKey(o.key, x => names.includes(x), 1, l)) {
|
|
50
|
+
const d = l.get('1') ?? 0;
|
|
51
|
+
l.delete('1');
|
|
52
|
+
const t = [...l].sort((a, b) => b[1] - a[1]);
|
|
53
|
+
for (const [x] of t)
|
|
54
|
+
reads.set(x, [...(reads.get(x) ?? []), { map: o.map, l: t, d }]);
|
|
55
|
+
}
|
|
56
|
+
else
|
|
57
|
+
for (const x of names)
|
|
58
|
+
if (key.includes(`"name":${JSON.stringify(x)}`))
|
|
59
|
+
wide.add(x);
|
|
60
|
+
});
|
|
61
|
+
return (bound, st, all) => names.map(x => {
|
|
62
|
+
const rs = reads.get(x);
|
|
63
|
+
if (!rs || wide.has(x))
|
|
64
|
+
return all();
|
|
65
|
+
const vals = new Set(Array.from({ length: bound + 2 }, (_, i) => i));
|
|
66
|
+
for (const r of rs)
|
|
67
|
+
for (const key of st.maps[r.map]?.keys() ?? []) {
|
|
68
|
+
let rest = key - r.d;
|
|
69
|
+
if (rest >= 0)
|
|
70
|
+
for (const [y, c] of r.l) {
|
|
71
|
+
const v = Math.floor(rest / c);
|
|
72
|
+
rest -= v * c;
|
|
73
|
+
if (y === x)
|
|
74
|
+
vals.add(v);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return [...vals];
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
// The tuples every watch has read a law at (core/dsl.ts's refuteByRuns counts its budget in them).
|
|
81
|
+
export const watchWork = { n: 0 };
|
|
37
82
|
// Watches one law or step law along one run: `start` with the state at the start, `step` after each step the run takes
|
|
38
83
|
// (the state before, the request, the state after). Each says whether the law still holds.
|
|
39
84
|
export function watch(m, run, w, params, bound) {
|
|
40
|
-
// At every tuple of the keys, one key per name.
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
const go = (i
|
|
44
|
-
|
|
85
|
+
// At every tuple of the keys (each name's own: keysPer), one key per name, in one environment set in place.
|
|
86
|
+
const names = w.forall ? [w.forall, ...(w.keys ?? [])] : [], per = keysPer(isStepLaw(w) ? w.then : w.holds, names);
|
|
87
|
+
const atKeys = (keys, env, f) => {
|
|
88
|
+
const go = (i) => {
|
|
89
|
+
if (i === names.length) {
|
|
90
|
+
watchWork.n++;
|
|
91
|
+
return f(env);
|
|
92
|
+
}
|
|
93
|
+
for (const key of keys[i]) {
|
|
94
|
+
env[names[i]] = key;
|
|
95
|
+
if (!go(i + 1))
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
};
|
|
100
|
+
return go(0);
|
|
45
101
|
};
|
|
46
102
|
if (!isStepLaw(w)) {
|
|
47
103
|
// A law with "there exists" (core/exists.ts): broken only where no value can be a witness, as far as that is decided
|
|
48
104
|
// (one natural or integer read linearly); undecided, it is kept.
|
|
49
|
-
const at = (env, st) => (w.some?.length ? someHolds(w.holds, w.some, env, st, m)?.holds ?? true : evalC(w.holds, env, st, m));
|
|
50
|
-
const holds = (st) => atKeys(
|
|
105
|
+
const at = (env, st) => (w.some?.length ? someHolds(w.holds, w.some, { ...env }, st, m)?.holds ?? true : evalC(w.holds, env, st, m));
|
|
106
|
+
const holds = (st) => atKeys(per(bound, st, () => keysOf(bound, st)), { ...params }, env => at(env, st));
|
|
51
107
|
return { start: holds, step: (_before, _input, after) => holds(after) };
|
|
52
108
|
}
|
|
53
109
|
const k = w.steps ?? 1, whens = w.when === undefined ? [] : Array.isArray(w.when) ? w.when : [w.when];
|
|
@@ -76,7 +132,7 @@ export function watch(m, run, w, params, bound) {
|
|
|
76
132
|
maps: { ...first.maps, ...Object.fromEntries(Object.entries(after.maps).map(([n, cells]) => [`${n}'`, cells])) },
|
|
77
133
|
defaults: { ...first.defaults, ...Object.fromEntries(Object.entries(after.defaults ?? {}).map(([n, d]) => [`${n}'`, d])) },
|
|
78
134
|
};
|
|
79
|
-
return atKeys(
|
|
135
|
+
return atKeys(per(bound, both, () => keysOf(bound, first, after)), { ...env }, e => evalC(w.then, e, both, primedMaps));
|
|
80
136
|
},
|
|
81
137
|
};
|
|
82
138
|
}
|
package/dist/kernel/cdcl.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
import { costs, env, refuteFast, solve, work } from "../core/solver.js";
|
|
21
21
|
import { checkRefutation } from "../core/check.js";
|
|
22
22
|
import { atomOf, canon, canonFlip, isMonomial, leafConstraints } from "./kernel.js";
|
|
23
|
-
import { cellPair, late, leafRowsOf, logged, nearOf, openAt, pairedKeys, queryHook, rowsAt, unitAtoms } from "./prove.js";
|
|
23
|
+
import { atPoint, cellPair, late, leafRowsOf, logged, nearOf, openAt, pairedKeys, queryHook, rowsAt, unitAtoms } from "./prove.js";
|
|
24
24
|
import { Clausal, Reader, namesOf } from "./reader.js";
|
|
25
25
|
import { Simplex } from "./simplex.js";
|
|
26
26
|
// A derivation's own inputs: the rows it reads, in order, and the steps renumbered to them.
|
|
@@ -56,7 +56,8 @@ const lpFill = Number(env.GDP_CDCL_FILL ?? 8), lpGrow = Number(env.GDP_CDCL_GROW
|
|
|
56
56
|
// Counters research/step reads (times only while `on`).
|
|
57
57
|
export const cdclStats = { on: false, runs: 0, proven: 0, conflicts: 0, decisions: 0, solveMs: 0, rowsMs: 0, coreMs: 0, unfoldMs: 0, leaves: 0, resolved: 0, coreSize: 0, pathSize: 0, lpMisses: 0, resolved2: 0, unfoldWhy: '', orderMs: 0, boundMs: 0, openMisses: 0, lpMs: 0, lpUnknown: 0, fmCalls: 0, pivots: 0, lpRebuilds: 0, lpRows: 0, lpNnz: 0, lpVars: 0, lpLoad: 0, nodes: 0, boundRounds: 0 };
|
|
58
58
|
// `opts.model`: only whether the goal has a model is wanted (core/bmc.ts): a refutation isn't unfolded into a tree, its
|
|
59
|
-
// outcome `unknown` with `why` REFUTED; each decision's phase is the simplex's point's (phaseAtPoint
|
|
59
|
+
// outcome `unknown` with `why` REFUTED; each decision's phase is the simplex's point's (phaseAtPoint; in the tree search too
|
|
60
|
+
// where prove.ts's `atPoint` is on); past `opts.wall` (wall time) the search stops as past its budget.
|
|
60
61
|
// `opts.core`, with `model`: a refutation's outcome also names the hypotheses its leaves read (`core`, their indices in
|
|
61
62
|
// goal.hyps): those alone have no model (each leaf's rows are those hypotheses' facts at its decisions, or rows true of
|
|
62
63
|
// any value: the trail's atoms, the naturals, the term columns' definitions), as core/infer.ts's join reads it.
|
|
@@ -1122,7 +1123,7 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
1122
1123
|
pick = x.name;
|
|
1123
1124
|
px = x;
|
|
1124
1125
|
}
|
|
1125
|
-
if (opts.model && lpSat && sx && open && px)
|
|
1126
|
+
if ((opts.model || atPoint.on) && lpSat && sx && open && px)
|
|
1126
1127
|
phaseAtPoint(px, sx);
|
|
1127
1128
|
if (!pick && verdict?.kind === 'unknown') {
|
|
1128
1129
|
for (const [x0, value] of Object.entries(verdict.point ?? {})) {
|
package/dist/kernel/kernel.d.ts
CHANGED
|
@@ -78,13 +78,13 @@ export declare const sumParts: (s: string) => {
|
|
|
78
78
|
x: string;
|
|
79
79
|
};
|
|
80
80
|
export declare function sumCovers(m: Machine): Record<string, E[]>;
|
|
81
|
-
export declare function sumMachine(m: Machine, given?: Record<string, E[]
|
|
81
|
+
export declare function sumMachine(m: Machine, given?: Record<string, E[]>, laws?: Law[]): {
|
|
82
82
|
machine: Machine;
|
|
83
83
|
goals: Goal[];
|
|
84
84
|
};
|
|
85
85
|
export declare function sumRuntime(m: Machine): Machine;
|
|
86
86
|
export declare const plainOf: (m: Machine) => Machine;
|
|
87
|
-
export declare const sideGoals: (m: Machine) => Goal[];
|
|
87
|
+
export declare const sideGoals: (m: Machine, laws?: Law[]) => Goal[];
|
|
88
88
|
export declare function obligations(m: Machine, laws: Law[], instances?: Record<string, Instances>, only?: number): Goal[];
|
|
89
89
|
export declare function checkLaws(m: Machine, laws: Law[], proof: {
|
|
90
90
|
instances: Record<string, Instances>;
|
package/dist/kernel/kernel.js
CHANGED
|
@@ -1086,8 +1086,14 @@ export function sumCovers(m) {
|
|
|
1086
1086
|
return [s, [...out.values()]];
|
|
1087
1087
|
}));
|
|
1088
1088
|
}
|
|
1089
|
-
//
|
|
1090
|
-
|
|
1089
|
+
// The cells' laws at a cover goal's key x (Sums.lean's cellLaws): each law about one key (no further key) that reads
|
|
1090
|
+
// nothing but cells of the maps the term reads, at its key, read at x. A cell's kind is one (a yes/no at most 1, a
|
|
1091
|
+
// choice below its count): the cover goal may lean on it because the laws are proven with it (Sums.lean's sum_cells).
|
|
1092
|
+
const cellLaws = (laws, read, x) => laws.flatMap(l => (l.forall && !l.keys?.length && sumCondOk(l.holds, l.forall)
|
|
1093
|
+
&& [...JSON.stringify(l.holds).matchAll(/"op":"get","map":"([^"]+)"/g)].every(y => read.includes(y[1])) ? [substC(l.holds, { vars: { [l.forall]: x }, maps: {}, flags: {} })] : []));
|
|
1094
|
+
// `given`: each sum's cover keys (core/conformance.ts's tampered twins), else sumCovers'. `laws`: the laws proven with
|
|
1095
|
+
// the cover goals, whose cells' laws they assume.
|
|
1096
|
+
export function sumMachine(m, given, laws = []) {
|
|
1091
1097
|
const sums = Object.entries(m.sums ?? {});
|
|
1092
1098
|
if (!sums.length)
|
|
1093
1099
|
return { machine: m, goals: [] };
|
|
@@ -1160,7 +1166,7 @@ export function sumMachine(m, given) {
|
|
|
1160
1166
|
if (!('each' in w) || !read.includes(map))
|
|
1161
1167
|
continue;
|
|
1162
1168
|
const X = { op: 'var', name: x };
|
|
1163
|
-
goals.push({ name: `${s} @cover ${map}`, hyps: [substC(m.assume ?? TRUE_C, lean), ...cs.map((c) => ({ op: 'not', x: { op: '=', a: X, b: c } })),
|
|
1169
|
+
goals.push({ name: `${s} @cover ${map}`, hyps: [substC(m.assume ?? TRUE_C, lean), ...cellLaws(laws, read, X), ...cs.map((c) => ({ op: 'not', x: { op: '=', a: X, b: c } })),
|
|
1164
1170
|
{ op: 'not', x: { op: '=', a: substE(substE(w.value, lean), { vars: { [w.each]: X }, maps: {}, flags: {} }), b: { op: 'get', map, key: X } } }] });
|
|
1165
1171
|
}
|
|
1166
1172
|
}
|
|
@@ -1184,13 +1190,13 @@ export function sumRuntime(m) {
|
|
|
1184
1190
|
}
|
|
1185
1191
|
// The plain machine any claim is proven of: with a history kernel.ts's historyMachine's, with sums sumMachine's.
|
|
1186
1192
|
export const plainOf = (m) => (m.history ? historyMachine(m).machine : m.sums && Object.keys(m.sums).length ? sumMachine(m).machine : m);
|
|
1187
|
-
// The goals beside a plain machine's own: a history's record goals, the sums' cover goals.
|
|
1188
|
-
export const sideGoals = (m) => (m.history ? historyMachine(m).goals : m.sums && Object.keys(m.sums).length ? sumMachine(m).goals : []);
|
|
1193
|
+
// The goals beside a plain machine's own: a history's record goals, the sums' cover goals (over the laws proven with them).
|
|
1194
|
+
export const sideGoals = (m, laws = []) => (m.history ? historyMachine(m).goals : m.sums && Object.keys(m.sums).length ? sumMachine(m, undefined, laws).goals : []);
|
|
1189
1195
|
// `only`: the goals of that law alone (the prover's instance search asks for one law's at a time).
|
|
1190
1196
|
export function obligations(m, laws, instances = {}, only) {
|
|
1191
1197
|
if (m.history || (m.sums && Object.keys(m.sums).length)) {
|
|
1192
|
-
const goals = sideGoals(m);
|
|
1193
|
-
return [...obligations(plainOf(m), laws, instances, only), ...
|
|
1198
|
+
const goals = only === undefined ? sideGoals(m, laws) : [];
|
|
1199
|
+
return [...obligations(plainOf(m), laws, instances, only), ...goals];
|
|
1194
1200
|
}
|
|
1195
1201
|
scope(m, laws);
|
|
1196
1202
|
const ok = [...Object.values(m.state), ...Object.values(m.step.state ?? {}), ...Object.values(m.step.maps ?? {}).flatMap(w => ('each' in w ? [w.value] : [w.key, w.value]))].every(natural)
|
package/dist/kernel/prove.d.ts
CHANGED
|
@@ -82,6 +82,17 @@ export declare const unitAtoms: (goal: Goal) => Lin[];
|
|
|
82
82
|
export declare function openAt(goal: Goal, path: Path, rows: {
|
|
83
83
|
lin: Lin;
|
|
84
84
|
}[]): Lin[];
|
|
85
|
+
export declare const keyValue: (cell: string, w: Record<string, number>) => number | undefined;
|
|
86
|
+
export declare const modelRounds = 4;
|
|
87
|
+
export declare function modelInstances(m: Machine, laws: Law[], inst: Instances, goal: Goal, w: Record<string, number>, most?: number): Instances | undefined;
|
|
88
|
+
export declare const modelShare = 3;
|
|
89
|
+
export declare function withModels<T>(m: Machine, laws: Law[], inst: Instances, goalOf: (i: Instances) => Goal[], ask: (gs: Goal[]) => T, modelOf: (t: T) => {
|
|
90
|
+
goal: Goal;
|
|
91
|
+
w: Record<string, number>;
|
|
92
|
+
} | undefined, settled: (t: T) => boolean): {
|
|
93
|
+
result: T;
|
|
94
|
+
inst: Instances;
|
|
95
|
+
};
|
|
85
96
|
export declare const minimal: {
|
|
86
97
|
on: boolean;
|
|
87
98
|
};
|
|
@@ -116,6 +127,9 @@ export declare function proveLaws(m: Machine, laws: Law[]): Report & {
|
|
|
116
127
|
trees: Record<string, Tree>;
|
|
117
128
|
};
|
|
118
129
|
};
|
|
130
|
+
export declare const atPoint: {
|
|
131
|
+
on: boolean;
|
|
132
|
+
};
|
|
119
133
|
export declare function proveLaw(m: Machine, laws: Law[], i: number): {
|
|
120
134
|
proven: true;
|
|
121
135
|
} | {
|