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,284 @@
|
|
|
1
|
+
// Section46.17 NEXT-PIN API ONLY: not selected by the production controller.
|
|
2
|
+
// The interim production policy remains planCountRetry with the narrow cap fix.
|
|
3
|
+
// Callers must split their callback into explicit body/case segments; this API
|
|
4
|
+
// neither suspends ledger endpoints nor attributes work merely by its label.
|
|
5
|
+
import { BudgetExpired, workLedger } from "./work-admission.js";
|
|
6
|
+
import { compareWork, workAdd, workShare, workSub, zeroWork } from "./work-amount.js";
|
|
7
|
+
import { countAttemptStop } from "./count-retry-budget.js";
|
|
8
|
+
// Identity metadata only: this never grants work or creates a ticket.
|
|
9
|
+
export function countDisjointContext(instance, bank = workLedger) {
|
|
10
|
+
const parent = bank.currentScope();
|
|
11
|
+
if (!parent || !bank.inBudget())
|
|
12
|
+
throw Error('disjoint count context needs an existing root');
|
|
13
|
+
return Object.freeze({ instance, bank, parentId: parent.id, parentEpoch: bank.snapshot().scopeEpoch, started: instance.snapshot().started });
|
|
14
|
+
}
|
|
15
|
+
function sameContext(context, instance, bank) {
|
|
16
|
+
return context.instance === instance && context.bank === bank && context.started === instance.snapshot().started
|
|
17
|
+
&& context.parentId === bank.currentScope()?.id && context.parentEpoch === bank.snapshot().scopeEpoch;
|
|
18
|
+
}
|
|
19
|
+
const limit = 1n << 4096n;
|
|
20
|
+
const valid = (n) => n.den > 0n && n.num >= 0n && n.den <= limit && n.num <= limit;
|
|
21
|
+
export function planDisjointCountRound(caps, body0, history, tickets, stop, bank = workLedger) {
|
|
22
|
+
bank.start('ticks', 1, 'disjoint count plan header');
|
|
23
|
+
if (!bank.inBudget())
|
|
24
|
+
return { kind: 'refused', reason: 'root' };
|
|
25
|
+
if (tickets.snapshot().terminal || tickets.snapshot().remaining === 0)
|
|
26
|
+
return { kind: 'refused', reason: 'tickets' };
|
|
27
|
+
if (!caps.cases.size || caps.cases.size > 63 || history.length > 7 || !valid(caps.leaf) || caps.leaf.num === 0n || !valid(body0))
|
|
28
|
+
return { kind: 'refused', reason: 'inventory' };
|
|
29
|
+
const cases = new Map();
|
|
30
|
+
let leaf = caps.leaf, total = zeroWork, minimumBody = body0;
|
|
31
|
+
if (stop && stop.kind !== 'soft-slice')
|
|
32
|
+
return { kind: 'refused', reason: 'stop' };
|
|
33
|
+
if (stop && stop.rootEpoch !== bank.snapshot().rootEpoch)
|
|
34
|
+
return { kind: 'refused', reason: 'root' };
|
|
35
|
+
let found = !stop;
|
|
36
|
+
for (const [key, cap] of caps.cases) {
|
|
37
|
+
bank.start('ticks', 1, 'disjoint count case validation');
|
|
38
|
+
if (!key || key.length > 256 || key === 'leaf' || key === 'body' || !valid(cap) || cap.num === 0n)
|
|
39
|
+
return { kind: 'refused', reason: 'inventory' };
|
|
40
|
+
if (stop?.key === key) {
|
|
41
|
+
if (compareWork(stop.allocation, cap) !== 0)
|
|
42
|
+
return { kind: 'refused', reason: 'stop' };
|
|
43
|
+
found = true;
|
|
44
|
+
}
|
|
45
|
+
const next = stop?.key === key ? workShare(cap, 2n, 1n) : cap;
|
|
46
|
+
cases.set(key, next);
|
|
47
|
+
total = workAdd(total, next);
|
|
48
|
+
}
|
|
49
|
+
if (stop?.key === 'leaf') {
|
|
50
|
+
if (compareWork(stop.allocation, leaf) !== 0 || !stop.caseKey || !cases.has(stop.caseKey))
|
|
51
|
+
return { kind: 'refused', reason: 'parent' };
|
|
52
|
+
leaf = workShare(leaf, 2n, 1n);
|
|
53
|
+
if (compareWork(leaf, cases.get(stop.caseKey)) > 0)
|
|
54
|
+
return { kind: 'refused', reason: 'parent' };
|
|
55
|
+
found = true;
|
|
56
|
+
}
|
|
57
|
+
if (!found)
|
|
58
|
+
return { kind: 'refused', reason: 'stop' };
|
|
59
|
+
let completed = false;
|
|
60
|
+
for (const entry of history) {
|
|
61
|
+
bank.start('ticks', 1, 'disjoint count body history');
|
|
62
|
+
if (!valid(entry.used) || entry.instance !== tickets || entry.rootEpoch !== bank.snapshot().rootEpoch)
|
|
63
|
+
return { kind: 'refused', reason: 'inventory' };
|
|
64
|
+
if (entry.completed && (!completed || compareWork(entry.used, minimumBody) > 0)) {
|
|
65
|
+
minimumBody = entry.used;
|
|
66
|
+
completed = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Read H only after every paid preparation step. It already intersects every
|
|
70
|
+
// live ancestor and outstanding reservation; no caller-supplied H is trusted.
|
|
71
|
+
const headroom = bank.available();
|
|
72
|
+
if (headroom === null)
|
|
73
|
+
return { kind: 'refused', reason: 'root' };
|
|
74
|
+
if (compareWork(workAdd(total, minimumBody), headroom) > 0)
|
|
75
|
+
return { kind: 'refused', reason: 'headroom' };
|
|
76
|
+
return Object.freeze({ kind: 'admitted', caps: { cases, leaf }, body: workSub(headroom, total), minimumBody, need: headroom, rootEpoch: bank.snapshot().rootEpoch, context: countDisjointContext(tickets, bank) });
|
|
77
|
+
}
|
|
78
|
+
export class CountFundingOwners {
|
|
79
|
+
plan;
|
|
80
|
+
bank;
|
|
81
|
+
completion;
|
|
82
|
+
failedSlice;
|
|
83
|
+
get slices() { return this.failedSlice ? [this.failedSlice] : []; }
|
|
84
|
+
active;
|
|
85
|
+
ending = false;
|
|
86
|
+
settling = false;
|
|
87
|
+
bodyUse = zeroWork;
|
|
88
|
+
caseUse = new Map();
|
|
89
|
+
ownerUse = zeroWork;
|
|
90
|
+
finished;
|
|
91
|
+
start;
|
|
92
|
+
constructor(plan, bank = workLedger, completion = zeroWork) {
|
|
93
|
+
this.plan = plan;
|
|
94
|
+
this.bank = bank;
|
|
95
|
+
this.completion = completion;
|
|
96
|
+
this.start = bank.actual();
|
|
97
|
+
}
|
|
98
|
+
ownsBank(bank) { return this.bank === bank; }
|
|
99
|
+
body(run) { return this.segment('body', 'body', workSub(this.plan.body, this.completion), run); }
|
|
100
|
+
// The runner reserves this tail inside the SAME body cap before user work.
|
|
101
|
+
// No case credit or new allowance can pay settlement after an interruption.
|
|
102
|
+
settle(run) {
|
|
103
|
+
if (this.ending || this.active)
|
|
104
|
+
throw new BudgetExpired('duplicate disjoint settlement');
|
|
105
|
+
this.ending = true;
|
|
106
|
+
this.settling = true;
|
|
107
|
+
try {
|
|
108
|
+
return this.segment('body', 'body', this.plan.body, run);
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
this.settling = false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
checkCoverage() {
|
|
115
|
+
const now = this.bank.actual(), live = this.active ? workSub(now, this.active.start) : zeroWork;
|
|
116
|
+
if (compareWork(workAdd(this.ownerUse, live), workSub(now, this.start)) !== 0)
|
|
117
|
+
throw new BudgetExpired('unowned or overlapping count round work');
|
|
118
|
+
}
|
|
119
|
+
case(key, run) {
|
|
120
|
+
const cap = this.plan.caps.cases.get(key);
|
|
121
|
+
if (!cap)
|
|
122
|
+
throw new BudgetExpired('unknown disjoint count case');
|
|
123
|
+
return this.segment('case', key, cap, run);
|
|
124
|
+
}
|
|
125
|
+
segment(kind, key, cap, run) {
|
|
126
|
+
if (this.finished || this.ending && !this.settling)
|
|
127
|
+
throw new BudgetExpired('closed disjoint count owners');
|
|
128
|
+
if (this.active)
|
|
129
|
+
throw new BudgetExpired('overlapping disjoint count owners');
|
|
130
|
+
const used = kind === 'body' ? this.bodyUse : this.caseUse.get(key) ?? zeroWork, left = workSub(cap, used), before = this.bank.actual();
|
|
131
|
+
if (compareWork(left, zeroWork) < 0)
|
|
132
|
+
throw new BudgetExpired('spent disjoint count owner');
|
|
133
|
+
try {
|
|
134
|
+
return this.bank.withBudget(left, () => {
|
|
135
|
+
this.active = { kind, key, start: before };
|
|
136
|
+
const scope = this.bank.currentScope(), slice = { key, allocation: cap, scopeId: scope.id, rootEpoch: this.plan.rootEpoch };
|
|
137
|
+
try {
|
|
138
|
+
this.bank.start('ticks', 1, 'disjoint count owner bookkeeping');
|
|
139
|
+
return run();
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
this.retainFailure(error, slice, kind === 'case');
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
this.active = undefined;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
const amount = workSub(this.bank.actual(), before);
|
|
152
|
+
this.ownerUse = workAdd(this.ownerUse, amount);
|
|
153
|
+
if (kind === 'body')
|
|
154
|
+
this.bodyUse = workAdd(this.bodyUse, amount);
|
|
155
|
+
else
|
|
156
|
+
this.caseUse.set(key, workAdd(used, amount));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
leaf(physicalKey, run, expectedCase) {
|
|
160
|
+
const owner = this.active;
|
|
161
|
+
if (this.finished)
|
|
162
|
+
throw new BudgetExpired('closed disjoint count owners');
|
|
163
|
+
if (!owner)
|
|
164
|
+
throw new BudgetExpired('unowned count leaf');
|
|
165
|
+
if (expectedCase !== undefined && (owner.kind !== 'case' || owner.key !== expectedCase))
|
|
166
|
+
throw new BudgetExpired('mismatched count leaf owner');
|
|
167
|
+
return this.bank.withBudget(this.plan.caps.leaf, () => {
|
|
168
|
+
const scope = this.bank.currentScope(), slice = { key: 'leaf', allocation: this.plan.caps.leaf, scopeId: scope.id, rootEpoch: this.plan.rootEpoch, caseKey: owner.kind === 'case' ? owner.key : undefined, physicalKey };
|
|
169
|
+
try {
|
|
170
|
+
this.bank.start('ticks', 1, 'disjoint count leaf bookkeeping');
|
|
171
|
+
return run();
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
this.retainFailure(error, slice, owner.kind === 'case');
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
retainFailure(error, slice, renewable) {
|
|
180
|
+
const refusal = this.bank.capacityRefusal(error);
|
|
181
|
+
if (renewable && refusal?.limiting.length === 1 && refusal.limiting[0].id === slice.scopeId) {
|
|
182
|
+
this.failedSlice = slice;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
receipt(complete) {
|
|
186
|
+
if (this.finished)
|
|
187
|
+
return this.finished;
|
|
188
|
+
if (this.active)
|
|
189
|
+
throw new BudgetExpired('live disjoint owner at return');
|
|
190
|
+
const round = workSub(this.bank.actual(), this.start);
|
|
191
|
+
if (compareWork(this.ownerUse, round) !== 0)
|
|
192
|
+
throw new BudgetExpired('unowned or overlapping count round work');
|
|
193
|
+
// No traversal/copy is hidden at an exhausted owner boundary. The private
|
|
194
|
+
// map is exposed as a read-only final view; all subsequent segments refuse.
|
|
195
|
+
return this.finished = Object.freeze({ body: this.bodyUse, cases: this.caseUse, sum: this.ownerUse, round, complete });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
export function runDisjointCountRound(plan, tickets, run, bank = workLedger, eligible) {
|
|
199
|
+
if (plan.kind === 'refused')
|
|
200
|
+
return { result: { kind: 'not-started', reason: plan.reason } };
|
|
201
|
+
if (!bank.inBudget() || plan.rootEpoch !== bank.snapshot().rootEpoch)
|
|
202
|
+
return { result: { kind: 'not-started', reason: 'missing-root' } };
|
|
203
|
+
if (!sameContext(plan.context, tickets, bank))
|
|
204
|
+
return { result: { kind: 'not-started', reason: 'context' } };
|
|
205
|
+
if (tickets.snapshot().terminal || tickets.snapshot().active)
|
|
206
|
+
return { result: { kind: 'not-started', reason: 'tickets' } };
|
|
207
|
+
// One terminal owner-entry tick and three fixed control operations: stop/
|
|
208
|
+
// coverage classification, ticket settlement, and final receipt preparation.
|
|
209
|
+
const completion = workShare(bank.weights.ticks, 4n, 1n);
|
|
210
|
+
try {
|
|
211
|
+
bank.checkAmount(plan.need, 'disjoint count atomic admission');
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
if (error instanceof BudgetExpired)
|
|
215
|
+
return { result: { kind: 'not-started', reason: 'headroom' } };
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
return bank.withBudget(plan.need, () => {
|
|
219
|
+
const owners = new CountFundingOwners(plan, bank, completion);
|
|
220
|
+
let started = false, failed = false, failure, refusal, value;
|
|
221
|
+
try {
|
|
222
|
+
refusal = owners.body(() => {
|
|
223
|
+
const active = countDisjointContext(tickets, bank);
|
|
224
|
+
if (eligible && !eligible())
|
|
225
|
+
return 'ineligible';
|
|
226
|
+
if (!sameContext(active, tickets, bank) || active.started !== plan.context.started)
|
|
227
|
+
return 'context';
|
|
228
|
+
if (tickets.snapshot().terminal || tickets.snapshot().active)
|
|
229
|
+
return 'tickets';
|
|
230
|
+
bank.start('ticks', 1, 'disjoint count ticket');
|
|
231
|
+
started = tickets.start();
|
|
232
|
+
return started ? undefined : 'tickets';
|
|
233
|
+
});
|
|
234
|
+
if (!refusal)
|
|
235
|
+
value = run(owners);
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
failed = true;
|
|
239
|
+
failure = error;
|
|
240
|
+
}
|
|
241
|
+
let result = { kind: 'not-started', reason: 'precommit' };
|
|
242
|
+
try {
|
|
243
|
+
owners.settle(() => {
|
|
244
|
+
bank.start('ticks', 1, 'disjoint terminal classification');
|
|
245
|
+
try {
|
|
246
|
+
owners.checkCoverage();
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
failed = true;
|
|
250
|
+
failure = error;
|
|
251
|
+
}
|
|
252
|
+
if (failed) {
|
|
253
|
+
const stop = countAttemptStop(failure, owners.slices, bank);
|
|
254
|
+
result = !started ? { kind: 'not-started', reason: 'precommit' } : stop.kind === 'soft-slice' ? { kind: 'unfinished', stop } : { kind: 'hard-cap', stop };
|
|
255
|
+
}
|
|
256
|
+
else
|
|
257
|
+
result = refusal ? { kind: 'not-started', reason: refusal } : value;
|
|
258
|
+
bank.start('ticks', 1, 'disjoint terminal ticket');
|
|
259
|
+
if (started)
|
|
260
|
+
tickets.finish(result.kind === 'proposal' || result.kind === 'decline' ? result.kind : result.kind === 'unfinished' ? 'unfinished' : 'hard-cap');
|
|
261
|
+
bank.start('ticks', 1, 'disjoint terminal receipt');
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
// If even the reserved tail cannot run (e.g. unowned work spent its credit),
|
|
266
|
+
// do not invent a free cleanup allowance. An active ticket stays unusable.
|
|
267
|
+
if (!(error instanceof BudgetExpired))
|
|
268
|
+
throw error;
|
|
269
|
+
return { result: { kind: 'hard-cap', stop: { kind: 'hard-cap', reason: 'unclassified', error } } };
|
|
270
|
+
}
|
|
271
|
+
let receipt;
|
|
272
|
+
try {
|
|
273
|
+
receipt = owners.receipt(!failed && !refusal);
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
failed = true;
|
|
277
|
+
failure = error;
|
|
278
|
+
result = { kind: 'hard-cap', stop: { kind: 'hard-cap', reason: 'unclassified', error } };
|
|
279
|
+
}
|
|
280
|
+
if (failed && !(failure instanceof BudgetExpired))
|
|
281
|
+
throw failure;
|
|
282
|
+
return { result, receipt };
|
|
283
|
+
});
|
|
284
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Count, type FrameCut } from '../kernel/kernel.js';
|
|
2
|
+
export declare class FrameFactPool {
|
|
3
|
+
readonly counts: Count[];
|
|
4
|
+
readonly frames: FrameCut[];
|
|
5
|
+
readonly until: number;
|
|
6
|
+
private offered;
|
|
7
|
+
private reused;
|
|
8
|
+
private validated;
|
|
9
|
+
private rejected;
|
|
10
|
+
private removed;
|
|
11
|
+
constructor(counts: Count[], frames: FrameCut[], until: number);
|
|
12
|
+
private pair;
|
|
13
|
+
offer(frame: FrameCut): boolean;
|
|
14
|
+
stats(): {
|
|
15
|
+
offered: number;
|
|
16
|
+
reused: number;
|
|
17
|
+
validated: number;
|
|
18
|
+
rejected: number;
|
|
19
|
+
removed: number;
|
|
20
|
+
frames: number;
|
|
21
|
+
guards: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Research-only per-emitter frame proposer. The final native certificate gate
|
|
2
|
+
// remains mandatory. Cached frames belong to one immutable count environment.
|
|
3
|
+
import { canon, frameActive, frameOk, simpE, whenPath } from "../kernel/kernel.js";
|
|
4
|
+
import { late } from "../kernel/prove.js";
|
|
5
|
+
export class FrameFactPool {
|
|
6
|
+
counts;
|
|
7
|
+
frames;
|
|
8
|
+
until;
|
|
9
|
+
offered = 0;
|
|
10
|
+
reused = 0;
|
|
11
|
+
validated = 0;
|
|
12
|
+
rejected = 0;
|
|
13
|
+
removed = 0;
|
|
14
|
+
constructor(counts, frames, until) { if (frames.length)
|
|
15
|
+
throw Error('frame pool must start empty'); this.counts = counts; this.frames = frames; this.until = until; }
|
|
16
|
+
pair(f) { return JSON.stringify([f.post, f.pre].sort()); }
|
|
17
|
+
offer(frame) {
|
|
18
|
+
this.offered++;
|
|
19
|
+
if (late(this.until))
|
|
20
|
+
return false;
|
|
21
|
+
const pair = this.pair(frame), path = whenPath(frame);
|
|
22
|
+
if (this.frames.some(f => this.pair(f) === pair && frameActive(f, path))) {
|
|
23
|
+
this.reused++;
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
const post = this.counts.find(c => c.v === frame.post), pre = this.counts.find(c => c.v === frame.pre);
|
|
27
|
+
if (!post || !pre || post.key !== pre.key) {
|
|
28
|
+
this.rejected++;
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
const seen = new Set(), all = () => { for (const key of path.keys())
|
|
32
|
+
seen.add(key); };
|
|
33
|
+
const tracked = new Proxy(path, { get(target, key) {
|
|
34
|
+
if (key === 'get')
|
|
35
|
+
return (id) => { const value = target.get(id); if (value !== undefined)
|
|
36
|
+
seen.add(id); return value; };
|
|
37
|
+
if (key === 'has')
|
|
38
|
+
return (id) => { const found = target.has(id); if (found)
|
|
39
|
+
seen.add(id); return found; };
|
|
40
|
+
if (key === 'size') {
|
|
41
|
+
all();
|
|
42
|
+
return target.size;
|
|
43
|
+
}
|
|
44
|
+
if (key === 'keys' || key === 'values' || key === 'entries' || key === Symbol.iterator || key === 'forEach') {
|
|
45
|
+
all();
|
|
46
|
+
const value = Reflect.get(target, key, target);
|
|
47
|
+
return value.bind(target);
|
|
48
|
+
}
|
|
49
|
+
const value = Reflect.get(target, key, target);
|
|
50
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
51
|
+
} });
|
|
52
|
+
const equal = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
53
|
+
const same = equal(simpE(post.below, tracked, post.key), simpE(pre.below, tracked, pre.key)) && equal(simpE(post.body, tracked, post.key), simpE(pre.body, tracked, pre.key));
|
|
54
|
+
const short = { ...frame, when: frame.when.filter(row => seen.has(canon(row))) };
|
|
55
|
+
let candidate = frame;
|
|
56
|
+
if (same) {
|
|
57
|
+
this.validated++;
|
|
58
|
+
if (frameOk(this.counts, short))
|
|
59
|
+
candidate = short;
|
|
60
|
+
else {
|
|
61
|
+
this.validated++;
|
|
62
|
+
if (!frameOk(this.counts, frame)) {
|
|
63
|
+
this.rejected++;
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.validated++;
|
|
70
|
+
if (!frameOk(this.counts, frame)) {
|
|
71
|
+
this.rejected++;
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const keys = new Set(candidate.when.map(canon));
|
|
76
|
+
for (let i = this.frames.length - 1; i >= 0; i--) {
|
|
77
|
+
const old = this.frames[i];
|
|
78
|
+
if (this.pair(old) === pair && [...keys].every(k => old.when.some(row => canon(row) === k))) {
|
|
79
|
+
this.frames.splice(i, 1);
|
|
80
|
+
this.removed++;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
this.frames.push(candidate);
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
stats() { return { offered: this.offered, reused: this.reused, validated: this.validated, rejected: this.rejected, removed: this.removed, frames: this.frames.length, guards: this.frames.reduce((n, f) => n + f.when.length, 0) }; }
|
|
87
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const familyStepProposal: unique symbol;
|
|
2
|
+
export type FamilyStepProposal = typeof familyStepProposal;
|
|
3
|
+
export declare const finalCountStepDeferralEnabled: () => boolean;
|
|
4
|
+
export declare const deferFinalCountStep: (key?: FamilyStepProposal) => boolean;
|
|
5
|
+
export declare function closingCountCheck(check: () => boolean): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Internal proposal capability, not a proof receipt or acceptance token.
|
|
2
|
+
// Public/standalone strategy entry points never supply it. Only the full-work
|
|
3
|
+
// counted dispatcher may defer STEP to its unchanged final family checker.
|
|
4
|
+
import { completeWorkProfile } from "./work-profile.js";
|
|
5
|
+
import { env } from "./solver.js";
|
|
6
|
+
export const familyStepProposal = Symbol('unchecked family STEP proposal');
|
|
7
|
+
export const finalCountStepDeferralEnabled = () => completeWorkProfile.enabled && env.GDP_COUNT_FINAL_DEFER_CHECKS === '1';
|
|
8
|
+
export const deferFinalCountStep = (key) => key === familyStepProposal && finalCountStepDeferralEnabled();
|
|
9
|
+
// No cache: every invocation calls the original checker on the current objects.
|
|
10
|
+
// The opt-in path turns malformed/throwing/expired checks into clean refusal.
|
|
11
|
+
export function closingCountCheck(check) {
|
|
12
|
+
if (!finalCountStepDeferralEnabled())
|
|
13
|
+
return check();
|
|
14
|
+
try {
|
|
15
|
+
return check();
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Law, type Machine } from './machine.js';
|
|
2
|
+
import { ownCountLawInstance } from './count-frames.js';
|
|
3
|
+
import { type CountRequestBuilder, type CountStrategyProof, type CountStrategyOptions } from './count-strategy.js';
|
|
4
|
+
export declare function proveFixedCountFrame(m: Machine, family: Law[], law: Law, seed: Parameters<typeof ownCountLawInstance>[1], until: number, requestFor: CountRequestBuilder, options?: CountStrategyOptions): CountStrategyProof | undefined;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { countsForReads } from "./count-facts.js";
|
|
2
|
+
import { countFrameConditions, fixedCountFrameCase, ownCountLawInstance, proveCountFrameGoal } from "./count-frames.js";
|
|
3
|
+
import { discoverCountGuardShape } from "./count-guard-shape.js";
|
|
4
|
+
import { finishCountStrategy } from "./count-strategy.js";
|
|
5
|
+
import { countedObligations, frameOk } from "../kernel/kernel.js";
|
|
6
|
+
import { fullRate, fullWork, late, withDeadline } from "../kernel/prove.js";
|
|
7
|
+
export function proveFixedCountFrame(m, family, law, seed, until, requestFor, options = {}) {
|
|
8
|
+
return withDeadline(until, () => {
|
|
9
|
+
if (late(until) || !family.includes(law))
|
|
10
|
+
return;
|
|
11
|
+
const choice = fixedCountFrameCase(m), shape = discoverCountGuardShape(m, law, family);
|
|
12
|
+
if (!choice || !shape)
|
|
13
|
+
return;
|
|
14
|
+
options.trace?.({ query: 'frame-eligibility', outcome: 'start' });
|
|
15
|
+
const start = fullWork();
|
|
16
|
+
const instances = ownCountLawInstance(law, seed), step = countedObligations(m, family, { [law.name]: instances }, family.indexOf(law)).at(-1);
|
|
17
|
+
const request = requestFor(step.goal, step.decls), counts = countsForReads(step.decls, request.reads), targets = new Set([shape.voteMap, shape.rowMap]), when = countFrameConditions(choice);
|
|
18
|
+
if (!counts)
|
|
19
|
+
return;
|
|
20
|
+
const post = request.reads.filter(r => r[1].endsWith('#') && targets.has(r[1].slice(0, -1)));
|
|
21
|
+
if (!post.length || post.some(([name, map, key]) => {
|
|
22
|
+
const pre = request.reads.find(r => r[1] === map.slice(0, -1) && JSON.stringify(r[2]) === JSON.stringify(key));
|
|
23
|
+
return !pre || !frameOk(counts, { post: name, pre: pre[0], when });
|
|
24
|
+
}))
|
|
25
|
+
return;
|
|
26
|
+
options.trace?.({ query: 'frame-eligibility', outcome: 'eligible', units: (fullWork() - start) / fullRate });
|
|
27
|
+
const cert = proveCountFrameGoal(step.goal, step.decls, request, choice, targets, until, undefined, { deferCheck: !!options.deferToComposition, trace: options.trace, minimalView: options.minimalView, leafUnits: options.leafUnits });
|
|
28
|
+
return cert && finishCountStrategy(m, family, law, instances, shape.voteMap, cert, until, requestFor, undefined, options);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Law, type Machine } from './machine.js';
|
|
2
|
+
import { type CountCert, type CountDecl, type Goal, type Instances } from '../kernel/kernel.js';
|
|
3
|
+
import type { Lin } from './solver.js';
|
|
4
|
+
export type FixedCountFrameCase = {
|
|
5
|
+
name: string;
|
|
6
|
+
value: number;
|
|
7
|
+
values: number[];
|
|
8
|
+
};
|
|
9
|
+
export declare function fixedCountFrameCase(m: Machine): FixedCountFrameCase | undefined;
|
|
10
|
+
export declare function ownCountLawInstance(law: Law, at: Instances): Instances;
|
|
11
|
+
export declare function countFrameConditions(choice: FixedCountFrameCase): Lin[];
|
|
12
|
+
export type CountCutTrace = {
|
|
13
|
+
kind: 'frame' | 'mono';
|
|
14
|
+
post: string;
|
|
15
|
+
pre: string;
|
|
16
|
+
checked: boolean;
|
|
17
|
+
why?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function proveCountFrameGoal(raw: Goal, decls: CountDecl[], request: Pick<CountCert, 'reads' | 'insts' | 'picks' | 'lemmas'>, choice: FixedCountFrameCase, targets: ReadonlySet<string>, until: number, trace?: (cut: CountCutTrace) => void, options?: {
|
|
20
|
+
deferCheck?: boolean;
|
|
21
|
+
minimalView?: boolean;
|
|
22
|
+
leafUnits?: number;
|
|
23
|
+
trace?: (event: Record<string, unknown>) => void;
|
|
24
|
+
extraWhen?: Lin[];
|
|
25
|
+
}): CountCert | undefined;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Untrusted, opt-in frame-first search for an explicitly fixed finite operation.
|
|
2
|
+
// No protocol names or values are built in. The returned certificate is checked
|
|
3
|
+
// against the original obligation; no inferred frame is accepted as an axiom.
|
|
4
|
+
import { n, same, x } from "./machine.js";
|
|
5
|
+
import { canon, checkMC, frameOk, framePath, mcGoal, monoOk } from "../kernel/kernel.js";
|
|
6
|
+
import { clock, fullRate, fullWork, grow, pastWall } from "../kernel/prove.js";
|
|
7
|
+
import { growCdcl } from "../kernel/cdcl.js";
|
|
8
|
+
import { countPrimitiveUnits } from "./count-primitive-budget.js";
|
|
9
|
+
import { countsForReads } from "./count-facts.js";
|
|
10
|
+
import { finiteCountChoice } from "./count-cases.js";
|
|
11
|
+
import { countSearchView, proveCountQuery } from "./count-query.js";
|
|
12
|
+
export function fixedCountFrameCase(m) {
|
|
13
|
+
const choice = finiteCountChoice(m);
|
|
14
|
+
if (!choice)
|
|
15
|
+
return;
|
|
16
|
+
const [name, values] = choice, fixed = new Set();
|
|
17
|
+
const visit = (c) => {
|
|
18
|
+
if (c.op === 'and') {
|
|
19
|
+
c.xs.forEach(visit);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (c.op !== '=')
|
|
23
|
+
return;
|
|
24
|
+
const [a, b] = c.a.op === 'var' ? [c.a, c.b] : [c.b, c.a];
|
|
25
|
+
if (a.op === 'var' && a.name === name && b.op === 'const')
|
|
26
|
+
fixed.add(b.value);
|
|
27
|
+
};
|
|
28
|
+
if (m.assume)
|
|
29
|
+
visit(m.assume);
|
|
30
|
+
if (fixed.size !== 1)
|
|
31
|
+
return;
|
|
32
|
+
const value = [...fixed][0];
|
|
33
|
+
if (!Number.isSafeInteger(value) || value < 0 || !values.has(value))
|
|
34
|
+
return;
|
|
35
|
+
return { name, value, values: [...values].sort((a, b) => a - b) };
|
|
36
|
+
}
|
|
37
|
+
export function ownCountLawInstance(law, at) {
|
|
38
|
+
if (!law.forall)
|
|
39
|
+
return at;
|
|
40
|
+
const tuple = [x(`${law.forall}#`), ...(law.keys ?? []).map(x)], had = at[law.name] ?? [], key = JSON.stringify(tuple);
|
|
41
|
+
for (let i = 0; i < had.length; i += tuple.length)
|
|
42
|
+
if (JSON.stringify(had.slice(i, i + tuple.length)) === key)
|
|
43
|
+
return at;
|
|
44
|
+
return { ...at, [law.name]: [...had, ...tuple] };
|
|
45
|
+
}
|
|
46
|
+
export function countFrameConditions(choice) {
|
|
47
|
+
const { name, value, values } = choice;
|
|
48
|
+
const rows = [{ [name]: 1, '1': -value }, { [name]: -1, '1': value }, ...values.filter(v => v !== value).map(v => v < value ? { [name]: -1, '1': v + 1 } : { [name]: 1, '1': 1 - v })];
|
|
49
|
+
const normalized = rows.map(row => Object.fromEntries(Object.entries(row).filter(([, coefficient]) => coefficient !== 0)));
|
|
50
|
+
return [...new Map(normalized.map(row => [canon(row), row])).values()];
|
|
51
|
+
}
|
|
52
|
+
export function proveCountFrameGoal(raw, decls, request, choice, targets, until, trace, options = {}) {
|
|
53
|
+
if (clock() >= until || pastWall())
|
|
54
|
+
return;
|
|
55
|
+
const goal = mcGoal(raw.hyps, decls, request), counts = countsForReads(decls, request.reads);
|
|
56
|
+
if (!goal || !counts)
|
|
57
|
+
return;
|
|
58
|
+
const when = [...countFrameConditions(choice), ...(options.extraWhen ?? [])], frames = [], monos = [];
|
|
59
|
+
const conditions = [same(x(choice.name), n(choice.value))];
|
|
60
|
+
for (const [post, map, key] of request.reads) {
|
|
61
|
+
if (!map.endsWith('#') || !targets.has(map.slice(0, -1)))
|
|
62
|
+
continue;
|
|
63
|
+
const pre = request.reads.find(r => r[1] === map.slice(0, -1) && JSON.stringify(r[2]) === JSON.stringify(key));
|
|
64
|
+
if (!pre)
|
|
65
|
+
continue;
|
|
66
|
+
const f = { when, post, pre: pre[0] };
|
|
67
|
+
const equal = frameOk(counts, f);
|
|
68
|
+
trace?.({ kind: 'frame', post, pre: pre[0], checked: equal });
|
|
69
|
+
if (equal) {
|
|
70
|
+
frames.push(f);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const postCount = counts.find(c => c.v === post), preCount = counts.find(c => c.v === pre[0]);
|
|
74
|
+
if (postCount.key !== preCount.key || clock() >= until || pastWall())
|
|
75
|
+
continue;
|
|
76
|
+
const auxiliary = { name: 'per-key cut', hyps: [...conditions, { op: '<', a: x(postCount.key), b: postCount.below }, { op: '<', a: preCount.body, b: postCount.body }] };
|
|
77
|
+
const out = grow(auxiliary, new Map(), { nodes: 0, until: Math.min(until, clock() + countPrimitiveUnits(100, options.leafUnits)) });
|
|
78
|
+
const cut = 'tree' in out ? { when: conditions, post, pre: pre[0], tree: out.tree } : undefined;
|
|
79
|
+
const checked = !!cut && monoOk(counts, cut);
|
|
80
|
+
trace?.({ kind: 'mono', post, pre: pre[0], checked, ...('stuck' in out ? { why: out.stuck } : {}) });
|
|
81
|
+
if (cut && checked)
|
|
82
|
+
monos.push(cut);
|
|
83
|
+
}
|
|
84
|
+
if (!frames.length && !monos.length)
|
|
85
|
+
return;
|
|
86
|
+
const minimal = options.minimalView ? countSearchView(raw, decls, request) : undefined;
|
|
87
|
+
const ask = (path) => {
|
|
88
|
+
if (clock() >= until || pastWall())
|
|
89
|
+
return;
|
|
90
|
+
if (minimal)
|
|
91
|
+
return proveCountQuery(goal, framePath(frames, request.lemmas ?? [], path, monos), until, { query: 'frame-leaf', minimal, leafUnits: options.leafUnits, trace: options.trace, deferCheck: options.deferCheck });
|
|
92
|
+
const start = fullWork(), at = framePath(frames, request.lemmas ?? [], path, monos);
|
|
93
|
+
const out = growCdcl(goal, at, { nodes: 0, until: Math.min(until, clock() + (options.leafUnits ?? Infinity)) });
|
|
94
|
+
options.trace?.({ query: 'frame-leaf', outcome: 'tree' in out ? 'proposed' : out.stuck, units: (fullWork() - start) / fullRate, remaining: until - clock(), hyps: goal.hyps.length, path: [...at.values()], ...(!('tree' in out) ? { goal } : {}) });
|
|
95
|
+
return 'tree' in out ? out.tree : undefined;
|
|
96
|
+
};
|
|
97
|
+
const search = (i, path) => {
|
|
98
|
+
if (clock() >= until || pastWall())
|
|
99
|
+
return;
|
|
100
|
+
if (i === when.length)
|
|
101
|
+
return ask(path);
|
|
102
|
+
const row = when[i], known = path.get(canon(row))?.holds;
|
|
103
|
+
if (known === true)
|
|
104
|
+
return search(i + 1, path);
|
|
105
|
+
if (known === false)
|
|
106
|
+
return ask(path);
|
|
107
|
+
const yes = search(i + 1, new Map(path).set(canon(row), { lin: row, holds: true }));
|
|
108
|
+
if (!yes)
|
|
109
|
+
return;
|
|
110
|
+
const no = ask(new Map(path).set(canon(row), { lin: row, holds: false }));
|
|
111
|
+
return no ? { split: row, yes, no } : undefined;
|
|
112
|
+
};
|
|
113
|
+
const tree = search(0, new Map());
|
|
114
|
+
if (!tree)
|
|
115
|
+
return;
|
|
116
|
+
const cert = { ...request, tree, frames, monos };
|
|
117
|
+
return options.deferCheck || checkMC(raw.hyps, decls, cert) ? cert : undefined;
|
|
118
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Scalar search guards use the same quantified-flag aliases as countedObligations.
|
|
2
|
+
// This is preprocessing, not a proof rule or an additional hypothesis.
|
|
3
|
+
import { n, same, walkOnce, x } from "./machine.js";
|
|
4
|
+
import { substC } from "../kernel/kernel.js";
|
|
5
|
+
export function inlineFrozenGuard(flags, root) {
|
|
6
|
+
const memo = new Map(), visiting = new Set();
|
|
7
|
+
const expand = (name) => {
|
|
8
|
+
const old = memo.get(name);
|
|
9
|
+
if (old)
|
|
10
|
+
return old;
|
|
11
|
+
if (visiting.has(name))
|
|
12
|
+
throw Error('cyclic guard flag ' + name);
|
|
13
|
+
const raw = Object.hasOwn(flags, name) ? flags[name] : undefined;
|
|
14
|
+
if (!raw)
|
|
15
|
+
throw Error('missing guard flag ' + name);
|
|
16
|
+
if (raw.op === 'all') {
|
|
17
|
+
const value = same(x('?' + name), n(1));
|
|
18
|
+
memo.set(name, value);
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
visiting.add(name);
|
|
22
|
+
const dependencies = {};
|
|
23
|
+
walkOnce(raw, (node) => { if (node.op === 'flag')
|
|
24
|
+
dependencies[node.name] = expand(node.name); });
|
|
25
|
+
const value = substC(raw, { vars: {}, maps: {}, flags: dependencies });
|
|
26
|
+
visiting.delete(name);
|
|
27
|
+
memo.set(name, value);
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
return expand(root);
|
|
31
|
+
}
|