gdp-wired 0.48.0 → 0.50.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 +6 -2
- package/dist/core/bmc.js +10 -7
- package/dist/core/candidate-seeds.d.ts +25 -0
- package/dist/core/candidate-seeds.js +90 -0
- package/dist/core/check.js +7 -2
- package/dist/core/cli.js +3 -0
- 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.d.ts +1 -0
- package/dist/core/count-support.js +26 -4
- 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/counted-candidate-seeds.d.ts +12 -0
- package/dist/core/counted-candidate-seeds.js +31 -0
- package/dist/core/counts.d.ts +37 -13
- package/dist/core/counts.js +999 -129
- 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 +32 -2
- package/dist/core/dsl.js +202 -64
- 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 +53 -10
- package/dist/core/field-laws.d.ts +3 -1
- package/dist/core/field-laws.js +159 -3
- 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 +49 -33
- package/dist/core/kind.js +2 -1
- package/dist/core/lemma-cuts.js +11 -10
- package/dist/core/lift-cli.d.ts +11 -0
- package/dist/core/lift-cli.js +113 -0
- 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/proof-output.d.ts +53 -0
- package/dist/core/proof-output.js +38 -0
- 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 +80 -17
- 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/function-instances.d.ts +45 -0
- package/dist/kernel/function-instances.js +460 -0
- package/dist/kernel/kernel.d.ts +47 -1
- package/dist/kernel/kernel.js +417 -68
- package/dist/kernel/prove.d.ts +61 -6
- package/dist/kernel/prove.js +625 -205
- 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/axiom-audit.d.ts +11 -0
- package/dist/lean-kernel/axiom-audit.js +50 -0
- package/dist/lean-kernel/emit.d.ts +34 -3
- package/dist/lean-kernel/emit.js +215 -28
- 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/legacy-family-order.d.ts +1 -0
- package/dist/lean-kernel/legacy-family-order.js +26 -0
- package/dist/lean-kernel/library.js +25 -3
- package/dist/lean-kernel/lift/counted-source-data.d.ts +7 -0
- package/dist/lean-kernel/lift/counted-source-data.js +78 -0
- package/dist/lean-kernel/lift/index.d.ts +82 -0
- package/dist/lean-kernel/lift/index.js +116 -0
- package/dist/lean-kernel/lift/project.d.ts +4 -0
- package/dist/lean-kernel/lift/project.js +15 -0
- package/dist/lean-kernel/lift/proof-capture.d.ts +104 -0
- package/dist/lean-kernel/lift/proof-capture.js +216 -0
- package/dist/lean-kernel/lift/proof-codec.d.ts +28 -0
- package/dist/lean-kernel/lift/proof-codec.js +299 -0
- package/dist/lean-kernel/lift/proof-counted-source.d.ts +16 -0
- package/dist/lean-kernel/lift/proof-counted-source.js +68 -0
- package/dist/lean-kernel/lift/proof-frontier.d.ts +19 -0
- package/dist/lean-kernel/lift/proof-frontier.js +153 -0
- package/dist/lean-kernel/lift/proof-graph.d.ts +17 -0
- package/dist/lean-kernel/lift/proof-graph.js +130 -0
- package/dist/lean-kernel/lift/proof-parts.d.ts +29 -0
- package/dist/lean-kernel/lift/proof-parts.js +131 -0
- package/dist/lean-kernel/lift/proof-prelude.d.ts +2 -0
- package/dist/lean-kernel/lift/proof-prelude.js +38 -0
- package/dist/lean-kernel/lift/proof-witness.d.ts +30 -0
- package/dist/lean-kernel/lift/proof-witness.js +283 -0
- package/dist/lean-kernel/lift/shape.d.ts +5 -0
- package/dist/lean-kernel/lift/shape.js +57 -0
- package/dist/lean-kernel/lift/source-projection.d.ts +16 -0
- package/dist/lean-kernel/lift/source-projection.js +81 -0
- package/dist/lean-kernel/lift/source.d.ts +23 -0
- package/dist/lean-kernel/lift/source.js +111 -0
- package/dist/lean-kernel/lift/witness-alpha.d.ts +9 -0
- package/dist/lean-kernel/lift/witness-alpha.js +31 -0
- package/dist/lean-kernel/lift-legacy.d.ts +58 -0
- package/dist/lean-kernel/lift-legacy.js +84 -0
- package/dist/lean-kernel/lift-names.d.ts +22 -0
- package/dist/lean-kernel/lift-names.js +36 -0
- package/dist/lean-kernel/lift-simulation/index.d.ts +29 -0
- package/dist/lean-kernel/lift-simulation/index.js +352 -0
- package/dist/lean-kernel/lift-simulation/shape.d.ts +41 -0
- package/dist/lean-kernel/lift-simulation/shape.js +173 -0
- package/dist/lean-kernel/lift-special/index.d.ts +36 -0
- package/dist/lean-kernel/lift-special/index.js +241 -0
- package/dist/lean-kernel/lift-special/structural.d.ts +25 -0
- package/dist/lean-kernel/lift-special/structural.js +126 -0
- package/dist/lean-kernel/lift-typed/index.d.ts +35 -0
- package/dist/lean-kernel/lift-typed/index.js +256 -0
- package/dist/lean-kernel/lift-typed/roles.d.ts +17 -0
- package/dist/lean-kernel/lift-typed/roles.js +170 -0
- package/dist/lean-kernel/lift-typed/shape.d.ts +1 -0
- package/dist/lean-kernel/lift-typed/shape.js +12 -0
- package/dist/lean-kernel/lift.d.ts +30 -0
- package/dist/lean-kernel/lift.js +97 -0
- package/package.json +5 -1
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { assumed, canon, frameOk, framePath, frameRows, linRows, mcGoal } from "../kernel/kernel.js";
|
|
2
|
+
import { late, rowsAt } from "../kernel/prove.js";
|
|
3
|
+
import { countsForReads } from "./count-facts.js";
|
|
4
|
+
export function countCertificateSize(cert) {
|
|
5
|
+
let leaves = 0, splits = 0, steps = 0;
|
|
6
|
+
const pending = [{ tree: cert.tree, exit: false }], active = new Set();
|
|
7
|
+
while (pending.length) {
|
|
8
|
+
const { tree, exit } = pending.pop();
|
|
9
|
+
if (exit) {
|
|
10
|
+
active.delete(tree);
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
if (active.has(tree))
|
|
14
|
+
throw Error('cyclic certificate tree');
|
|
15
|
+
if ('leaf' in tree) {
|
|
16
|
+
leaves++;
|
|
17
|
+
steps += tree.leaf.length;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
active.add(tree);
|
|
21
|
+
splits++;
|
|
22
|
+
pending.push({ tree, exit: true }, { tree: tree.no, exit: false }, { tree: tree.yes, exit: false });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { leaves, splits, steps, frames: cert.frames?.length ?? 0, lins: cert.lins?.length ?? 0, monos: cert.monos?.length ?? 0, instances: cert.insts.length };
|
|
26
|
+
}
|
|
27
|
+
// Remove only exact duplicate instantiated formulas. Plain laws and unknown
|
|
28
|
+
// flag instances stay; the caller rebuilds its original goal and reindexes.
|
|
29
|
+
export function dedupeCountInstances(family, facts, original) {
|
|
30
|
+
const laws = [...family, ...facts], seen = new Set(laws.filter(l => !l.forall).flatMap(l => assumed([l], {})).map(h => JSON.stringify(h)));
|
|
31
|
+
const instances = {}, removed = [];
|
|
32
|
+
for (const [name, terms] of Object.entries(original)) {
|
|
33
|
+
const law = laws.find(l => l.name === name), arity = law?.forall ? 1 + (law.keys?.length ?? 0) : 0;
|
|
34
|
+
if (!law || !arity || terms.length % arity) {
|
|
35
|
+
instances[name] = terms;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const kept = [];
|
|
39
|
+
for (let i = 0; i < terms.length; i += arity) {
|
|
40
|
+
const tuple = terms.slice(i, i + arity), keys = assumed([law], { [name]: tuple }).map(h => JSON.stringify(h));
|
|
41
|
+
if (keys.length && keys.every(key => seen.has(key)))
|
|
42
|
+
removed.push(name);
|
|
43
|
+
else {
|
|
44
|
+
kept.push(...tuple);
|
|
45
|
+
keys.forEach(key => seen.add(key));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (kept.length)
|
|
49
|
+
instances[name] = kept;
|
|
50
|
+
}
|
|
51
|
+
return { instances, removed };
|
|
52
|
+
}
|
|
53
|
+
export function minimizeCountCertificate(hyps, decls, original, until, options = {}) {
|
|
54
|
+
const before = countCertificateSize(original), stats = { before, after: before, liftAttempts: 0, liftedSplits: 0, frameMerges: 0, unusedFrames: 0, unusedLins: 0, duplicateLins: 0, fastRejected: 0, visits: 0, rowsBuilt: 0, aborted: false, missing: [] };
|
|
55
|
+
if (late(until)) {
|
|
56
|
+
stats.aborted = true;
|
|
57
|
+
return { cert: original, stats };
|
|
58
|
+
}
|
|
59
|
+
const goal = mcGoal(hyps, decls, original), counts = countsForReads(decls, original.reads);
|
|
60
|
+
if (!goal || !counts)
|
|
61
|
+
return { cert: original, stats };
|
|
62
|
+
const live = () => { const ok = !late(until) && stats.visits++ < (options.maxVisits ?? 200000); if (!ok)
|
|
63
|
+
stats.aborted = true; return ok; };
|
|
64
|
+
const rowGetter = (g, c) => {
|
|
65
|
+
const cache = new Map();
|
|
66
|
+
return (path) => {
|
|
67
|
+
const key = JSON.stringify([...path]);
|
|
68
|
+
let rows = cache.get(key);
|
|
69
|
+
if (!rows) {
|
|
70
|
+
rows = rowsAt(g, framePath(c.frames ?? [], c.lemmas ?? [], path, c.monos ?? [], c.lins ?? []));
|
|
71
|
+
stats.rowsBuilt++;
|
|
72
|
+
if (cache.size >= 4096)
|
|
73
|
+
cache.delete(cache.keys().next().value);
|
|
74
|
+
cache.set(key, rows);
|
|
75
|
+
}
|
|
76
|
+
return rows;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
const rowIndices = new WeakMap();
|
|
80
|
+
const transport = (tree, from, to, oldRows, newRows, missing, depth = 0) => {
|
|
81
|
+
if (!live() || depth > 512)
|
|
82
|
+
return undefined;
|
|
83
|
+
if ('split' in tree) {
|
|
84
|
+
const id = canon(tree.split);
|
|
85
|
+
if (to.has(id))
|
|
86
|
+
return undefined;
|
|
87
|
+
const next = (path, holds) => new Map(path).set(id, { lin: tree.split, holds });
|
|
88
|
+
const yes = transport(tree.yes, next(from, true), next(to, true), oldRows, newRows, missing, depth + 1);
|
|
89
|
+
const no = yes && transport(tree.no, next(from, false), next(to, false), oldRows, newRows, missing, depth + 1);
|
|
90
|
+
return yes && no ? { split: tree.split, yes, no } : undefined;
|
|
91
|
+
}
|
|
92
|
+
const a = oldRows(from), b = newRows(to);
|
|
93
|
+
let indices = rowIndices.get(b);
|
|
94
|
+
if (!indices) {
|
|
95
|
+
indices = new Map();
|
|
96
|
+
b.forEach((r, i) => { const key = canon(r.lin); if (!indices.has(key))
|
|
97
|
+
indices.set(key, i); });
|
|
98
|
+
rowIndices.set(b, indices);
|
|
99
|
+
}
|
|
100
|
+
const squares = tree.squares?.length ?? 0, products = tree.products ?? [];
|
|
101
|
+
const index = (i, limit = a.length + squares + products.length) => {
|
|
102
|
+
if (!Number.isSafeInteger(i) || i < 0 || i >= limit)
|
|
103
|
+
return undefined;
|
|
104
|
+
if (i >= a.length)
|
|
105
|
+
return i - a.length + b.length;
|
|
106
|
+
const key = canon(a[i].lin), j = indices.get(key);
|
|
107
|
+
if (j === undefined && missing.length < 8)
|
|
108
|
+
missing.push(key);
|
|
109
|
+
return j;
|
|
110
|
+
};
|
|
111
|
+
const leaf = [];
|
|
112
|
+
for (const step of tree.leaf) {
|
|
113
|
+
if (step.kind !== 'input')
|
|
114
|
+
leaf.push(step);
|
|
115
|
+
else {
|
|
116
|
+
const i = index(step.index);
|
|
117
|
+
if (i === undefined)
|
|
118
|
+
return undefined;
|
|
119
|
+
leaf.push({ ...step, index: i });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const pairs = [];
|
|
123
|
+
for (let n = 0; n < products.length; n++) {
|
|
124
|
+
const [a0, b0] = products[n], i = index(a0, a.length + squares + n), j = index(b0, a.length + squares + n);
|
|
125
|
+
if (i === undefined || j === undefined)
|
|
126
|
+
return undefined;
|
|
127
|
+
pairs.push([i, j]);
|
|
128
|
+
}
|
|
129
|
+
return { leaf, ...(tree.products ? { products: pairs } : {}), ...(tree.squares ? { squares: tree.squares } : {}) };
|
|
130
|
+
};
|
|
131
|
+
let cert = original;
|
|
132
|
+
const oldRows = rowGetter(goal, original);
|
|
133
|
+
if (options.merge !== false) {
|
|
134
|
+
const used = new Set();
|
|
135
|
+
const collect = (tree, path, depth = 0) => {
|
|
136
|
+
if (!live() || depth > 512) {
|
|
137
|
+
stats.aborted = true;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if ('split' in tree) {
|
|
141
|
+
const id = canon(tree.split);
|
|
142
|
+
collect(tree.yes, new Map(path).set(id, { lin: tree.split, holds: true }), depth + 1);
|
|
143
|
+
collect(tree.no, new Map(path).set(id, { lin: tree.split, holds: false }), depth + 1);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const rows = oldRows(path), indices = [...tree.leaf.flatMap(s => s.kind === 'input' ? [s.index] : []), ...(tree.products ?? []).flat()];
|
|
147
|
+
for (const i of indices)
|
|
148
|
+
if (rows[i])
|
|
149
|
+
used.add(canon(rows[i].lin));
|
|
150
|
+
};
|
|
151
|
+
if ((original.frames?.length ?? 0) || (original.lins?.length ?? 0))
|
|
152
|
+
collect(original.tree, new Map());
|
|
153
|
+
const groups = new Map();
|
|
154
|
+
const neededFrames = (original.frames ?? []).filter(f => frameRows(f).some(row => used.has(canon(row))));
|
|
155
|
+
stats.unusedFrames = (original.frames?.length ?? 0) - neededFrames.length;
|
|
156
|
+
for (const frame of neededFrames) {
|
|
157
|
+
const key = JSON.stringify([frame.post, frame.pre]), group = groups.get(key) ?? [];
|
|
158
|
+
groups.set(key, group);
|
|
159
|
+
group.push(frame);
|
|
160
|
+
}
|
|
161
|
+
const frames = [];
|
|
162
|
+
for (const group of groups.values()) {
|
|
163
|
+
const kept = [];
|
|
164
|
+
for (const frame of group) {
|
|
165
|
+
let merged = false;
|
|
166
|
+
for (let i = 0; i < kept.length; i++) {
|
|
167
|
+
const prior = kept[i], keys = new Set(frame.when.map(canon)), candidate = { post: frame.post, pre: frame.pre, when: prior.when.filter(w => keys.has(canon(w))) };
|
|
168
|
+
if (frameOk(counts, candidate)) {
|
|
169
|
+
kept[i] = candidate;
|
|
170
|
+
stats.frameMerges++;
|
|
171
|
+
merged = true;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (!merged)
|
|
176
|
+
kept.push(frame);
|
|
177
|
+
}
|
|
178
|
+
frames.push(...kept);
|
|
179
|
+
}
|
|
180
|
+
const side = (terms) => { const sum = new Map(); for (const [k, name] of terms)
|
|
181
|
+
sum.set(name, (sum.get(name) ?? 0) + k); return [...sum].filter(([, k]) => k !== 0).sort(([a], [b]) => a.localeCompare(b)); };
|
|
182
|
+
const seen = new Set(), lins = (original.lins ?? []).filter(cut => { if (!linRows(cut).some(row => used.has(canon(row)))) {
|
|
183
|
+
stats.unusedLins++;
|
|
184
|
+
return false;
|
|
185
|
+
} const key = JSON.stringify([cut.when.map(c => JSON.stringify(c)).sort(), side(cut.pos), side(cut.neg)]); if (seen.has(key)) {
|
|
186
|
+
stats.duplicateLins++;
|
|
187
|
+
return false;
|
|
188
|
+
} seen.add(key); return true; });
|
|
189
|
+
const candidate = { ...original, frames, lins };
|
|
190
|
+
if (stats.frameMerges || stats.duplicateLins || stats.unusedFrames || stats.unusedLins) {
|
|
191
|
+
const tree = transport(original.tree, new Map(), new Map(), oldRows, rowGetter(goal, candidate), []);
|
|
192
|
+
if (tree)
|
|
193
|
+
cert = { ...candidate, tree };
|
|
194
|
+
else {
|
|
195
|
+
stats.frameMerges = 0;
|
|
196
|
+
stats.duplicateLins = 0;
|
|
197
|
+
stats.unusedFrames = 0;
|
|
198
|
+
stats.unusedLins = 0;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (options.lift !== false) {
|
|
203
|
+
const rows = rowGetter(goal, cert), metadata = new WeakMap();
|
|
204
|
+
const mark = (tree, path) => {
|
|
205
|
+
const known = metadata.get(tree);
|
|
206
|
+
if (known)
|
|
207
|
+
return known;
|
|
208
|
+
let meta;
|
|
209
|
+
if ('leaf' in tree) {
|
|
210
|
+
const keys = [...framePath(cert.frames ?? [], cert.lemmas ?? [], path, cert.monos ?? [], cert.lins ?? []).keys()], used = new Set();
|
|
211
|
+
for (const i of [...tree.leaf.flatMap(s => s.kind === 'input' ? [s.index] : []), ...(tree.products ?? []).flat()])
|
|
212
|
+
if (i < keys.length && path.has(keys[i]))
|
|
213
|
+
used.add(keys[i]);
|
|
214
|
+
meta = { leaves: 1, used };
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const key = canon(tree.split), yes = mark(tree.yes, new Map(path).set(key, { lin: tree.split, holds: true })), no = mark(tree.no, new Map(path).set(key, { lin: tree.split, holds: false }));
|
|
218
|
+
meta = { leaves: yes.leaves + no.leaves, used: new Set([...yes.used, ...no.used]) };
|
|
219
|
+
}
|
|
220
|
+
metadata.set(tree, meta);
|
|
221
|
+
return meta;
|
|
222
|
+
};
|
|
223
|
+
const visit = (tree, path, depth = 0) => {
|
|
224
|
+
if (!live() || depth > 512) {
|
|
225
|
+
stats.aborted = true;
|
|
226
|
+
return tree;
|
|
227
|
+
}
|
|
228
|
+
if ('leaf' in tree) {
|
|
229
|
+
const leaf = { ...tree };
|
|
230
|
+
mark(leaf, path);
|
|
231
|
+
return leaf;
|
|
232
|
+
}
|
|
233
|
+
const key = canon(tree.split), yesPath = new Map(path).set(key, { lin: tree.split, holds: true }), noPath = new Map(path).set(key, { lin: tree.split, holds: false });
|
|
234
|
+
const yes = visit(tree.yes, yesPath, depth + 1), no = visit(tree.no, noPath, depth + 1), children = [[yes, yesPath], [no, noPath]];
|
|
235
|
+
if (!metadata.has(yes) || !metadata.has(no))
|
|
236
|
+
return { split: tree.split, yes, no };
|
|
237
|
+
children.sort(([a], [b]) => metadata.get(a).leaves - metadata.get(b).leaves);
|
|
238
|
+
for (const [child, from] of children) {
|
|
239
|
+
stats.liftAttempts++;
|
|
240
|
+
// Like the ordinary prover's lift, conservatively leave a subtree
|
|
241
|
+
// that directly uses the discarded path decision intact.
|
|
242
|
+
if (metadata.get(child).used.has(key)) {
|
|
243
|
+
stats.fastRejected++;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
const missing = [], lifted = transport(child, from, path, rows, rows, missing);
|
|
247
|
+
if (lifted) {
|
|
248
|
+
stats.liftedSplits++;
|
|
249
|
+
mark(lifted, path);
|
|
250
|
+
return lifted;
|
|
251
|
+
}
|
|
252
|
+
if (stats.missing.length < 10 && missing.length)
|
|
253
|
+
stats.missing.push({ split: key, rows: missing });
|
|
254
|
+
}
|
|
255
|
+
const result = { split: tree.split, yes, no };
|
|
256
|
+
mark(result, path);
|
|
257
|
+
return result;
|
|
258
|
+
};
|
|
259
|
+
cert = { ...cert, tree: visit(cert.tree, new Map()) };
|
|
260
|
+
}
|
|
261
|
+
stats.after = countCertificateSize(cert);
|
|
262
|
+
return { cert, stats };
|
|
263
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type CountClosedOptions = Readonly<{
|
|
2
|
+
basis?: ReadonlySet<string>;
|
|
3
|
+
tick?: () => void;
|
|
4
|
+
}>;
|
|
5
|
+
export type CountBlockerPath = Readonly<{
|
|
6
|
+
blocker: string;
|
|
7
|
+
path: readonly string[];
|
|
8
|
+
}>;
|
|
9
|
+
export type ClosedCountFamily = Readonly<{
|
|
10
|
+
members: readonly string[];
|
|
11
|
+
missing: ReadonlyMap<string, readonly string[]>;
|
|
12
|
+
blockers: readonly string[];
|
|
13
|
+
paths: ReadonlyMap<string, readonly CountBlockerPath[]>;
|
|
14
|
+
}>;
|
|
15
|
+
export declare function greatestClosedCountFamily(order: readonly string[], held: ReadonlyMap<string, readonly string[]>, options?: CountClosedOptions): ClosedCountFamily;
|
|
16
|
+
export type HeldCountPayload<T> = Readonly<{
|
|
17
|
+
id: string;
|
|
18
|
+
premises: readonly string[];
|
|
19
|
+
payload: T;
|
|
20
|
+
}>;
|
|
21
|
+
export type CountCloseCallbacks<T, R> = Readonly<{
|
|
22
|
+
legacy: () => R;
|
|
23
|
+
reserve: (members: readonly HeldCountPayload<T>[]) => boolean;
|
|
24
|
+
submit: (members: readonly HeldCountPayload<T>[]) => R;
|
|
25
|
+
}>;
|
|
26
|
+
export declare function closeGreatestCountFamily<T, R>(target: string, held: readonly HeldCountPayload<T>[], callbacks: CountCloseCallbacks<T, R>, options?: CountClosedOptions): Readonly<{
|
|
27
|
+
plan: ClosedCountFamily;
|
|
28
|
+
targetInFamily: boolean;
|
|
29
|
+
route: 'legacy' | 'subset' | 'empty' | 'unfunded';
|
|
30
|
+
submitted: boolean;
|
|
31
|
+
result?: R;
|
|
32
|
+
}>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// Untrusted closure bookkeeping. Only the existing native family check can accept.
|
|
2
|
+
import { startWork } from "./work-admission.js";
|
|
3
|
+
import { checkWall } from "./wall.js";
|
|
4
|
+
import { workSetArray, workStrings } from "./work-collections.js";
|
|
5
|
+
const control = () => { checkWall('closed counted family'); startWork('ticks', 1, 'closed counted family'); };
|
|
6
|
+
// Frozen H/S: monotone deletion removes at most |H| members. Every closed subset
|
|
7
|
+
// survives every deletion, hence the fixed point is the unique greatest one.
|
|
8
|
+
export function greatestClosedCountFamily(order, held, options = {}) {
|
|
9
|
+
const tick = options.tick ?? control, rank = new Map(), dependencies = new Map(), basis = new Set();
|
|
10
|
+
for (const name of options.basis ?? []) {
|
|
11
|
+
tick();
|
|
12
|
+
basis.add(name);
|
|
13
|
+
}
|
|
14
|
+
for (const name of order) {
|
|
15
|
+
tick();
|
|
16
|
+
if (rank.has(name))
|
|
17
|
+
throw Error('duplicate family member');
|
|
18
|
+
rank.set(name, rank.size);
|
|
19
|
+
}
|
|
20
|
+
for (const [name, premises] of held) {
|
|
21
|
+
tick();
|
|
22
|
+
if (!rank.has(name))
|
|
23
|
+
throw Error('held member missing from family order');
|
|
24
|
+
const copy = [], seen = new Set();
|
|
25
|
+
for (const premise of premises) {
|
|
26
|
+
tick();
|
|
27
|
+
if (!seen.has(premise)) {
|
|
28
|
+
seen.add(premise);
|
|
29
|
+
copy.push(premise);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
dependencies.set(name, copy);
|
|
33
|
+
}
|
|
34
|
+
const members = new Set();
|
|
35
|
+
for (const name of order) {
|
|
36
|
+
tick();
|
|
37
|
+
if (dependencies.has(name))
|
|
38
|
+
members.add(name);
|
|
39
|
+
}
|
|
40
|
+
let changed = true;
|
|
41
|
+
while (changed) {
|
|
42
|
+
changed = false;
|
|
43
|
+
for (const name of order) {
|
|
44
|
+
tick();
|
|
45
|
+
if (!members.has(name))
|
|
46
|
+
continue;
|
|
47
|
+
for (const premise of dependencies.get(name)) {
|
|
48
|
+
tick();
|
|
49
|
+
if (!members.has(premise) && !basis.has(premise)) {
|
|
50
|
+
members.delete(name);
|
|
51
|
+
changed = true;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const closed = [], missing = new Map(), paths = new Map(), allRoots = new Set();
|
|
58
|
+
for (const name of order) {
|
|
59
|
+
tick();
|
|
60
|
+
if (members.has(name)) {
|
|
61
|
+
closed.push(name);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (!dependencies.has(name))
|
|
65
|
+
continue;
|
|
66
|
+
const outside = [];
|
|
67
|
+
for (const premise of dependencies.get(name)) {
|
|
68
|
+
tick();
|
|
69
|
+
if (!members.has(premise) && !basis.has(premise))
|
|
70
|
+
outside.push(premise);
|
|
71
|
+
}
|
|
72
|
+
missing.set(name, outside);
|
|
73
|
+
const seen = new Set(), queue = [{ name, path: [name] }], found = [];
|
|
74
|
+
for (let at = 0; at < queue.length; at++) {
|
|
75
|
+
tick();
|
|
76
|
+
const item = queue[at];
|
|
77
|
+
if (seen.has(item.name) || basis.has(item.name) || members.has(item.name))
|
|
78
|
+
continue;
|
|
79
|
+
seen.add(item.name);
|
|
80
|
+
const next = dependencies.get(item.name);
|
|
81
|
+
if (!next) {
|
|
82
|
+
allRoots.add(item.name);
|
|
83
|
+
found.push({ blocker: item.name, path: item.path });
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
for (const premise of next) {
|
|
87
|
+
tick();
|
|
88
|
+
const path = [];
|
|
89
|
+
for (const part of item.path) {
|
|
90
|
+
tick();
|
|
91
|
+
path.push(part);
|
|
92
|
+
}
|
|
93
|
+
path.push(premise);
|
|
94
|
+
queue.push({ name: premise, path });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
paths.set(name, found);
|
|
98
|
+
}
|
|
99
|
+
const blockers = [];
|
|
100
|
+
for (const name of order) {
|
|
101
|
+
tick();
|
|
102
|
+
if (allRoots.delete(name))
|
|
103
|
+
blockers.push(name);
|
|
104
|
+
}
|
|
105
|
+
for (const name of workStrings(workSetArray(allRoots, 'closed-family:unknown-roots'), 'closed-family:unknown-blockers')) {
|
|
106
|
+
tick();
|
|
107
|
+
blockers.push(name);
|
|
108
|
+
}
|
|
109
|
+
return { members: closed, missing, blockers, paths };
|
|
110
|
+
}
|
|
111
|
+
// A owns callbacks, checked-basis policy and native verdict interpretation.
|
|
112
|
+
// The legacy callback receives no reconstructed family. No callback result is
|
|
113
|
+
// promoted to success for an outside target, even when its subset was accepted.
|
|
114
|
+
export function closeGreatestCountFamily(target, held, callbacks, options = {}) {
|
|
115
|
+
const tick = options.tick ?? control, order = [], byName = new Map(), dependencies = new Map();
|
|
116
|
+
for (const row of held) {
|
|
117
|
+
tick();
|
|
118
|
+
if (byName.has(row.id))
|
|
119
|
+
throw Error('duplicate held payload');
|
|
120
|
+
order.push(row.id);
|
|
121
|
+
byName.set(row.id, row);
|
|
122
|
+
dependencies.set(row.id, row.premises);
|
|
123
|
+
}
|
|
124
|
+
const plan = greatestClosedCountFamily(order, dependencies, options);
|
|
125
|
+
let containsTarget = false;
|
|
126
|
+
for (const name of plan.members) {
|
|
127
|
+
tick();
|
|
128
|
+
if (name === target)
|
|
129
|
+
containsTarget = true;
|
|
130
|
+
}
|
|
131
|
+
if (containsTarget)
|
|
132
|
+
return { plan, targetInFamily: true, route: 'legacy', submitted: true, result: callbacks.legacy() };
|
|
133
|
+
if (!plan.members.length)
|
|
134
|
+
return { plan, targetInFamily: false, route: 'empty', submitted: false };
|
|
135
|
+
const selected = [];
|
|
136
|
+
for (const name of plan.members) {
|
|
137
|
+
tick();
|
|
138
|
+
selected.push(byName.get(name));
|
|
139
|
+
}
|
|
140
|
+
if (!callbacks.reserve(selected))
|
|
141
|
+
return { plan, targetInFamily: false, route: 'unfunded', submitted: false };
|
|
142
|
+
return { plan, targetInFamily: false, route: 'subset', submitted: true, result: callbacks.submit(selected) };
|
|
143
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CountTierBudget } from './count-tier-budget.js';
|
|
2
|
+
export type CountClosingBudget = CountTierBudget & Readonly<{
|
|
3
|
+
closingMode: 'family-check-once';
|
|
4
|
+
closingFloor: number;
|
|
5
|
+
searchUntil: number;
|
|
6
|
+
initialUntil: number;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function reserveCountClosing(budget: CountTierBudget, enabled?: boolean, rootUntil?: number): CountTierBudget | CountClosingBudget;
|
|
9
|
+
export declare function reserveCheckedCountClosing(budget: CountClosingBudget, costs: readonly number[], now: number): CountClosingBudget;
|
|
10
|
+
export declare function countOrdinaryUntil(budget: CountTierBudget): number;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Opt-in family check-once scheduling, not proof acceptance or calibration.
|
|
2
|
+
import { countTierBudget } from "./count-tier-budget.js";
|
|
3
|
+
import { budgetEnd } from "../kernel/prove.js";
|
|
4
|
+
// Explicit replacement allocation: generation <=1/4, strategy floor7/20,
|
|
5
|
+
// ordinary/INIT floor1/40, closing native floor3/8. They sum to one root W.
|
|
6
|
+
// The old ordinary-search floor3/10 is NOT claimed in this opt-in mode.
|
|
7
|
+
export function reserveCountClosing(budget, enabled = false, rootUntil = budgetEnd()) {
|
|
8
|
+
if (!enabled || !budget.active)
|
|
9
|
+
return budget;
|
|
10
|
+
if (Number.isNaN(rootUntil) || rootUntil === -Infinity)
|
|
11
|
+
throw new RangeError('invalid root endpoint');
|
|
12
|
+
const until = Math.min(budget.until, rootUntil);
|
|
13
|
+
if (until < budget.until) {
|
|
14
|
+
const start = budget.until - budget.workAllowance, clamped = countTierBudget(start, until, 1);
|
|
15
|
+
budget = Object.freeze({ ...clamped, generationUntil: Math.min(budget.generationUntil, clamped.generationUntil) });
|
|
16
|
+
}
|
|
17
|
+
if ('closingMode' in budget) {
|
|
18
|
+
if (budget.closingMode !== 'family-check-once')
|
|
19
|
+
throw new RangeError('unknown closing mode');
|
|
20
|
+
return budget;
|
|
21
|
+
}
|
|
22
|
+
const width = budget.workAllowance;
|
|
23
|
+
if (!Number.isFinite(width) || width < 0 || !Number.isFinite(budget.until))
|
|
24
|
+
throw new RangeError('invalid closing allowance');
|
|
25
|
+
const ordinaryFloor = width / 40, closingFloor = width * 3 / 8, searchUntil = budget.until - closingFloor;
|
|
26
|
+
const strategyUntil = Math.min(budget.strategyUntil ?? budget.until, searchUntil - ordinaryFloor);
|
|
27
|
+
return Object.freeze({ ...budget, ordinaryFloor, strategyUntil, closingMode: 'family-check-once', closingFloor, searchUntil, initialUntil: searchUntil });
|
|
28
|
+
}
|
|
29
|
+
// An observed-cost estimate, NOT a worst-case kernel bound. Two times the
|
|
30
|
+
// checked held packets' measured replay/check cost leaves an explicit margin.
|
|
31
|
+
// If there is no measurement retain the old reserve. Insufficient estimates
|
|
32
|
+
// can only produce UNKNOWN at the unchanged root/native acceptance boundary.
|
|
33
|
+
export function reserveCheckedCountClosing(budget, costs, now) {
|
|
34
|
+
if (!Number.isFinite(now))
|
|
35
|
+
throw new RangeError('invalid reserve clock');
|
|
36
|
+
if (costs.some(cost => !Number.isFinite(cost) || cost < 0))
|
|
37
|
+
throw new RangeError('invalid checked packet cost');
|
|
38
|
+
if (!costs.length)
|
|
39
|
+
return budget;
|
|
40
|
+
const total = costs.reduce((sum, cost) => sum + cost, 0);
|
|
41
|
+
const closingFloor = Math.min(budget.workAllowance, Math.max(0, budget.until - now), Math.max(1, total * 2));
|
|
42
|
+
const searchUntil = budget.until - closingFloor;
|
|
43
|
+
const ordinaryFloor = Math.min(budget.ordinaryFloor, Math.max(0, searchUntil - now));
|
|
44
|
+
const strategyUntil = searchUntil - ordinaryFloor;
|
|
45
|
+
return Object.freeze({ ...budget, ordinaryFloor, closingFloor, searchUntil, initialUntil: searchUntil, strategyUntil });
|
|
46
|
+
}
|
|
47
|
+
export function countOrdinaryUntil(budget) {
|
|
48
|
+
return 'closingMode' in budget ? budget.searchUntil : budget.until;
|
|
49
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Untrusted scheduling only. Missing or cyclic proof metadata never authorizes
|
|
2
|
+
// acceptance; the final family is still replayed and checked by the kernel.
|
|
3
|
+
export function countClosingNeeds(callers, scopes) {
|
|
4
|
+
const needed = new Set(callers);
|
|
5
|
+
for (const name of needed)
|
|
6
|
+
for (const premise of scopes.get(name)?.premises ?? [])
|
|
7
|
+
needed.add(premise.name);
|
|
8
|
+
return needed;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Pure remaining-pool allocation. The caller supplies an already-clamped
|
|
2
|
+
// component endpoint; this helper never creates a new root or tier grant.
|
|
3
|
+
export function countComponentAttemptBudget(now, componentEnd, unattempted, minimum = 1, fair = false) {
|
|
4
|
+
if (!Number.isFinite(now) || !Number.isFinite(componentEnd) || !Number.isInteger(unattempted) || unattempted < 1 || !Number.isFinite(minimum) || minimum < 0)
|
|
5
|
+
throw new RangeError('invalid component allowance');
|
|
6
|
+
const width = Math.max(0, componentEnd - now), floor = Math.min(minimum, width / unattempted);
|
|
7
|
+
const reserved = fair ? width - width / unattempted : floor * (unattempted - 1), allotted = fair ? width / unattempted : Math.max(0, width - reserved);
|
|
8
|
+
return { end: Math.min(componentEnd, now + allotted), allotted, reserved };
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Machine } from './machine.js';
|
|
2
|
+
import { type CountGuardShape } from './count-guard-shape.js';
|
|
3
|
+
export type CountRowCopy = {
|
|
4
|
+
from: string;
|
|
5
|
+
to: string;
|
|
6
|
+
guard: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function discoverCountRowCopy(m: Machine, shape: CountGuardShape, choice: {
|
|
9
|
+
name: string;
|
|
10
|
+
value: number;
|
|
11
|
+
}): CountRowCopy | undefined;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Structural hints only; a matched write still needs an ordinary checked proof.
|
|
2
|
+
import { walkOnce } from "./machine.js";
|
|
3
|
+
const atoms = (c) => c.op === 'and' ? c.xs.flatMap(atoms) : [c];
|
|
4
|
+
export function discoverCountRowCopy(m, shape, choice) {
|
|
5
|
+
const write = m.step.maps?.[shape.thresholdField];
|
|
6
|
+
if (!write || !('each' in write))
|
|
7
|
+
return;
|
|
8
|
+
const found = [];
|
|
9
|
+
walkOnce(write.value, (node) => {
|
|
10
|
+
if (node.op !== 'if' || node.then.op !== 'get' || node.then.map !== shape.thresholdField || node.then.key.op !== 'var' || !m.inputs.includes(node.then.key.name))
|
|
11
|
+
return;
|
|
12
|
+
const gate = atoms(node.c), target = gate.flatMap(c => {
|
|
13
|
+
if (c.op !== '=')
|
|
14
|
+
return [];
|
|
15
|
+
const [a, b] = c.a.op === 'var' && c.a.name === write.each ? [c.a, c.b] : [c.b, c.a];
|
|
16
|
+
return a.op === 'var' && a.name === write.each && b.op === 'var' && m.inputs.includes(b.name) ? [b.name] : [];
|
|
17
|
+
});
|
|
18
|
+
if (target.length !== 1)
|
|
19
|
+
return;
|
|
20
|
+
for (const c of gate) {
|
|
21
|
+
if (c.op !== 'flag')
|
|
22
|
+
continue;
|
|
23
|
+
const guard = m.step.flags?.[c.name];
|
|
24
|
+
if (!guard || guard.op === 'all' || !atoms(guard).some(a => {
|
|
25
|
+
if (a.op !== '=')
|
|
26
|
+
return false;
|
|
27
|
+
const [v, n] = a.a.op === 'var' ? [a.a, a.b] : [a.b, a.a];
|
|
28
|
+
return v.op === 'var' && v.name === choice.name && n.op === 'const' && n.value === choice.value;
|
|
29
|
+
}))
|
|
30
|
+
continue;
|
|
31
|
+
let used = false;
|
|
32
|
+
walkOnce(m.step.maps?.[shape.membershipMap], (node) => { if (node.op === 'flag' && node.name === c.name)
|
|
33
|
+
used = true; });
|
|
34
|
+
if (used)
|
|
35
|
+
found.push({ from: node.then.key.name, to: target[0], guard: c.name });
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const unique = [...new Map(found.map(copy => [JSON.stringify(copy), copy])).values()];
|
|
39
|
+
return unique.length === 1 ? unique[0] : undefined;
|
|
40
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type WorkLedger } from './work-admission.js';
|
|
2
|
+
import { type WorkAmount } from './work-amount.js';
|
|
3
|
+
import { CountAttemptTickets, type CountAttemptStop, type CountSlice } from './count-retry-budget.js';
|
|
4
|
+
import { type CountRoundValue, type CountRoundResult } from './count-retry-round.js';
|
|
5
|
+
export type CountFundingCaps = Readonly<{
|
|
6
|
+
cases: ReadonlyMap<string, WorkAmount>;
|
|
7
|
+
leaf: WorkAmount;
|
|
8
|
+
}>;
|
|
9
|
+
export type CountBodyHistory = Readonly<{
|
|
10
|
+
completed: boolean;
|
|
11
|
+
used: WorkAmount;
|
|
12
|
+
instance: CountAttemptTickets;
|
|
13
|
+
rootEpoch: number;
|
|
14
|
+
}>;
|
|
15
|
+
export type CountDisjointContext = Readonly<{
|
|
16
|
+
instance: CountAttemptTickets;
|
|
17
|
+
bank: WorkLedger;
|
|
18
|
+
parentId: number;
|
|
19
|
+
parentEpoch: number;
|
|
20
|
+
started: number;
|
|
21
|
+
}>;
|
|
22
|
+
export declare function countDisjointContext(instance: CountAttemptTickets, bank?: WorkLedger): CountDisjointContext;
|
|
23
|
+
export type CountDisjointPlan = Readonly<{
|
|
24
|
+
kind: 'admitted';
|
|
25
|
+
caps: CountFundingCaps;
|
|
26
|
+
body: WorkAmount;
|
|
27
|
+
minimumBody: WorkAmount;
|
|
28
|
+
need: WorkAmount;
|
|
29
|
+
rootEpoch: number;
|
|
30
|
+
context: CountDisjointContext;
|
|
31
|
+
}> | Readonly<{
|
|
32
|
+
kind: 'refused';
|
|
33
|
+
reason: 'tickets' | 'root' | 'headroom' | 'parent' | 'stop' | 'inventory';
|
|
34
|
+
}>;
|
|
35
|
+
export declare function planDisjointCountRound(caps: CountFundingCaps, body0: WorkAmount, history: readonly CountBodyHistory[], tickets: CountAttemptTickets, stop?: CountAttemptStop & {
|
|
36
|
+
caseKey?: string;
|
|
37
|
+
}, bank?: WorkLedger): CountDisjointPlan;
|
|
38
|
+
export type CountOwnerReceipt = Readonly<{
|
|
39
|
+
body: WorkAmount;
|
|
40
|
+
cases: ReadonlyMap<string, WorkAmount>;
|
|
41
|
+
sum: WorkAmount;
|
|
42
|
+
round: WorkAmount;
|
|
43
|
+
complete: boolean;
|
|
44
|
+
}>;
|
|
45
|
+
export declare class CountFundingOwners {
|
|
46
|
+
private plan;
|
|
47
|
+
private bank;
|
|
48
|
+
private completion;
|
|
49
|
+
private failedSlice;
|
|
50
|
+
get slices(): readonly CountSlice[];
|
|
51
|
+
private active;
|
|
52
|
+
private ending;
|
|
53
|
+
private settling;
|
|
54
|
+
private bodyUse;
|
|
55
|
+
private caseUse;
|
|
56
|
+
private ownerUse;
|
|
57
|
+
private finished;
|
|
58
|
+
private readonly start;
|
|
59
|
+
constructor(plan: Extract<CountDisjointPlan, {
|
|
60
|
+
kind: 'admitted';
|
|
61
|
+
}>, bank?: WorkLedger, completion?: WorkAmount);
|
|
62
|
+
ownsBank(bank: WorkLedger): boolean;
|
|
63
|
+
body<T>(run: () => T): T;
|
|
64
|
+
settle<T>(run: () => T): T;
|
|
65
|
+
checkCoverage(): void;
|
|
66
|
+
case<T>(key: string, run: () => T): T;
|
|
67
|
+
private segment;
|
|
68
|
+
leaf<T>(physicalKey: string, run: () => T, expectedCase?: string): T;
|
|
69
|
+
private retainFailure;
|
|
70
|
+
receipt(complete: boolean): CountOwnerReceipt;
|
|
71
|
+
}
|
|
72
|
+
export declare function runDisjointCountRound<T>(plan: CountDisjointPlan, tickets: CountAttemptTickets, run: (owners: CountFundingOwners) => CountRoundValue<T>, bank?: WorkLedger, eligible?: () => boolean): Readonly<{
|
|
73
|
+
result: CountRoundResult<T>;
|
|
74
|
+
receipt?: CountOwnerReceipt;
|
|
75
|
+
}>;
|