gdp-wired 0.47.0 → 0.48.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 +15 -4
- package/dist/core/carry.d.ts +15 -0
- package/dist/core/carry.js +651 -0
- package/dist/core/cli.d.ts +3 -1
- package/dist/core/cli.js +28 -8
- package/dist/core/count-cases.d.ts +24 -0
- package/dist/core/count-cases.js +320 -0
- package/dist/core/count-cert-grow.d.ts +4 -0
- package/dist/core/count-cert-grow.js +37 -0
- package/dist/core/count-cert-transport.d.ts +3 -0
- package/dist/core/count-cert-transport.js +58 -0
- package/dist/core/count-completion.d.ts +9 -0
- package/dist/core/count-completion.js +27 -0
- package/dist/core/count-cubes.d.ts +8 -0
- package/dist/core/count-cubes.js +69 -0
- package/dist/core/count-demand.d.ts +37 -0
- package/dist/core/count-demand.js +361 -0
- package/dist/core/count-facts.d.ts +52 -0
- package/dist/core/count-facts.js +247 -0
- package/dist/core/count-focus-proof.d.ts +8 -0
- package/dist/core/count-focus-proof.js +140 -0
- package/dist/core/count-focused.d.ts +22 -0
- package/dist/core/count-focused.js +676 -0
- package/dist/core/count-ranges.d.ts +5 -0
- package/dist/core/count-ranges.js +65 -0
- package/dist/core/count-recovery/action-guard.d.ts +5 -0
- package/dist/core/count-recovery/action-guard.js +51 -0
- package/dist/core/count-recovery/boolean-core.d.ts +16 -0
- package/dist/core/count-recovery/boolean-core.js +258 -0
- package/dist/core/count-recovery/carried-case.d.ts +2 -0
- package/dist/core/count-recovery/carried-case.js +24 -0
- package/dist/core/count-recovery/conditional-check-cache.d.ts +23 -0
- package/dist/core/count-recovery/conditional-check-cache.js +130 -0
- package/dist/core/count-recovery/conditional-cuts.d.ts +6 -0
- package/dist/core/count-recovery/conditional-cuts.js +318 -0
- package/dist/core/count-recovery/conditional-proof.d.ts +19 -0
- package/dist/core/count-recovery/conditional-proof.js +306 -0
- package/dist/core/count-recovery/derivability-closure.d.ts +14 -0
- package/dist/core/count-recovery/derivability-closure.js +533 -0
- package/dist/core/count-recovery/empty-count-source.d.ts +2 -0
- package/dist/core/count-recovery/empty-count-source.js +40 -0
- package/dist/core/count-recovery/field-bound-lemmas.d.ts +23 -0
- package/dist/core/count-recovery/field-bound-lemmas.js +640 -0
- package/dist/core/count-recovery/field-case.d.ts +5 -0
- package/dist/core/count-recovery/field-case.js +89 -0
- package/dist/core/count-recovery/field-demand.d.ts +46 -0
- package/dist/core/count-recovery/field-demand.js +47 -0
- package/dist/core/count-recovery/field-only.d.ts +3 -0
- package/dist/core/count-recovery/field-only.js +18 -0
- package/dist/core/count-recovery/fold-path.d.ts +6 -0
- package/dist/core/count-recovery/fold-path.js +35 -0
- package/dist/core/count-recovery/frame-lemmas.d.ts +9 -0
- package/dist/core/count-recovery/frame-lemmas.js +120 -0
- package/dist/core/count-recovery/guard-cases.d.ts +12 -0
- package/dist/core/count-recovery/guard-cases.js +138 -0
- package/dist/core/count-recovery/key-closure.d.ts +14 -0
- package/dist/core/count-recovery/key-closure.js +62 -0
- package/dist/core/count-recovery/leaf-allowance.d.ts +4 -0
- package/dist/core/count-recovery/leaf-allowance.js +7 -0
- package/dist/core/count-recovery/lift-count-proxies.d.ts +6 -0
- package/dist/core/count-recovery/lift-count-proxies.js +175 -0
- package/dist/core/count-recovery/live-dependencies.d.ts +6 -0
- package/dist/core/count-recovery/live-dependencies.js +76 -0
- package/dist/core/count-recovery/member-inclusions.d.ts +11 -0
- package/dist/core/count-recovery/member-inclusions.js +168 -0
- package/dist/core/count-recovery/member-premises.d.ts +29 -0
- package/dist/core/count-recovery/member-premises.js +114 -0
- package/dist/core/count-recovery/natural-cases.d.ts +6 -0
- package/dist/core/count-recovery/natural-cases.js +59 -0
- package/dist/core/count-recovery/ops.d.ts +6 -0
- package/dist/core/count-recovery/ops.js +8 -0
- package/dist/core/count-recovery/pre-state-source.d.ts +8 -0
- package/dist/core/count-recovery/pre-state-source.js +18 -0
- package/dist/core/count-recovery/rebase-path.d.ts +9 -0
- package/dist/core/count-recovery/rebase-path.js +70 -0
- package/dist/core/count-recovery/rename-proof.d.ts +2 -0
- package/dist/core/count-recovery/rename-proof.js +102 -0
- package/dist/core/count-recovery/row-cases.d.ts +16 -0
- package/dist/core/count-recovery/row-cases.js +291 -0
- package/dist/core/count-recovery/scalar-guards.d.ts +7 -0
- package/dist/core/count-recovery/scalar-guards.js +291 -0
- package/dist/core/count-recovery/source-memo.d.ts +12 -0
- package/dist/core/count-recovery/source-memo.js +67 -0
- package/dist/core/count-select.d.ts +16 -0
- package/dist/core/count-select.js +24 -0
- package/dist/core/count-support.d.ts +598 -0
- package/dist/core/count-support.js +2080 -0
- package/dist/core/count-unions.d.ts +2 -0
- package/dist/core/count-unions.js +139 -0
- package/dist/core/count-witness-flags.d.ts +9 -0
- package/dist/core/count-witness-flags.js +37 -0
- package/dist/core/count-write-frames.d.ts +12 -0
- package/dist/core/count-write-frames.js +206 -0
- package/dist/core/counts.d.ts +20 -2
- package/dist/core/counts.js +807 -156
- package/dist/core/dsl.d.ts +50 -6
- package/dist/core/dsl.js +307 -65
- package/dist/core/effect.js +8 -1
- package/dist/core/exists.d.ts +1 -1
- package/dist/core/exists.js +80 -15
- package/dist/core/extract-check.d.ts +7 -1
- package/dist/core/extract-check.js +130 -13
- package/dist/core/extract-read.d.ts +22 -8
- package/dist/core/extract-read.js +29 -11
- package/dist/core/extract-shapes.js +122 -41
- package/dist/core/extract-standalone.js +53 -9
- package/dist/core/extract.js +9 -3
- package/dist/core/field-laws.d.ts +2 -0
- package/dist/core/field-laws.js +100 -0
- package/dist/core/finite-frontiers.d.ts +5 -0
- package/dist/core/finite-frontiers.js +116 -0
- package/dist/core/finite-houdini.d.ts +52 -0
- package/dist/core/finite-houdini.js +460 -0
- package/dist/core/finite-model.d.ts +13 -0
- package/dist/core/finite-model.js +68 -0
- package/dist/core/finite-tiny.d.ts +72 -0
- package/dist/core/finite-tiny.js +1052 -0
- package/dist/core/infer.d.ts +1 -1
- package/dist/core/infer.js +32 -9
- package/dist/core/laws.d.ts +2 -1
- package/dist/core/laws.js +47 -14
- package/dist/core/lemma-cuts.d.ts +38 -0
- package/dist/core/lemma-cuts.js +365 -0
- package/dist/core/machine.d.ts +39 -2
- package/dist/core/machine.js +240 -35
- package/dist/core/mutate.d.ts +55 -0
- package/dist/core/mutate.js +210 -0
- package/dist/core/native-domain.d.ts +6 -0
- package/dist/core/native-domain.js +114 -0
- package/dist/core/native-law.d.ts +3 -0
- package/dist/core/native-law.js +174 -0
- package/dist/core/quorum-laws.d.ts +5 -0
- package/dist/core/quorum-laws.js +239 -0
- package/dist/core/relational.js +10 -2
- package/dist/core/relevance.d.ts +4 -0
- package/dist/core/relevance.js +79 -0
- package/dist/core/runtime-wall.d.ts +3 -0
- package/dist/core/runtime-wall.js +4 -0
- package/dist/core/sample-step.d.ts +16 -0
- package/dist/core/sample-step.js +28 -0
- package/dist/core/source-check.d.ts +44 -0
- package/dist/core/source-check.js +126 -0
- package/dist/core/source-diagnostic.d.ts +1 -0
- package/dist/core/source-diagnostic.js +34 -0
- package/dist/core/support-budget.d.ts +2 -0
- package/dist/core/support-budget.js +6 -0
- package/dist/core/system.js +2 -0
- package/dist/core/wall.d.ts +6 -0
- package/dist/core/wall.js +23 -0
- package/dist/core/watch.js +4 -0
- package/dist/kernel/cdcl.d.ts +4 -0
- package/dist/kernel/cdcl.js +20 -5
- package/dist/kernel/kernel.d.ts +10 -0
- package/dist/kernel/kernel.js +56 -3
- package/dist/kernel/model-sequence.d.ts +2 -2
- package/dist/kernel/model-sequence.js +4 -3
- package/dist/kernel/model-values.d.ts +2 -0
- package/dist/kernel/model-values.js +60 -0
- package/dist/kernel/prove.d.ts +10 -0
- package/dist/kernel/prove.js +56 -8
- package/dist/kernel/prover-rows.d.ts +29 -0
- package/dist/kernel/prover-rows.js +114 -0
- package/dist/lean-kernel/emit.d.ts +39 -2
- package/dist/lean-kernel/emit.js +136 -24
- package/dist/lean-kernel/lean-terms.d.ts +1 -0
- package/dist/lean-kernel/lean-terms.js +13 -5
- package/dist/lean-kernel/library.js +4 -0
- package/dist/lean-kernel/qalpha.d.ts +7 -0
- package/dist/lean-kernel/qalpha.js +40 -0
- package/package.json +5 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// A count-free live conclusion should not pay for unrelated count instances.
|
|
2
|
+
// Every projection is weakening-only, and every tree is transported to g.
|
|
3
|
+
import { walkOnce } from "../machine.js";
|
|
4
|
+
import { canon, linear, truth } from "../../kernel/kernel.js";
|
|
5
|
+
import { sub } from "../solver.js";
|
|
6
|
+
import { clock, grow, rowsAt, widen, withDeadline } from "../../kernel/prove.js";
|
|
7
|
+
import { refuteFast } from "../solver.js";
|
|
8
|
+
import { modelSequence } from "../../kernel/model-sequence.js";
|
|
9
|
+
import { REFUTED } from "../../kernel/cdcl.js";
|
|
10
|
+
import { fieldOnlyGoal } from "./field-only.js";
|
|
11
|
+
import { foldPath } from "./fold-path.js";
|
|
12
|
+
import { booleanCore, walkChoices } from "./boolean-core.js";
|
|
13
|
+
import { observeFieldLeaf } from "./field-demand.js";
|
|
14
|
+
export function fieldDirection(claim, path) {
|
|
15
|
+
let direction;
|
|
16
|
+
walkChoices(claim, path, (read) => {
|
|
17
|
+
if (read.op !== 'get')
|
|
18
|
+
return;
|
|
19
|
+
walkOnce(read.key, (o) => {
|
|
20
|
+
if (direction || o.op !== 'sub' || o.a.op !== 'var' || o.b.op !== 'var' || truth({ op: '<=', a: o.a, b: o.b }, path) !== undefined)
|
|
21
|
+
return;
|
|
22
|
+
const a = linear(o.a, path), b = linear(o.b, path);
|
|
23
|
+
if (a && b)
|
|
24
|
+
direction = sub(a, b);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return direction;
|
|
28
|
+
}
|
|
29
|
+
export function fieldCase(m, g, cert, claim, path, until, trace, naturalDepth = 0, memo) {
|
|
30
|
+
const cached = memo?.get(g, path, until);
|
|
31
|
+
if (cached) {
|
|
32
|
+
trace?.({ stage: 'source-memo', scope: 'field-case' });
|
|
33
|
+
return cached;
|
|
34
|
+
}
|
|
35
|
+
const tree = fieldCaseImpl(m, g, cert, claim, path, until, trace, naturalDepth, memo);
|
|
36
|
+
if (tree)
|
|
37
|
+
memo?.put(g, path, tree);
|
|
38
|
+
return tree;
|
|
39
|
+
}
|
|
40
|
+
function fieldCaseImpl(m, g, cert, claim, path, until, trace, naturalDepth, memo) {
|
|
41
|
+
const field = fieldOnlyGoal(g, m, cert, claim, path);
|
|
42
|
+
if (!field || clock() >= until)
|
|
43
|
+
return undefined;
|
|
44
|
+
const began = clock();
|
|
45
|
+
// Close already-linear leaves before asking the model oracle to rediscover
|
|
46
|
+
// them. The ordinary arithmetic derivation is still transported in full.
|
|
47
|
+
const direct = refuteFast(rowsAt(field, path), 256);
|
|
48
|
+
if (direct?.kind === 'refuted') {
|
|
49
|
+
const tree = withDeadline(until, () => widen(field, g, { leaf: direct.steps }, {}, path, path));
|
|
50
|
+
trace?.({ stage: 'field-case', hyps: field.hyps.length, ms: Math.round(clock() - began), proposed: !!tree, outcome: 'linear' });
|
|
51
|
+
return tree;
|
|
52
|
+
}
|
|
53
|
+
// Expose a scalar direction before natural subtraction makes copied read
|
|
54
|
+
// keys opaque. Both source paths are proved; no direction is assumed.
|
|
55
|
+
const folded = foldPath(field, path), query = modelSequence(path)(folded.goal, until);
|
|
56
|
+
observeFieldLeaf(folded.goal, path, query);
|
|
57
|
+
if (!('tree' in query) && query.stuck === 'sat') {
|
|
58
|
+
trace?.({ stage: 'field-case', hyps: field.hyps.length, ms: Math.round(clock() - began), proposed: false, outcome: query.stuck, model: query.witness });
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
const reduced = !('tree' in query) && query.why === REFUTED && query.core?.length ? { ...folded.goal, hyps: query.core.map(i => folded.goal.hyps[i]) } : folded.goal;
|
|
62
|
+
const direction = naturalDepth < 2 && !('tree' in query) && query.why === REFUTED ? fieldDirection({ op: 'and', xs: reduced.hyps }, path) : undefined;
|
|
63
|
+
if (direction) {
|
|
64
|
+
const id = canon(direction), yes = fieldCase(m, g, cert, claim, new Map(path).set(id, { lin: direction, holds: true }), until, trace, naturalDepth + 1, memo);
|
|
65
|
+
const no = yes && fieldCase(m, g, cert, claim, new Map(path).set(id, { lin: direction, holds: false }), until, trace, naturalDepth + 1, memo);
|
|
66
|
+
const tree = yes && no ? { split: direction, yes, no } : undefined;
|
|
67
|
+
trace?.({ stage: 'field-natural-direction', ms: Math.round(clock() - began), proposed: !!tree });
|
|
68
|
+
return tree;
|
|
69
|
+
}
|
|
70
|
+
const keys = new Set();
|
|
71
|
+
let packed = false;
|
|
72
|
+
if (!('tree' in query) && query.why === REFUTED && query.core?.length && query.core.length <= 8)
|
|
73
|
+
walkOnce(reduced.hyps, (o) => {
|
|
74
|
+
if (o.op !== 'get' || ['var', 'const'].includes(o.key.op))
|
|
75
|
+
return;
|
|
76
|
+
packed = true;
|
|
77
|
+
walkOnce(o.key, (k) => { if (k.op === 'var' && !m.inputs.includes(k.name) && !m.params.includes(k.name) && !(k.name in m.state))
|
|
78
|
+
keys.add(k.name); });
|
|
79
|
+
});
|
|
80
|
+
const events = [], point = packed ? booleanCore(reduced, path, keys, until, events, { extended: true, scalarGuards: true, deferCheck: true }) : undefined;
|
|
81
|
+
for (const event of events)
|
|
82
|
+
trace?.(event);
|
|
83
|
+
const out = point ? { tree: point } : 'tree' in query ? query : grow(reduced, path, { nodes: 0, until, units: true });
|
|
84
|
+
const expanded = 'tree' in out ? withDeadline(until, () => widen(reduced, folded.goal, out.tree, {}, path, path)) : undefined;
|
|
85
|
+
const lifted = expanded && withDeadline(until, () => widen(folded.goal, field, expanded, folded.opaque, path, path));
|
|
86
|
+
const tree = lifted && withDeadline(until, () => widen(field, g, lifted, {}, path, path));
|
|
87
|
+
trace?.({ stage: 'field-case', hyps: field.hyps.length, core: query.core?.length, ms: Math.round(clock() - began), proposed: !!tree, outcome: 'tree' in query ? 'tree' : query.stuck, ...(!('tree' in query) && query.stuck === 'sat' ? { model: query.witness } : {}) });
|
|
88
|
+
return tree;
|
|
89
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type C } from '../machine.js';
|
|
2
|
+
import { type Goal, type Path } from '../../kernel/kernel.js';
|
|
3
|
+
export type FieldDemand = {
|
|
4
|
+
modelColumns: string[];
|
|
5
|
+
coreColumns: string[];
|
|
6
|
+
modelKnown: boolean;
|
|
7
|
+
coreKnown: boolean;
|
|
8
|
+
scope?: string;
|
|
9
|
+
};
|
|
10
|
+
export type FieldAttempt = {
|
|
11
|
+
candidate: C;
|
|
12
|
+
cellColumns: string[];
|
|
13
|
+
demand?: FieldDemand;
|
|
14
|
+
units: number;
|
|
15
|
+
emitted: boolean;
|
|
16
|
+
source: string;
|
|
17
|
+
requested: boolean | undefined;
|
|
18
|
+
start?: number;
|
|
19
|
+
end?: number;
|
|
20
|
+
id?: number;
|
|
21
|
+
parent?: number;
|
|
22
|
+
inclusiveUnits?: number;
|
|
23
|
+
scope?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare const fieldAttemptObserver: {
|
|
26
|
+
on?: (event: FieldAttempt) => void;
|
|
27
|
+
};
|
|
28
|
+
type Attempt = {
|
|
29
|
+
candidate: C;
|
|
30
|
+
path: Path;
|
|
31
|
+
demand?: FieldDemand;
|
|
32
|
+
source: string;
|
|
33
|
+
start: number;
|
|
34
|
+
children: number;
|
|
35
|
+
id: number;
|
|
36
|
+
parent?: Attempt;
|
|
37
|
+
};
|
|
38
|
+
export declare function beginFieldAttempt(candidate: C, path: Path, demand: FieldDemand | undefined, source: string): Attempt | undefined;
|
|
39
|
+
export declare function endFieldAttempt(frame: Attempt | undefined, emitted: boolean): void;
|
|
40
|
+
export declare function observeFieldLeaf(goal: Goal, path: Path, result: {
|
|
41
|
+
core?: number[];
|
|
42
|
+
witness?: Record<string, number>;
|
|
43
|
+
}): void;
|
|
44
|
+
export declare const fieldDemandAt: (path: Path) => FieldDemand | undefined;
|
|
45
|
+
export declare function recordFieldAttempt(candidate: C, path: Path, demand: FieldDemand | undefined, units: number, emitted: boolean, source: string, span?: Pick<FieldAttempt, 'id' | 'parent' | 'start' | 'end' | 'inclusiveUnits'>): void;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { leafConstraints, linear } from "../../kernel/kernel.js";
|
|
2
|
+
import { clock } from "../../kernel/prove.js";
|
|
3
|
+
export const fieldAttemptObserver = {};
|
|
4
|
+
const demands = new WeakMap();
|
|
5
|
+
const scopeKey = (path) => JSON.stringify([...path].map(([key, atom]) => [key, atom.holds]).sort((a, b) => String(a[0]).localeCompare(String(b[0]))));
|
|
6
|
+
let serial = 0, current;
|
|
7
|
+
export function beginFieldAttempt(candidate, path, demand, source) {
|
|
8
|
+
if (!fieldAttemptObserver.on)
|
|
9
|
+
return;
|
|
10
|
+
const frame = { candidate, path: new Map(path), demand, source, start: clock(), children: 0, id: serial++, parent: current };
|
|
11
|
+
current = frame;
|
|
12
|
+
return frame;
|
|
13
|
+
}
|
|
14
|
+
export function endFieldAttempt(frame, emitted) {
|
|
15
|
+
if (!frame)
|
|
16
|
+
return;
|
|
17
|
+
const end = clock(), inclusive = end - frame.start;
|
|
18
|
+
if (current !== frame)
|
|
19
|
+
throw Error('field attempt stack mismatch');
|
|
20
|
+
current = frame.parent;
|
|
21
|
+
if (frame.parent)
|
|
22
|
+
frame.parent.children += inclusive;
|
|
23
|
+
recordFieldAttempt(frame.candidate, frame.path, frame.demand, Math.max(0, inclusive - frame.children), emitted, frame.source, { id: frame.id, parent: frame.parent?.id, start: frame.start, end, inclusiveUnits: inclusive });
|
|
24
|
+
}
|
|
25
|
+
export function observeFieldLeaf(goal, path, result) {
|
|
26
|
+
if (!fieldAttemptObserver.on)
|
|
27
|
+
return;
|
|
28
|
+
const selected = new Set(result.core), columns = new Set();
|
|
29
|
+
if (result.core)
|
|
30
|
+
for (const row of leafConstraints(goal, path)) {
|
|
31
|
+
const source = row.src;
|
|
32
|
+
if (source?.fact !== undefined && selected.has(source.fact))
|
|
33
|
+
for (const name of Object.keys(row.lin))
|
|
34
|
+
if (name !== '1')
|
|
35
|
+
columns.add(name);
|
|
36
|
+
}
|
|
37
|
+
demands.set(path, { scope: scopeKey(path), modelColumns: Object.keys(result.witness ?? {}), coreColumns: [...columns], modelKnown: result.witness !== undefined, coreKnown: result.core !== undefined });
|
|
38
|
+
}
|
|
39
|
+
export const fieldDemandAt = (path) => fieldAttemptObserver.on ? demands.get(path) : undefined;
|
|
40
|
+
export function recordFieldAttempt(candidate, path, demand, units, emitted, source, span = {}) {
|
|
41
|
+
if (!fieldAttemptObserver.on)
|
|
42
|
+
return;
|
|
43
|
+
const cell = candidate.op === '<=' || candidate.op === '<' ? (candidate.a.op === 'if' ? candidate.a.then : candidate.a) : undefined;
|
|
44
|
+
const cellColumns = cell ? Object.keys(linear(cell, path) ?? {}).filter(k => k !== '1') : [], columns = new Set([...(demand?.coreColumns ?? []), ...(demand?.modelColumns ?? [])]);
|
|
45
|
+
const known = !!demand && (demand.modelKnown || demand.coreKnown) && (demand.scope === undefined || demand.scope === scopeKey(path));
|
|
46
|
+
fieldAttemptObserver.on({ candidate, cellColumns, demand, units, emitted, source, ...span, scope: scopeKey(path), requested: known ? cellColumns.some(c => columns.has(c)) : undefined });
|
|
47
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type C, type Machine } from '../machine.js';
|
|
2
|
+
import { type CountCert, type Goal, type Path } from '../../kernel/kernel.js';
|
|
3
|
+
export declare function fieldOnlyGoal(g: Goal, m: Machine, cert: Pick<CountCert, 'reads' | 'insts'>, claim?: C, path?: Path): Goal | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { walkLive } from "./live-dependencies.js";
|
|
2
|
+
export function fieldOnlyGoal(g, m, cert, claim, path = new Map()) {
|
|
3
|
+
const counted = new Set(cert.reads.map(r => r[0])), maps = new Set(cert.reads.map(r => r[1])), wits = new Set(cert.insts.map(i => i.wit));
|
|
4
|
+
const hasCount = (c) => { let hit = false; walkLive(c, path, (o) => { if (o.op === 'get' && (maps.has(o.map) || m.counts?.[o.map.replace(/#$/, '')]) || o.op === 'var' && (counted.has(o.name) || wits.has(o.name)))
|
|
5
|
+
hit = true; }); return hit; };
|
|
6
|
+
const end = g.hyps.length - cert.insts.length, original = g.hyps.slice(0, end);
|
|
7
|
+
const conclusion = claim ?? original.at(-1), index = original.findIndex(c => c === conclusion);
|
|
8
|
+
if (!conclusion || index < 0 || hasCount(conclusion))
|
|
9
|
+
return undefined;
|
|
10
|
+
const weaker = (c) => {
|
|
11
|
+
if (c.op === 'and') {
|
|
12
|
+
const xs = c.xs.flatMap(child => { const next = weaker(child); return next ? [next] : []; });
|
|
13
|
+
return xs.length ? { op: 'and', xs } : undefined;
|
|
14
|
+
}
|
|
15
|
+
return hasCount(c) ? undefined : c;
|
|
16
|
+
};
|
|
17
|
+
return { ...g, hyps: original.filter((_, i) => i !== index).flatMap(c => { const next = weaker(c); return next ? [next] : []; }).concat(conclusion) };
|
|
18
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { canon, linear, truth } from "../../kernel/kernel.js";
|
|
2
|
+
const expressions = new Set(['var', 'const', 'mul', 'prod', 'add', 'sub', 'min', 'max', 'if', 'get', 'tup', 'proj']);
|
|
3
|
+
const conditions = new Set(['not', 'and', 'or', '<', '<=', '=']);
|
|
4
|
+
export function foldPath(g, path) {
|
|
5
|
+
const seen = new WeakMap(), opaque = {};
|
|
6
|
+
const yes = { op: 'and', xs: [] }, no = { op: 'or', xs: [] };
|
|
7
|
+
const f = (o) => {
|
|
8
|
+
if (!o || typeof o !== 'object')
|
|
9
|
+
return o;
|
|
10
|
+
if (seen.has(o))
|
|
11
|
+
return seen.get(o);
|
|
12
|
+
let out;
|
|
13
|
+
if (Array.isArray(o))
|
|
14
|
+
out = o.map(f);
|
|
15
|
+
else if (conditions.has(o.op) && truth(o, path) !== undefined)
|
|
16
|
+
out = truth(o, path) ? yes : no;
|
|
17
|
+
else if (o.op === 'if' && truth(o.c, path) !== undefined)
|
|
18
|
+
out = f(truth(o.c, path) ? o.then : o.else);
|
|
19
|
+
else {
|
|
20
|
+
out = Object.fromEntries(Object.entries(o).map(([k, v]) => [k, f(v)]));
|
|
21
|
+
if (out.op === 'and' || out.op === 'or') {
|
|
22
|
+
const neutral = out.op === 'and' ? 'and' : 'or', xs = out.xs.filter((c) => !((c.op === 'and' || c.op === 'or') && c.op === neutral && c.xs.length === 0));
|
|
23
|
+
out = xs.length === 1 ? xs[0] : { ...out, xs };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
seen.set(o, out);
|
|
27
|
+
if (expressions.has(o.op)) {
|
|
28
|
+
const a = linear(out, path), b = linear(o, path), entry = a && Object.entries(a);
|
|
29
|
+
if (a && b && entry?.length === 1 && entry[0][0] !== '1' && entry[0][1] === 1 && canon(a) !== canon(b))
|
|
30
|
+
opaque[entry[0][0]] = o;
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
};
|
|
34
|
+
return { goal: { ...g, hyps: g.hyps.map(f) }, opaque };
|
|
35
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type CountCert, type Goal, type Path, type Tree } from '../../kernel/kernel.js';
|
|
2
|
+
type Proposal = Pick<CountCert, 'reads' | 'insts'>;
|
|
3
|
+
export declare const frameLemmas: typeof frameLemmasImpl;
|
|
4
|
+
declare function frameLemmasImpl(g: Goal, cert: Proposal, until: number, trace: object[], root?: Path, options?: {
|
|
5
|
+
stopAfterFailed?: number;
|
|
6
|
+
boolean?: boolean;
|
|
7
|
+
deferCheck?: boolean;
|
|
8
|
+
}): Tree | undefined;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Factor valid count-frame inequalities out of a large counted obligation.
|
|
2
|
+
// Every cut is an ordinary checked Tree split; no frame is trusted as a fact.
|
|
3
|
+
import { walkOnce, x } from "../machine.js";
|
|
4
|
+
import { canon, substC } from "../../kernel/kernel.js";
|
|
5
|
+
import { clock, usedHyps } from "../../kernel/prove.js";
|
|
6
|
+
import { REFUTED } from "../../kernel/cdcl.js";
|
|
7
|
+
import { liftCountProxies } from "./lift-count-proxies.js";
|
|
8
|
+
import { piecesAt, walkLive } from "./live-dependencies.js";
|
|
9
|
+
import { booleanCore } from "./boolean-core.js";
|
|
10
|
+
import { wallTree, check, grow, widen, modelSequence } from "./ops.js";
|
|
11
|
+
export const frameLemmas = (...args) => wallTree('proposal-control', () => frameLemmasImpl(...args));
|
|
12
|
+
function frameLemmasImpl(g, cert, until, trace, root = new Map(), options = {}) {
|
|
13
|
+
let failed = 0;
|
|
14
|
+
const seq = modelSequence(root), base = g.hyps.slice(0, g.hyps.length - cert.insts.length), ctx = [], path = new Map(root), lemmas = [];
|
|
15
|
+
const reads = new Map(cert.reads.map(r => [r[0], r])), maps = new Set(cert.reads.map(r => r[1])), wits = new Set(cert.insts.map(i => i.wit));
|
|
16
|
+
const weaken = (c, wit) => {
|
|
17
|
+
if (c.op === 'and') {
|
|
18
|
+
const xs = c.xs.flatMap(x => { const y = weaken(x, wit); return y ? [y] : []; });
|
|
19
|
+
return xs.length ? { op: 'and', xs } : undefined;
|
|
20
|
+
}
|
|
21
|
+
let count = false, other = false, own = false;
|
|
22
|
+
walkLive(c, root, (o) => { if (o.op === 'get' && maps.has(o.map))
|
|
23
|
+
count = true; if (o.op === 'var' && wits.has(o.name)) {
|
|
24
|
+
if (o.name === wit)
|
|
25
|
+
own = true;
|
|
26
|
+
else
|
|
27
|
+
other = true;
|
|
28
|
+
} });
|
|
29
|
+
return count || other && !own ? undefined : c;
|
|
30
|
+
};
|
|
31
|
+
const project = (hyps) => {
|
|
32
|
+
const maps = Object.fromEntries([...new Set(cert.reads.map(r => r[1]))].map(map => [map, (key) => { const r = cert.reads.find(r => r[1] === map && JSON.stringify(r[2]) === JSON.stringify(key)); return r ? x(r[0]) : { op: 'get', map, key }; }]));
|
|
33
|
+
const flags = {};
|
|
34
|
+
walkOnce(hyps, (o) => { if (o.op === 'flag')
|
|
35
|
+
flags[o.name] = { op: 'flag', name: o.name }; });
|
|
36
|
+
return hyps.map(c => substC(c, { vars: {}, maps, flags })).flatMap(c => piecesAt(c, root)).filter(c => { let skip = false; walkLive(c, root, (o) => { if (o.op === 'get' || o.op === 'var' && wits.has(o.name))
|
|
37
|
+
skip = true; }); return !skip; });
|
|
38
|
+
};
|
|
39
|
+
const solve = (goal, limit, finish = false) => {
|
|
40
|
+
if (finish) {
|
|
41
|
+
const hyps = project(goal.hyps);
|
|
42
|
+
const numeric = { ...goal, hyps }, start = clock(), q = seq(numeric, Math.min(until, clock() + 150));
|
|
43
|
+
trace.push({ stage: 'frame-arithmetic', hyps: hyps.length, ms: Math.round(clock() - start), outcome: 'tree' in q ? 'tree' : q.stuck, core: q.core?.length });
|
|
44
|
+
let proof = 'tree' in q ? q.tree : undefined;
|
|
45
|
+
if (!proof && !('tree' in q) && q.why === REFUTED && q.core?.length) {
|
|
46
|
+
const reduced = { ...numeric, hyps: q.core.map(i => hyps[i]) }, out = grow(reduced, root, { nodes: 0, until: Math.min(until, clock() + 150), units: false });
|
|
47
|
+
if ('tree' in out)
|
|
48
|
+
proof = widen(reduced, numeric, out.tree, {}, root, root);
|
|
49
|
+
}
|
|
50
|
+
if (proof) {
|
|
51
|
+
const lifted = liftCountProxies(numeric, goal, proof, cert.reads, root, root, event => trace.push({ stage: 'proxy-lift', ...event }), options);
|
|
52
|
+
trace.push({ stage: 'frame-arithmetic-lift', ms: Math.round(clock() - start), proved: !!lifted });
|
|
53
|
+
if (lifted)
|
|
54
|
+
return lifted;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const q = seq(goal, Math.min(until, clock() + limit));
|
|
58
|
+
if ('tree' in q)
|
|
59
|
+
return q.tree;
|
|
60
|
+
if (q.why !== REFUTED || !q.core?.length)
|
|
61
|
+
return undefined;
|
|
62
|
+
const reduced = { ...goal, hyps: q.core.map(i => goal.hyps[i]) };
|
|
63
|
+
if (options.boolean && q.core.length <= 8) {
|
|
64
|
+
const tree = booleanCore(reduced, root, wits, Math.min(until, clock() + 100), trace, options);
|
|
65
|
+
if (tree)
|
|
66
|
+
return widen(reduced, goal, tree, {}, root, root);
|
|
67
|
+
}
|
|
68
|
+
const out = grow(reduced, root, { nodes: 0, until: Math.min(until, clock() + 200), units: false });
|
|
69
|
+
return 'tree' in out ? widen(reduced, goal, out.tree, {}, root, root) : undefined;
|
|
70
|
+
};
|
|
71
|
+
const candidates = cert.insts.flatMap((instance, i) => {
|
|
72
|
+
if (instance.unit !== 0 || instance.terms.length !== 2)
|
|
73
|
+
return [];
|
|
74
|
+
const [a, b] = instance.terms.map(t => reads.get(t[1])), h = g.hyps[base.length + i];
|
|
75
|
+
return a && b && a[1].replace(/#$/, '') === b[1].replace(/#$/, '') && a[1].endsWith('#') !== b[1].endsWith('#') && JSON.stringify(a[2]) === JSON.stringify(b[2]) && h?.op === 'or' && h.xs[0]?.op === '<=' ? [{ i, instance, h, good: h.xs[0] }] : [];
|
|
76
|
+
});
|
|
77
|
+
let selected;
|
|
78
|
+
if (candidates.length && clock() < until) {
|
|
79
|
+
const numeric = project(base), trial = { ...g, hyps: [...numeric, ...candidates.map(c => c.good)] }, start = clock(), q = seq(trial, Math.min(until, clock() + 150));
|
|
80
|
+
const core = 'tree' in q ? usedHyps(trial, q.tree, root) : q.why === REFUTED && q.core ? new Set(q.core) : undefined;
|
|
81
|
+
if (core)
|
|
82
|
+
selected = new Set(candidates.filter((_, i) => core.has(numeric.length + i)).map(c => c.i));
|
|
83
|
+
trace.push({ stage: 'frame-core', pool: candidates.length, selected: selected ? [...selected] : null, ms: Math.round(clock() - start) });
|
|
84
|
+
}
|
|
85
|
+
for (const { i, instance, h, good } of candidates) {
|
|
86
|
+
if (clock() >= until)
|
|
87
|
+
break;
|
|
88
|
+
if (selected && !selected.has(i))
|
|
89
|
+
continue;
|
|
90
|
+
const split = Object.fromEntries(instance.terms.map(([n, v]) => [v, n])), noPath = new Map(path).set(canon(split), { lin: split, holds: false });
|
|
91
|
+
const relevant = base.flatMap(c => piecesAt(c, root)).flatMap(c => { const kept = weaken(c, instance.wit); return kept ? [kept] : []; });
|
|
92
|
+
const part = { ...g, hyps: [...relevant, ...ctx, h, { op: 'not', x: good }] }, start = clock(), tree = solve(part, 150);
|
|
93
|
+
const no = tree && widen(part, g, tree, {}, root, noPath);
|
|
94
|
+
trace.push({ stage: 'frame-lemma', index: i, ms: Math.round(clock() - start), proved: !!no });
|
|
95
|
+
if (!no) {
|
|
96
|
+
if (++failed >= (options.stopAfterFailed ?? Infinity) && !lemmas.length)
|
|
97
|
+
return undefined;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
lemmas.push({ split, no });
|
|
101
|
+
ctx.push(good);
|
|
102
|
+
path.set(canon(split), { lin: split, holds: true });
|
|
103
|
+
}
|
|
104
|
+
if (clock() >= until)
|
|
105
|
+
return undefined;
|
|
106
|
+
if (!lemmas.length) {
|
|
107
|
+
if (selected?.size !== 0)
|
|
108
|
+
return undefined;
|
|
109
|
+
const tree = solve(g, Math.max(0, until - clock()), true);
|
|
110
|
+
return tree && (options.deferCheck || check(g, tree, root)) ? tree : undefined;
|
|
111
|
+
}
|
|
112
|
+
const part = { ...g, hyps: [...g.hyps, ...ctx] }, start = clock(), found = solve(part, Math.max(150, until - clock() - 200), true);
|
|
113
|
+
let tree = found && widen(part, g, found, {}, root, path);
|
|
114
|
+
trace.push({ stage: 'frame-conclusion', facts: lemmas.length, ms: Math.round(clock() - start), proved: !!tree });
|
|
115
|
+
if (!tree)
|
|
116
|
+
return undefined;
|
|
117
|
+
for (const lemma of [...lemmas].reverse())
|
|
118
|
+
tree = { split: lemma.split, yes: tree, no: lemma.no };
|
|
119
|
+
return options.deferCheck || check(g, tree, root) ? tree : undefined;
|
|
120
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type C, type Machine } from '../machine.js';
|
|
2
|
+
import { type CountCert, type CountDecl, type Goal, type Path, type Tree } from '../../kernel/kernel.js';
|
|
3
|
+
import { type SourceProofMemo } from './source-memo.js';
|
|
4
|
+
type Proposal = Pick<CountCert, 'reads' | 'insts'>;
|
|
5
|
+
export declare const guardCases: typeof guardCasesImpl;
|
|
6
|
+
declare function guardCasesImpl(m: Machine, ds: CountDecl[], g: Goal, cert: Proposal, guard: C, until: number, trace: object[], slot?: number, root?: Path, options?: {
|
|
7
|
+
deferCheck?: boolean;
|
|
8
|
+
claim?: C;
|
|
9
|
+
memo?: SourceProofMemo;
|
|
10
|
+
conditional?: boolean;
|
|
11
|
+
}): Tree | undefined;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// Untrusted activation case splitting. Every leaf is transported back to
|
|
2
|
+
// the original goal/path, and the complete split tree is checked once more.
|
|
3
|
+
import { plus, n } from "../machine.js";
|
|
4
|
+
import { canon, linear, truth } from "../../kernel/kernel.js";
|
|
5
|
+
import { sub } from "../solver.js";
|
|
6
|
+
import { atPoint, clock, wallAt, withDeadline } from "../../kernel/prove.js";
|
|
7
|
+
import { fieldBoundLemmas } from "./field-bound-lemmas.js";
|
|
8
|
+
import { frameLemmas } from "./frame-lemmas.js";
|
|
9
|
+
import { fieldCase } from "./field-case.js";
|
|
10
|
+
import { rowPairs } from "./row-cases.js";
|
|
11
|
+
import { leafAllowance } from "./leaf-allowance.js";
|
|
12
|
+
import { fieldDemandAt } from "./field-demand.js";
|
|
13
|
+
import { checkConditionalProof as check, hasConditionalProof, transportConditionalProof } from "./conditional-proof.js";
|
|
14
|
+
import { wallTree, solve, grow, rowsAt, widen } from "./ops.js";
|
|
15
|
+
export const guardCases = (...args) => wallTree('guard-case-reconstruction', () => guardCasesImpl(...args));
|
|
16
|
+
function guardCasesImpl(m, ds, g, cert, guard, until, trace, slot = 0, root = new Map(), options = {}) {
|
|
17
|
+
const deferNested = !!options.deferCheck;
|
|
18
|
+
const conditions = [], booleans = true;
|
|
19
|
+
const collect = (c) => {
|
|
20
|
+
if (c.op === 'and' || booleans && c.op === 'or')
|
|
21
|
+
return c.xs.every(collect);
|
|
22
|
+
if (booleans && c.op === 'not')
|
|
23
|
+
return collect(c.x);
|
|
24
|
+
if (c.op === '=') {
|
|
25
|
+
conditions.push({ op: '<=', a: c.a, b: c.b }, { op: '<=', a: c.b, b: c.a });
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (c.op === '<=') {
|
|
29
|
+
conditions.push(c);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
if (c.op === '<') {
|
|
33
|
+
conditions.push({ op: '<=', a: plus(c.a, n(1)), b: c.b });
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
};
|
|
38
|
+
if (!collect(guard) || conditions.length > 12)
|
|
39
|
+
return undefined;
|
|
40
|
+
const inactiveGoal = { ...g, hyps: [...g.hyps.slice(0, slot), { op: 'not', x: guard }, ...g.hyps.slice(slot)] };
|
|
41
|
+
let inactive, attempted = false, inactiveLeaf;
|
|
42
|
+
const leaf = (hyps, path, active) => {
|
|
43
|
+
if (clock() >= until)
|
|
44
|
+
return undefined;
|
|
45
|
+
const assumption = active ? guard : { op: 'and', xs: hyps }, sourceOnly = false, goal = sourceOnly ? g : { ...g, hyps: [...g.hyps.slice(0, slot), assumption, ...g.hyps.slice(slot)] }, start = clock(), end = active ? Math.min(until, start + leafAllowance(until - start, 1)) : Math.min(until, start + 500);
|
|
46
|
+
trace.push({ stage: 'guard-leaf-budget', active, start, until, end, draw: Math.max(0, end - start) });
|
|
47
|
+
const cached = options.memo?.get(g, path, end);
|
|
48
|
+
if (cached && (deferNested || check(g, cached, path))) {
|
|
49
|
+
trace.push({ stage: 'source-memo', scope: 'guard', active });
|
|
50
|
+
return cached;
|
|
51
|
+
}
|
|
52
|
+
const rowDependent = active && rowPairs(m, cert, path, options.claim).length > 0;
|
|
53
|
+
let proof = rowDependent ? undefined : fieldCase(m, goal, cert, options.claim, path, Math.min(end, clock() + 150), e => trace.push({ ...e, guardActive: active }), 0, options.memo);
|
|
54
|
+
if (!proof && !active) {
|
|
55
|
+
if (!attempted) {
|
|
56
|
+
attempted = true;
|
|
57
|
+
const begun = clock();
|
|
58
|
+
inactive = frameLemmas(inactiveGoal, cert, end, trace, root, { stopAfterFailed: 2, deferCheck: deferNested });
|
|
59
|
+
trace.push({ stage: 'shared-frame', ms: Math.round(clock() - begun), proved: !!inactive });
|
|
60
|
+
}
|
|
61
|
+
if (inactive) {
|
|
62
|
+
const shared = widen(inactiveGoal, g, inactive, {}, root, path), accepted = !!shared && (deferNested || check(g, shared, path));
|
|
63
|
+
trace.push({ stage: 'shared-frame-lift', ms: Math.round(clock() - start), checked: accepted && !deferNested, proposed: !!shared, deferred: deferNested });
|
|
64
|
+
if (accepted)
|
|
65
|
+
return shared;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!proof && !active && inactiveLeaf) {
|
|
69
|
+
const shared = withDeadline(Math.min(end, clock() + 50), () => widen(g, g, inactiveLeaf.tree, {}, inactiveLeaf.path, path)), accepted = !!shared && (deferNested || check(g, shared, path));
|
|
70
|
+
trace.push({ stage: 'inactive-path-reuse', ms: Math.round(clock() - start), checked: accepted && !deferNested, proposed: !!shared, deferred: deferNested });
|
|
71
|
+
if (accepted)
|
|
72
|
+
return shared;
|
|
73
|
+
}
|
|
74
|
+
if (!proof && !active) {
|
|
75
|
+
const simple = solve(rowsAt(goal, path), 500);
|
|
76
|
+
if (simple.kind === 'refuted')
|
|
77
|
+
proof = { leaf: simple.steps };
|
|
78
|
+
}
|
|
79
|
+
if (!proof)
|
|
80
|
+
proof = active ? fieldBoundLemmas(m, ds, goal, cert, end, trace, undefined, path, { deferCheck: true, fieldClaim: options.claim, memo: options.memo, conditional: options.conditional, fieldDemand: fieldDemandAt(path) }) : frameLemmas(goal, cert, end, trace, path, { deferCheck: deferNested });
|
|
81
|
+
if (!proof && clock() < end) {
|
|
82
|
+
const before = atPoint.on;
|
|
83
|
+
atPoint.on = false;
|
|
84
|
+
try {
|
|
85
|
+
const out = grow(goal, path, { nodes: 0, until: end, units: false });
|
|
86
|
+
if ('tree' in out)
|
|
87
|
+
proof = out.tree;
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
atPoint.on = before;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// The complete guard tree below checks active proofs after source transport.
|
|
94
|
+
// Avoid checking the same large active tree before and after that transport.
|
|
95
|
+
const lifted = proof && (sourceOnly ? proof : hasConditionalProof(proof) ? transportConditionalProof(goal, g, proof, path, path, Math.min(wallAt(), performance.now() + Math.max(0, end - clock()) * 10)) : widen(goal, g, proof, {}, path, path)), accepted = !!lifted && (active || deferNested || check(g, lifted, path));
|
|
96
|
+
if (accepted && lifted && !hasConditionalProof(lifted))
|
|
97
|
+
options.memo?.put(g, path, lifted);
|
|
98
|
+
if (!active && accepted && lifted && !inactiveLeaf)
|
|
99
|
+
inactiveLeaf = { tree: lifted, path: new Map(path) };
|
|
100
|
+
trace.push({ stage: 'guard-leaf', active, sourceOnly, hyps: hyps.length, ms: Math.round(clock() - start), checked: !active && !deferNested && accepted, proposed: !!proof, transported: !!lifted, deferred: active || deferNested });
|
|
101
|
+
return accepted ? lifted : undefined;
|
|
102
|
+
};
|
|
103
|
+
const visit = (i, hyps, path) => {
|
|
104
|
+
if (booleans) {
|
|
105
|
+
const active = truth(guard, path);
|
|
106
|
+
if (active !== undefined)
|
|
107
|
+
return leaf(hyps, path, active);
|
|
108
|
+
if (i === conditions.length)
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
else if (i === conditions.length)
|
|
112
|
+
return leaf(hyps, path, true);
|
|
113
|
+
if (clock() >= until)
|
|
114
|
+
return undefined;
|
|
115
|
+
const c = conditions[i];
|
|
116
|
+
if (c.op !== '<=')
|
|
117
|
+
return undefined;
|
|
118
|
+
const known = truth(c, path);
|
|
119
|
+
if (known === true)
|
|
120
|
+
return visit(i + 1, [...hyps, c], path);
|
|
121
|
+
if (known === false)
|
|
122
|
+
return booleans ? visit(i + 1, [...hyps, { op: 'not', x: c }], path) : leaf([...hyps, { op: 'not', x: c }], path, false);
|
|
123
|
+
const a = linear(c.a, path), b = linear(c.b, path);
|
|
124
|
+
if (!a || !b)
|
|
125
|
+
return undefined;
|
|
126
|
+
const split = sub(a, b), id = canon(split);
|
|
127
|
+
const noPath = new Map(path).set(id, { lin: split, holds: false }), no = booleans ? visit(i + 1, [...hyps, { op: 'not', x: c }], noPath) : leaf([...hyps, { op: 'not', x: c }], noPath, false);
|
|
128
|
+
if (!no)
|
|
129
|
+
return undefined;
|
|
130
|
+
const yesPath = new Map(path).set(id, { lin: split, holds: true }), yes = visit(i + 1, [...hyps, c], yesPath);
|
|
131
|
+
return yes ? { split, yes, no } : undefined;
|
|
132
|
+
};
|
|
133
|
+
const tree = visit(0, [], new Map(root));
|
|
134
|
+
const accepted = !!tree && (options.deferCheck || check(g, tree, root));
|
|
135
|
+
trace.push({ stage: 'guard-complete', cuts: conditions.length, checked: !options.deferCheck && accepted, ...(options.deferCheck ? { proposed: !!tree, deferred: true } : {}) });
|
|
136
|
+
// Deferred trees are proposals only; the composing caller must check them.
|
|
137
|
+
return accepted ? tree : undefined;
|
|
138
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type E } from '../machine.js';
|
|
2
|
+
import { type Goal, type Path, type Tree } from '../../kernel/kernel.js';
|
|
3
|
+
export declare const closeKeyReads: typeof closeKeyReadsImpl;
|
|
4
|
+
declare function closeKeyReadsImpl(g: Goal, root: Path, reads: {
|
|
5
|
+
map: string;
|
|
6
|
+
key: E;
|
|
7
|
+
}[], wits: Set<string>, until: number): {
|
|
8
|
+
path: Path;
|
|
9
|
+
cuts: {
|
|
10
|
+
split: Record<string, number>;
|
|
11
|
+
no: Tree;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Untrusted closure of arithmetic read-key guards. All added facts carry a
|
|
2
|
+
// refutation of their opposite branch; the caller checks the combined tree.
|
|
3
|
+
import { walkOnce } from "../machine.js";
|
|
4
|
+
import { canon, facts, truth } from "../../kernel/kernel.js";
|
|
5
|
+
import { scale } from "../solver.js";
|
|
6
|
+
import { clock } from "../../kernel/prove.js";
|
|
7
|
+
import { wallSpan, refuteFast, rowsAt } from "./ops.js";
|
|
8
|
+
export const closeKeyReads = (...args) => wallSpan('key-proposals', () => closeKeyReadsImpl(...args));
|
|
9
|
+
function closeKeyReadsImpl(g, root, reads, wits, until) {
|
|
10
|
+
const proposals = [], seen = new Set(), cuts = [], cells = new Map();
|
|
11
|
+
let path = root;
|
|
12
|
+
const add = (c) => { const id = JSON.stringify(c); if (!seen.has(id)) {
|
|
13
|
+
seen.add(id);
|
|
14
|
+
proposals.push(c);
|
|
15
|
+
} };
|
|
16
|
+
const member = (key) => { let hit = false; walkOnce(key, (o) => { if (o.op === 'var' && wits.has(o.name))
|
|
17
|
+
hit = true; }); return hit; };
|
|
18
|
+
for (const { map, key } of reads) {
|
|
19
|
+
const xs = cells.get(map) ?? [];
|
|
20
|
+
if (!xs.some(k => JSON.stringify(k) === JSON.stringify(key)))
|
|
21
|
+
xs.push(key);
|
|
22
|
+
cells.set(map, xs);
|
|
23
|
+
if (!member(key))
|
|
24
|
+
continue;
|
|
25
|
+
const subs = [];
|
|
26
|
+
walkOnce(key, (o) => { if (o.op === 'sub')
|
|
27
|
+
subs.push(o); });
|
|
28
|
+
for (const s of subs.reverse())
|
|
29
|
+
add({ op: '<=', a: s.b, b: s.a });
|
|
30
|
+
}
|
|
31
|
+
for (const keys of cells.values())
|
|
32
|
+
for (let i = 0; i < keys.length; i++)
|
|
33
|
+
for (let j = i + 1; j < keys.length; j++)
|
|
34
|
+
if (member(keys[i]) || member(keys[j]))
|
|
35
|
+
add({ op: '=', a: keys[i], b: keys[j] });
|
|
36
|
+
const force = (split) => {
|
|
37
|
+
const id = canon(split);
|
|
38
|
+
if (path.get(id)?.holds === true)
|
|
39
|
+
return true;
|
|
40
|
+
if (clock() >= until)
|
|
41
|
+
return false;
|
|
42
|
+
const other = new Map(path).set(id, { lin: split, holds: false }), out = refuteFast(rowsAt(g, other), 128);
|
|
43
|
+
if (out?.kind !== 'refuted')
|
|
44
|
+
return false;
|
|
45
|
+
cuts.push({ split, no: { leaf: out.steps } });
|
|
46
|
+
path = new Map(path).set(id, { lin: split, holds: true });
|
|
47
|
+
return true;
|
|
48
|
+
};
|
|
49
|
+
for (const c of proposals.slice(0, 24)) {
|
|
50
|
+
if (clock() >= until)
|
|
51
|
+
break;
|
|
52
|
+
if (truth(c, path) !== undefined)
|
|
53
|
+
continue;
|
|
54
|
+
for (const split of facts(c, path))
|
|
55
|
+
if (!force(split)) {
|
|
56
|
+
const inverse = scale(split, -1);
|
|
57
|
+
inverse['1'] = (inverse['1'] ?? 0) + 1;
|
|
58
|
+
force(inverse);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { path, cuts };
|
|
62
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** One even share of the still-unspent goal allowance, capped at one third.
|
|
2
|
+
* Split children receive the same absolute deadline; the second spends only
|
|
3
|
+
* what the first leaves. Unspent allowance is retained, not a final-leaf bonus. */
|
|
4
|
+
export declare const leafAllowance: (remaining: number, leavesLeft: number) => number;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** One even share of the still-unspent goal allowance, capped at one third.
|
|
2
|
+
* Split children receive the same absolute deadline; the second spends only
|
|
3
|
+
* what the first leaves. Unspent allowance is retained, not a final-leaf bonus. */
|
|
4
|
+
export const leafAllowance = (remaining, leavesLeft) => {
|
|
5
|
+
const available = Math.max(0, remaining);
|
|
6
|
+
return Math.min(available / Math.max(1, leavesLeft), available / 3);
|
|
7
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type CountCert, type Goal, type Path, type Tree } from '../../kernel/kernel.js';
|
|
2
|
+
export declare const liftCountProxies: typeof liftCountProxiesImpl;
|
|
3
|
+
declare function liftCountProxiesImpl(part: Goal, whole: Goal, tree: Tree, reads: CountCert['reads'], pp?: Path, wp?: Path, diagnose?: (event: object) => void, options?: {
|
|
4
|
+
deferCheck?: boolean;
|
|
5
|
+
}): Tree | undefined;
|
|
6
|
+
export {};
|