gdp-wired 0.48.0 → 0.49.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 +2 -2
- package/dist/core/bmc.js +10 -7
- package/dist/core/check.js +7 -2
- package/dist/core/count-attempt-work.d.ts +29 -0
- package/dist/core/count-attempt-work.js +96 -0
- package/dist/core/count-boolean-partition.d.ts +5 -0
- package/dist/core/count-boolean-partition.js +47 -0
- package/dist/core/count-bounded-quotient.d.ts +2 -0
- package/dist/core/count-bounded-quotient.js +13 -0
- package/dist/core/count-case-compose.d.ts +20 -0
- package/dist/core/count-case-compose.js +289 -0
- package/dist/core/count-cases.js +3 -2
- package/dist/core/count-cert-rename.d.ts +10 -0
- package/dist/core/count-cert-rename.js +69 -0
- package/dist/core/count-cert-transport.d.ts +10 -2
- package/dist/core/count-cert-transport.js +60 -9
- package/dist/core/count-certificate-minimize.d.ts +57 -0
- package/dist/core/count-certificate-minimize.js +263 -0
- package/dist/core/count-closed-family.d.ts +32 -0
- package/dist/core/count-closed-family.js +143 -0
- package/dist/core/count-closing-budget.d.ts +10 -0
- package/dist/core/count-closing-budget.js +49 -0
- package/dist/core/count-closing-needs.d.ts +5 -0
- package/dist/core/count-closing-needs.js +9 -0
- package/dist/core/count-component-budget.d.ts +5 -0
- package/dist/core/count-component-budget.js +9 -0
- package/dist/core/count-copy-shape.d.ts +11 -0
- package/dist/core/count-copy-shape.js +40 -0
- package/dist/core/count-disjoint-funding.d.ts +75 -0
- package/dist/core/count-disjoint-funding.js +284 -0
- package/dist/core/count-emitter-frame-pool.d.ts +23 -0
- package/dist/core/count-emitter-frame-pool.js +87 -0
- package/dist/core/count-final-step.d.ts +5 -0
- package/dist/core/count-final-step.js +20 -0
- package/dist/core/count-fixed-frame.d.ts +4 -0
- package/dist/core/count-fixed-frame.js +30 -0
- package/dist/core/count-frames.d.ts +25 -0
- package/dist/core/count-frames.js +118 -0
- package/dist/core/count-frozen-guard.d.ts +2 -0
- package/dist/core/count-frozen-guard.js +31 -0
- package/dist/core/count-generation-phase.d.ts +7 -0
- package/dist/core/count-generation-phase.js +33 -0
- package/dist/core/count-guard-composition.d.ts +12 -0
- package/dist/core/count-guard-composition.js +48 -0
- package/dist/core/count-guard-context.d.ts +11 -0
- package/dist/core/count-guard-context.js +50 -0
- package/dist/core/count-guard-facts.d.ts +50 -0
- package/dist/core/count-guard-facts.js +97 -0
- package/dist/core/count-guard-proposals.d.ts +7 -0
- package/dist/core/count-guard-proposals.js +106 -0
- package/dist/core/count-guard-shape.d.ts +18 -0
- package/dist/core/count-guard-shape.js +100 -0
- package/dist/core/count-guard-tree.d.ts +17 -0
- package/dist/core/count-guard-tree.js +125 -0
- package/dist/core/count-leader-facts.d.ts +10 -0
- package/dist/core/count-leader-facts.js +52 -0
- package/dist/core/count-leader.d.ts +10 -0
- package/dist/core/count-leader.js +331 -0
- package/dist/core/count-lemma-transport.d.ts +8 -0
- package/dist/core/count-lemma-transport.js +47 -0
- package/dist/core/count-lifted-budget.d.ts +54 -0
- package/dist/core/count-lifted-budget.js +97 -0
- package/dist/core/count-lifted-copy.d.ts +3 -0
- package/dist/core/count-lifted-copy.js +166 -0
- package/dist/core/count-lifted-increment.d.ts +3 -0
- package/dist/core/count-lifted-increment.js +146 -0
- package/dist/core/count-lifted-load.d.ts +5 -0
- package/dist/core/count-lifted-load.js +179 -0
- package/dist/core/count-lifted-prerequisite.d.ts +14 -0
- package/dist/core/count-lifted-prerequisite.js +53 -0
- package/dist/core/count-lifted-replacement.d.ts +3 -0
- package/dist/core/count-lifted-replacement.js +540 -0
- package/dist/core/count-lifted-shape.d.ts +63 -0
- package/dist/core/count-lifted-shape.js +115 -0
- package/dist/core/count-lifted-strategy.d.ts +7 -0
- package/dist/core/count-lifted-strategy.js +226 -0
- package/dist/core/count-lifted-transports.d.ts +32 -0
- package/dist/core/count-lifted-transports.js +293 -0
- package/dist/core/count-load-shape.d.ts +17 -0
- package/dist/core/count-load-shape.js +67 -0
- package/dist/core/count-minimal-view.d.ts +26 -0
- package/dist/core/count-minimal-view.js +46 -0
- package/dist/core/count-operation-observation.d.ts +9 -0
- package/dist/core/count-operation-observation.js +22 -0
- package/dist/core/count-operation-order.d.ts +5 -0
- package/dist/core/count-operation-order.js +4 -0
- package/dist/core/count-phase.d.ts +9 -0
- package/dist/core/count-phase.js +127 -0
- package/dist/core/count-premise-search.d.ts +9 -0
- package/dist/core/count-premise-search.js +41 -0
- package/dist/core/count-premise-view.d.ts +19 -0
- package/dist/core/count-premise-view.js +220 -0
- package/dist/core/count-prerequisite-components.d.ts +67 -0
- package/dist/core/count-prerequisite-components.js +239 -0
- package/dist/core/count-prerequisite-memory.d.ts +24 -0
- package/dist/core/count-prerequisite-memory.js +37 -0
- package/dist/core/count-prerequisite-plan.d.ts +12 -0
- package/dist/core/count-prerequisite-plan.js +88 -0
- package/dist/core/count-primitive-budget.d.ts +1 -0
- package/dist/core/count-primitive-budget.js +8 -0
- package/dist/core/count-project-free.d.ts +3 -0
- package/dist/core/count-project-free.js +24 -0
- package/dist/core/count-project-witness.d.ts +4 -0
- package/dist/core/count-project-witness.js +48 -0
- package/dist/core/count-proof-rescope.d.ts +14 -0
- package/dist/core/count-proof-rescope.js +71 -0
- package/dist/core/count-proof-scope.d.ts +68 -0
- package/dist/core/count-proof-scope.js +333 -0
- package/dist/core/count-prune-owned-root.d.ts +5 -0
- package/dist/core/count-prune-owned-root.js +27 -0
- package/dist/core/count-query-context.d.ts +3 -0
- package/dist/core/count-query-context.js +7 -0
- package/dist/core/count-query.d.ts +15 -0
- package/dist/core/count-query.js +59 -0
- package/dist/core/count-quorum-leaf.d.ts +9 -0
- package/dist/core/count-quorum-leaf.js +38 -0
- package/dist/core/count-reachability-budget.d.ts +1 -0
- package/dist/core/count-reachability-budget.js +7 -0
- package/dist/core/count-reachability-reconcile.d.ts +11 -0
- package/dist/core/count-reachability-reconcile.js +19 -0
- package/dist/core/count-reachability.d.ts +50 -0
- package/dist/core/count-reachability.js +351 -0
- package/dist/core/count-rebase-path.d.ts +9 -0
- package/dist/core/count-rebase-path.js +68 -0
- package/dist/core/count-recipe-context.d.ts +45 -0
- package/dist/core/count-recipe-context.js +71 -0
- package/dist/core/count-recipe-controller.d.ts +115 -0
- package/dist/core/count-recipe-controller.js +417 -0
- package/dist/core/count-recipe-graph.d.ts +36 -0
- package/dist/core/count-recipe-graph.js +211 -0
- package/dist/core/count-recovery/conditional-check-cache.js +3 -2
- package/dist/core/count-recovery/conditional-cuts.js +5 -4
- package/dist/core/count-recovery/conditional-proof.d.ts +37 -3
- package/dist/core/count-recovery/conditional-proof.js +72 -30
- package/dist/core/count-recovery/derivability-closure.js +2 -1
- package/dist/core/count-recovery/guard-cases.js +2 -1
- package/dist/core/count-recovery/reframe-tree.d.ts +2 -0
- package/dist/core/count-recovery/reframe-tree.js +24 -0
- package/dist/core/count-recovery/replay-linear-skeleton.d.ts +2 -0
- package/dist/core/count-recovery/replay-linear-skeleton.js +28 -0
- package/dist/core/count-recovery/row-cases.js +2 -1
- package/dist/core/count-rejection-budget.d.ts +8 -0
- package/dist/core/count-rejection-budget.js +15 -0
- package/dist/core/count-replacement.d.ts +5 -0
- package/dist/core/count-replacement.js +129 -0
- package/dist/core/count-replay-diagnostic.d.ts +21 -0
- package/dist/core/count-replay-diagnostic.js +49 -0
- package/dist/core/count-replay-skeleton.d.ts +4 -0
- package/dist/core/count-replay-skeleton.js +28 -0
- package/dist/core/count-rescope-funding.d.ts +3 -0
- package/dist/core/count-rescope-funding.js +17 -0
- package/dist/core/count-restrictions.d.ts +11 -0
- package/dist/core/count-restrictions.js +31 -0
- package/dist/core/count-retry-budget.d.ts +67 -0
- package/dist/core/count-retry-budget.js +114 -0
- package/dist/core/count-retry-round.d.ts +24 -0
- package/dist/core/count-retry-round.js +44 -0
- package/dist/core/count-row-agreement.d.ts +35 -0
- package/dist/core/count-row-agreement.js +270 -0
- package/dist/core/count-row-aliases.d.ts +3 -0
- package/dist/core/count-row-aliases.js +59 -0
- package/dist/core/count-row-composition.d.ts +6 -0
- package/dist/core/count-row-composition.js +55 -0
- package/dist/core/count-row-copy-linear.d.ts +4 -0
- package/dist/core/count-row-copy-linear.js +83 -0
- package/dist/core/count-row-copy.d.ts +4 -0
- package/dist/core/count-row-copy.js +94 -0
- package/dist/core/count-row-policy.d.ts +3 -0
- package/dist/core/count-row-policy.js +56 -0
- package/dist/core/count-row-reindex.d.ts +11 -0
- package/dist/core/count-row-reindex.js +126 -0
- package/dist/core/count-row-support.d.ts +9 -0
- package/dist/core/count-row-support.js +42 -0
- package/dist/core/count-row-symmetry.d.ts +7 -0
- package/dist/core/count-row-symmetry.js +100 -0
- package/dist/core/count-scope-hyps.d.ts +2 -0
- package/dist/core/count-scope-hyps.js +163 -0
- package/dist/core/count-scope-row-reuse.d.ts +3 -0
- package/dist/core/count-scope-row-reuse.js +92 -0
- package/dist/core/count-search-allowance.d.ts +1 -0
- package/dist/core/count-search-allowance.js +17 -0
- package/dist/core/count-stabilize-tree.d.ts +9 -0
- package/dist/core/count-stabilize-tree.js +35 -0
- package/dist/core/count-stage-trace.d.ts +8 -0
- package/dist/core/count-stage-trace.js +45 -0
- package/dist/core/count-strategies.d.ts +16 -0
- package/dist/core/count-strategies.js +155 -0
- package/dist/core/count-strategy-premises.d.ts +5 -0
- package/dist/core/count-strategy-premises.js +14 -0
- package/dist/core/count-strategy.d.ts +41 -0
- package/dist/core/count-strategy.js +76 -0
- package/dist/core/count-support.js +3 -2
- package/dist/core/count-tier-budget.d.ts +14 -0
- package/dist/core/count-tier-budget.js +64 -0
- package/dist/core/count-unwritten-prefix.d.ts +24 -0
- package/dist/core/count-unwritten-prefix.js +97 -0
- package/dist/core/count-write-shape.d.ts +15 -0
- package/dist/core/count-write-shape.js +73 -0
- package/dist/core/counts.d.ts +37 -13
- package/dist/core/counts.js +990 -127
- package/dist/core/cycles.js +5 -4
- package/dist/core/cyclic.js +11 -10
- package/dist/core/data.js +16 -15
- package/dist/core/dsl-deadline.d.ts +3 -0
- package/dist/core/dsl-deadline.js +27 -0
- package/dist/core/dsl.d.ts +9 -0
- package/dist/core/dsl.js +156 -51
- package/dist/core/evaluation-admission.d.ts +1 -0
- package/dist/core/evaluation-admission.js +3 -0
- package/dist/core/exists.d.ts +6 -1
- package/dist/core/exists.js +51 -9
- package/dist/core/field-laws.d.ts +3 -1
- package/dist/core/field-laws.js +140 -2
- package/dist/core/finite-houdini.d.ts +6 -0
- package/dist/core/finite-houdini.js +63 -21
- package/dist/core/finite-tiny.js +95 -67
- package/dist/core/fixtures/count-completion/paxos-decision.json +1 -0
- package/dist/core/fresh.js +5 -1
- package/dist/core/infer.js +45 -30
- package/dist/core/kind.js +2 -1
- package/dist/core/lemma-cuts.js +11 -10
- package/dist/core/linear-admission.d.ts +14 -0
- package/dist/core/linear-admission.js +151 -0
- package/dist/core/machine.d.ts +5 -2
- package/dist/core/machine.js +105 -31
- package/dist/core/meter.d.ts +22 -0
- package/dist/core/meter.js +34 -0
- package/dist/core/nonterm.js +4 -3
- package/dist/core/prover-row-budget.d.ts +3 -0
- package/dist/core/prover-row-budget.js +106 -0
- package/dist/core/quorum-laws.d.ts +21 -1
- package/dist/core/quorum-laws.js +27 -3
- package/dist/core/rationals.js +3 -2
- package/dist/core/rejection-discovery.d.ts +34 -0
- package/dist/core/rejection-discovery.js +36 -0
- package/dist/core/rejection-stage.d.ts +39 -0
- package/dist/core/rejection-stage.js +205 -0
- package/dist/core/request-quotient.d.ts +8 -0
- package/dist/core/request-quotient.js +299 -0
- package/dist/core/row-agreement-shape.d.ts +15 -0
- package/dist/core/row-agreement-shape.js +68 -0
- package/dist/core/runtime-wall.d.ts +2 -0
- package/dist/core/search-policy.d.ts +15 -0
- package/dist/core/search-policy.js +68 -0
- package/dist/core/solver.d.ts +1 -1
- package/dist/core/solver.js +40 -6
- package/dist/core/step-work.d.ts +12 -0
- package/dist/core/step-work.js +14 -0
- package/dist/core/strategy-premises.d.ts +8 -0
- package/dist/core/strategy-premises.js +64 -0
- package/dist/core/system.js +4 -3
- package/dist/core/table-admission.d.ts +1 -0
- package/dist/core/table-admission.js +3 -0
- package/dist/core/trace-clock.d.ts +3 -0
- package/dist/core/trace-clock.js +16 -0
- package/dist/core/transfer.js +3 -2
- package/dist/core/translate.js +16 -3
- package/dist/core/wall.d.ts +6 -1
- package/dist/core/wall.js +23 -9
- package/dist/core/watch.d.ts +1 -1
- package/dist/core/watch.js +13 -4
- package/dist/core/work-admission.d.ts +164 -0
- package/dist/core/work-admission.js +418 -0
- package/dist/core/work-amount.d.ts +21 -0
- package/dist/core/work-amount.js +80 -0
- package/dist/core/work-collections.d.ts +11 -0
- package/dist/core/work-collections.js +198 -0
- package/dist/core/work-kinds.d.ts +11 -0
- package/dist/core/work-kinds.js +9 -0
- package/dist/core/work-meter.d.ts +8 -0
- package/dist/core/work-meter.js +83 -0
- package/dist/core/work-observe.d.ts +12 -0
- package/dist/core/work-observe.js +39 -0
- package/dist/core/work-profile.d.ts +10 -0
- package/dist/core/work-profile.js +21 -0
- package/dist/core/work-refusal.d.ts +1 -0
- package/dist/core/work-refusal.js +6 -0
- package/dist/interchange/format.js +2 -0
- package/dist/kernel/cdcl.js +93 -40
- package/dist/kernel/epr.js +23 -8
- package/dist/kernel/kernel.d.ts +47 -1
- package/dist/kernel/kernel.js +417 -68
- package/dist/kernel/prove.d.ts +49 -3
- package/dist/kernel/prove.js +468 -122
- package/dist/kernel/prover-rows.d.ts +1 -0
- package/dist/kernel/prover-rows.js +12 -1
- package/dist/kernel/reader.d.ts +1 -1
- package/dist/kernel/reader.js +57 -12
- package/dist/kernel/simplex.js +9 -2
- package/dist/lean-kernel/emit.d.ts +9 -1
- package/dist/lean-kernel/emit.js +144 -22
- package/dist/lean-kernel/legacy-family-library.d.ts +1 -0
- package/dist/lean-kernel/legacy-family-library.js +5 -0
- package/dist/lean-kernel/library.js +3 -3
- package/package.json +1 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Generic ordinary guard-restricted count facts for optional proof strategies.
|
|
2
|
+
// Every result is an ordinary checkMC/check proof under its explicitly recorded
|
|
3
|
+
// conditions; a proposal is never added to the original goal as an axiom.
|
|
4
|
+
import { atMost, get, n, not, same, walkOnce } from "./machine.js";
|
|
5
|
+
import { countsForReads } from "./count-facts.js";
|
|
6
|
+
import { check, checkMC, linOk, mcGoal } from "../kernel/kernel.js";
|
|
7
|
+
import { brokenOf, clock, grow, pastWall } from "../kernel/prove.js";
|
|
8
|
+
import { growCdcl } from "../kernel/cdcl.js";
|
|
9
|
+
import { minimalViewFirst } from "./count-minimal-view.js";
|
|
10
|
+
import { projectCountFree } from "./count-project-free.js";
|
|
11
|
+
const mentions = (t, key) => { let found = false; walkOnce(t, (v) => { if (v.op === 'var' && v.name === key)
|
|
12
|
+
found = true; }); return found; };
|
|
13
|
+
export function guardCountFact(premises, decls, reads, proposal, wit, until, observe) {
|
|
14
|
+
if (pastWall() || clock() >= until || !proposal.terms.length || proposal.when.some(c => mentions(c, wit)))
|
|
15
|
+
return;
|
|
16
|
+
const counts = countsForReads(decls, reads), terms = proposal.terms;
|
|
17
|
+
if (!counts || new Set(terms.map(t => t[1])).size !== terms.length)
|
|
18
|
+
return;
|
|
19
|
+
const first = counts.find(c => c.v === terms[0][1]);
|
|
20
|
+
if (!first)
|
|
21
|
+
return;
|
|
22
|
+
let positive = n(0), negative = n(0);
|
|
23
|
+
for (const [coefficient, name] of terms) {
|
|
24
|
+
if (!Number.isSafeInteger(coefficient) || !coefficient)
|
|
25
|
+
return;
|
|
26
|
+
const read = reads.find(r => r[0] === name), count = counts.find(c => c.v === name);
|
|
27
|
+
if (!read || !count || JSON.stringify(count.below) !== JSON.stringify(first.below))
|
|
28
|
+
return;
|
|
29
|
+
const value = { op: 'mul', k: Math.abs(coefficient), a: get(read[1], read[2]) };
|
|
30
|
+
if (coefficient > 0)
|
|
31
|
+
positive = { op: 'add', a: positive, b: value };
|
|
32
|
+
else
|
|
33
|
+
negative = { op: 'add', a: negative, b: value };
|
|
34
|
+
}
|
|
35
|
+
const claim = atMost(positive, negative), goal = { name: proposal.name, hyps: [...premises, ...proposal.when, not(claim)] };
|
|
36
|
+
const request = { reads, insts: [{ wit, below: first.below, terms, unit: 0 }], picks: [] }, encoded = mcGoal(goal.hyps, decls, request);
|
|
37
|
+
if (!encoded) {
|
|
38
|
+
observe?.({ outcome: 'invalid-encoding' });
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const result = grow(encoded, new Map(), { nodes: 0, until });
|
|
42
|
+
if (!('tree' in result)) {
|
|
43
|
+
const witness = 'witness' in result ? result.witness : undefined, broken = witness ? brokenOf(encoded)(witness) : undefined;
|
|
44
|
+
if (witness && broken?.length)
|
|
45
|
+
throw Error('invalid auxiliary witness');
|
|
46
|
+
observe?.({ outcome: result.stuck, encoded, witness, broken });
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const cert = { ...request, tree: result.tree }, checked = checkMC(goal.hyps, decls, cert);
|
|
50
|
+
observe?.({ outcome: checked ? 'proof' : 'rejected-proof', encoded });
|
|
51
|
+
return checked ? { proposal, claim, goal, cert } : undefined;
|
|
52
|
+
}
|
|
53
|
+
export function guardLinearFact(decls, reads, proposal, until, observe, search = 'grow', options = {}) {
|
|
54
|
+
if (pastWall() || clock() >= until || !proposal.terms.length)
|
|
55
|
+
return;
|
|
56
|
+
const counts = countsForReads(decls, reads);
|
|
57
|
+
if (!counts)
|
|
58
|
+
return;
|
|
59
|
+
const pos = [], neg = [];
|
|
60
|
+
for (const [coefficient, name] of proposal.terms) {
|
|
61
|
+
if (!Number.isSafeInteger(coefficient) || !coefficient || !counts.some(c => c.v === name))
|
|
62
|
+
return;
|
|
63
|
+
if (coefficient > 0)
|
|
64
|
+
pos.push([coefficient, name]);
|
|
65
|
+
else
|
|
66
|
+
neg.push([-coefficient, name]);
|
|
67
|
+
}
|
|
68
|
+
const first = counts.find(c => c.v === proposal.terms[0][1]);
|
|
69
|
+
if (counts.filter(c => proposal.terms.some(t => t[1] === c.v)).some(c => c.key !== first.key || JSON.stringify(c.below) !== JSON.stringify(first.below)))
|
|
70
|
+
return;
|
|
71
|
+
const term = (side) => side.reduceRight((rest, [k, name]) => ({ op: 'add', a: { op: 'mul', k, a: counts.find(c => c.v === name).body }, b: rest }), n(0));
|
|
72
|
+
const goal = { name: proposal.name, hyps: [...proposal.when, { op: '<', a: { op: 'var', name: first.key }, b: first.below }, { op: '<', a: term(neg), b: term(pos) }] };
|
|
73
|
+
const policy = minimalViewFirst(goal, { ...goal, hyps: projectCountFree(goal.hyps, new Map(), new Set()) }, new Map(), until, search === 'cdcl' ? growCdcl : grow, new Map(), options);
|
|
74
|
+
const result = policy ? (policy.tree ? { tree: policy.tree, nodes: 0 } : { stuck: policy.kind === 'sat' ? 'sat' : 'unknown', path: new Map(), witness: policy.witness, why: policy.kind }) : search === 'cdcl' ? growCdcl(goal, new Map(), { nodes: 0, until }) : grow(goal, new Map(), { nodes: 0, until });
|
|
75
|
+
const searchEnd = clock();
|
|
76
|
+
if (searchEnd >= until) {
|
|
77
|
+
observe?.({ outcome: 'deadline', encoded: goal, searchEnd });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (!('tree' in result)) {
|
|
81
|
+
const witness = 'witness' in result ? result.witness : undefined, broken = witness ? brokenOf(goal)(witness) : undefined;
|
|
82
|
+
if (witness && broken?.length)
|
|
83
|
+
throw Error('invalid linear auxiliary witness');
|
|
84
|
+
observe?.({ outcome: result.stuck, encoded: goal, witness, broken, searchEnd, ...(policy ? { minimal: { kind: policy.minimalKind, fallback: policy.fallback, units: policy.minimalUnits, fallbackUnits: policy.fallbackUnits } } : {}) });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const cut = { when: proposal.when, pos, neg, tree: result.tree }, checked = options.deferCheck || linOk(counts, cut);
|
|
88
|
+
observe?.({ outcome: checked ? (options.deferCheck ? 'proposal' : 'proof') : 'rejected-proof', encoded: goal, searchEnd, ...(policy ? { minimal: { kind: policy.minimalKind, fallback: policy.fallback, units: policy.minimalUnits, fallbackUnits: policy.fallbackUnits } } : {}) });
|
|
89
|
+
return checked ? { proposal, goal, cut, ...(options.deferCheck ? { status: 'unchecked' } : {}) } : undefined;
|
|
90
|
+
}
|
|
91
|
+
export function guardBodyFact(proposal, until) {
|
|
92
|
+
if (pastWall() || clock() >= until)
|
|
93
|
+
return;
|
|
94
|
+
const goal = { name: proposal.name, hyps: [...proposal.when, not(same(proposal.pre, proposal.post))] };
|
|
95
|
+
const result = grow(goal, new Map(), { nodes: 0, until });
|
|
96
|
+
return 'tree' in result && check(goal, result.tree) ? { proposal, goal, tree: result.tree } : undefined;
|
|
97
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type C } from './machine.js';
|
|
2
|
+
import { type Count, type CountDecl, type MapRead, type Path } from '../kernel/kernel.js';
|
|
3
|
+
import type { GuardBodyProposal, GuardCountProposal } from './count-guard-facts.js';
|
|
4
|
+
export declare function guardRegionProposals(rawCounts: Count[], reads: MapRead[], decls: CountDecl[], inputMaps: readonly string[], operation: C, path?: Path): {
|
|
5
|
+
counts: GuardCountProposal[];
|
|
6
|
+
bodies: GuardBodyProposal[];
|
|
7
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Structural proposals only: existing count declarations, no protocol names,
|
|
2
|
+
// operation values, trusted facts, or synthesized count declarations.
|
|
3
|
+
import { all, atMost, n, not, same, walkOnce, x } from "./machine.js";
|
|
4
|
+
import { simpE } from "../kernel/kernel.js";
|
|
5
|
+
const text = (t) => JSON.stringify(t);
|
|
6
|
+
const has = (t, p) => { let yes = false; walkOnce(t, (v) => { if (p(v))
|
|
7
|
+
yes = true; }); return yes; };
|
|
8
|
+
const keyed = (t, key) => has(t, v => v.op === 'var' && v.name === key);
|
|
9
|
+
const atoms = (c) => c.op === 'and' ? c.xs.flatMap(atoms) : [c];
|
|
10
|
+
function negativeMap(c, map, negative = false) {
|
|
11
|
+
if (c.op === 'not')
|
|
12
|
+
return negativeMap(c.x, map, !negative);
|
|
13
|
+
if (c.op === 'and' || c.op === 'or')
|
|
14
|
+
return c.xs.some(v => negativeMap(v, map, negative));
|
|
15
|
+
return negative && has(c, v => v.op === 'get' && v.map === map);
|
|
16
|
+
}
|
|
17
|
+
function rowOf(read, decl) {
|
|
18
|
+
const e = read[2];
|
|
19
|
+
return decl.base ? e.op === 'add' && e.a.op === 'mul' && e.a.k === decl.base ? e.a.a : undefined : e;
|
|
20
|
+
}
|
|
21
|
+
export function guardRegionProposals(rawCounts, reads, decls, inputMaps, operation, path = new Map()) {
|
|
22
|
+
// Simplification guides discovery only. Returned body goals retain original expressions.
|
|
23
|
+
const counts = rawCounts.map(c => ({ ...c, body: simpE(c.body, path, c.key) }));
|
|
24
|
+
const out = [], bodies = [], seen = new Set();
|
|
25
|
+
const add = (proposal) => {
|
|
26
|
+
const when = [...proposal.when];
|
|
27
|
+
// A packed read is tied to its certificate label only while its low part is in range.
|
|
28
|
+
for (const [, name] of proposal.terms) {
|
|
29
|
+
const r = reads.find(r => r[0] === name), d = r && decls.find(d => d.map === r[1]);
|
|
30
|
+
if (!r || !d)
|
|
31
|
+
return;
|
|
32
|
+
if (d.base) {
|
|
33
|
+
const key = r[2];
|
|
34
|
+
if (key.op !== 'add' || key.a.op !== 'mul' || key.a.k !== d.base)
|
|
35
|
+
return;
|
|
36
|
+
const bound = { op: '<', a: key.b, b: n(d.base) };
|
|
37
|
+
if (!when.some(c => text(c) === text(bound)))
|
|
38
|
+
when.push(bound);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const p = { ...proposal, when }, id = text([p.when, p.terms]);
|
|
42
|
+
if (!seen.has(id)) {
|
|
43
|
+
seen.add(id);
|
|
44
|
+
out.push(p);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
for (const post of counts) {
|
|
48
|
+
const read = reads.find(r => r[0] === post.v), decl = read && decls.find(d => d.map === read[1]);
|
|
49
|
+
if (!read || !decl || !read[1].endsWith('#'))
|
|
50
|
+
continue;
|
|
51
|
+
const preRead = reads.find(r => r[1] === read[1].slice(0, -1) && text(r[2]) === text(read[2])), pre = preRead && counts.find(c => c.v === preRead[0]), row = rowOf(read, decl);
|
|
52
|
+
if (!pre || !row)
|
|
53
|
+
continue;
|
|
54
|
+
// A row which is unchanged is still a checked count fact, not a name test.
|
|
55
|
+
if (text(pre.body) === text(post.body))
|
|
56
|
+
for (const sign of [1, -1])
|
|
57
|
+
add({ name: `unchanged ${post.v} ${sign}`, kind: 'row-frame', when: [operation], terms: [[sign, post.v], [-sign, pre.v]] });
|
|
58
|
+
const comparisons = [];
|
|
59
|
+
walkOnce(post.body, (v) => { if (v.op === '<' && keyed(v.a, post.key) && !keyed(v.b, post.key))
|
|
60
|
+
comparisons.push(v); });
|
|
61
|
+
for (const comparison of comparisons) {
|
|
62
|
+
const updates = [];
|
|
63
|
+
walkOnce(comparison.a, (v) => { if (v.op === 'if' && !keyed(v.then, post.key) && v.else?.op === 'get' && keyed(v.else.key, post.key))
|
|
64
|
+
updates.push(v); });
|
|
65
|
+
for (const update of updates) {
|
|
66
|
+
const parts = atoms(update.c), guard = parts.find(c => keyed(c, post.key) && has(c, v => v.op === 'get' && inputMaps.includes(v.map))), active = parts.filter(c => !keyed(c, post.key));
|
|
67
|
+
if (!guard || update.else.op !== 'get')
|
|
68
|
+
continue;
|
|
69
|
+
const raisedMap = update.else.map, sources = [];
|
|
70
|
+
walkOnce(update.then, (v) => { if (v.op === 'get' && v.map === raisedMap && !keyed(v.key, post.key))
|
|
71
|
+
sources.push(v.key); });
|
|
72
|
+
const source = sources[0];
|
|
73
|
+
if (!source)
|
|
74
|
+
continue;
|
|
75
|
+
const guardMap = inputMaps.find(map => has(guard, v => v.op === 'get' && v.map === map));
|
|
76
|
+
if (!guardMap)
|
|
77
|
+
continue;
|
|
78
|
+
const preComparisons = [];
|
|
79
|
+
walkOnce(pre.body, (v) => { if (v.op === '<' && has(v.a, z => z.op === 'get' && z.map === raisedMap && keyed(z.key, pre.key)) && !keyed(v.b, pre.key))
|
|
80
|
+
preComparisons.push(v); });
|
|
81
|
+
for (const restricted of counts) {
|
|
82
|
+
const rr = reads.find(r => r[0] === restricted.v);
|
|
83
|
+
if (!rr || rr[1].endsWith('#') || restricted.body.op !== 'if' || !has(restricted.body, v => v.op === 'get' && v.map === guardMap))
|
|
84
|
+
continue;
|
|
85
|
+
const rd = decls.find(d => d.map === rr[1]), restrictedRow = rd && rowOf(rr, rd);
|
|
86
|
+
// A global/input count has no row parameter. Do not pretend its read key identifies a row.
|
|
87
|
+
if (!rd || !restrictedRow || !has(rd.body, v => v.op === 'var' && (v.name === rd.j || v.name === (rd.lo ?? rd.j))))
|
|
88
|
+
continue;
|
|
89
|
+
if (negativeMap(restricted.body.c, guardMap))
|
|
90
|
+
add({ name: `guard complement ${post.v} <= ${restricted.v}`, kind: 'guard-complement-upper', when: [operation, all(...active), same(row, restrictedRow), atMost(comparison.b, update.then)], terms: [[1, post.v], [-1, restricted.v]] });
|
|
91
|
+
else
|
|
92
|
+
for (const bound of preComparisons)
|
|
93
|
+
add({ name: `guard intersection ${restricted.v} <= ${pre.v}`, kind: 'guard-intersection-lower', when: [operation, all(...active), same(row, restrictedRow), atMost(update.then, bound.b)], terms: [[1, restricted.v], [-1, pre.v]] });
|
|
94
|
+
}
|
|
95
|
+
// On the complement of the member guard and away from every changed
|
|
96
|
+
// key-free field read, both per-member predicates must be identical.
|
|
97
|
+
const exclusions = [operation, { op: '<', a: x(post.key), b: post.below }, not(guard), not(same(x(post.key), source))];
|
|
98
|
+
walkOnce(pre.body, (v) => { if (v.op === 'get' && !keyed(v.key, pre.key))
|
|
99
|
+
exclusions.push(not(same(v.key, source))); });
|
|
100
|
+
const unique = [...new Map(exclusions.map(c => [text(c), c])).values()];
|
|
101
|
+
bodies.push({ name: `guard-excluded body ${post.v}`, kind: 'excluded-body-frame', when: unique, pre: rawCounts.find(c => c.v === pre.v).body, post: rawCounts.find(c => c.v === post.v).body });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return { counts: out, bodies };
|
|
106
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Law, type Machine } from './machine.js';
|
|
2
|
+
export type CountGuardShape = {
|
|
3
|
+
voteMap: string;
|
|
4
|
+
rowMap: string;
|
|
5
|
+
memberField: string;
|
|
6
|
+
thresholdField: string;
|
|
7
|
+
memberKey: string;
|
|
8
|
+
rowKey: string;
|
|
9
|
+
otherKey: string;
|
|
10
|
+
width: number;
|
|
11
|
+
membershipMap: string;
|
|
12
|
+
phase?: {
|
|
13
|
+
name: string;
|
|
14
|
+
laws: Law[];
|
|
15
|
+
};
|
|
16
|
+
weakerLaw?: Law;
|
|
17
|
+
};
|
|
18
|
+
export declare function discoverCountGuardShape(m: Machine, law: Law, family: readonly Law[]): CountGuardShape | undefined;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Untrusted structural discovery for optional guarded-count strategies.
|
|
2
|
+
// A match supplies names and existing laws, never a premise or a verdict.
|
|
3
|
+
import { n, walkOnce, x } from "./machine.js";
|
|
4
|
+
import { substC } from "../kernel/kernel.js";
|
|
5
|
+
const json = (value) => JSON.stringify(value);
|
|
6
|
+
const atoms = (c) => c.op === 'and' ? c.xs.flatMap(atoms) : [c];
|
|
7
|
+
const indicator = (d) => d.body.op === 'if' && json(d.body.then) === json(n(1)) && json(d.body.else) === json(n(0));
|
|
8
|
+
export function discoverCountGuardShape(m, law, family) {
|
|
9
|
+
if (!law.forall || law.keys?.length !== 1)
|
|
10
|
+
return;
|
|
11
|
+
let voteMap, rowMap;
|
|
12
|
+
walkOnce(law.holds, (node) => {
|
|
13
|
+
if (node.op !== '<=' || node.a.op !== 'mul' || node.a.k !== 2 || node.a.a.op !== 'get' || node.b.op !== 'get')
|
|
14
|
+
return;
|
|
15
|
+
const vote = m.counts?.[node.a.a.map], row = m.counts?.[node.b.map];
|
|
16
|
+
if (!vote?.base || !row || row.base || !indicator(vote) || !indicator(row) || json(vote.below) !== json(row.below))
|
|
17
|
+
return;
|
|
18
|
+
const packed = node.a.a.key;
|
|
19
|
+
if (packed.op !== 'add' || packed.a.op !== 'mul' || packed.a.k !== vote.base || json(packed.a.a) !== json(x(law.forall)) || json(packed.b) !== json(x(law.keys[0])) || json(node.b.key) !== json(x(law.forall)))
|
|
20
|
+
return;
|
|
21
|
+
const membership = substC(row.body.c, { vars: { [row.j]: x(vote.j), [row.key]: x(vote.key) }, maps: {}, flags: {} });
|
|
22
|
+
if (!atoms(vote.body.c).some(c => json(c) === json(membership)))
|
|
23
|
+
return;
|
|
24
|
+
voteMap = node.a.a.map;
|
|
25
|
+
rowMap = node.b.map;
|
|
26
|
+
});
|
|
27
|
+
if (!voteMap || !rowMap)
|
|
28
|
+
return;
|
|
29
|
+
const vote = m.counts[voteMap];
|
|
30
|
+
if (!indicator(vote))
|
|
31
|
+
return;
|
|
32
|
+
const comparisons = atoms(vote.body.c);
|
|
33
|
+
const threshold = comparisons.find(c => c.op === '<' && c.a.op === 'get' && c.b.op === 'get' && json(c.a.key) === json(x(vote.key)) && json(c.b.key) === json(x(vote.lo ?? vote.j)));
|
|
34
|
+
if (!threshold || threshold.op !== '<' || threshold.a.op !== 'get' || threshold.b.op !== 'get' || !(threshold.a.map in (m.maps ?? {})) || !(threshold.b.map in (m.maps ?? {})))
|
|
35
|
+
return;
|
|
36
|
+
const thresholdField = threshold.b.map, phaseNames = new Set(), phaseLaws = [];
|
|
37
|
+
for (const candidate of family) {
|
|
38
|
+
if (!candidate.forall || candidate.keys?.length)
|
|
39
|
+
continue;
|
|
40
|
+
const fields = new Set(), variables = new Set();
|
|
41
|
+
walkOnce(candidate.holds, (node) => { if (node.op === 'get')
|
|
42
|
+
fields.add(node.map); if (node.op === 'var')
|
|
43
|
+
variables.add(node.name); });
|
|
44
|
+
const phases = Object.keys(m.state).filter(name => variables.has(name));
|
|
45
|
+
if (fields.size && [...fields].every(name => name === thresholdField) && phases.length) {
|
|
46
|
+
phases.forEach(name => phaseNames.add(name));
|
|
47
|
+
phaseLaws.push(candidate);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Several existing zero-phase laws can hold (e.g. before selection and
|
|
51
|
+
// before activation). Prefer only a unique phase named by every non-frame
|
|
52
|
+
// threshold-write guard. This remains a proposal: all resulting proofs check.
|
|
53
|
+
if (phaseNames.size > 1) {
|
|
54
|
+
const write = m.step.maps?.[thresholdField], gates = [];
|
|
55
|
+
if (write && 'each' in write)
|
|
56
|
+
walkOnce(write.value, (node) => {
|
|
57
|
+
if (node.op !== 'if' || node.then.op === 'if' || node.then.op === 'get' && node.then.map === thresholdField && node.then.key.op === 'var' && node.then.key.name === write.each)
|
|
58
|
+
return;
|
|
59
|
+
const names = new Set(), seen = new Set();
|
|
60
|
+
const scan = (value) => walkOnce(value, (part) => {
|
|
61
|
+
if (part.op === 'var' && phaseNames.has(part.name))
|
|
62
|
+
names.add(part.name);
|
|
63
|
+
if (part.op === 'flag' && !seen.has(part.name)) {
|
|
64
|
+
seen.add(part.name);
|
|
65
|
+
const flag = m.step.flags?.[part.name];
|
|
66
|
+
if (flag)
|
|
67
|
+
scan(flag.op === 'all' ? flag.c : flag);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
scan(node.c);
|
|
71
|
+
gates.push(names);
|
|
72
|
+
});
|
|
73
|
+
const common = gates.length ? [...phaseNames].filter(name => gates.every(gate => gate.has(name))) : [];
|
|
74
|
+
if (common.length === 1) {
|
|
75
|
+
phaseNames.clear();
|
|
76
|
+
phaseNames.add(common[0]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const serialized = new Set(comparisons.map(json));
|
|
80
|
+
const weakerLaw = family.find(candidate => {
|
|
81
|
+
if (!candidate.forall || candidate.keys?.length !== 1)
|
|
82
|
+
return false;
|
|
83
|
+
let found = false;
|
|
84
|
+
walkOnce(candidate.holds, (node) => {
|
|
85
|
+
const count = node.op === 'get' && m.counts?.[node.map];
|
|
86
|
+
if (count && node.map !== voteMap && count.base && indicator(count) && atoms(count.body.c).length < comparisons.length && atoms(count.body.c).every(c => serialized.has(json(c))))
|
|
87
|
+
found = true;
|
|
88
|
+
});
|
|
89
|
+
return found;
|
|
90
|
+
});
|
|
91
|
+
const row = m.counts[rowMap];
|
|
92
|
+
const membershipMaps = new Set();
|
|
93
|
+
if (indicator(row))
|
|
94
|
+
walkOnce(row.body.c, (node) => { if (node.op === 'get')
|
|
95
|
+
membershipMaps.add(node.map); });
|
|
96
|
+
if (membershipMaps.size !== 1)
|
|
97
|
+
return;
|
|
98
|
+
return { membershipMap: [...membershipMaps][0], voteMap, rowMap, memberField: threshold.a.map, thresholdField, memberKey: vote.key, rowKey: vote.j, otherKey: vote.lo ?? vote.j, width: vote.base, ...(phaseNames.size === 1 ? { phase: { name: [...phaseNames][0], laws: phaseLaws.filter(law => { let found = false; walkOnce(law.holds, (node) => { if (node.op === 'var' && phaseNames.has(node.name))
|
|
99
|
+
found = true; }); return found; }) } } : {}), ...(weakerLaw ? { weakerLaw } : {}) };
|
|
100
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type C } from './machine.js';
|
|
2
|
+
import { type Lin } from './solver.js';
|
|
3
|
+
import { type Path, type Tree } from '../kernel/kernel.js';
|
|
4
|
+
type Branch = (path: Path) => Tree | undefined;
|
|
5
|
+
export type HoistRow = {
|
|
6
|
+
row: Lin;
|
|
7
|
+
reject: Branch;
|
|
8
|
+
name?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function countGuardTree(until: number, options?: {
|
|
11
|
+
yesFirst?: boolean;
|
|
12
|
+
}): {
|
|
13
|
+
rows: (conditions: Lin[], path: Path, yes: Branch, no: Branch) => Tree | undefined;
|
|
14
|
+
condition: (c: C, path: Path, yes: Branch, no: Branch) => Tree | undefined;
|
|
15
|
+
hoist: (queries: readonly HoistRow[], cases: readonly C[], path: Path, yes: Branch, trace?: (event: Record<string, unknown>) => void) => Tree | undefined;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Exhaustive ordinary scalar splits. Unsupported syntax only declines a hint.
|
|
2
|
+
import { walkOnce } from "./machine.js";
|
|
3
|
+
import { add, k, scale, sub } from "./solver.js";
|
|
4
|
+
import { canon, linear, truth } from "../kernel/kernel.js";
|
|
5
|
+
import { clock, pastWall } from "../kernel/prove.js";
|
|
6
|
+
// Only exact two-sided equalities identify variables. Opaque linear columns
|
|
7
|
+
// remain opaque; a missed alias merely leaves a row at its original position.
|
|
8
|
+
function rowAliases(path) {
|
|
9
|
+
const parent = new Map();
|
|
10
|
+
const root = (name) => { const next = parent.get(name); return next === undefined ? name : root(next); };
|
|
11
|
+
for (const atom of path.values()) {
|
|
12
|
+
if (!atom.holds || (atom.lin['1'] ?? 0) !== 0)
|
|
13
|
+
continue;
|
|
14
|
+
const keys = Object.keys(atom.lin).filter(name => name !== '1' && atom.lin[name] !== 0);
|
|
15
|
+
if (keys.length !== 2 || atom.lin[keys[0]] !== 1 || atom.lin[keys[1]] !== -1 || path.get(canon(scale(atom.lin, -1)))?.holds !== true)
|
|
16
|
+
continue;
|
|
17
|
+
const a = root(keys[0]), b = root(keys[1]);
|
|
18
|
+
if (a !== b)
|
|
19
|
+
parent.set(a < b ? b : a, a < b ? a : b);
|
|
20
|
+
}
|
|
21
|
+
return root;
|
|
22
|
+
}
|
|
23
|
+
export function countGuardTree(until, options = {}) {
|
|
24
|
+
const rows = (conditions, path, yes, no) => {
|
|
25
|
+
if (clock() >= until || pastWall())
|
|
26
|
+
return;
|
|
27
|
+
if (!conditions.length)
|
|
28
|
+
return yes(path);
|
|
29
|
+
const [row, ...rest] = conditions, id = canon(row), known = Object.keys(row).every(k => k === '1') ? (row['1'] ?? 0) <= 0 : path.get(id)?.holds;
|
|
30
|
+
if (known !== undefined)
|
|
31
|
+
return known ? rows(rest, path, yes, no) : no(path);
|
|
32
|
+
const accept = () => rows(rest, new Map(path).set(id, { lin: row, holds: true }), yes, no);
|
|
33
|
+
const reject = () => no(new Map(path).set(id, { lin: row, holds: false }));
|
|
34
|
+
if (options.yesFirst) {
|
|
35
|
+
const accepted = accept();
|
|
36
|
+
if (!accepted)
|
|
37
|
+
return;
|
|
38
|
+
const rejected = reject();
|
|
39
|
+
return rejected ? { split: row, yes: accepted, no: rejected } : undefined;
|
|
40
|
+
}
|
|
41
|
+
const rejected = reject();
|
|
42
|
+
if (!rejected)
|
|
43
|
+
return;
|
|
44
|
+
const accepted = accept();
|
|
45
|
+
return accepted ? { split: row, yes: accepted, no: rejected } : undefined;
|
|
46
|
+
};
|
|
47
|
+
const condition = (c, path, yes, no) => {
|
|
48
|
+
if (clock() >= until || pastWall())
|
|
49
|
+
return;
|
|
50
|
+
let unsupported = false;
|
|
51
|
+
walkOnce(c, (node) => { if (node.op === 'flag' || node.op === 'all')
|
|
52
|
+
unsupported = true; });
|
|
53
|
+
if (unsupported)
|
|
54
|
+
return;
|
|
55
|
+
const known = truth(c, path);
|
|
56
|
+
if (known !== undefined)
|
|
57
|
+
return known ? yes(path) : no(path);
|
|
58
|
+
if (c.op === 'not')
|
|
59
|
+
return condition(c.x, path, no, yes);
|
|
60
|
+
if (c.op === 'and' || c.op === 'or') {
|
|
61
|
+
const [head, ...tail] = c.xs;
|
|
62
|
+
if (!head)
|
|
63
|
+
return c.op === 'and' ? yes(path) : no(path);
|
|
64
|
+
const rest = { op: c.op, xs: tail };
|
|
65
|
+
return c.op === 'and' ? condition(head, path, p => condition(rest, p, yes, no), no) : condition(head, path, yes, p => condition(rest, p, yes, no));
|
|
66
|
+
}
|
|
67
|
+
if (c.op !== '<' && c.op !== '<=' && c.op !== '=')
|
|
68
|
+
return;
|
|
69
|
+
const a = linear(c.a, path), b = linear(c.b, path);
|
|
70
|
+
if (!a || !b)
|
|
71
|
+
return;
|
|
72
|
+
const d = sub(a, b);
|
|
73
|
+
return rows(c.op === '=' ? [d, scale(d, -1)] : [c.op === '<' ? add(d, k(1)) : d], path, yes, no);
|
|
74
|
+
};
|
|
75
|
+
const hoist = (queries, cases, path, yes, trace) => {
|
|
76
|
+
if (clock() >= until || pastWall())
|
|
77
|
+
return;
|
|
78
|
+
const alias = rowAliases(path), variables = (row) => new Set(Object.keys(row).filter(name => name !== '1' && row[name] !== 0).map(alias)), caseVariables = new Set();
|
|
79
|
+
let supported = true;
|
|
80
|
+
for (const c of cases)
|
|
81
|
+
walkOnce(c, (node) => {
|
|
82
|
+
if (node.op === 'flag' || node.op === 'all')
|
|
83
|
+
supported = false;
|
|
84
|
+
if (!['=', '<', '<='].includes(node.op))
|
|
85
|
+
return;
|
|
86
|
+
const a = linear(node.a, path), b = linear(node.b, path);
|
|
87
|
+
if (!a || !b) {
|
|
88
|
+
supported = false;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
for (const name of variables(sub(a, b)))
|
|
92
|
+
caseVariables.add(name);
|
|
93
|
+
});
|
|
94
|
+
let at = path;
|
|
95
|
+
const cuts = [], wrap = (tree) => { for (const cut of [...cuts].reverse())
|
|
96
|
+
tree = { split: cut.row, yes: tree, no: cut.no }; return tree; };
|
|
97
|
+
for (const query of queries) {
|
|
98
|
+
if (clock() >= until || pastWall())
|
|
99
|
+
return;
|
|
100
|
+
const vars = variables(query.row), independent = supported && [...vars].every(name => !caseVariables.has(name)), id = canon(query.row);
|
|
101
|
+
trace?.({ kind: 'hoist-row', name: query.name, row: query.row, variables: [...vars].sort(), caseVariables: [...caseVariables].sort(), independent });
|
|
102
|
+
if (!independent || at.get(id)?.holds === true)
|
|
103
|
+
continue;
|
|
104
|
+
if (at.get(id)?.holds === false) {
|
|
105
|
+
const tree = query.reject(at);
|
|
106
|
+
if (tree)
|
|
107
|
+
return wrap(tree);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
// Failure to close the complement is not permission to assume the row.
|
|
111
|
+
// Leave it for the original, more-specific branch instead.
|
|
112
|
+
const no = query.reject(new Map(at).set(id, { lin: query.row, holds: false }));
|
|
113
|
+
if (!no) {
|
|
114
|
+
trace?.({ kind: 'hoist-row', name: query.name, outcome: 'deferred' });
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
cuts.push({ row: query.row, no });
|
|
118
|
+
at = new Map(at).set(id, { lin: query.row, holds: true });
|
|
119
|
+
trace?.({ kind: 'hoist-row', name: query.name, outcome: 'hoisted' });
|
|
120
|
+
}
|
|
121
|
+
const tree = yes(at);
|
|
122
|
+
return tree ? wrap(tree) : undefined;
|
|
123
|
+
};
|
|
124
|
+
return { rows, condition, hoist };
|
|
125
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Law } from './machine.js';
|
|
2
|
+
import { type GuardCountContext } from './count-guard-context.js';
|
|
3
|
+
import { type CountRequestBuilder } from './count-strategy.js';
|
|
4
|
+
import { type CheckedGuardLinearFact, type GuardCountProposal } from './count-guard-facts.js';
|
|
5
|
+
import { type MapRead } from '../kernel/kernel.js';
|
|
6
|
+
export declare function leaderCountProposals(proposals: readonly GuardCountProposal[]): GuardCountProposal[];
|
|
7
|
+
export declare function proveLeaderCountFacts(context: GuardCountContext, family: Law[], law: Law, until: number, requestFor: CountRequestBuilder, leafUnits?: number): {
|
|
8
|
+
reads: MapRead[];
|
|
9
|
+
facts: CheckedGuardLinearFact[];
|
|
10
|
+
} | undefined;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Generate and prove ordinary per-key facts from the current fixed operation.
|
|
2
|
+
// Nothing is loaded from a saved proof packet or a protocol-specific table.
|
|
3
|
+
import { n, same, x } from "./machine.js";
|
|
4
|
+
import { countPrimitiveUnits } from "./count-primitive-budget.js";
|
|
5
|
+
import { countFrameConditions, fixedCountFrameCase, ownCountLawInstance } from "./count-frames.js";
|
|
6
|
+
import { guardRegionProposals } from "./count-guard-proposals.js";
|
|
7
|
+
import { guardLinearFact } from "./count-guard-facts.js";
|
|
8
|
+
import { countsForReads } from "./count-facts.js";
|
|
9
|
+
import { canon, countedObligations } from "../kernel/kernel.js";
|
|
10
|
+
import { clock, pastWall } from "../kernel/prove.js";
|
|
11
|
+
// The leader closure uses a voter upper bound on the guard complement and a
|
|
12
|
+
// pre <= post row bound. Opposite-direction frames and guard-intersection
|
|
13
|
+
// proposals are not premises of this closure. Selection is untrusted: retained
|
|
14
|
+
// proposals are still proved, and the final original obligation still checks.
|
|
15
|
+
export function leaderCountProposals(proposals) {
|
|
16
|
+
return proposals.filter(p => p.kind === 'guard-complement-upper' ||
|
|
17
|
+
p.kind === 'row-frame' && p.terms.length === 2 && p.terms[0][0] === -1).slice(0, 24);
|
|
18
|
+
}
|
|
19
|
+
export function proveLeaderCountFacts(context, family, law, until, requestFor, leafUnits) {
|
|
20
|
+
const m = context.machine, choice = fixedCountFrameCase(m), index = family.indexOf(law);
|
|
21
|
+
if (!choice || index < 0 || clock() >= until || pastWall())
|
|
22
|
+
return;
|
|
23
|
+
const step = countedObligations(m, family, { [law.name]: ownCountLawInstance(law, {}) }, index).at(-1);
|
|
24
|
+
const base = requestFor(step.goal, step.decls), reads = [...base.reads];
|
|
25
|
+
const taken = new Set(reads.map(r => r[0])), scope = JSON.stringify([m, family]);
|
|
26
|
+
let serial = 0;
|
|
27
|
+
for (const entry of context.restrictions)
|
|
28
|
+
for (const r of base.reads.filter(r => r[1] === entry.base))
|
|
29
|
+
for (const map of [entry.positive, entry.negative]) {
|
|
30
|
+
if (reads.some(t => t[1] === map && JSON.stringify(t[2]) === JSON.stringify(r[2])))
|
|
31
|
+
continue;
|
|
32
|
+
let name;
|
|
33
|
+
do {
|
|
34
|
+
name = `guard$r${serial++}`;
|
|
35
|
+
} while (taken.has(name) || scope.includes(JSON.stringify(name)));
|
|
36
|
+
taken.add(name);
|
|
37
|
+
reads.push([name, map, r[2]]);
|
|
38
|
+
}
|
|
39
|
+
const counts = countsForReads(step.decls, reads);
|
|
40
|
+
if (!counts)
|
|
41
|
+
return;
|
|
42
|
+
const path = new Map(countFrameConditions(choice).map(lin => [canon(lin), { lin, holds: true }]));
|
|
43
|
+
const proposals = guardRegionProposals(counts, reads, step.decls, m.inputMaps ?? [], same(x(choice.name), n(choice.value)), path), facts = [];
|
|
44
|
+
for (const proposal of leaderCountProposals(proposals.counts)) {
|
|
45
|
+
if (clock() >= until || pastWall())
|
|
46
|
+
return;
|
|
47
|
+
const fact = guardLinearFact(step.decls, reads, proposal, Math.min(until, clock() + countPrimitiveUnits(150, leafUnits)));
|
|
48
|
+
if (fact)
|
|
49
|
+
facts.push(fact);
|
|
50
|
+
}
|
|
51
|
+
return { reads, facts };
|
|
52
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Law, type Machine } from './machine.js';
|
|
2
|
+
import { type GuardCountContext } from './count-guard-context.js';
|
|
3
|
+
import { type CountRequestBuilder, type CountStrategyProof, type CountStrategyOptions } from './count-strategy.js';
|
|
4
|
+
import { type Instances } from '../kernel/kernel.js';
|
|
5
|
+
export declare function countLeaderPremise(m: Machine, shape: GuardCountContext['shape'], family: readonly Law[]): {
|
|
6
|
+
law: Law;
|
|
7
|
+
maps: string[];
|
|
8
|
+
eligibilityMap: string | undefined;
|
|
9
|
+
} | undefined;
|
|
10
|
+
export declare function proveCountLeader(context: GuardCountContext, family: Law[], law: Law, seed: Instances, until: number, requestFor: CountRequestBuilder, observe?: (stage: string, checked: boolean) => void, options?: CountStrategyOptions): CountStrategyProof | undefined;
|