gdp-wired 0.47.0 → 0.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -6
- package/dist/core/bmc.js +10 -7
- package/dist/core/carry.d.ts +15 -0
- package/dist/core/carry.js +651 -0
- package/dist/core/check.js +7 -2
- package/dist/core/cli.d.ts +3 -1
- package/dist/core/cli.js +28 -8
- 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.d.ts +24 -0
- package/dist/core/count-cases.js +321 -0
- package/dist/core/count-cert-grow.d.ts +4 -0
- package/dist/core/count-cert-grow.js +37 -0
- package/dist/core/count-cert-rename.d.ts +10 -0
- package/dist/core/count-cert-rename.js +69 -0
- package/dist/core/count-cert-transport.d.ts +11 -0
- package/dist/core/count-cert-transport.js +109 -0
- 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-completion.d.ts +9 -0
- package/dist/core/count-completion.js +27 -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-cubes.d.ts +8 -0
- package/dist/core/count-cubes.js +69 -0
- package/dist/core/count-demand.d.ts +37 -0
- package/dist/core/count-demand.js +361 -0
- package/dist/core/count-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-facts.d.ts +52 -0
- package/dist/core/count-facts.js +247 -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-focus-proof.d.ts +8 -0
- package/dist/core/count-focus-proof.js +140 -0
- package/dist/core/count-focused.d.ts +22 -0
- package/dist/core/count-focused.js +676 -0
- package/dist/core/count-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-ranges.d.ts +5 -0
- package/dist/core/count-ranges.js +65 -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/action-guard.d.ts +5 -0
- package/dist/core/count-recovery/action-guard.js +51 -0
- package/dist/core/count-recovery/boolean-core.d.ts +16 -0
- package/dist/core/count-recovery/boolean-core.js +258 -0
- package/dist/core/count-recovery/carried-case.d.ts +2 -0
- package/dist/core/count-recovery/carried-case.js +24 -0
- package/dist/core/count-recovery/conditional-check-cache.d.ts +23 -0
- package/dist/core/count-recovery/conditional-check-cache.js +131 -0
- package/dist/core/count-recovery/conditional-cuts.d.ts +6 -0
- package/dist/core/count-recovery/conditional-cuts.js +319 -0
- package/dist/core/count-recovery/conditional-proof.d.ts +53 -0
- package/dist/core/count-recovery/conditional-proof.js +348 -0
- package/dist/core/count-recovery/derivability-closure.d.ts +14 -0
- package/dist/core/count-recovery/derivability-closure.js +534 -0
- package/dist/core/count-recovery/empty-count-source.d.ts +2 -0
- package/dist/core/count-recovery/empty-count-source.js +40 -0
- package/dist/core/count-recovery/field-bound-lemmas.d.ts +23 -0
- package/dist/core/count-recovery/field-bound-lemmas.js +640 -0
- package/dist/core/count-recovery/field-case.d.ts +5 -0
- package/dist/core/count-recovery/field-case.js +89 -0
- package/dist/core/count-recovery/field-demand.d.ts +46 -0
- package/dist/core/count-recovery/field-demand.js +47 -0
- package/dist/core/count-recovery/field-only.d.ts +3 -0
- package/dist/core/count-recovery/field-only.js +18 -0
- package/dist/core/count-recovery/fold-path.d.ts +6 -0
- package/dist/core/count-recovery/fold-path.js +35 -0
- package/dist/core/count-recovery/frame-lemmas.d.ts +9 -0
- package/dist/core/count-recovery/frame-lemmas.js +120 -0
- package/dist/core/count-recovery/guard-cases.d.ts +12 -0
- package/dist/core/count-recovery/guard-cases.js +139 -0
- package/dist/core/count-recovery/key-closure.d.ts +14 -0
- package/dist/core/count-recovery/key-closure.js +62 -0
- package/dist/core/count-recovery/leaf-allowance.d.ts +4 -0
- package/dist/core/count-recovery/leaf-allowance.js +7 -0
- package/dist/core/count-recovery/lift-count-proxies.d.ts +6 -0
- package/dist/core/count-recovery/lift-count-proxies.js +175 -0
- package/dist/core/count-recovery/live-dependencies.d.ts +6 -0
- package/dist/core/count-recovery/live-dependencies.js +76 -0
- package/dist/core/count-recovery/member-inclusions.d.ts +11 -0
- package/dist/core/count-recovery/member-inclusions.js +168 -0
- package/dist/core/count-recovery/member-premises.d.ts +29 -0
- package/dist/core/count-recovery/member-premises.js +114 -0
- package/dist/core/count-recovery/natural-cases.d.ts +6 -0
- package/dist/core/count-recovery/natural-cases.js +59 -0
- package/dist/core/count-recovery/ops.d.ts +6 -0
- package/dist/core/count-recovery/ops.js +8 -0
- package/dist/core/count-recovery/pre-state-source.d.ts +8 -0
- package/dist/core/count-recovery/pre-state-source.js +18 -0
- package/dist/core/count-recovery/rebase-path.d.ts +9 -0
- package/dist/core/count-recovery/rebase-path.js +70 -0
- package/dist/core/count-recovery/reframe-tree.d.ts +2 -0
- package/dist/core/count-recovery/reframe-tree.js +24 -0
- package/dist/core/count-recovery/rename-proof.d.ts +2 -0
- package/dist/core/count-recovery/rename-proof.js +102 -0
- package/dist/core/count-recovery/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.d.ts +16 -0
- package/dist/core/count-recovery/row-cases.js +292 -0
- package/dist/core/count-recovery/scalar-guards.d.ts +7 -0
- package/dist/core/count-recovery/scalar-guards.js +291 -0
- package/dist/core/count-recovery/source-memo.d.ts +12 -0
- package/dist/core/count-recovery/source-memo.js +67 -0
- package/dist/core/count-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-select.d.ts +16 -0
- package/dist/core/count-select.js +24 -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 +598 -0
- package/dist/core/count-support.js +2081 -0
- package/dist/core/count-tier-budget.d.ts +14 -0
- package/dist/core/count-tier-budget.js +64 -0
- package/dist/core/count-unions.d.ts +2 -0
- package/dist/core/count-unions.js +139 -0
- package/dist/core/count-unwritten-prefix.d.ts +24 -0
- package/dist/core/count-unwritten-prefix.js +97 -0
- package/dist/core/count-witness-flags.d.ts +9 -0
- package/dist/core/count-witness-flags.js +37 -0
- package/dist/core/count-write-frames.d.ts +12 -0
- package/dist/core/count-write-frames.js +206 -0
- package/dist/core/count-write-shape.d.ts +15 -0
- package/dist/core/count-write-shape.js +73 -0
- package/dist/core/counts.d.ts +49 -7
- package/dist/core/counts.js +1679 -165
- 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 +59 -6
- package/dist/core/dsl.js +459 -112
- package/dist/core/effect.js +8 -1
- package/dist/core/evaluation-admission.d.ts +1 -0
- package/dist/core/evaluation-admission.js +3 -0
- package/dist/core/exists.d.ts +7 -2
- package/dist/core/exists.js +131 -24
- package/dist/core/extract-check.d.ts +7 -1
- package/dist/core/extract-check.js +130 -13
- package/dist/core/extract-read.d.ts +22 -8
- package/dist/core/extract-read.js +29 -11
- package/dist/core/extract-shapes.js +122 -41
- package/dist/core/extract-standalone.js +53 -9
- package/dist/core/extract.js +9 -3
- package/dist/core/field-laws.d.ts +4 -0
- package/dist/core/field-laws.js +238 -0
- package/dist/core/finite-frontiers.d.ts +5 -0
- package/dist/core/finite-frontiers.js +116 -0
- package/dist/core/finite-houdini.d.ts +58 -0
- package/dist/core/finite-houdini.js +502 -0
- package/dist/core/finite-model.d.ts +13 -0
- package/dist/core/finite-model.js +68 -0
- package/dist/core/finite-tiny.d.ts +72 -0
- package/dist/core/finite-tiny.js +1080 -0
- package/dist/core/fixtures/count-completion/paxos-decision.json +1 -0
- package/dist/core/fresh.js +5 -1
- package/dist/core/infer.d.ts +1 -1
- package/dist/core/infer.js +76 -38
- package/dist/core/kind.js +2 -1
- package/dist/core/laws.d.ts +2 -1
- package/dist/core/laws.js +47 -14
- package/dist/core/lemma-cuts.d.ts +38 -0
- package/dist/core/lemma-cuts.js +366 -0
- package/dist/core/linear-admission.d.ts +14 -0
- package/dist/core/linear-admission.js +151 -0
- package/dist/core/machine.d.ts +44 -4
- package/dist/core/machine.js +342 -63
- package/dist/core/meter.d.ts +22 -0
- package/dist/core/meter.js +34 -0
- package/dist/core/mutate.d.ts +55 -0
- package/dist/core/mutate.js +210 -0
- package/dist/core/native-domain.d.ts +6 -0
- package/dist/core/native-domain.js +114 -0
- package/dist/core/native-law.d.ts +3 -0
- package/dist/core/native-law.js +174 -0
- package/dist/core/nonterm.js +4 -3
- package/dist/core/prover-row-budget.d.ts +3 -0
- package/dist/core/prover-row-budget.js +106 -0
- package/dist/core/quorum-laws.d.ts +25 -0
- package/dist/core/quorum-laws.js +263 -0
- 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/relational.js +10 -2
- package/dist/core/relevance.d.ts +4 -0
- package/dist/core/relevance.js +79 -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 +5 -0
- package/dist/core/runtime-wall.js +4 -0
- package/dist/core/sample-step.d.ts +16 -0
- package/dist/core/sample-step.js +28 -0
- package/dist/core/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/source-check.d.ts +44 -0
- package/dist/core/source-check.js +126 -0
- package/dist/core/source-diagnostic.d.ts +1 -0
- package/dist/core/source-diagnostic.js +34 -0
- package/dist/core/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/support-budget.d.ts +2 -0
- package/dist/core/support-budget.js +6 -0
- package/dist/core/system.js +6 -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 +11 -0
- package/dist/core/wall.js +37 -0
- package/dist/core/watch.d.ts +1 -1
- package/dist/core/watch.js +15 -2
- 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.d.ts +4 -0
- package/dist/kernel/cdcl.js +109 -41
- package/dist/kernel/epr.js +23 -8
- package/dist/kernel/kernel.d.ts +56 -0
- package/dist/kernel/kernel.js +466 -64
- package/dist/kernel/model-sequence.d.ts +2 -2
- package/dist/kernel/model-sequence.js +4 -3
- package/dist/kernel/model-values.d.ts +2 -0
- package/dist/kernel/model-values.js +60 -0
- package/dist/kernel/prove.d.ts +59 -3
- package/dist/kernel/prove.js +524 -130
- package/dist/kernel/prover-rows.d.ts +30 -0
- package/dist/kernel/prover-rows.js +125 -0
- package/dist/kernel/reader.d.ts +1 -1
- package/dist/kernel/reader.js +57 -12
- package/dist/kernel/simplex.js +9 -2
- package/dist/lean-kernel/emit.d.ts +47 -2
- package/dist/lean-kernel/emit.js +270 -36
- package/dist/lean-kernel/lean-terms.d.ts +1 -0
- package/dist/lean-kernel/lean-terms.js +13 -5
- package/dist/lean-kernel/legacy-family-library.d.ts +1 -0
- package/dist/lean-kernel/legacy-family-library.js +5 -0
- package/dist/lean-kernel/library.js +4 -0
- package/dist/lean-kernel/qalpha.d.ts +7 -0
- package/dist/lean-kernel/qalpha.js +40 -0
- package/package.json +5 -1
package/dist/core/counts.js
CHANGED
|
@@ -1,20 +1,79 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { searchNow as countedSearchNow, traceNow as countedTraceNow, wallDeadline } from "./wall.js";
|
|
2
|
+
import { isLocalCountExpiration } from "./count-tier-budget.js";
|
|
3
|
+
import { withSearchAllowance } from "./count-search-allowance.js";
|
|
4
|
+
import { canUseCountedProxy, withCountedSearchPolicy } from "./search-policy.js";
|
|
5
|
+
import { workRefusalWhy } from "./work-refusal.js";
|
|
6
|
+
import { withEvaluationAdmission } from "./work-observe.js";
|
|
7
|
+
import { finalCountStepDeferralEnabled, closingCountCheck } from "./count-final-step.js";
|
|
8
|
+
import { assumed, checkCountedLaws, checkMC, countedObligations, mcGoal, scope, substC, substE } from "../kernel/kernel.js";
|
|
9
|
+
import { BudgetExpired, brokenOf, clock, counted, fullRate, fullWork, grow, modelInstances, wallAt, widen, withDeadline, withinDeadline, withWall } from "../kernel/prove.js";
|
|
3
10
|
import { REFUTED, cdclStats } from "../kernel/cdcl.js";
|
|
4
11
|
import { modelSequence } from "../kernel/model-sequence.js";
|
|
5
12
|
import { inferLaws } from "./infer.js";
|
|
13
|
+
import { carryCandidates, scanPrefixes } from "./carry.js";
|
|
14
|
+
import { relevantGoals, relevantLaws } from "./relevance.js";
|
|
15
|
+
import { countPoolKey, countSignature, grammarPool, ids, polaritySelection, readTuples, refinementSignature, reservationReadClosure, reservationState, reservePool, prepareSupport, smallSelection, sparseReadInstances, sourceContext, coarseContext, selectedCertificate, chosenView, candidateWork, stableState, UnsupportedCountProposal } from "./count-support.js";
|
|
16
|
+
import { fieldLaws, selectFieldLaws } from "./field-laws.js";
|
|
17
|
+
import { quorumLaws } from "./quorum-laws.js";
|
|
18
|
+
import { countCubes, liftedOneKeyCounts } from "./count-cubes.js";
|
|
19
|
+
import { finiteHoudini } from "./finite-houdini.js";
|
|
20
|
+
import { finiteModelChecker } from "./finite-model.js";
|
|
21
|
+
import { countsForReads, proposeCountFacts } from "./count-facts.js";
|
|
22
|
+
import { completeCountLawInstances } from "./count-completion.js";
|
|
23
|
+
import { rangeInstances, rangeViolations } from "./count-ranges.js";
|
|
24
|
+
import { attemptShare, supportBudget } from "./support-budget.js";
|
|
25
|
+
export { attemptShare, supportBudget } from "./support-budget.js";
|
|
26
|
+
import { proposeCountUnions } from "./count-unions.js";
|
|
27
|
+
import { focusedCountRecoveryEnabled, proveFocusedCounts } from "./count-focus-proof.js";
|
|
28
|
+
import { preferMemberInclusions } from "./count-recovery/member-inclusions.js";
|
|
29
|
+
import { fixedCountFrameCase, ownCountLawInstance, proveCountFrameGoal } from "./count-frames.js";
|
|
30
|
+
import { independentCountInstances } from "./count-focused.js";
|
|
31
|
+
import { admitMemberWitnesses, instantiateMemberPremises, memberHints, memberPremiseState } from "./count-recovery/member-premises.js";
|
|
6
32
|
import { smallOf, trueSmall } from "./exists.js";
|
|
33
|
+
import { WallExpired, checkWall, searchWall } from "./wall.js";
|
|
7
34
|
import { env } from "./solver.js";
|
|
35
|
+
import { proofOrigins, proposeLemmaCuts } from "./lemma-cuts.js";
|
|
36
|
+
import { countedCertificateHyps, transportCountCertificate } from "./count-cert-transport.js";
|
|
37
|
+
import { scopeCountProof, replayScopedCountProof, isCheckedReducedScope, withCountScopeIdentityObservation, countScopeContextKey } from "./count-proof-scope.js";
|
|
38
|
+
import { assertLiftedWorkLease, prepareCountStrategyMachine, proveCountStrategies, proposeCountStrategiesForClosing, proveCountStrategyKind, proposeCountStrategyKindForClosing, selectedCountStrategies } from "./count-strategies.js";
|
|
39
|
+
import { CountRecipeContexts } from "./count-recipe-context.js";
|
|
40
|
+
import { CountRecipePass, runCountRecipeController } from "./count-recipe-controller.js";
|
|
41
|
+
import { discoverLiftedCountGuard, discoverLiftedCountOperations } from "./count-lifted-shape.js";
|
|
42
|
+
import { completeWorkProfile } from "./work-profile.js";
|
|
43
|
+
import { workLedger } from "./work-admission.js";
|
|
44
|
+
import { exactRaw, workAdd, workSub, zeroWork } from "./work-amount.js";
|
|
45
|
+
import { workMap, workFilter, workEntries } from "./work-collections.js";
|
|
46
|
+
import { countTierBudget, remainingCountTierBudget, ordinaryTierShare } from "./count-tier-budget.js";
|
|
47
|
+
import { countRejectionBudget, remainingRejectionAllowance } from "./count-rejection-budget.js";
|
|
48
|
+
import { countGenerationPhase } from "./count-generation-phase.js";
|
|
49
|
+
import { countReachabilityScreen, optionalReachabilityScreen } from "./count-reachability.js";
|
|
50
|
+
import { reconcileReachableRejections, withoutReachableRejections } from "./count-reachability-reconcile.js";
|
|
51
|
+
import { rejectionStage } from "./rejection-discovery.js";
|
|
52
|
+
import { rejectionFamily } from "./rejection-stage.js";
|
|
53
|
+
import { reserveCountClosing, reserveCheckedCountClosing, countOrdinaryUntil } from "./count-closing-budget.js";
|
|
54
|
+
import { rescopeCountProof } from "./count-proof-rescope.js";
|
|
55
|
+
import { countRescopeFunding } from "./count-rescope-funding.js";
|
|
56
|
+
import { countClosingNeeds } from "./count-closing-needs.js";
|
|
57
|
+
import { countPrerequisiteComponents } from "./count-prerequisite-components.js";
|
|
58
|
+
import { countPrerequisiteSchedule } from "./count-prerequisite-plan.js";
|
|
59
|
+
import { countComponentAttemptBudget } from "./count-component-budget.js";
|
|
60
|
+
import { prepareCountPrerequisiteMemory } from "./count-prerequisite-memory.js";
|
|
61
|
+
import { discoverRowAgreement } from "./row-agreement-shape.js";
|
|
62
|
+
import { countPremiseContext } from "./count-premise-view.js";
|
|
63
|
+
import { countPremiseSearch } from "./count-premise-search.js";
|
|
8
64
|
// (GDP_COUNTS_PROF: where a counted search's time goes, by phase, on stderr at the end; `countsDump.on`, set by research's
|
|
9
65
|
// profiles: each step goal left unknown or with a model past GDP_COUNTS_DUMP_MIN (300) hypotheses, the first GDP_COUNTS_DUMP_N (3))
|
|
10
66
|
export const cprof = {};
|
|
11
67
|
export const countsDump = {};
|
|
12
68
|
const tally = (k, n = 1) => { cprof[k] = (cprof[k] ?? 0) + n; };
|
|
13
|
-
const ptime = (k, f) => { const t =
|
|
14
|
-
|
|
69
|
+
const ptime = (k, f) => { const t = countedTraceNow(); try {
|
|
70
|
+
checkWall(k);
|
|
71
|
+
const out = f();
|
|
72
|
+
checkWall(k);
|
|
73
|
+
return out;
|
|
15
74
|
}
|
|
16
75
|
finally {
|
|
17
|
-
cprof[k] = (cprof[k] ?? 0) +
|
|
76
|
+
cprof[k] = (cprof[k] ?? 0) + countedTraceNow() - t;
|
|
18
77
|
} };
|
|
19
78
|
let dumped = 0;
|
|
20
79
|
// (GDP_COUNTS_LAZY=0: every instance and pick certFor proposes in the goal at once, as before; `wide`: the narrow
|
|
@@ -24,15 +83,19 @@ const v = (name) => ({ op: 'var', name }), k = (value) => ({ op: 'const', value
|
|
|
24
83
|
const json = (t) => JSON.stringify(t);
|
|
25
84
|
const one = k(1), zero = k(0);
|
|
26
85
|
// Every term t with `get(map, t)` in t0.
|
|
27
|
-
function reads(t0, map, out = new Map()) {
|
|
86
|
+
function reads(t0, map, out = new Map(), more) {
|
|
28
87
|
const go = (x) => {
|
|
88
|
+
if (more && !more())
|
|
89
|
+
return false;
|
|
29
90
|
if (!x || typeof x !== 'object')
|
|
30
|
-
return;
|
|
91
|
+
return true;
|
|
31
92
|
const o = x;
|
|
32
93
|
if (o.op === 'get' && map(o.map))
|
|
33
94
|
out.set(json([o.map, o.key]), [o.map, o.key]);
|
|
34
95
|
for (const y of Object.values(o))
|
|
35
|
-
go(y)
|
|
96
|
+
if (!go(y))
|
|
97
|
+
return false;
|
|
98
|
+
return true;
|
|
36
99
|
};
|
|
37
100
|
go(t0);
|
|
38
101
|
return out;
|
|
@@ -41,6 +104,7 @@ const mentions = (t, name) => json(t).includes(`"name":${json(name)}`);
|
|
|
41
104
|
// Whether some object within t0 meets p (a condition nested in a term's `if` too).
|
|
42
105
|
const some = (t0, p) => !!t0 && typeof t0 === 'object' && (p(t0) || Object.values(t0).some(y => some(y, p)));
|
|
43
106
|
const atoms = (c) => (c.op === 'and' || c.op === 'or' ? c.xs.flatMap(atoms) : c.op === 'not' ? atoms(c.x) : [c]);
|
|
107
|
+
const quorumCandidates = new WeakSet();
|
|
44
108
|
// --- candidates from the guard's shape -----------------------------------------------------------------------------------
|
|
45
109
|
export function guardLaws(m) {
|
|
46
110
|
const counts = {}, laws = [];
|
|
@@ -73,6 +137,14 @@ export function guardLaws(m) {
|
|
|
73
137
|
}
|
|
74
138
|
}
|
|
75
139
|
}
|
|
140
|
+
// Lift row-majority bodies beside the stored-set loop. Their laws are admitted
|
|
141
|
+
// after the old candidate families; merely recognizing a shape trusts nothing.
|
|
142
|
+
const lifted = quorumLaws(m);
|
|
143
|
+
Object.assign(counts, lifted.counts);
|
|
144
|
+
for (const law of lifted.laws) {
|
|
145
|
+
laws.push(law);
|
|
146
|
+
quorumCandidates.add(law);
|
|
147
|
+
}
|
|
76
148
|
for (const [mp, w] of Object.entries(m.step.maps ?? {})) {
|
|
77
149
|
// (the written key: a request's value t, or two, t and u, composed N·t + u (a relation's cell): a count of two
|
|
78
150
|
// parameters, read at the law's N·a + b with b < N)
|
|
@@ -197,91 +269,145 @@ export function guardLaws(m) {
|
|
|
197
269
|
// The count cells the goal reads (each before the step with its post name's twin), instances over pairs of them with one
|
|
198
270
|
// bound (a count that doesn't drop, +1 and −1; two that meet, +1, +1 and −1), each with a fresh witness; and the laws and
|
|
199
271
|
// quantified flags at the witnesses (returned, for the goal's law's instances).
|
|
200
|
-
export function certFor(goal, decls, wide = false, most = wide ? 24 : 10) {
|
|
201
|
-
const byMap = new Map(decls.map(d => [d.map, d])), last = goal.hyps.at(-1);
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
const all0 = [...reads(goal.hyps, mp => byMap.has(mp)).values()], inLast = [...reads(last, mp => byMap.has(mp)).keys()];
|
|
272
|
+
export function certFor(goal, decls, wide = false, most = wide ? 24 : 10, more, structured = true) {
|
|
273
|
+
const tick = more ?? (() => true), byMap = new Map(decls.map(d => [d.map, d])), last = goal.hyps.at(-1), lastText = json(last);
|
|
274
|
+
const own = (t) => t.op === 'const' || (t.op === 'var' && lastText.includes(`"name":${json(t.name)}`));
|
|
275
|
+
const all0 = [...reads(goal.hyps, mp => byMap.has(mp), new Map(), more).values()], inLast = [...reads(last, mp => byMap.has(mp), new Map(), more).keys()];
|
|
205
276
|
const rank = ([mp, t]) => (inLast.includes(json([mp, t])) ? 0 : own(t) ? 1 : 2);
|
|
206
277
|
const rs = all0.sort((x, y) => rank(x) - rank(y));
|
|
207
|
-
|
|
208
|
-
|
|
278
|
+
for (const [mp, t] of [...rs]) {
|
|
279
|
+
if (!tick())
|
|
280
|
+
break;
|
|
209
281
|
if (mp.endsWith('#') && byMap.has(mp.slice(0, -1)) && !rs.some(([m2, t2]) => m2 === mp.slice(0, -1) && json(t2) === json(t)))
|
|
210
282
|
rs.push([mp.slice(0, -1), t]);
|
|
211
|
-
|
|
283
|
+
}
|
|
212
284
|
const once = new Set(), keyless = (mp) => { const d = byMap.get(mp); return !mentions([d.below, d.body], d.j); };
|
|
213
285
|
const rs1 = rs.filter(([mp]) => !keyless(mp) || (!once.has(mp) && !!once.add(mp)));
|
|
214
|
-
const named = rs1.map(([mp, t], i) => [
|
|
215
|
-
const
|
|
216
|
-
const
|
|
217
|
-
const add = (terms, unit, below) => { const w = `w$${insts.length}`; wits.push(w); insts.push({ wit: w, below, terms, unit }); };
|
|
218
|
-
// first: a count after the step at least each other one (it doesn't drop; what the step adds); then two counts before it
|
|
219
|
-
// that meet, the first of the pair one the conclusion or the law's own names read; then the rest at most another
|
|
286
|
+
const named = rs1.map(([mp, t], i) => ['r' + '$' + i, mp, t]), bound = (r) => json(byMap.get(r[1]).below);
|
|
287
|
+
const insts = [], wits = [], cap = most, initialCap = wide ? Math.min(10, cap) : cap;
|
|
288
|
+
const add = (terms, unit, below) => { const w = 'w' + '$' + insts.length; wits.push(w); insts.push({ wit: w, below, terms, unit }); };
|
|
220
289
|
const post = (r) => r[1].endsWith('#'), ranked = (r) => rank([r[1], r[2]]) <= 1;
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
290
|
+
// Stop enumeration as soon as the requested prefix is complete. Later entries
|
|
291
|
+
// were sliced away before too; the order and contents of completed prefixes stay exact.
|
|
292
|
+
initial: {
|
|
293
|
+
for (const c of named)
|
|
294
|
+
if (post(c))
|
|
295
|
+
for (const a of named) {
|
|
296
|
+
if ((!!more && insts.length >= initialCap) || !tick())
|
|
297
|
+
break initial;
|
|
298
|
+
if (a !== c && !post(a) && bound(a) === bound(c))
|
|
299
|
+
add([[1, a[0]], [-1, c[0]]], 0, byMap.get(c[1]).below);
|
|
300
|
+
}
|
|
301
|
+
for (const [i, a] of named.entries())
|
|
302
|
+
for (const [j, c] of named.entries()) {
|
|
303
|
+
if ((!!more && insts.length >= initialCap) || !tick())
|
|
304
|
+
break initial;
|
|
305
|
+
if (i < j && (ranked(a) || ranked(c)) && bound(a) === bound(c) && !post(a) && !post(c))
|
|
306
|
+
add([[1, a[0]], [1, c[0]]], -1, byMap.get(a[1]).below);
|
|
307
|
+
}
|
|
308
|
+
for (const [i, a] of named.entries())
|
|
309
|
+
for (const [j, c] of named.entries()) {
|
|
310
|
+
if ((!!more && insts.length >= initialCap) || !tick())
|
|
311
|
+
break initial;
|
|
312
|
+
if (i < j && !(ranked(a) || ranked(c)) && bound(a) === bound(c) && !post(a) && !post(c))
|
|
313
|
+
add([[1, a[0]], [1, c[0]]], -1, byMap.get(a[1]).below);
|
|
314
|
+
}
|
|
315
|
+
for (const c of named)
|
|
316
|
+
if (post(c) && rank([c[1], c[2]]) === 0)
|
|
317
|
+
for (const a of named)
|
|
318
|
+
for (const d of named) {
|
|
319
|
+
if ((!!more && insts.length >= initialCap) || !tick())
|
|
320
|
+
break initial;
|
|
321
|
+
if (a !== d && !post(a) && !post(d) && keyless(a[1]) && keyless(d[1]) && bound(a) === bound(c) && bound(d) === bound(c))
|
|
322
|
+
add([[1, a[0]], [-1, d[0]], [-1, c[0]]], 0, byMap.get(c[1]).below);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
246
325
|
if (wide) {
|
|
247
|
-
insts.splice(10)
|
|
248
|
-
|
|
249
|
-
|
|
326
|
+
insts.splice(10);
|
|
327
|
+
wits.splice(10);
|
|
328
|
+
pairs: for (const a of named)
|
|
329
|
+
for (const c of named) {
|
|
330
|
+
if ((!!more && insts.length >= cap) || !tick())
|
|
331
|
+
break pairs;
|
|
250
332
|
if (a !== c && bound(a) === bound(c) && !(post(c) && !post(a)))
|
|
251
333
|
add([[1, a[0]], [-1, c[0]]], 0, byMap.get(a[1]).below);
|
|
252
|
-
|
|
334
|
+
}
|
|
335
|
+
for (const a of named) {
|
|
336
|
+
if ((!!more && insts.length >= cap) || !tick())
|
|
337
|
+
break;
|
|
253
338
|
add([[1, a[0]]], 0, byMap.get(a[1]).below);
|
|
254
|
-
|
|
339
|
+
}
|
|
255
340
|
if (cap > 24) {
|
|
256
|
-
for (const a of named)
|
|
341
|
+
for (const a of named) {
|
|
342
|
+
if ((!!more && insts.length >= cap) || !tick())
|
|
343
|
+
break;
|
|
257
344
|
add([[1, a[0]]], -1, byMap.get(a[1]).below);
|
|
345
|
+
}
|
|
258
346
|
const had = new Set(insts.map(i => json([i.terms, i.unit])));
|
|
259
|
-
for (const [i, a] of named.entries())
|
|
260
|
-
for (const [j, c] of named.entries())
|
|
347
|
+
meets: for (const [i, a] of named.entries())
|
|
348
|
+
for (const [j, c] of named.entries()) {
|
|
349
|
+
if ((!!more && insts.length >= cap) || !tick())
|
|
350
|
+
break meets;
|
|
261
351
|
if (i < j && bound(a) === bound(c) && post(a) === post(c) && !had.has(json([[[1, a[0]], [1, c[0]]], -1])))
|
|
262
352
|
add([[1, a[0]], [1, c[0]]], -1, byMap.get(a[1]).below);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
// Structured identities supplement the legacy pool; they must not displace
|
|
356
|
+
// its witness prefix at the same cap. Both generators remain available on
|
|
357
|
+
// expansion; every proposal is checked as an ordinary witness certificate.
|
|
358
|
+
// Do not construct a tail that the unchanged cap would immediately discard.
|
|
359
|
+
const cs = structured && insts.length < cap ? countsForReads(decls, named) : undefined;
|
|
360
|
+
if (cs && tick()) {
|
|
361
|
+
const facts = proposeCountFacts(cs, goal, { maxFacts: Math.min(cap, 256), reserved: wits });
|
|
362
|
+
for (const q of facts.insts) {
|
|
363
|
+
if ((!!more && insts.length >= cap) || !tick())
|
|
364
|
+
break;
|
|
365
|
+
if (q.terms.length >= 3)
|
|
366
|
+
add(q.terms, q.unit, q.below);
|
|
367
|
+
}
|
|
368
|
+
const heads = named.filter(r => ranked(r)).sort((a, b) => Number(post(b)) - Number(post(a)));
|
|
369
|
+
const carried = named.filter(r => !post(r) && keyless(r[1]));
|
|
370
|
+
const pairs = heads.flatMap(a => carried.filter(b => b !== a && bound(a) === bound(b)).map(b => [a[0], b[0]]));
|
|
371
|
+
for (const q of proposeCountUnions(cs, pairs, Math.min(cap, 128))) {
|
|
372
|
+
if ((!!more && insts.length >= cap) || !tick())
|
|
373
|
+
break;
|
|
374
|
+
add(q.terms, q.unit, q.below);
|
|
375
|
+
}
|
|
263
376
|
}
|
|
264
377
|
}
|
|
265
|
-
// (wide: each count picked at the keys the goal reads the maps its body reads at its key and its instances' witnesses:
|
|
266
|
-
// at least its body there, at every two of them and at all of them)
|
|
267
378
|
const picks = [];
|
|
379
|
+
// A counted member can be one component of a tuple/packed key, not only
|
|
380
|
+
// the whole map key. These are candidate naturals, never inverse-function
|
|
381
|
+
// axioms: mcGoal/checkMC still check the count body at every picked key.
|
|
382
|
+
const memberKeys = (pattern, term, key) => {
|
|
383
|
+
if (pattern.op === 'var')
|
|
384
|
+
return pattern.name === key ? [term] : [];
|
|
385
|
+
if (pattern.op !== term.op)
|
|
386
|
+
return [];
|
|
387
|
+
const p = pattern, t = term;
|
|
388
|
+
return ['a', 'b', 'key', 'then', 'else'].flatMap(k => p[k] && t[k] ? memberKeys(p[k], t[k], key) : []);
|
|
389
|
+
};
|
|
268
390
|
if (wide)
|
|
269
391
|
for (const r of named) {
|
|
270
|
-
|
|
392
|
+
if (!tick())
|
|
393
|
+
break;
|
|
394
|
+
const d = byMap.get(r[1]), at = [...reads(d.body, () => true, new Map(), more).values()].filter(([, key]) => mentions(key, d.key));
|
|
271
395
|
if (!at.length)
|
|
272
396
|
continue;
|
|
273
397
|
// (the key terms the goal reads those maps at, and the witnesses of the instances that name this count: a member the
|
|
274
398
|
// counting lemma found is a key too; three of each first, six at most)
|
|
275
|
-
const
|
|
399
|
+
const candidates = [...reads(goal.hyps, mp => at.some(([p]) => p === mp), new Map(), more).values()].flatMap(([mp, t]) => at.filter(([p]) => p === mp).flatMap(([, pattern]) => memberKeys(pattern, t, d.key)));
|
|
400
|
+
const gs = [...new Map(candidates.map(t => [json(t), t])).values()].filter(t => !mentions(t, d.key));
|
|
276
401
|
const ws = insts.slice(0, cap).filter(i => i.terms.some(([, x]) => x === r[0])).map(i => v(i.wit)), ts0 = [...gs.slice(0, 3), ...ws.slice(0, 3), ...gs.slice(3), ...ws.slice(3)];
|
|
277
402
|
const ts = [...new Map(ts0.map(t => [json(t), t])).values()].slice(0, 6);
|
|
403
|
+
for (const t of ts)
|
|
404
|
+
picks.push([r[0], [t]]);
|
|
278
405
|
for (let i = 0; i < ts.length; i++)
|
|
279
406
|
for (let j = i + 1; j < ts.length; j++)
|
|
280
407
|
picks.push([r[0], [ts[i], ts[j]]]);
|
|
281
408
|
if (ts.length > 2)
|
|
282
409
|
picks.push([r[0], ts]);
|
|
283
410
|
}
|
|
284
|
-
// (loose: a read no instance among the first ten names, which only widening ties to its cells)
|
|
285
411
|
const loose = named.some(r => !insts.slice(0, 10).some(i => i.terms.some(([, x]) => x === r[0])));
|
|
286
412
|
return { reads: named, insts: insts.slice(0, cap), wits: wits.slice(0, cap), picks, loose };
|
|
287
413
|
}
|
|
@@ -290,7 +416,8 @@ export function certFor(goal, decls, wide = false, most = wide ? 24 : 10) {
|
|
|
290
416
|
// small instances reach; the guards' count comparisons (guardLaws, `guarded`); one key a row; the engine's minimal ∀
|
|
291
417
|
// cubes of at most two literals (core/infer.ts's `cubes`, read off these small states, within a quarter of the search's
|
|
292
418
|
// budget `ms`, 15 s at most), its template `shapes` (the caller's laws, or an ∃ law's frame), each guard `u < param` loosened where a caller reads u with no param bound.
|
|
293
|
-
export function candidates(src, m, caller, shapes, guarded, ms, until) {
|
|
419
|
+
export function candidates(src, m, caller, shapes, guarded, ms, until, support = new Set(), publish) {
|
|
420
|
+
const source = 'machine' in src ? src.machine : src;
|
|
294
421
|
const states = ptime('small', () => smallOf(m));
|
|
295
422
|
// (a law of the state only: one the kernel's scope refuses, reading an input or a count of the request (a guard's
|
|
296
423
|
// comparison with a second request count), has no value at a state, and is not proposed)
|
|
@@ -298,7 +425,9 @@ export function candidates(src, m, caller, shapes, guarded, ms, until) {
|
|
|
298
425
|
scope(m, [l]);
|
|
299
426
|
return true;
|
|
300
427
|
}
|
|
301
|
-
catch {
|
|
428
|
+
catch (error) {
|
|
429
|
+
if (publish && error instanceof BudgetExpired)
|
|
430
|
+
throw error;
|
|
302
431
|
return false;
|
|
303
432
|
} };
|
|
304
433
|
const trueAll = (l) => clock() < until && ofState(l) && trueSmall(m, [l]);
|
|
@@ -343,7 +472,10 @@ export function candidates(src, m, caller, shapes, guarded, ms, until) {
|
|
|
343
472
|
const w = { ...c, name: name === c.name ? `${c.name} (any ${shown.join(', ')})` : name, holds: { op: 'or', xs: c.holds.xs.map(d => (d.op === 'not' ? { op: 'not', x: { op: 'and', xs: conjs(d.x).filter(keep) } } : d)) } };
|
|
344
473
|
return trueAll(w) ? w : c;
|
|
345
474
|
};
|
|
346
|
-
const
|
|
475
|
+
const loadedFields = env.GDP_COUNT_STRATEGIES === '1';
|
|
476
|
+
const cubes = cubes0.map(loosened), fields = fieldLaws(m, false, loadedFields);
|
|
477
|
+
const lifted = guarded.filter(l => quorumCandidates.has(l)), ordinary = guarded.filter(l => !quorumCandidates.has(l));
|
|
478
|
+
const newFields = fieldLaws(m, true, loadedFields).slice(fields.length, fields.length + Math.max(0, 32 - lifted.length));
|
|
347
479
|
if (env.GDP_COUNTS_TRACE)
|
|
348
480
|
console.error(`counts: small ${states.map(({ sts }) => sts.length).join('/')}; cubes ${cubes.length} in ${Math.round(clock() - t1)} ms: ${cubes.map(l => l.name).join('; ')}`);
|
|
349
481
|
// (a candidate whose every conjunct a law before it states, its keys named apart by place, is not proposed again: a
|
|
@@ -355,13 +487,69 @@ export function candidates(src, m, caller, shapes, guarded, ms, until) {
|
|
|
355
487
|
for (const l of caller)
|
|
356
488
|
for (const q of parts(l))
|
|
357
489
|
said.add(q);
|
|
358
|
-
const
|
|
490
|
+
const prefixes = scanPrefixes(m, [...caller, ...kinds, ...guarded, ...rowLaws, ...cubes]);
|
|
491
|
+
const admitted = publish ? [] : undefined;
|
|
492
|
+
const admit = (l) => { const ps = parts(l); if (ps.every(q => said.has(q)) || !trueAll(l))
|
|
359
493
|
return false; for (const q of ps)
|
|
360
|
-
said.add(q);
|
|
494
|
+
said.add(q); if (admitted) {
|
|
495
|
+
admitted.push(l);
|
|
496
|
+
publish?.(admitted.slice());
|
|
497
|
+
} return true; };
|
|
498
|
+
let out = ptime('filter', () => [...kinds, ...ordinary, ...rowLaws, ...fields, ...prefixes, ...cubes].filter(admit));
|
|
499
|
+
const carried = carryCandidates(m, [...caller, ...kinds, ...guarded, ...rowLaws, ...cubes]);
|
|
500
|
+
out.push(...ptime('filter', () => carried.filter(admit)));
|
|
501
|
+
// (a guarded field law is a weakening: admitted only when the stronger form it weakens was not)
|
|
502
|
+
out.push(...ptime('quorumFilter', () => loadedFields ? selectFieldLaws([...lifted, ...newFields], admit) : [...lifted, ...newFields].filter(admit)));
|
|
503
|
+
if (lifted.length) {
|
|
504
|
+
// Counts used only by rejected liftings must not spawn another family.
|
|
505
|
+
const liftedCounts = new Set([...reads([...caller, ...out], mp => !!m.counts?.[mp]).values()].map(([mp]) => mp));
|
|
506
|
+
for (const name of liftedCounts)
|
|
507
|
+
for (const [mp] of reads(m.counts[name].body, () => true).values())
|
|
508
|
+
if (m.counts?.[mp])
|
|
509
|
+
liftedCounts.add(mp);
|
|
510
|
+
if (liftedOneKeyCounts(source, m).some(name => liftedCounts.has(name))) {
|
|
511
|
+
out.push(...ptime('countCubes', () => countCubes(source, m, states, liftedCounts).filter(admit)));
|
|
512
|
+
out = ptime('finiteHoudini', () => finiteHoudini(source, m, caller, out, states, {
|
|
513
|
+
// Deterministic generation prefix: proposals, predecessor checks and
|
|
514
|
+
// request trials share one allowance, not a machine-speed wall stop.
|
|
515
|
+
...(loadedFields ? { workLimit: 2_000 } : {}),
|
|
516
|
+
onFinish: row => { if (env.GDP_COUNTS_TRACE)
|
|
517
|
+
console.error(`counts: finite result ${JSON.stringify(row)}`); },
|
|
518
|
+
onDrop: d => { if (env.GDP_COUNTS_TRACE)
|
|
519
|
+
console.error(`counts: finite drop ${d.round} ${d.law.name}`); },
|
|
520
|
+
onRound: row => { if (env.GDP_COUNTS_TRACE)
|
|
521
|
+
console.error(`counts: finite Houdini ${JSON.stringify(row)}`); },
|
|
522
|
+
}));
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
// A rejected proposal must not enlarge every later counted goal. Retain only
|
|
526
|
+
// lifted counts read by an admitted law (and their transitive dependencies).
|
|
527
|
+
const proposed = new Set([...reads(lifted, mp => !!m.counts?.[mp]).values()].map(([mp]) => mp));
|
|
528
|
+
const used = new Set([...reads([...caller, ...out], () => true).values()].map(([mp]) => mp));
|
|
529
|
+
for (const name of used)
|
|
530
|
+
if (m.counts?.[name])
|
|
531
|
+
for (const [mp] of reads(m.counts[name].body, () => true).values())
|
|
532
|
+
used.add(mp);
|
|
533
|
+
for (const name of proposed)
|
|
534
|
+
if (!used.has(name))
|
|
535
|
+
delete m.counts[name];
|
|
536
|
+
for (const l of out)
|
|
537
|
+
if (prefixes.includes(l) || carried.includes(l))
|
|
538
|
+
support.add(l);
|
|
361
539
|
if (env.GDP_COUNTS_TRACE)
|
|
362
|
-
console.error(`counts: ${kinds.length + guarded.length + rowLaws.length + cubes.length - out.length} candidates said before or false on the small instances`);
|
|
540
|
+
console.error(`counts: ${kinds.length + guarded.length + rowLaws.length + fields.length + prefixes.length + carried.length + cubes.length - out.length} candidates said before or false on the small instances`);
|
|
363
541
|
return out;
|
|
364
542
|
}
|
|
543
|
+
// Recovery proposals must not consume a successful ordinary attempt's allowance.
|
|
544
|
+
// A deferred proposal keeps the latest warmed context, but never extends its deadline.
|
|
545
|
+
export function withDeferredCountRecovery(until, attempt, ready = () => true) {
|
|
546
|
+
let recover;
|
|
547
|
+
const ordinary = attempt(next => { recover = next; });
|
|
548
|
+
if ('proof' in ordinary || ordinary.refuted === true || !recover || !ready() || clock() >= until)
|
|
549
|
+
return ordinary;
|
|
550
|
+
const proof = recover();
|
|
551
|
+
return proof === undefined ? ordinary : { proof };
|
|
552
|
+
}
|
|
365
553
|
export function cone(m, set, attempt, until, houdini = false) {
|
|
366
554
|
const kept = new Map(), inCone = (l) => kept.has(l.name), tried = new Map(), times = new Map(), asked = new Set(), slow = new Set();
|
|
367
555
|
const stopAt = until - (until - clock()) / 3, brief = (stopAt - clock()) / Math.max(1, set.length);
|
|
@@ -411,32 +599,982 @@ export function cone(m, set, attempt, until, houdini = false) {
|
|
|
411
599
|
while (tier(2) && clock() < stopAt);
|
|
412
600
|
return kept;
|
|
413
601
|
}
|
|
602
|
+
// --- the counted search ----------------------------------------------------------------------------------------------
|
|
603
|
+
// Scheduling only. Candidate membership never authorizes an assumption or a result.
|
|
604
|
+
export const activeSupport = (set, support) => set.some(l => support.has(l));
|
|
605
|
+
// A selected row strategy runs before either ordinary pass, never after a
|
|
606
|
+
// count-first attempt has already consumed its share. Default order is unchanged.
|
|
607
|
+
function firstCountPass(m, law, countFirst) {
|
|
608
|
+
return countFirst && !(env.GDP_COUNT_STRATEGIES === '1' && discoverRowAgreement(m, law)) ? 1 : 0;
|
|
609
|
+
}
|
|
610
|
+
// Count-specific scheduling needs count or global-state context, not merely a
|
|
611
|
+
// primitive pointwise implication. Otherwise preserve the ordinary family first.
|
|
612
|
+
export function countSupportContext(m, caller, set, support) {
|
|
613
|
+
if (!activeSupport(set, support) || set.some(l => support.has(l) && (reads(l.holds, map => !!m.counts?.[map]).size || !l.forall && some(l.holds, node => node.op === 'var' && typeof node.name === 'string' && Object.hasOwn(m.state, node.name) && !l.some?.includes(node.name)))))
|
|
614
|
+
return { laws: set, support };
|
|
615
|
+
return { laws: set.filter(l => caller.includes(l) || !support.has(l)), support: new Set() };
|
|
616
|
+
}
|
|
617
|
+
export function supportOrder(set, caller, support, forModels = false, m) {
|
|
618
|
+
if (forModels && !activeSupport(set, support))
|
|
619
|
+
return set;
|
|
620
|
+
const ordered = !activeSupport(set, support)
|
|
621
|
+
? [...set.filter(l => !caller.includes(l)), ...set.filter(l => caller.includes(l))]
|
|
622
|
+
: [...set.filter(l => support.has(l) && !caller.includes(l)), ...set.filter(l => caller.includes(l)), ...set.filter(l => !support.has(l) && !caller.includes(l))];
|
|
623
|
+
// Admission order only: keep model hypotheses, family membership, support
|
|
624
|
+
// status and every per-attempt allowance unchanged.
|
|
625
|
+
if (forModels || !m)
|
|
626
|
+
return ordered;
|
|
627
|
+
const countReaders = new Set(ordered.filter(l => reads(l.holds, mp => !!m.counts?.[mp]).size > 0));
|
|
628
|
+
if (env.GDP_COUNT_STRATEGIES === '1') {
|
|
629
|
+
const rows = new Set(ordered.filter(l => !countReaders.has(l) && discoverRowAgreement(m, l)));
|
|
630
|
+
if (rows.size) {
|
|
631
|
+
const ordinary = ordered.filter(l => !countReaders.has(l) && !rows.has(l));
|
|
632
|
+
return [...ordered.filter(l => countReaders.has(l)), ...ordered.filter(l => rows.has(l)),
|
|
633
|
+
...ordinary.filter(l => support.has(l) && !caller.includes(l)), ...ordinary.filter(l => caller.includes(l)),
|
|
634
|
+
...ordinary.filter(l => !support.has(l) && !caller.includes(l))];
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
if (!countReaders.size)
|
|
638
|
+
return ordered;
|
|
639
|
+
return [...ordered.filter(l => countReaders.has(l)),
|
|
640
|
+
...ordered.filter(l => !countReaders.has(l) && support.has(l) && !caller.includes(l)),
|
|
641
|
+
...ordered.filter(l => !countReaders.has(l) && caller.includes(l)),
|
|
642
|
+
...ordered.filter(l => !countReaders.has(l) && !support.has(l) && !caller.includes(l))];
|
|
643
|
+
}
|
|
644
|
+
// Observation only. The controller catches observer failures; they never
|
|
645
|
+
// replace the production native verdict or replenish its work allowance.
|
|
646
|
+
export const countRecipeClosingCapture = {};
|
|
414
647
|
// On the counted clock (kernel/prove.ts's `counted`, the cost model's work at fullRate a millisecond), as the engine's
|
|
415
|
-
// search is:
|
|
416
|
-
// wall
|
|
417
|
-
//
|
|
418
|
-
//
|
|
419
|
-
//
|
|
648
|
+
// search is: counted fuel and ordering are unchanged up to the wall cutoff. The
|
|
649
|
+
// wall is an independent hard ceiling, including sampling and generation. A slow
|
|
650
|
+
// machine may stop earlier on the same counted-work prefix, never get extra time.
|
|
651
|
+
// The ordinary family gets its complete existing path first. Structured
|
|
652
|
+
// witness families are retried only after failure, under the same absolute
|
|
653
|
+
// deadline and counted fuel; no generated family is removed.
|
|
654
|
+
function structuredFallback(until, attempt) {
|
|
655
|
+
const ordinary = attempt(false);
|
|
656
|
+
if (ordinary.proven || clock() >= until)
|
|
657
|
+
return ordinary;
|
|
658
|
+
checkWall('structured fallback');
|
|
659
|
+
countsDump.on?.({ phase: 'structured-family-expansion' });
|
|
660
|
+
const structured = attempt(true);
|
|
661
|
+
// A local refusal may have crossed the direct caller's inherited phase.
|
|
662
|
+
// Check before withDeadline restores that phase on the return path.
|
|
663
|
+
checkWall('structured fallback completion');
|
|
664
|
+
return structured;
|
|
665
|
+
}
|
|
420
666
|
export function searchCounted(m0, caller, ms = 60_000) {
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
const run = () =>
|
|
667
|
+
const reject = env.GDP_COUNT_REJECTIONS === '1' && env.GDP_COUNT_TIERS === '1' && env.GDP_COUNT_STRATEGIES === '1';
|
|
668
|
+
let m = m0, rejecting = false;
|
|
669
|
+
const run = () => {
|
|
670
|
+
const result = withWall(searchWall(ms), () => {
|
|
671
|
+
try {
|
|
672
|
+
const start = reject ? fullWork() / fullRate : 0;
|
|
673
|
+
const g = ptime('guards', () => guardLaws(m0));
|
|
674
|
+
m = { ...m0, counts: { ...m0.counts, ...g.counts } };
|
|
675
|
+
if (reject && g.laws.some(law => quorumCandidates.has(law))) {
|
|
676
|
+
rejecting = true;
|
|
677
|
+
return withCountedSearchPolicy(true, () => counted(fullRate, () => searchCounted0(m0, g, m, caller, ms, remainingCountTierBudget(start, ms, 1)), true));
|
|
678
|
+
}
|
|
679
|
+
// Leave the native preparation wall before selecting a legacy proxy.
|
|
680
|
+
// Locked rejecting ancestors and ordinary legacy mode keep the old path.
|
|
681
|
+
if (canUseCountedProxy())
|
|
682
|
+
return () => withCountedSearchPolicy(false, () => withWall(searchWall(ms), () => {
|
|
683
|
+
try {
|
|
684
|
+
ptime('small', () => smallOf(m, m0));
|
|
685
|
+
return counted(fullRate, () => searchCounted0(m0, g, m, caller, ms), true);
|
|
686
|
+
}
|
|
687
|
+
catch (error) {
|
|
688
|
+
if (!(error instanceof WallExpired))
|
|
689
|
+
throw error;
|
|
690
|
+
return { proven: false, laws: caller, m, why: error.message };
|
|
691
|
+
}
|
|
692
|
+
}));
|
|
693
|
+
ptime('small', () => smallOf(m, m0));
|
|
694
|
+
return counted(fullRate, () => searchCounted0(m0, g, m, caller, ms), true);
|
|
695
|
+
}
|
|
696
|
+
catch (e) {
|
|
697
|
+
if (!(e instanceof WallExpired) && !(rejecting && e instanceof BudgetExpired))
|
|
698
|
+
throw e;
|
|
699
|
+
return { proven: false, laws: caller, m, why: e instanceof BudgetExpired ? workRefusalWhy(e) : e.message };
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
return typeof result === 'function' ? result() : result;
|
|
703
|
+
};
|
|
424
704
|
if (!env.GDP_COUNTS_PROF)
|
|
425
705
|
return run();
|
|
426
706
|
cdclStats.on = true;
|
|
427
|
-
const t =
|
|
428
|
-
console.error(`counts: prof total ${Math.round(
|
|
707
|
+
const t = countedSearchNow(), out = run();
|
|
708
|
+
console.error(`counts: prof total ${Math.round(countedSearchNow() - t)} ms; ${Object.entries(cprof).map(([k2, x]) => `${k2} ${Math.round(x)}`).join(', ')}; cdcl runs ${cdclStats.runs} conflicts ${cdclStats.conflicts} decisions ${cdclStats.decisions} solveMs ${Math.round(cdclStats.solveMs)} rowsMs ${Math.round(cdclStats.rowsMs)} coreMs ${Math.round(cdclStats.coreMs)} unfoldMs ${Math.round(cdclStats.unfoldMs)} lpMs ${Math.round(cdclStats.lpMs)} boundMs ${Math.round(cdclStats.boundMs)} orderMs ${Math.round(cdclStats.orderMs)} fmCalls ${cdclStats.fmCalls} lpMisses ${cdclStats.lpMisses} lpUnknown ${cdclStats.lpUnknown} missMs ${Math.round(cdclStats.missMs)} fastMs ${Math.round(cdclStats.fastMs)} fmOpenMs ${Math.round(cdclStats.fmOpenMs)} fmLeafMs ${Math.round(cdclStats.fmLeafMs)} nodes ${cdclStats.nodes}`);
|
|
429
709
|
return out;
|
|
430
710
|
}
|
|
431
|
-
function searchCounted0(m0, g, m, caller, ms) {
|
|
432
|
-
|
|
711
|
+
function searchCounted0(m0, g, m, caller, ms, tiers) {
|
|
712
|
+
if (tiers)
|
|
713
|
+
return searchCountedWithRejection(m0, g, m, caller, ms, tiers);
|
|
714
|
+
const tierRun = { start: clock(), source: m0 }, until = tierRun.start + ms;
|
|
433
715
|
if (!caller.every(l => clock() < until && trueSmall(m, [l])))
|
|
434
716
|
return { proven: false, laws: caller, m, why: clock() < until ? 'a law fails on the small instances' : 'time' };
|
|
435
717
|
const t1 = clock();
|
|
436
718
|
// (GDP_COUNTS_GIVEN=1, research's: the callers alone, no candidate: whether a set written whole goes through)
|
|
437
|
-
|
|
719
|
+
const support = new Set();
|
|
720
|
+
let set = env.GDP_COUNTS_GIVEN === '1' ? [...caller] : [...caller, ...candidates(m0, m, caller, caller, g.laws, ms, until, support)];
|
|
721
|
+
countsDump.on?.({ phase: 'candidates', machine: m, laws: set });
|
|
438
722
|
if (env.GDP_COUNTS_TRACE)
|
|
439
723
|
console.error(`counts: candidates at ${Math.round(clock() - t1)} ms: ${set.map(l => l.name).join('; ')}`);
|
|
724
|
+
const context = countSupportContext(m, caller, set, support);
|
|
725
|
+
return structuredFallback(until, structured => {
|
|
726
|
+
const result = admitCountedFamilyOnce(m, caller, context.laws, context.support, until, structured, tierRun);
|
|
727
|
+
// Preserve full-context fallback before trying extra witness families.
|
|
728
|
+
return result.proven || context.laws.length === set.length || clock() >= until ? result : admitCountedFamilyOnce(m, caller, set, context.support, until, structured, tierRun);
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
// Production rejection is a relative size-two pass inside the existing generation
|
|
732
|
+
// tier. Its single ledger and absolute endpoints survive every admission fallback.
|
|
733
|
+
function searchCountedWithRejection(m0, g, m, caller, ms, tiers) {
|
|
734
|
+
const plan = countRejectionBudget(tiers, true);
|
|
735
|
+
if (!plan)
|
|
736
|
+
return searchCounted0(m0, g, m, caller, ms);
|
|
737
|
+
const until = tiers.until, tierRun = { start: until - tiers.workAllowance, budget: tiers, source: m0 }, support = new Set(), originalCounts = { ...m.counts };
|
|
738
|
+
let partial = [...caller];
|
|
739
|
+
const generated = countGenerationPhase(plan.captureUntil, () => {
|
|
740
|
+
for (const law of g.laws) {
|
|
741
|
+
try {
|
|
742
|
+
scope(m, [law]);
|
|
743
|
+
partial.push(law);
|
|
744
|
+
}
|
|
745
|
+
catch (error) {
|
|
746
|
+
if (error instanceof BudgetExpired)
|
|
747
|
+
throw error;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
ptime('small', () => smallOf(m, m0));
|
|
751
|
+
if (!caller.every(law => clock() < until && trueSmall(m, [law])))
|
|
752
|
+
return { valid: false, set: [...caller] };
|
|
753
|
+
const set = env.GDP_COUNTS_GIVEN === '1' ? [...caller] : [...caller, ...candidates(m0, m, caller, caller, g.laws, ms, plan.captureUntil, support, laws => { partial = [...caller, ...laws]; })];
|
|
754
|
+
return { valid: true, set };
|
|
755
|
+
});
|
|
756
|
+
if (!generated.complete)
|
|
757
|
+
m.counts = { ...originalCounts, ...m.counts };
|
|
758
|
+
const bundle = generated.complete ? generated.value : { valid: true, set: partial };
|
|
759
|
+
countsDump.on?.({ phase: 'count-generation-result', complete: generated.complete, ...plan, workAllowance: tiers.workAllowance });
|
|
760
|
+
if (!bundle.valid)
|
|
761
|
+
return { proven: false, laws: caller, m, why: 'a law fails on the small instances' };
|
|
762
|
+
let set = bundle.set;
|
|
763
|
+
countsDump.on?.({ phase: 'candidates', machine: m, laws: set, partial: !generated.complete });
|
|
764
|
+
const allowance = remainingRejectionAllowance(plan, clock());
|
|
765
|
+
const rejections = rejectionStage(m0, m, caller, set, allowance);
|
|
766
|
+
set = rejections.active();
|
|
767
|
+
countsDump.on?.({ phase: 'count-rejection-result', work: rejections.screenWork, replayWork: rejections.work(), removed: rejections.evidence().map(e => ({ kind: e.kind, name: e.law.name })), phases: rejections.phases, remaining: set.length, safety: rejections.safety(), replayEvidence: () => rejections.evidence() });
|
|
768
|
+
countsDump.on?.({ phase: 'post-rejection-candidates', machine: m, laws: set });
|
|
769
|
+
const context = countSupportContext(m, caller, set, support);
|
|
770
|
+
return structuredFallback(until, structured => {
|
|
771
|
+
const result = admitCountedFamilyOnce(m, caller, context.laws, support, until, structured, tierRun, rejections);
|
|
772
|
+
return result.proven || context.laws.length === set.length || clock() >= until ? result : admitCountedFamilyOnce(m, caller, set, support, until, structured, tierRun, rejections);
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
// Candidate scheduling only. Every returned family still goes through finish.
|
|
776
|
+
export function admitCountedFamily(m, caller, initial, support, until, tiers) {
|
|
777
|
+
if (tiers && tiers.until !== until)
|
|
778
|
+
throw new RangeError('mismatched tier deadline');
|
|
779
|
+
const tierRun = { start: tiers ? until - tiers.workAllowance : clock(), budget: tiers?.active ? tiers : undefined, source: m };
|
|
780
|
+
return structuredFallback(until, structured => admitCountedFamilyOnce(m, caller, initial, support, until, structured, tierRun));
|
|
781
|
+
}
|
|
782
|
+
function admitCountedFamilyOnce(m, caller, initial, support, until, structured, tierRun, rejections) {
|
|
783
|
+
if (rejections)
|
|
784
|
+
initial = rejectionFamily(rejections, initial);
|
|
785
|
+
const previous = proofOrigins.enabled;
|
|
786
|
+
if (env.GDP_COUNT_LEMMA_CUTS === '1')
|
|
787
|
+
proofOrigins.enabled = true;
|
|
788
|
+
try {
|
|
789
|
+
if (env.GDP_COUNT_STRATEGIES === '1')
|
|
790
|
+
m = prepareCountStrategyMachine(m, initial, until, event => countsDump.on?.({ phase: 'count-strategy-context', ...event }));
|
|
791
|
+
const selected = env.GDP_COUNT_STRATEGIES === '1' && env.GDP_COUNT_TIERS === '1' ? new Set(selectedCountStrategies(m, initial)) : new Set();
|
|
792
|
+
const budget = selected.size ? (tierRun.budget = reserveCountClosing(tierRun.budget ?? countTierBudget(tierRun.start, until, selected.size), finalCountStepDeferralEnabled() && env.GDP_COUNT_CLOSING_RESERVE === '1')) : undefined;
|
|
793
|
+
if (budget)
|
|
794
|
+
countsDump.on?.({ phase: 'count-tier-plan', ...budget, selected: [...selected].map(law => law.name) });
|
|
795
|
+
return admitCountedFamily0(m, caller, initial, support, until, structured, budget, selected, budget && 'closingMode' in budget ? budget.workAllowance : Math.max(0, until - tierRun.start), tierRun, rejections);
|
|
796
|
+
}
|
|
797
|
+
finally {
|
|
798
|
+
proofOrigins.enabled = previous;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
function admitCountedFamily0(m, caller, initial, support, until, structured, budget, selected, workAllowance, tierRun, rejections) {
|
|
802
|
+
if (!caller.every(l => initial.includes(l)))
|
|
803
|
+
return { proven: false, laws: initial, m, why: 'missing caller' };
|
|
804
|
+
let closingBudget = budget && 'closingMode' in budget ? budget : undefined;
|
|
805
|
+
if (closingBudget)
|
|
806
|
+
until = countOrdinaryUntil(closingBudget);
|
|
807
|
+
const prerequisiteFirst = !!closingBudget && env.GDP_COUNT_PREREQUISITES === '1';
|
|
808
|
+
const proofGuided = prerequisiteFirst && env.GDP_COUNT_PROOF_GUIDED_SCHEDULING === '1';
|
|
809
|
+
const beforeClosing = (body, onLocalExpiration) => {
|
|
810
|
+
if (!prerequisiteFirst)
|
|
811
|
+
return body();
|
|
812
|
+
return withSearchAllowance(until, body, error => {
|
|
813
|
+
if (!isLocalCountExpiration(error, closingBudget.until))
|
|
814
|
+
throw error;
|
|
815
|
+
onLocalExpiration?.();
|
|
816
|
+
return undefined;
|
|
817
|
+
});
|
|
818
|
+
};
|
|
819
|
+
let set = rejections ? rejectionFamily(rejections, initial) : initial.slice();
|
|
820
|
+
let reach;
|
|
821
|
+
if (proofGuided)
|
|
822
|
+
reach = optionalReachabilityScreen(() => {
|
|
823
|
+
const setup = clock(), key = JSON.stringify(m);
|
|
824
|
+
if (tierRun.reachability?.key !== key)
|
|
825
|
+
tierRun.reachability = { key, screen: countReachabilityScreen(tierRun.source ?? m, m, caller, workAllowance, undefined, tierRun.reachFunding ??= new Map()) };
|
|
826
|
+
const screen = tierRun.reachability.screen;
|
|
827
|
+
set = withoutReachableRejections(set, screen.rejectedNames());
|
|
828
|
+
countsDump.on?.({ phase: 'count-reachability-setup', units: (clock() - setup) * fullRate });
|
|
829
|
+
return screen;
|
|
830
|
+
});
|
|
831
|
+
const scopeEnabled = env.GDP_COUNT_STRATEGIES === '1';
|
|
832
|
+
const attempts = countedAttempts(m, caller, support, proofGuided ? closingBudget.until : until, structured, selected, workAllowance, budget, prerequisiteFirst ? initial : undefined), traced = attempts.traced;
|
|
833
|
+
const isCount = (mp) => !!m.counts?.[mp];
|
|
834
|
+
// Prove the proposed set together. A preliminary cone reproved many helpers in
|
|
835
|
+
// several smaller contexts before asking these same induction goals. Houdini
|
|
836
|
+
// drops failed helpers and carries proofs whose instantiated support survives.
|
|
837
|
+
// Every returned set still passes checkCountedLaws, including all caller laws.
|
|
838
|
+
const finish = (ls, proof, targetFamily = true) => {
|
|
839
|
+
const close = (candidate) => {
|
|
840
|
+
if (!closingBudget)
|
|
841
|
+
return closingCountCheck(() => checkCountedLaws(m, ls, candidate));
|
|
842
|
+
const start = clock();
|
|
843
|
+
countsDump.on?.({ phase: 'count-family-closing', stage: 'start', at: start, end: withinDeadline(closingBudget.until), laws: ls.map(l => l.name) });
|
|
844
|
+
const checked = withDeadline(closingBudget.until, () => closingCountCheck(() => checkCountedLaws(m, ls, candidate)));
|
|
845
|
+
countsDump.on?.({ phase: 'count-family-closing', stage: 'end', checked, at: clock(), units: (clock() - start) * fullRate });
|
|
846
|
+
return checked;
|
|
847
|
+
};
|
|
848
|
+
let proposed = proof;
|
|
849
|
+
if (env.GDP_COUNT_LEMMA_CUTS === '1') {
|
|
850
|
+
// This pass performs no search work. Reuse the enclosing wall deadline; outside one,
|
|
851
|
+
// conservatively cap its wall time by the remaining counted allowance. Neither budget is extended.
|
|
852
|
+
const wall = wallAt(), end = Number.isFinite(wall) ? wall : countedSearchNow() + Math.max(0, until - clock());
|
|
853
|
+
for (const { goal, decls } of countedObligations(m, ls, proof.instances)) {
|
|
854
|
+
if (countedSearchNow() >= end)
|
|
855
|
+
break;
|
|
856
|
+
const cert = proof.certs[goal.name];
|
|
857
|
+
if (!cert || cert.lemmas?.length)
|
|
858
|
+
continue;
|
|
859
|
+
const expanded = mcGoal(goal.hyps, decls, cert);
|
|
860
|
+
const shared = expanded && proposeLemmaCuts(expanded, cert.tree, { until: end });
|
|
861
|
+
if (shared)
|
|
862
|
+
proposed = { ...proposed, certs: { ...proposed.certs, [goal.name]: { ...cert, tree: shared.tree, lemmas: shared.lemmas } } };
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
if (proposed !== proof && ptime('kernel', () => close(proposed))) {
|
|
866
|
+
// Sharing may retain a wider independent-cut source slice. Never attach
|
|
867
|
+
// pre-sharing premise metadata to a different final certificate.
|
|
868
|
+
if (!scopeEnabled)
|
|
869
|
+
proof = proposed;
|
|
870
|
+
else {
|
|
871
|
+
const premises = { ...proof.premises };
|
|
872
|
+
for (const law of ls)
|
|
873
|
+
if ([' @start', ' @step'].some(suffix => proposed.certs[law.name + suffix] !== proof.certs[law.name + suffix])) {
|
|
874
|
+
const scoped = ptime('premise-scope', () => scopeCountProof(m, law, ls, { instances: proposed.instances[law.name] ?? {}, certs: proposed.certs }, until));
|
|
875
|
+
if (scoped)
|
|
876
|
+
premises[law.name] = scoped.premises.map(p => p.name);
|
|
877
|
+
else
|
|
878
|
+
delete premises[law.name];
|
|
879
|
+
}
|
|
880
|
+
proof = { ...proposed, premises };
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
else if (!ptime('kernel', () => close(proof)))
|
|
884
|
+
return { proven: false, laws: ls, m, why: 'the kernel refused the set' };
|
|
885
|
+
// Output-only observation, after the unchanged checker accepts every obligation.
|
|
886
|
+
countsDump.on?.({ phase: targetFamily ? 'closed-family' : 'closed-subfamily', machine: m, laws: ls, proof, checked: true });
|
|
887
|
+
if (!targetFamily)
|
|
888
|
+
return { proven: false, laws: ls, m, why: 'closed subfamily excludes caller' };
|
|
889
|
+
return { proven: true, laws: ls, m, proof };
|
|
890
|
+
};
|
|
891
|
+
const recipeJoint = () => {
|
|
892
|
+
const prepared = beforeClosing(() => {
|
|
893
|
+
const context = countScopeContextKey(m, set);
|
|
894
|
+
const pass = (tierRun.recipeContexts ??= new CountRecipeContexts()).acquire(context, structured, () => {
|
|
895
|
+
const plan = countPrerequisiteSchedule(m, set, selected, until);
|
|
896
|
+
const members = workMap(set, (law, reference) => ({ name: law.name, reference, recipes: workMap(plan.recipes.get(law.name) ?? [], recipe => {
|
|
897
|
+
const shape = recipe.id === 'lifted' ? discoverLiftedCountGuard(m, law, set) : undefined;
|
|
898
|
+
const operations = shape && discoverLiftedCountOperations(m, shape);
|
|
899
|
+
return { ...recipe, ...(operations ? { caseKeys: workMap(operations, operation => 'op:' + operation.value, 'count recipe case inventory') } : {}) };
|
|
900
|
+
}, 'count recipe inventory') }), 'count member inventory');
|
|
901
|
+
return new CountRecipePass(members, context);
|
|
902
|
+
}, event => countsDump.on?.(event));
|
|
903
|
+
if (!pass)
|
|
904
|
+
return { kind: 'context-changed' };
|
|
905
|
+
return { kind: 'ready', pass,
|
|
906
|
+
lawByName: new Map(workMap(set, law => [law.name, law], 'count recipe law lookup')),
|
|
907
|
+
active: new Set(workMap(set, law => law.name, 'count active inventory')),
|
|
908
|
+
targets: workMap(caller, law => law.name, 'count recipe targets') };
|
|
909
|
+
});
|
|
910
|
+
if (!prepared || prepared.kind !== 'ready')
|
|
911
|
+
return { proven: false, laws: set, m, why: prepared?.kind === 'context-changed' ? 'recipe fixed inventory context changed' : 'recipe planning budget' };
|
|
912
|
+
const { lawByName, active, targets, pass } = prepared;
|
|
913
|
+
const tick = () => workLedger.start('ticks', 1, 'count recipe adapter');
|
|
914
|
+
const reconcile = () => { if (reach)
|
|
915
|
+
for (const name of reach.rejectedNames()) {
|
|
916
|
+
tick();
|
|
917
|
+
active.delete(name);
|
|
918
|
+
} };
|
|
919
|
+
const screen = (law, ordinary, citing) => {
|
|
920
|
+
if (!reach)
|
|
921
|
+
return true;
|
|
922
|
+
try {
|
|
923
|
+
const row = reach.screen(law, ordinary, citing, Infinity, attempts.countermodel(law));
|
|
924
|
+
if (row)
|
|
925
|
+
countsDump.on?.({ phase: 'count-reachability', ...row });
|
|
926
|
+
return !!row && row.outcome !== 'rejected' && reach.safety() !== 'broken';
|
|
927
|
+
}
|
|
928
|
+
finally {
|
|
929
|
+
reconcile();
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
if (beforeClosing(() => { reconcile(); return true; }) !== true)
|
|
933
|
+
return { proven: false, laws: set, m, why: 'recipe reconciliation budget' };
|
|
934
|
+
attempts.houdini = true;
|
|
935
|
+
const transportDeclined = undefined;
|
|
936
|
+
const outcome = runCountRecipeController(pass, targets, {
|
|
937
|
+
active, observe: event => countsDump.on?.(event),
|
|
938
|
+
beforeClosing: countRecipeClosingCapture.on ? controller => countRecipeClosingCapture.on({
|
|
939
|
+
version: 'counted-recipe-closing/v1', controller, m, set, caller, initial, selected, structured,
|
|
940
|
+
closingBudget, until, workAllowance, scopeEnabled, active, reachAbsent: reach === undefined, transportDeclined
|
|
941
|
+
}) : undefined,
|
|
942
|
+
preflight: (name, recipe) => {
|
|
943
|
+
const law = lawByName.get(name);
|
|
944
|
+
// The requested legacy screen allowance is clipped by the existing
|
|
945
|
+
// exact member/phase/root scopes; it never creates a new root.
|
|
946
|
+
return !!law && active.has(name) && (recipe.kind !== 'ordinary' || screen(law, workAllowance, 0));
|
|
947
|
+
},
|
|
948
|
+
construct: (name, recipe, lease) => {
|
|
949
|
+
const law = lawByName.get(name);
|
|
950
|
+
if (!law || !active.has(name) || reach?.safety() === 'broken')
|
|
951
|
+
return;
|
|
952
|
+
let proof;
|
|
953
|
+
if (recipe.kind === 'strategy') {
|
|
954
|
+
if (recipe.caseKeys !== undefined)
|
|
955
|
+
proof = lease && attempts.exactStrategy(law, set, lease);
|
|
956
|
+
else if (recipe.id === 'row' || recipe.id === 'guard')
|
|
957
|
+
proof = attempts.strategyProposal(law, set, recipe.id);
|
|
958
|
+
else
|
|
959
|
+
countsDump.on?.({ phase: 'count-strategy', law: name, stage: 'decline', reason: recipe.id === 'lifted' ? 'missing-lifted-case-inventory' : 'unsupported-strategy-recipe', recipe: recipe.id });
|
|
960
|
+
}
|
|
961
|
+
else {
|
|
962
|
+
let result = traced(law, set, 0, Infinity, false);
|
|
963
|
+
if (!('proof' in result) && !result.refuted && attempts.counted)
|
|
964
|
+
result = traced(law, set, 1, Infinity, false);
|
|
965
|
+
if ('proof' in result)
|
|
966
|
+
proof = result.proof;
|
|
967
|
+
else if (result.expired)
|
|
968
|
+
throw new BudgetExpired('ordinary recipe cutoff');
|
|
969
|
+
}
|
|
970
|
+
return proof;
|
|
971
|
+
},
|
|
972
|
+
capture: (name, recipe, proof) => {
|
|
973
|
+
const law = lawByName.get(name);
|
|
974
|
+
if (!law)
|
|
975
|
+
return;
|
|
976
|
+
const before = workLedger.actual();
|
|
977
|
+
let identity = zeroWork;
|
|
978
|
+
const captured = withCountScopeIdentityObservation(amount => { identity = workAdd(identity, amount); }, () => {
|
|
979
|
+
const scoped = rescopeCountProof(m, law, set, proof, new Set(pass.held().keys()), Infinity, event => countsDump.on?.({ phase: 'count-component-rescope', law: name, ...event }), countRescopeFunding());
|
|
980
|
+
if (!scoped)
|
|
981
|
+
return;
|
|
982
|
+
const checkedReduced = isCheckedReducedScope(scoped, m, set);
|
|
983
|
+
return { payload: scoped, premises: workMap(scoped.premises, p => p.name, 'count recipe scoped names'), checkedReduced };
|
|
984
|
+
});
|
|
985
|
+
countsDump.on?.({ phase: 'count-rescope-identity', law: name, rawWork: exactRaw(identity), rootEpoch: workLedger.snapshot().rootEpoch });
|
|
986
|
+
if (!captured)
|
|
987
|
+
return;
|
|
988
|
+
const effective = new Set();
|
|
989
|
+
for (const dependency of captured.premises) {
|
|
990
|
+
tick();
|
|
991
|
+
effective.add(dependency);
|
|
992
|
+
}
|
|
993
|
+
if (!captured.checkedReduced)
|
|
994
|
+
for (const dependency of recipe.required ?? []) {
|
|
995
|
+
tick();
|
|
996
|
+
effective.add(dependency);
|
|
997
|
+
}
|
|
998
|
+
for (const dependency of effective) {
|
|
999
|
+
tick();
|
|
1000
|
+
const premise = lawByName.get(dependency);
|
|
1001
|
+
if (premise && !screen(premise, 0, workAllowance))
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
return { ...captured, checkCost: workSub(workLedger.actual(), before) };
|
|
1005
|
+
},
|
|
1006
|
+
close: (rows, targetInFamily, wholeClosed) => {
|
|
1007
|
+
const replay = (selected, route) => {
|
|
1008
|
+
const declines = [];
|
|
1009
|
+
const names = new Set(workMap(selected, row => row.id, 'count closing inventory'));
|
|
1010
|
+
const family = workFilter(set, law => names.has(law.name), 'count closing family'), instances = {}, certs = {}, premises = {};
|
|
1011
|
+
if (reach?.safety() === 'broken')
|
|
1012
|
+
return { result: { proven: false, laws: family, m, why: 'reachable caller counterexample' }, replayDeclined: false };
|
|
1013
|
+
for (const row of selected) {
|
|
1014
|
+
tick();
|
|
1015
|
+
// Transport the original captured payload on the unchanged model;
|
|
1016
|
+
// never search, repair a certificate, or reuse a partial first try.
|
|
1017
|
+
const proof = replayScopedCountProof(m, family, row.payload, Infinity, { deferToClosing: true, sourceFamily: set, onDecline: decline => declines.push(decline), diagnostic: { route } });
|
|
1018
|
+
if (!proof) {
|
|
1019
|
+
const decline = declines[declines.length - 1];
|
|
1020
|
+
countsDump.on?.({ phase: 'count-recipe-closing-decline', family: route, member: row.id, obligation: decline?.obligation ?? null, case: decline?.case ?? null, reason: decline?.reason ?? 'unclassified', detail: decline });
|
|
1021
|
+
const why = declines.map(d => 'member=' + d.member + ', obligation=' + (d.obligation ?? '<family>') + ', case=' + d.case + ':' + d.reason + (d.premise ? ', law=' + d.premise : '')).join(' | ');
|
|
1022
|
+
const blockers = decline?.blockers ?? (decline?.reason === 'missing-premise' && decline.premise ? [decline.premise] : []);
|
|
1023
|
+
if (blockers.length)
|
|
1024
|
+
countsDump.on?.({ phase: 'count-recipe-closing-blocker', family: route, member: row.id, laws: blockers, detail: decline });
|
|
1025
|
+
const label = blockers.length ? 'BLOCKER outside-closing-family laws ' + blockers.join(', ') : 'recipe closing replay declined';
|
|
1026
|
+
return { result: { proven: false, laws: family, m, why: label + ' [' + route + ']: ' + (why || 'member=' + row.id + ', unclassified') }, replayDeclined: true };
|
|
1027
|
+
}
|
|
1028
|
+
instances[row.id] = proof.instances;
|
|
1029
|
+
for (const [name, cert] of workEntries(proof.certs, 'count closing certificates'))
|
|
1030
|
+
certs[name] = cert;
|
|
1031
|
+
premises[row.id] = proof.premises ?? row.premises;
|
|
1032
|
+
}
|
|
1033
|
+
if (reach)
|
|
1034
|
+
countsDump.on?.({ phase: 'count-reachability-summary', rows: reach.receipts(initial), replayEvidence: reach.evidence });
|
|
1035
|
+
let hasCallers = targetInFamily;
|
|
1036
|
+
for (const law of caller) {
|
|
1037
|
+
tick();
|
|
1038
|
+
if (!names.has(law.name))
|
|
1039
|
+
hasCallers = false;
|
|
1040
|
+
}
|
|
1041
|
+
return { result: finish(family, { instances, certs, premises }, hasCallers), replayDeclined: false };
|
|
1042
|
+
};
|
|
1043
|
+
// Choose the greatest already CLOSED HELD family before replay. No
|
|
1044
|
+
// supplier reconstruction, retry, new recipe, scope or native fallback.
|
|
1045
|
+
return replay(wholeClosed?.() ?? rows, wholeClosed ? 'whole-held' : 'needed').result;
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
countsDump.on?.({ phase: 'count-recipe-summary', reason: outcome.reason, failure: outcome.failure, closingRoute: outcome.closingRoute, proven: outcome.result?.proven ?? false });
|
|
1049
|
+
const diagnostic = 'recipe pass: ' + outcome.reason + (outcome.failure ? '; ' + outcome.failure.reason : '');
|
|
1050
|
+
if (!outcome.result)
|
|
1051
|
+
return { proven: false, laws: set, m, why: diagnostic };
|
|
1052
|
+
return outcome.result.proven ? outcome.result : { ...outcome.result, why: (outcome.result.why ? outcome.result.why + '; ' : '') + diagnostic };
|
|
1053
|
+
};
|
|
1054
|
+
const joint = () => {
|
|
1055
|
+
const planned = beforeClosing(() => countPrerequisiteSchedule(m, set, selected, until));
|
|
1056
|
+
if (!planned)
|
|
1057
|
+
return { proven: false, laws: set, m, why: 'prerequisite planning budget' };
|
|
1058
|
+
const ranked = [...new Set([...caller, ...supportOrder(set, caller, support, false, m)])];
|
|
1059
|
+
const order = ranked.sort((a, b) => planned.costs.get(a.name) - planned.costs.get(b.name));
|
|
1060
|
+
const restored = prepareCountPrerequisiteMemory(tierRun.prerequisites, m, set), remembered = tierRun.prerequisites = restored.state;
|
|
1061
|
+
const scopes = remembered.scopes, ends = new Map(), attempted = new Set();
|
|
1062
|
+
const queue = countPrerequisiteComponents(order.map(l => l.name), planned.requirements, [...selected].map(l => l.name), [...remembered.committed], { ...planned, discoveryFirst: true, proofGuided, discoveryContexts: remembered.discoveryContexts, targets: caller.map(l => l.name), held: new Map([...scopes].map(([name, scope]) => [name, scope.premises.map(p => p.name)])), discovered: [...remembered.discovered], failed: [...remembered.failed] });
|
|
1063
|
+
const ordinaryCount = Math.max(1, set.filter(l => !selected.has(l)).length);
|
|
1064
|
+
const reachSummary = () => { if (reach)
|
|
1065
|
+
countsDump.on?.({ phase: 'count-reachability-summary', rows: reach.receipts(initial), replayEvidence: reach.evidence }); };
|
|
1066
|
+
let activeAttempt, restarted = false;
|
|
1067
|
+
const members = new Set(order.map(law => law.name));
|
|
1068
|
+
const reconcile = () => {
|
|
1069
|
+
if (!reach)
|
|
1070
|
+
return;
|
|
1071
|
+
const delta = reconcileReachableRejections(queue, members, reach.rejectedNames(), scopes, remembered.committed, activeAttempt);
|
|
1072
|
+
if (!delta.rejected.length)
|
|
1073
|
+
return;
|
|
1074
|
+
activeAttempt = undefined;
|
|
1075
|
+
restarted = true;
|
|
1076
|
+
remembered.failed = new Set(queue.failed());
|
|
1077
|
+
remembered.discoveryContexts = queue.discoveryContexts();
|
|
1078
|
+
set = withoutReachableRejections(set, delta.rejected);
|
|
1079
|
+
countsDump.on?.({ phase: 'count-reachability-invalidated', ...delta });
|
|
1080
|
+
};
|
|
1081
|
+
const probe = (law, ordinary, citing, end) => {
|
|
1082
|
+
if (!reach)
|
|
1083
|
+
return undefined;
|
|
1084
|
+
const screen = reach;
|
|
1085
|
+
reconcile();
|
|
1086
|
+
if (restarted)
|
|
1087
|
+
return undefined;
|
|
1088
|
+
const before = clock();
|
|
1089
|
+
let row;
|
|
1090
|
+
try {
|
|
1091
|
+
row = beforeClosing(() => screen.screen(law, ordinary, citing, end, attempts.countermodel(law)));
|
|
1092
|
+
}
|
|
1093
|
+
finally {
|
|
1094
|
+
reconcile();
|
|
1095
|
+
}
|
|
1096
|
+
if (row)
|
|
1097
|
+
countsDump.on?.({ phase: 'count-reachability', ...row, invocationUnits: (clock() - before) * fullRate });
|
|
1098
|
+
return row;
|
|
1099
|
+
};
|
|
1100
|
+
const updateReserve = () => {
|
|
1101
|
+
if (!proofGuided)
|
|
1102
|
+
return;
|
|
1103
|
+
const costs = [...scopes.values()].flatMap(scope => scope.checkWork === undefined ? [] : [scope.checkWork]);
|
|
1104
|
+
closingBudget = reserveCheckedCountClosing(closingBudget, costs, clock());
|
|
1105
|
+
budget = tierRun.budget = closingBudget;
|
|
1106
|
+
until = closingBudget.searchUntil;
|
|
1107
|
+
countsDump.on?.({ phase: 'count-closing-reserve', at: clock(), checkedPackets: costs.length, checkedWork: costs.reduce((a, b) => a + b, 0), ...closingBudget });
|
|
1108
|
+
};
|
|
1109
|
+
reconcile();
|
|
1110
|
+
updateReserve();
|
|
1111
|
+
attempts.houdini = true;
|
|
1112
|
+
countsDump.on?.({ phase: 'count-prerequisite-plan', premises: Object.fromEntries(planned.requirements), recipes: Object.fromEntries(planned.recipes), until, rootUntil: closingBudget.until });
|
|
1113
|
+
countsDump.on?.({ phase: 'count-prerequisite-memory', held: [...scopes.keys()], members: [...remembered.committed], invalidated: restored.invalidated });
|
|
1114
|
+
const closeReady = () => {
|
|
1115
|
+
const available = new Set(queue.available()), needed = countClosingNeeds(caller.map(l => l.name), scopes);
|
|
1116
|
+
if (![...needed].every(name => available.has(name) && scopes.has(name)))
|
|
1117
|
+
return undefined;
|
|
1118
|
+
const family = set.filter(l => needed.has(l.name)), instances = {}, certs = {}, premises = {};
|
|
1119
|
+
for (const member of family) {
|
|
1120
|
+
const proof = beforeClosing(() => ptime('premise-replay', () => replayScopedCountProof(m, family, scopes.get(member.name), until, { deferToClosing: true, sourceFamily: set })));
|
|
1121
|
+
if (!proof)
|
|
1122
|
+
return { proven: false, laws: set, m, why: 'component replay declined' };
|
|
1123
|
+
instances[member.name] = proof.instances;
|
|
1124
|
+
Object.assign(certs, proof.certs);
|
|
1125
|
+
premises[member.name] = proof.premises ?? [];
|
|
1126
|
+
}
|
|
1127
|
+
reachSummary();
|
|
1128
|
+
return finish(family, { instances, certs, premises });
|
|
1129
|
+
};
|
|
1130
|
+
const alreadyClosed = closeReady();
|
|
1131
|
+
if (alreadyClosed)
|
|
1132
|
+
return alreadyClosed;
|
|
1133
|
+
while (clock() < until) {
|
|
1134
|
+
restarted = false;
|
|
1135
|
+
const decision = queue.next();
|
|
1136
|
+
if (!decision)
|
|
1137
|
+
break;
|
|
1138
|
+
activeAttempt = decision.kind === 'attempt' ? decision.name : undefined;
|
|
1139
|
+
if (decision.kind === 'ready') {
|
|
1140
|
+
let blocked = false;
|
|
1141
|
+
if (reach)
|
|
1142
|
+
for (const name of decision.members) {
|
|
1143
|
+
const member = set.find(l => l.name === name), row = probe(member, 0, scopes.get(name)?.checkWork ?? 0, until);
|
|
1144
|
+
if (reach.safety() === 'broken')
|
|
1145
|
+
return { proven: false, laws: set, m, why: 'reachable caller counterexample' };
|
|
1146
|
+
if (restarted) {
|
|
1147
|
+
blocked = true;
|
|
1148
|
+
break;
|
|
1149
|
+
}
|
|
1150
|
+
if (row?.outcome === 'rejected')
|
|
1151
|
+
return { proven: false, laws: set, m, why: 'rejected member remained ready' };
|
|
1152
|
+
if (!row) {
|
|
1153
|
+
blocked = true;
|
|
1154
|
+
break;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
if (blocked)
|
|
1158
|
+
continue;
|
|
1159
|
+
queue.commit(decision.members);
|
|
1160
|
+
for (const name of decision.members) {
|
|
1161
|
+
remembered.committed.add(name);
|
|
1162
|
+
if (reach)
|
|
1163
|
+
countsDump.on?.({ phase: 'count-required-promotion', kind: 'member', law: name, reducedScopeSize: scopes.get(name)?.premises.length ?? 0, committed: true, proposed: true, checked: false });
|
|
1164
|
+
}
|
|
1165
|
+
countsDump.on?.({ phase: 'count-component-closed', members: decision.members, proposed: true, checked: false });
|
|
1166
|
+
for (const name of decision.members)
|
|
1167
|
+
countsDump.on?.({ phase: 'count-prerequisite-complete', law: name, premises: scopes.get(name)?.premises.map(p => p.name) ?? [], proposed: true, component: decision.members });
|
|
1168
|
+
const closed = closeReady();
|
|
1169
|
+
if (closed)
|
|
1170
|
+
return closed;
|
|
1171
|
+
continue;
|
|
1172
|
+
}
|
|
1173
|
+
const law = set.find(l => l.name === decision.name), context = set.filter(l => decision.context.includes(l.name));
|
|
1174
|
+
const discoveryOnly = decision.purpose === 'discovery';
|
|
1175
|
+
const ordinaryMembers = decision.component.filter(name => !selected.has(set.find(l => l.name === name))).length;
|
|
1176
|
+
const horizon = Math.min(until, discoveryOnly ? until : budget.strategyUntil + budget.ordinaryFloor * ordinaryMembers / ordinaryCount);
|
|
1177
|
+
const key = JSON.stringify([decision.purpose, decision.component, ...discoveryOnly ? [law.name] : []]), available = new Set(queue.available()), failed = new Set(queue.failed());
|
|
1178
|
+
if (!ends.has(key) || proofGuided && !discoveryOnly) {
|
|
1179
|
+
const eligible = set.filter(l => !available.has(l.name) && !failed.has(l.name)).length;
|
|
1180
|
+
ends.set(key, discoveryOnly ? clock() + Math.max(0, horizon - clock()) / Math.max(1, eligible) : horizon);
|
|
1181
|
+
}
|
|
1182
|
+
const componentEnd = Math.min(horizon, ends.get(key));
|
|
1183
|
+
const unattempted = discoveryOnly ? 1 : Math.max(1, decision.component.filter(name => !scopes.has(name) && (proofGuided || !attempted.has(JSON.stringify([key, name])))).length);
|
|
1184
|
+
const allowStrategy = !discoveryOnly && decision.recipe.kind === 'strategy', start = clock();
|
|
1185
|
+
const { end, allotted, reserved } = countComponentAttemptBudget(clock(), componentEnd, unattempted, 1, proofGuided && !allowStrategy);
|
|
1186
|
+
if (reach && !discoveryOnly && !allowStrategy) {
|
|
1187
|
+
const row = probe(law, allotted, 0, end);
|
|
1188
|
+
if (reach.safety() === 'broken')
|
|
1189
|
+
return { proven: false, laws: set, m, why: 'reachable caller counterexample' };
|
|
1190
|
+
if (restarted) {
|
|
1191
|
+
updateReserve();
|
|
1192
|
+
continue;
|
|
1193
|
+
}
|
|
1194
|
+
if (row?.outcome === 'rejected')
|
|
1195
|
+
return { proven: false, laws: set, m, why: 'rejected prerequisite remained active' };
|
|
1196
|
+
if (!row)
|
|
1197
|
+
break;
|
|
1198
|
+
}
|
|
1199
|
+
attempted.add(JSON.stringify([key, law.name]));
|
|
1200
|
+
if (discoveryOnly)
|
|
1201
|
+
remembered.discovered.add(law.name);
|
|
1202
|
+
countsDump.on?.({ phase: 'count-component-attempt', law: law.name, component: decision.component, mode: decision.phase, recipe: decision.recipe.id, context: decision.context, end, componentEnd, allotted, reserved, discovery: decision.discovery, purpose: decision.purpose, required: queue.required(), ...(proofGuided ? { pass: decision.pass ?? 0 } : {}) });
|
|
1203
|
+
countsDump.on?.({ phase: 'count-tier-attempt', law: law.name, tier: selected.has(law) && allowStrategy ? 'strategy' : 'ordinary', end, allotted });
|
|
1204
|
+
let result = { stuck: 'unknown' }, expired = allotted <= 0;
|
|
1205
|
+
if (allotted > 0)
|
|
1206
|
+
result = withSearchAllowance(end, () => {
|
|
1207
|
+
const invoke = (pass) => traced(law, context, pass, Math.max(0, end - clock()), allowStrategy);
|
|
1208
|
+
const first = invoke(proofGuided ? decision.pass ?? 0 : 0);
|
|
1209
|
+
return !proofGuided && !discoveryOnly && !('proof' in first) && !first.refuted && (!selected.has(law) || !allowStrategy) && attempts.counted && clock() < end ? invoke(1) : first;
|
|
1210
|
+
}, error => { if (!isLocalCountExpiration(error, closingBudget.until))
|
|
1211
|
+
throw error; expired = true; return result; });
|
|
1212
|
+
if (!('proof' in result) && result.expired)
|
|
1213
|
+
expired = true;
|
|
1214
|
+
let scope;
|
|
1215
|
+
if ('proof' in result) {
|
|
1216
|
+
scope = withSearchAllowance(end, () => beforeClosing(() => proofGuided
|
|
1217
|
+
? ptime('premise-rescope', () => rescopeCountProof(m, law, context, result.proof, new Set(scopes.keys()), end, event => countsDump.on?.({ phase: 'count-component-rescope', law: law.name, ...event }), countRescopeFunding()))
|
|
1218
|
+
: ptime('premise-scope', () => scopeCountProof(m, law, context, result.proof, end)),
|
|
1219
|
+
// The enclosing closing reserve may consume this local refusal.
|
|
1220
|
+
// Preserve its classification even when exact admission stops before end.
|
|
1221
|
+
() => { expired = true; }), error => { if (!isLocalCountExpiration(error, withinDeadline(closingBudget.until)))
|
|
1222
|
+
throw error; expired = true; return undefined; });
|
|
1223
|
+
}
|
|
1224
|
+
if ('proof' in result && !scope && !expired && clock() >= end) {
|
|
1225
|
+
const error = new BudgetExpired('component premise scope');
|
|
1226
|
+
if (!isLocalCountExpiration(error, withinDeadline(closingBudget.until)))
|
|
1227
|
+
throw error;
|
|
1228
|
+
expired = true;
|
|
1229
|
+
}
|
|
1230
|
+
let rejectedPremise = false;
|
|
1231
|
+
if (scope && reach) {
|
|
1232
|
+
const citedBy = law.name, reducedScopeSize = scope.premises.length, citingWork = clock() - start;
|
|
1233
|
+
for (const premise of scope.premises) {
|
|
1234
|
+
const dependency = set.find(l => l.name === premise.name);
|
|
1235
|
+
if (!dependency)
|
|
1236
|
+
continue;
|
|
1237
|
+
const row = probe(dependency, 0, citingWork, until);
|
|
1238
|
+
countsDump.on?.({ phase: 'count-required-promotion-screen', law: premise.name, citedBy, reducedScopeSize, screened: !!row, outcome: row?.outcome });
|
|
1239
|
+
if (reach.safety() === 'broken')
|
|
1240
|
+
return { proven: false, laws: set, m, why: 'reachable caller counterexample' };
|
|
1241
|
+
if (restarted) {
|
|
1242
|
+
scope = undefined;
|
|
1243
|
+
break;
|
|
1244
|
+
}
|
|
1245
|
+
if (row?.outcome === 'rejected')
|
|
1246
|
+
rejectedPremise = true;
|
|
1247
|
+
if (!row) {
|
|
1248
|
+
expired = true;
|
|
1249
|
+
scope = undefined;
|
|
1250
|
+
break;
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
if (rejectedPremise)
|
|
1254
|
+
scope = undefined;
|
|
1255
|
+
}
|
|
1256
|
+
if (restarted) {
|
|
1257
|
+
updateReserve();
|
|
1258
|
+
continue;
|
|
1259
|
+
}
|
|
1260
|
+
let status = rejectedPremise ? { kind: 'unknown', reason: 'reachable-refuted premise' } : scope ? { kind: 'proof', citations: scope.premises.map(p => p.name) } : expired ? { kind: 'unknown', reason: 'budget-expired' } : 'proof' in result ? (proofGuided ? { kind: 'unknown', reason: 'checked rescope declined' } : { kind: 'refused', reason: 'returned proof has no valid scope' }) : result.refuted ? { kind: 'refuted' } : { kind: 'unknown', reason: result.reason ?? result.stuck };
|
|
1261
|
+
if ((discoveryOnly || proofGuided) && status.kind === 'refuted')
|
|
1262
|
+
status = { kind: 'unknown', reason: 'narrow-sat' };
|
|
1263
|
+
const outcome = queue.finish(law.name, status);
|
|
1264
|
+
activeAttempt = undefined;
|
|
1265
|
+
remembered.failed = new Set(queue.failed());
|
|
1266
|
+
if (proofGuided)
|
|
1267
|
+
remembered.discoveryContexts = queue.discoveryContexts();
|
|
1268
|
+
for (const invalidated of outcome.invalidated) {
|
|
1269
|
+
scopes.delete(invalidated);
|
|
1270
|
+
remembered.committed.delete(invalidated);
|
|
1271
|
+
}
|
|
1272
|
+
if (outcome.held && scope) {
|
|
1273
|
+
scopes.set(law.name, scope);
|
|
1274
|
+
if (reach)
|
|
1275
|
+
for (const premise of scope.premises)
|
|
1276
|
+
countsDump.on?.({ phase: 'count-required-promotion', kind: 'dependency', law: premise.name, citedBy: law.name, reducedScopeSize: scope.premises.length, committed: false, proposed: true, checked: false });
|
|
1277
|
+
}
|
|
1278
|
+
else if (decision.phase !== 'dissolve')
|
|
1279
|
+
scopes.delete(law.name);
|
|
1280
|
+
updateReserve();
|
|
1281
|
+
countsDump.on?.({ phase: 'count-component-result', law: law.name, mode: decision.phase, purpose: decision.purpose, component: decision.component, at: clock(), outcome: outcome.held ? 'proof' : status.kind, reason: 'reason' in status ? status.reason : undefined, units: (clock() - start) * fullRate, held: outcome.held, failed: queue.failed(), unknown: queue.unknown(), invalidated: outcome.invalidated, retries: queue.retryCount(), premises: scope?.premises.map(p => p.name) ?? [] });
|
|
1282
|
+
}
|
|
1283
|
+
reachSummary();
|
|
1284
|
+
countsDump.on?.({ phase: 'count-prerequisite-incomplete', unknown: queue.unknown(), failed: queue.failed() });
|
|
1285
|
+
return { proven: false, laws: set, m, why: 'component proposals did not close caller' };
|
|
1286
|
+
};
|
|
1287
|
+
const join = (kept = new Map()) => {
|
|
1288
|
+
const keptProof = () => ({ instances: Object.fromEntries([...kept].map(([n, pr]) => [n, pr.instances])), certs: Object.assign({}, ...[...kept.values()].map(pr => pr.certs)), ...(scopeEnabled ? { premises: Object.fromEntries([...kept].flatMap(([name, pr]) => pr.premises ? [[name, pr.premises]] : [])) } : {}) });
|
|
1289
|
+
if (caller.every(l => kept.has(l.name)))
|
|
1290
|
+
return finish(set.filter(l => kept.has(l.name)), keptProof());
|
|
1291
|
+
// Each untried law gets an even share of what remains now, not what
|
|
1292
|
+
// remained at round entry. Cheap proofs return their underspend to the pool.
|
|
1293
|
+
let carried = new Map();
|
|
1294
|
+
const scopes = new Map();
|
|
1295
|
+
const neededForSearch = () => countClosingNeeds([...caller.map(l => l.name), ...set.filter(l => selected.has(l) && scopes.has(l.name)).map(l => l.name)], scopes);
|
|
1296
|
+
attempts.houdini = true;
|
|
1297
|
+
for (let round = 0; clock() < until; round++) {
|
|
1298
|
+
const { instances, certs, premises = {} } = keptProof();
|
|
1299
|
+
const failed = new Set(), proofs = new Map();
|
|
1300
|
+
const pending = new Set(set.filter(l => !selected.has(l) && !kept.has(l.name) && !carried.has(l.name)).map(l => l.name));
|
|
1301
|
+
// Count readers first, then explicit supports and callers; unrelated
|
|
1302
|
+
// scalar helpers cannot consume the whole allowance before count admission.
|
|
1303
|
+
const order = supportOrder(set, caller, support, false, env.GDP_COUNT_STRATEGIES === '1' ? m : undefined);
|
|
1304
|
+
const todo = [...order.filter(l => selected.has(l)), ...order.filter(l => !selected.has(l))];
|
|
1305
|
+
for (let position = 0; position < todo.length; position++) {
|
|
1306
|
+
if (closingBudget && !selected.has(todo[position])) {
|
|
1307
|
+
const needed = neededForSearch();
|
|
1308
|
+
const prerequisites = new Set([...scopes.values()].filter(s => selected.has(set.find(l => l.name === s.owner.name))).flatMap(s => s.premises.map(p => p.name)));
|
|
1309
|
+
let next = todo.findIndex((l, i) => i >= position && prerequisites.has(l.name) && !proofs.has(l.name));
|
|
1310
|
+
if (next < 0)
|
|
1311
|
+
next = todo.findIndex((l, i) => i >= position && needed.has(l.name));
|
|
1312
|
+
if (next > position)
|
|
1313
|
+
[todo[position], todo[next]] = [todo[next], todo[position]];
|
|
1314
|
+
}
|
|
1315
|
+
const law = todo[position];
|
|
1316
|
+
checkWall('Houdini round');
|
|
1317
|
+
if (clock() > until)
|
|
1318
|
+
return { proven: false, laws: set, m, why: 'time' };
|
|
1319
|
+
if (kept.has(law.name))
|
|
1320
|
+
continue;
|
|
1321
|
+
const was = carried.get(law.name);
|
|
1322
|
+
const required = closingBudget ? neededForSearch() : undefined;
|
|
1323
|
+
const focused = required && new Set([...pending].filter(name => required.has(name)));
|
|
1324
|
+
const share = budget && !closingBudget ? ordinaryTierShare(budget, clock(), pending) : attemptShare(until - clock(), focused?.size ? focused : pending);
|
|
1325
|
+
pending.delete(law.name);
|
|
1326
|
+
const structural = support.has(law) && !caller.includes(law);
|
|
1327
|
+
const strategy = selected.has(law), boundedSupport = !budget && activeSupport(set, support);
|
|
1328
|
+
const allotted = strategy ? Math.max(0, budget.strategyUntil - clock()) : budget ? share : supportBudget(until - clock(), share, boundedSupport && caller.includes(law), structural);
|
|
1329
|
+
const supportUntil = strategy ? budget.strategyUntil : Math.min(until, clock() + (boundedSupport ? Math.min(allotted, 5_000) : allotted)), supportWall = wallDeadline(countedSearchNow() + 4_800);
|
|
1330
|
+
let proofContext = closingBudget && !strategy && required ? set.filter(l => required.has(l.name) || l === law) : set;
|
|
1331
|
+
const ask = (pass) => {
|
|
1332
|
+
const ms = Math.min(allotted, Math.max(0, (boundedSupport ? supportUntil : until) - clock()));
|
|
1333
|
+
if (scopeEnabled)
|
|
1334
|
+
countsDump.on?.({ phase: 'houdini-attempt', law: law.name, round, pass });
|
|
1335
|
+
if (budget)
|
|
1336
|
+
countsDump.on?.({ phase: 'count-tier-attempt', law: law.name, tier: strategy ? 'strategy' : 'ordinary', end: supportUntil, allotted });
|
|
1337
|
+
const run = () => {
|
|
1338
|
+
const invoke = (allowance) => strategy ? withDeadline(supportUntil, () => traced(law, proofContext, pass, allowance)) : boundedSupport ? withWall(supportWall, () => withDeadline(supportUntil, () => traced(law, proofContext, pass, allowance))) : traced(law, proofContext, pass, allowance);
|
|
1339
|
+
let result = invoke(ms);
|
|
1340
|
+
if (closingBudget && proofContext !== set && !('proof' in result) && clock() < Math.min(supportUntil, until)) {
|
|
1341
|
+
proofContext = set;
|
|
1342
|
+
result = invoke(Math.min(ms, Math.max(0, Math.min(supportUntil, until) - clock())));
|
|
1343
|
+
}
|
|
1344
|
+
return result;
|
|
1345
|
+
};
|
|
1346
|
+
if (!closingBudget)
|
|
1347
|
+
return run();
|
|
1348
|
+
return withSearchAllowance(Math.min(supportUntil, until), run, error => {
|
|
1349
|
+
if (!isLocalCountExpiration(error, closingBudget.until))
|
|
1350
|
+
throw error;
|
|
1351
|
+
return { stuck: 'unknown' };
|
|
1352
|
+
});
|
|
1353
|
+
};
|
|
1354
|
+
const countFirst = !strategy && firstCountPass(m, law, (env.GDP_COUNTS_COUNT_FIRST === '1' || boundedSupport && env.GDP_COUNTS_COUNT_FIRST !== '0') && (reads(law.holds, isCount).size > 0 || boundedSupport && !!law.keys?.length)) === 1;
|
|
1355
|
+
let r = was ? { proof: was } : ask(countFirst ? 1 : 0);
|
|
1356
|
+
if (!('proof' in r) && !r.refuted && !strategy && (countFirst || attempts.counted))
|
|
1357
|
+
r = ask(countFirst ? 0 : 1);
|
|
1358
|
+
if (closingBudget)
|
|
1359
|
+
countsDump.on?.({ phase: 'count-family-collection', law: law.name, proposed: 'proof' in r, at: clock() });
|
|
1360
|
+
if (!('proof' in r)) {
|
|
1361
|
+
failed.add(law.name);
|
|
1362
|
+
continue;
|
|
1363
|
+
}
|
|
1364
|
+
if (!was && scopeEnabled) {
|
|
1365
|
+
const scoped = ptime('premise-scope', () => scopeCountProof(m, law, proofContext, r.proof, until));
|
|
1366
|
+
if (scoped) {
|
|
1367
|
+
scopes.set(law.name, scoped);
|
|
1368
|
+
r.proof = { ...r.proof, premises: scoped.premises.map(p => p.name) };
|
|
1369
|
+
}
|
|
1370
|
+
else
|
|
1371
|
+
scopes.delete(law.name);
|
|
1372
|
+
if (closingBudget)
|
|
1373
|
+
countsDump.on?.({ phase: 'count-family-scope', law: law.name, scoped: !!scoped, premises: scoped?.premises.map(p => p.name) ?? [] });
|
|
1374
|
+
}
|
|
1375
|
+
proofs.set(law.name, r.proof);
|
|
1376
|
+
instances[law.name] = r.proof.instances;
|
|
1377
|
+
if (r.proof.premises)
|
|
1378
|
+
premises[law.name] = r.proof.premises;
|
|
1379
|
+
Object.assign(certs, r.proof.certs);
|
|
1380
|
+
if (closingBudget) {
|
|
1381
|
+
const needed = countClosingNeeds(caller.map(l => l.name), scopes);
|
|
1382
|
+
if ([...needed].every(name => proofs.has(name) && scopes.has(name))) {
|
|
1383
|
+
const family = set.filter(l => needed.has(l.name)), instances = {}, certs = {}, premises = {};
|
|
1384
|
+
let ready = true;
|
|
1385
|
+
for (const member of family) {
|
|
1386
|
+
const replayed = ptime('premise-replay', () => replayScopedCountProof(m, family, scopes.get(member.name), until, { deferToClosing: true, sourceFamily: set }));
|
|
1387
|
+
if (!replayed) {
|
|
1388
|
+
ready = false;
|
|
1389
|
+
break;
|
|
1390
|
+
}
|
|
1391
|
+
instances[member.name] = replayed.instances;
|
|
1392
|
+
Object.assign(certs, replayed.certs);
|
|
1393
|
+
premises[member.name] = replayed.premises ?? [];
|
|
1394
|
+
}
|
|
1395
|
+
if (ready)
|
|
1396
|
+
return finish(family, { instances, certs, premises });
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
if (env.GDP_COUNTS_TRACE)
|
|
1401
|
+
console.error(`counts: round ${round}: ${set.length} laws, ${kept.size} kept, ${carried.size} carried, failed ${[...failed].join('; ').slice(0, 600)}`);
|
|
1402
|
+
if (!failed.size)
|
|
1403
|
+
return closingBudget ? { proven: false, laws: set, m, why: 'closing scope incomplete' } : finish(set, { instances, certs, ...(scopeEnabled ? { premises } : {}) });
|
|
1404
|
+
const next = set.filter(l => !failed.has(l.name) || caller.includes(l));
|
|
1405
|
+
// (only callers fail: drop nothing more, give up)
|
|
1406
|
+
if (next.length === set.length)
|
|
1407
|
+
return { proven: false, laws: set, m, why: `not proven: ${[...failed].join(', ')}` };
|
|
1408
|
+
// Instantiating a law does not mean the proof used it. Replay only the
|
|
1409
|
+
// recorded premise scope, against the exact reduced row layout, without
|
|
1410
|
+
// solving again. Missing premises and failed checks reopen the attempt.
|
|
1411
|
+
carried = new Map();
|
|
1412
|
+
if (!scopeEnabled) {
|
|
1413
|
+
const dropped = set.filter(l => !next.includes(l));
|
|
1414
|
+
carried = new Map([...proofs].filter(([, pr]) => dropped.every(d => d.forall && !pr.instances[d.name]?.length)));
|
|
1415
|
+
}
|
|
1416
|
+
else
|
|
1417
|
+
for (const name of proofs.keys()) {
|
|
1418
|
+
const scoped = scopes.get(name);
|
|
1419
|
+
const replayed = scoped && ptime('premise-replay', () => replayScopedCountProof(m, next, scoped, until, { deferToClosing: finalCountStepDeferralEnabled(), sourceFamily: set }));
|
|
1420
|
+
countsDump.on?.({ phase: 'premise-replay', law: name, round, retained: !!replayed, premises: scoped?.premises.map(p => p.name) });
|
|
1421
|
+
if (replayed)
|
|
1422
|
+
carried.set(name, replayed);
|
|
1423
|
+
else
|
|
1424
|
+
scopes.delete(name);
|
|
1425
|
+
}
|
|
1426
|
+
set = next;
|
|
1427
|
+
}
|
|
1428
|
+
return { proven: false, laws: set, m, why: 'time' };
|
|
1429
|
+
};
|
|
1430
|
+
// Flags off retain the exact pre-scoping dependency/carry algorithm.
|
|
1431
|
+
const dependencies = (owner, proof, context) => {
|
|
1432
|
+
const conservative = () => new Set(context.filter(l => !l.forall || proof.instances[l.name]?.length).map(l => l.name)), used = new Set();
|
|
1433
|
+
for (const { goal, decls } of countedObligations(m, context, { [owner.name]: proof.instances }, context.indexOf(owner))) {
|
|
1434
|
+
const cert = proof.certs[goal.name];
|
|
1435
|
+
if (!cert)
|
|
1436
|
+
return conservative();
|
|
1437
|
+
const expanded = mcGoal(goal.hyps, decls, cert), refs = expanded && countedCertificateHyps(expanded, cert);
|
|
1438
|
+
if (!refs)
|
|
1439
|
+
return conservative();
|
|
1440
|
+
for (const index of refs)
|
|
1441
|
+
if (index < goal.hyps.length)
|
|
1442
|
+
used.add(json(goal.hyps[index]));
|
|
1443
|
+
}
|
|
1444
|
+
return new Set(context.filter(l => assumed([l], proof.instances).some(h => used.has(json(h)))).map(l => l.name));
|
|
1445
|
+
};
|
|
1446
|
+
const legacyDemand = () => {
|
|
1447
|
+
const known = new Map();
|
|
1448
|
+
attempts.houdini = true;
|
|
1449
|
+
while (clock() < until) {
|
|
1450
|
+
if (!activeSupport(set, support))
|
|
1451
|
+
return join();
|
|
1452
|
+
const required = new Set(caller.map(l => l.name)), available = new Set(set.map(l => l.name));
|
|
1453
|
+
for (const name of required) {
|
|
1454
|
+
const saved = known.get(name);
|
|
1455
|
+
if (saved)
|
|
1456
|
+
for (const dep of saved.deps)
|
|
1457
|
+
if (available.has(dep))
|
|
1458
|
+
required.add(dep);
|
|
1459
|
+
}
|
|
1460
|
+
const law = supportOrder(set, caller, support, false, env.GDP_COUNT_STRATEGIES === '1' ? m : undefined).find(l => required.has(l.name) && !known.has(l.name));
|
|
1461
|
+
if (!law) {
|
|
1462
|
+
const kept = set.filter(l => required.has(l.name)), instances = {}, certs = {};
|
|
1463
|
+
for (const l of kept) {
|
|
1464
|
+
const saved = known.get(l.name);
|
|
1465
|
+
instances[l.name] = saved.proof.instances;
|
|
1466
|
+
const src = countedObligations(m, saved.context, { [l.name]: saved.proof.instances }, saved.context.indexOf(l)), dst = countedObligations(m, kept, { [l.name]: saved.proof.instances }, kept.indexOf(l));
|
|
1467
|
+
for (let i = 0; i < dst.length; i++) {
|
|
1468
|
+
const cert = saved.proof.certs[src[i].goal.name];
|
|
1469
|
+
if (!cert)
|
|
1470
|
+
return join();
|
|
1471
|
+
const a = mcGoal(src[i].goal.hyps, src[i].decls, cert), b = mcGoal(dst[i].goal.hyps, dst[i].decls, cert), lifted = a && b && transportCountCertificate(a, b, cert, wallAt(), { declarations: { from: src[i].decls, to: dst[i].decls }, diagnostic: { member: l.name, obligation: dst[i].goal.name, route: 'retained-family' } });
|
|
1472
|
+
if (!lifted)
|
|
1473
|
+
return join();
|
|
1474
|
+
certs[dst[i].goal.name] = lifted;
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
return finish(kept, { instances, certs });
|
|
1478
|
+
}
|
|
1479
|
+
const remaining = until - clock(), share = remaining / Math.max(1, set.length - known.size), allotted = supportBudget(remaining, share, caller.includes(law), support.has(law) && !caller.includes(law)), stop = Math.min(until, clock() + Math.min(allotted, 5000)), wall = wallDeadline(countedSearchNow() + 4800);
|
|
1480
|
+
const countFirst = env.GDP_COUNTS_COUNT_FIRST !== '0' && (reads(law.holds, isCount).size > 0 || !!law.keys?.length);
|
|
1481
|
+
const ask = (context) => withWall(wall, () => withDeadline(stop, () => {
|
|
1482
|
+
const pass = countFirst ? 1 : 0;
|
|
1483
|
+
let result = traced(law, context, pass, Math.min(allotted, Math.max(0, stop - clock())));
|
|
1484
|
+
if (!('proof' in result) && !result.refuted && (countFirst || attempts.counted) && clock() < stop)
|
|
1485
|
+
result = traced(law, context, pass ? 0 : 1, Math.min(allotted, Math.max(0, stop - clock())));
|
|
1486
|
+
return result;
|
|
1487
|
+
}));
|
|
1488
|
+
let context = coarseContext(m, set, [...caller, law], support), result = ask(context);
|
|
1489
|
+
if (!('proof' in result) && context.length < set.length && clock() < stop) {
|
|
1490
|
+
context = set;
|
|
1491
|
+
result = ask(context);
|
|
1492
|
+
}
|
|
1493
|
+
countsDump.on?.({ phase: 'demand-attempt', law: law.name, context: context.length, required: required.size, known: known.size, outcome: 'proof' in result ? 'proof' : result.stuck });
|
|
1494
|
+
if ('proof' in result) {
|
|
1495
|
+
known.set(law.name, { proof: result.proof, context: context.slice(), deps: dependencies(law, result.proof, context) });
|
|
1496
|
+
continue;
|
|
1497
|
+
}
|
|
1498
|
+
if (caller.includes(law))
|
|
1499
|
+
return join();
|
|
1500
|
+
set = set.filter(l => l !== law);
|
|
1501
|
+
for (const [name, saved] of known)
|
|
1502
|
+
if (saved.deps.has(law.name))
|
|
1503
|
+
known.delete(name);
|
|
1504
|
+
}
|
|
1505
|
+
return { proven: false, laws: set, m, why: 'time' };
|
|
1506
|
+
};
|
|
1507
|
+
const demand = () => {
|
|
1508
|
+
const known = new Map();
|
|
1509
|
+
attempts.houdini = true;
|
|
1510
|
+
while (clock() < until) {
|
|
1511
|
+
if (!activeSupport(set, support))
|
|
1512
|
+
return join();
|
|
1513
|
+
const required = new Set(caller.map(l => l.name)), available = new Set(set.map(l => l.name));
|
|
1514
|
+
for (const name of required) {
|
|
1515
|
+
const saved = known.get(name);
|
|
1516
|
+
if (saved)
|
|
1517
|
+
for (const dep of saved.premises)
|
|
1518
|
+
if (available.has(dep.name))
|
|
1519
|
+
required.add(dep.name);
|
|
1520
|
+
}
|
|
1521
|
+
const law = supportOrder(set, caller, support, false, env.GDP_COUNT_STRATEGIES === '1' ? m : undefined).find(l => required.has(l.name) && !known.has(l.name));
|
|
1522
|
+
if (!law) {
|
|
1523
|
+
const kept = set.filter(l => required.has(l.name)), instances = {}, certs = {}, premises = {};
|
|
1524
|
+
for (const l of kept) {
|
|
1525
|
+
const replayed = ptime('premise-replay', () => replayScopedCountProof(m, kept, known.get(l.name), until, { deferToClosing: finalCountStepDeferralEnabled(), sourceFamily: set }));
|
|
1526
|
+
if (!replayed)
|
|
1527
|
+
return join();
|
|
1528
|
+
instances[l.name] = replayed.instances;
|
|
1529
|
+
premises[l.name] = replayed.premises ?? [];
|
|
1530
|
+
Object.assign(certs, replayed.certs);
|
|
1531
|
+
}
|
|
1532
|
+
return finish(kept, { instances, certs, premises });
|
|
1533
|
+
}
|
|
1534
|
+
const remaining = until - clock(), share = remaining / Math.max(1, set.length - known.size), allotted = supportBudget(remaining, share, caller.includes(law), support.has(law) && !caller.includes(law)), stop = Math.min(until, clock() + Math.min(allotted, 5000));
|
|
1535
|
+
const countFirst = firstCountPass(m, law, env.GDP_COUNTS_COUNT_FIRST !== '0' && (reads(law.holds, isCount).size > 0 || !!law.keys?.length)) === 1;
|
|
1536
|
+
const ask = (context) => withDeadline(stop, () => {
|
|
1537
|
+
const pass = countFirst ? 1 : 0;
|
|
1538
|
+
let result = traced(law, context, pass, Math.min(allotted, Math.max(0, stop - clock())));
|
|
1539
|
+
if (!('proof' in result) && !result.refuted && (countFirst || attempts.counted) && clock() < stop)
|
|
1540
|
+
result = traced(law, context, pass ? 0 : 1, Math.min(allotted, Math.max(0, stop - clock())));
|
|
1541
|
+
return result;
|
|
1542
|
+
});
|
|
1543
|
+
let context = coarseContext(m, set, [...caller, law], support), result = ask(context);
|
|
1544
|
+
if (!('proof' in result) && context.length < set.length && clock() < stop) {
|
|
1545
|
+
context = set;
|
|
1546
|
+
result = ask(context);
|
|
1547
|
+
}
|
|
1548
|
+
countsDump.on?.({ phase: 'demand-attempt', law: law.name, context: context.length, required: required.size, known: known.size, outcome: 'proof' in result ? 'proof' : result.stuck });
|
|
1549
|
+
if ('proof' in result) {
|
|
1550
|
+
const scoped = ptime('premise-scope', () => scopeCountProof(m, law, context, result.proof, until));
|
|
1551
|
+
if (!scoped)
|
|
1552
|
+
return join();
|
|
1553
|
+
known.set(law.name, scoped);
|
|
1554
|
+
continue;
|
|
1555
|
+
}
|
|
1556
|
+
if (caller.includes(law))
|
|
1557
|
+
return join();
|
|
1558
|
+
set = set.filter(l => l !== law);
|
|
1559
|
+
for (const [name, saved] of known)
|
|
1560
|
+
if (saved.premises.some(p => p.name === law.name))
|
|
1561
|
+
known.delete(name);
|
|
1562
|
+
}
|
|
1563
|
+
return { proven: false, laws: set, m, why: 'time' };
|
|
1564
|
+
};
|
|
1565
|
+
return prerequisiteFirst ? proofGuided && completeWorkProfile.enabled ? recipeJoint() : joint() : budget ? join() : activeSupport(set, support) ? scopeEnabled ? demand() : legacyDemand() : join();
|
|
1566
|
+
}
|
|
1567
|
+
// The production attempt also serves the fixed-family research replay. Candidate
|
|
1568
|
+
// generation and scheduling stay outside; inference, selection, reservation and
|
|
1569
|
+
// all budget checks have exactly one implementation.
|
|
1570
|
+
export function countedAttempts(m, caller, support, until, structured = true, focusedOrStrategies = true, budgetOrWork, tierBudget, shapeFamily) {
|
|
1571
|
+
// Preserve I's boolean/tier API and B's explicit strategy-set/work API.
|
|
1572
|
+
const allowFocused = typeof focusedOrStrategies === 'boolean' ? focusedOrStrategies : true;
|
|
1573
|
+
const strategyOnly = typeof focusedOrStrategies === 'boolean' ? new Set() : focusedOrStrategies;
|
|
1574
|
+
const tiers = typeof budgetOrWork === 'number' ? tierBudget : budgetOrWork;
|
|
1575
|
+
const workAllowance = typeof budgetOrWork === 'number' ? budgetOrWork : tiers?.workAllowance ?? Math.max(0, until - clock());
|
|
1576
|
+
// Capture the enclosing phase before entering any per-law or subset share.
|
|
1577
|
+
const enclosingEnd = withinDeadline(until);
|
|
440
1578
|
// (the law's own names and the request's values that key a map: an action's value keys none)
|
|
441
1579
|
const keys0 = [...[...reads([m.step, m.assume ?? null], () => true).values()].map(([, key]) => key), ...Object.values(m.step.maps ?? {}).flatMap(w => ('each' in w ? [] : [w.key]))];
|
|
442
1580
|
const keyed = m.inputs.filter(i => keys0.some(key => mentions(key, i))).map(v);
|
|
@@ -455,46 +1593,246 @@ function searchCounted0(m0, g, m, caller, ms) {
|
|
|
455
1593
|
// Cone tiers and Houdini may ask the same law again with more instances. Keep a
|
|
456
1594
|
// bounded set of sessions; each independently resets unless its hypotheses are
|
|
457
1595
|
// still present verbatim. This reuses work, never a verdict from a weaker goal.
|
|
458
|
-
const decisions = new Map();
|
|
459
|
-
|
|
1596
|
+
const decisions = new Map(), focusEnabled = allowFocused && focusedCountRecoveryEnabled(m);
|
|
1597
|
+
// Opt-in until the fixed-operation census and preservation gate have been qualified.
|
|
1598
|
+
const frameChoice = env.GDP_COUNT_FRAMES === '1' ? fixedCountFrameCase(m) : undefined;
|
|
1599
|
+
// Scheduling history only, never a cached verdict. A different family must
|
|
1600
|
+
// earn its own ordinary attempts before using the finite recovery search.
|
|
1601
|
+
const plainFailures = new WeakMap();
|
|
1602
|
+
let finite;
|
|
1603
|
+
const ordinaryAttempt = (law, ls, pass, ms, attemptEnd, defer) => {
|
|
460
1604
|
// A cached model can return before the no-count optimization below. A helper
|
|
461
1605
|
// without count reads must not suppress the next law's counting-lemma pass.
|
|
462
1606
|
if (!pass)
|
|
463
1607
|
counted = true;
|
|
464
1608
|
const ts = terms(law), id = `${pass} ${law.name}`, cti = models.get(id);
|
|
1609
|
+
const supported = ls.some(l => support.has(l)), modelLaws = supportOrder(ls, caller, support, true);
|
|
1610
|
+
let memberState;
|
|
1611
|
+
const members = () => memberState ??= memberPremiseState([m, ls]);
|
|
1612
|
+
// A source predicate may be instantiated at a count witness, but no
|
|
1613
|
+
// count-read key may depend on that same witness (checkMC freshness).
|
|
1614
|
+
const independent = (before, next, wits = []) => {
|
|
1615
|
+
if (!next)
|
|
1616
|
+
return undefined;
|
|
1617
|
+
const blocked = [...memberState?.witnesses.values() ?? [], ...cti?.wits ?? []];
|
|
1618
|
+
return blocked.length ? independentCountInstances(m, modelLaws, before, next, [...blocked, ...wits]) : next;
|
|
1619
|
+
};
|
|
1620
|
+
// Try ordinary counted reasoning before finite recovery when the plain
|
|
1621
|
+
// pass needs counts. Keep the no-count fallback and the existing wide-pool
|
|
1622
|
+
// recovery, using only the current attempt's remaining allowance.
|
|
1623
|
+
if (focusEnabled && m.inputMaps?.length && !reads(law.holds, isCount).size && (!pass || plainFailures.get(law)?.has(ls))) {
|
|
1624
|
+
defer(() => ptime('focused', () => proveFocusedCounts(m, ls, law, {}, Math.min(attemptEnd, clock() + Math.min(ms, 5000)), (g, ds) => certFor(g, ds, true, pool, undefined, structured))));
|
|
1625
|
+
}
|
|
465
1626
|
// (the model broken: the attempt starts at the instances it asks for, its last attempt's and the tuples the new laws
|
|
466
1627
|
// break it at, where the rounds of models would lead it again)
|
|
467
1628
|
let seed;
|
|
1629
|
+
const refuted = (gg, w, instances) => {
|
|
1630
|
+
const completion = (finite ??= finiteModelChecker(m))(ls, law, w, () => clock() >= attemptEnd);
|
|
1631
|
+
countsDump.on?.({ phase: 'finite-model', law: law.name, pass, completion });
|
|
1632
|
+
if (env.GDP_COUNTS_DUMP_ALL_PASSES === '1')
|
|
1633
|
+
countsDump.on?.({ phase: completion.genuine ? 'final-sat' : 'uncertified-model', stuck: completion.genuine || !pass ? 'sat' : 'unknown', law: law.name, pass, machine: m, laws: ls, goal: gg, witness: w, at: instances });
|
|
1634
|
+
models.set(id, { gg, w, at: instances, ls: new Set(ls.map(l => l.name)), wits: [...memberState?.witnesses.values() ?? [], ...cti?.wits ?? []] });
|
|
1635
|
+
return completion.genuine ? { stuck: 'sat', refuted: true } : { stuck: pass ? 'unknown' : 'sat' };
|
|
1636
|
+
};
|
|
468
1637
|
// (not where the attempt may widen: its narrow model is no model of the widened goal)
|
|
469
|
-
if (cti && !(houdini && caller.some(l => l.name === law.name) && !widened.has(law.name)) && !ls.some(l => !cti.ls.has(l.name) && reads(l.holds, isCount).size)) {
|
|
1638
|
+
if (cti && !(tiers?.active && ls.some(l => !cti.ls.has(l.name))) && !(supported && pass) && !(houdini && caller.some(l => l.name === law.name) && !widened.has(law.name)) && !ls.some(l => !cti.ls.has(l.name) && reads(l.holds, isCount).size)) {
|
|
470
1639
|
const at0 = Object.fromEntries(Object.entries(cti.at).filter(([n]) => n.startsWith('?') || ls.some(l => l.name === n)));
|
|
471
|
-
if (!(seed = ptime('mbqi', () => modelInstances(m,
|
|
472
|
-
return
|
|
1640
|
+
if (!(seed = ptime('mbqi', () => independent(at0, modelInstances(m, modelLaws, at0, cti.gg, cti.w)))))
|
|
1641
|
+
return refuted(cti.gg, cti.w, cti.at);
|
|
473
1642
|
}
|
|
474
|
-
|
|
475
|
-
|
|
1643
|
+
// Supported obligations seed quantified flags only at demanded source terms.
|
|
1644
|
+
// Ordinary MBQI remains the fallback; arbitrary inputs are not initial witnesses.
|
|
1645
|
+
let at = seed ?? (supported ? {} : Object.fromEntries(Object.entries(m.step.flags ?? {}).flatMap(([f, q]) => (q.op === 'all' && !q.keys?.length ? [[`?${f}`, ts]] : []))));
|
|
1646
|
+
if (pass && frameChoice && ls.includes(law) && reads(law.holds, isCount).size)
|
|
1647
|
+
at = ownCountLawInstance(law, at);
|
|
476
1648
|
const obligations = (i) => ptime('encode', () => countedObligations(m, ls, { [law.name]: i }, ls.indexOf(law)));
|
|
1649
|
+
// A fixed-operation frame proof needs only the ordinary own-key premise.
|
|
1650
|
+
// Try it before count-pool construction. INIT is still a separate obligation:
|
|
1651
|
+
// its zero counts need ordinary unary witnesses, absent from a narrow pool
|
|
1652
|
+
// containing only post-state reads. Neither its truth nor its proof is assumed.
|
|
1653
|
+
if (pass && frameChoice && ls.includes(law) && reads(law.holds, isCount).size) {
|
|
1654
|
+
const end = Math.min(attemptEnd, clock() + Math.min(ms, 500));
|
|
1655
|
+
try {
|
|
1656
|
+
const early = ptime('frames', () => withDeadline(end, () => {
|
|
1657
|
+
const packets = obligations(at), step = packets.at(-1);
|
|
1658
|
+
if (!step)
|
|
1659
|
+
return;
|
|
1660
|
+
const more = () => clock() < end;
|
|
1661
|
+
const request = certFor(step.goal, step.decls, false, 0, more, structured);
|
|
1662
|
+
const maps = new Set([...reads(law.holds, isCount).values()].map(([map]) => map));
|
|
1663
|
+
const cert = proveCountFrameGoal(step.goal, step.decls, request, frameChoice, maps, end, cut => countsDump.on?.({ phase: 'count-cut', law: law.name, goal: step.goal.name, pass, ...cut }));
|
|
1664
|
+
if (!cert)
|
|
1665
|
+
return;
|
|
1666
|
+
const emit = (p, c, phase) => countsDump.on?.({ law: law.name, goal: p.goal.name, pass, phase, rawGoal: p.goal, decls: p.decls, instances: at, certificateRequest: c, hyps: mcGoal(p.goal.hyps, p.decls, c)?.hyps });
|
|
1667
|
+
emit(step, cert, 'frame-proven');
|
|
1668
|
+
const certs = { [step.goal.name]: cert };
|
|
1669
|
+
for (const initial of packets.slice(0, -1)) {
|
|
1670
|
+
const request = certFor(initial.goal, initial.decls, true, 24, more, structured);
|
|
1671
|
+
const gg = mcGoal(initial.goal.hyps, initial.decls, request);
|
|
1672
|
+
const out = gg && grow(gg, new Map(), { nodes: 0, until: end });
|
|
1673
|
+
if (!out || !('tree' in out))
|
|
1674
|
+
return;
|
|
1675
|
+
const c = { reads: request.reads, insts: request.insts, picks: request.picks, tree: out.tree };
|
|
1676
|
+
if (!checkMC(initial.goal.hyps, initial.decls, c))
|
|
1677
|
+
return;
|
|
1678
|
+
emit(initial, c, 'frame-start-proven');
|
|
1679
|
+
certs[initial.goal.name] = c;
|
|
1680
|
+
}
|
|
1681
|
+
return { instances: at, certs };
|
|
1682
|
+
}));
|
|
1683
|
+
if (early)
|
|
1684
|
+
return { proof: early };
|
|
1685
|
+
}
|
|
1686
|
+
catch (error) {
|
|
1687
|
+
if (!(error instanceof WallExpired) || clock() >= attemptEnd)
|
|
1688
|
+
throw error;
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
477
1691
|
// (`wide`: the count instances widened once, where a model is left that the narrow ones and the laws don't refute, for
|
|
478
1692
|
// a caller's law or where a read is in none of them: the cone's many refuted candidates keep the narrow ones)
|
|
1693
|
+
// Source-only proposals share one 64-tuple/4-per-source budget for this attempt.
|
|
1694
|
+
// The ordinary MBQI path remains available and is unchanged without support.
|
|
1695
|
+
const generation = candidateWork();
|
|
1696
|
+
let seedCount = 0;
|
|
1697
|
+
let sourceMaps = new Set();
|
|
1698
|
+
if (supported) {
|
|
1699
|
+
const prepared = prepareSupport(m, ls, law, at, pass, generation);
|
|
1700
|
+
at = prepared.at;
|
|
1701
|
+
seedCount = prepared.seedCount;
|
|
1702
|
+
sourceMaps = prepared.sourceMaps;
|
|
1703
|
+
}
|
|
479
1704
|
let wide = false;
|
|
480
1705
|
const isCaller = houdini && caller.some(l => l.name === law.name);
|
|
481
1706
|
// (lazy (CEGAR): the goal carries the counting lemma's instances and picks some model of it broke, of all certFor
|
|
482
1707
|
// proposes: each model read against the rest, as a state, and those it breaks added, until a model breaks none; an
|
|
483
1708
|
// instance by the reads it names, a pick by its read and terms, so the choice outlives the goal's rebuilds)
|
|
484
1709
|
const chosen = new Set();
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
1710
|
+
const selections = new Map();
|
|
1711
|
+
const poolCache = new Map();
|
|
1712
|
+
const memberSources = new Map();
|
|
1713
|
+
// Demand-driven ranges (Fable b89dd77a / Lane B): retain a goal's demand
|
|
1714
|
+
// across rebuilds, without crowding out ordinary member inclusions.
|
|
1715
|
+
// Every proposed range remains an ordinary kernel-checked count instance.
|
|
1716
|
+
const rangeWanted = new Map();
|
|
1717
|
+
const withRanges = (goal, decls, c, all) => {
|
|
1718
|
+
const wanted = rangeWanted.get(goal.name);
|
|
1719
|
+
if (!pass || !wanted?.size)
|
|
1720
|
+
return c;
|
|
1721
|
+
const taken = new Set([...all.map(r => r[0]), ...c.insts.map(i => i.wit), ...m.params, ...m.inputs, ...Object.keys(m.state)]);
|
|
1722
|
+
const ranges = rangeInstances(decls, all.filter(r => wanted.has(r[0])), taken, c.insts);
|
|
1723
|
+
if (!ranges.length)
|
|
1724
|
+
return c;
|
|
1725
|
+
const have = new Set(c.reads.map(r => r[0])), named = new Set(ranges.map(i => i.terms[0][1]));
|
|
1726
|
+
const reads = [...c.reads, ...all.filter(r => !have.has(r[0]) && named.has(r[0]))];
|
|
1727
|
+
return { ...c, reads, insts: [...c.insts, ...ranges], ...(c.wits ? { wits: [...c.wits, ...ranges.map(i => i.wit)] } : {}) };
|
|
1728
|
+
};
|
|
1729
|
+
// (a model that puts a read's count above its bound: those reads' ranges wanted from now on; whether any is new)
|
|
1730
|
+
const wantRanges = (goal, decls, all, w) => {
|
|
1731
|
+
let set = rangeWanted.get(goal.name);
|
|
1732
|
+
if (!set)
|
|
1733
|
+
rangeWanted.set(goal.name, (set = new Set()));
|
|
1734
|
+
let grew = false;
|
|
1735
|
+
for (const read of rangeViolations(decls, all, w))
|
|
1736
|
+
if (!set.has(read[0])) {
|
|
1737
|
+
set.add(read[0]);
|
|
1738
|
+
grew = true;
|
|
1739
|
+
}
|
|
1740
|
+
return grew;
|
|
1741
|
+
};
|
|
1742
|
+
const rawBuild = () => obligations(at).map(({ goal, decls }) => {
|
|
1743
|
+
if (pass && supported && lazyMode === 'wide') {
|
|
1744
|
+
if (generation.state.deadline || countedSearchNow() >= wallAt())
|
|
1745
|
+
throw new UnsupportedCountProposal('reservation deadline');
|
|
1746
|
+
let selection = selections.get(goal.name);
|
|
1747
|
+
const reservation = selection && reservationReadClosure(goal, decls, selection.previous, selection.decls, selection.chosen, [...m.params, ...m.inputs, ...Object.keys(m.state)]);
|
|
1748
|
+
// Primitive PRE instances cannot introduce another count read. Reuse
|
|
1749
|
+
// the proposal pool while only those instances grow; retained picks
|
|
1750
|
+
// are still reified against this goal, and additional picks may wait
|
|
1751
|
+
// for failure-driven widening. This caches proposals, never a proof.
|
|
1752
|
+
const key = countPoolKey(goal, decls);
|
|
1753
|
+
const cached = poolCache.get(goal.name);
|
|
1754
|
+
const pool0 = cached?.key === key ? cached.value : grammarPool(goal, decls, pool, generation, structured, m);
|
|
1755
|
+
if (cached?.key !== key)
|
|
1756
|
+
poolCache.set(goal.name, { key, value: pool0 });
|
|
1757
|
+
if (!selection) {
|
|
1758
|
+
const ordinary = readTuples(goal.hyps.at(-1), generation.tick).some(([mp]) => mp.endsWith('#') && decls.some(d => d.map === mp))
|
|
1759
|
+
? polaritySelection(goal, decls, pool0, generation, sourceMaps).pick
|
|
1760
|
+
: smallSelection(goal, decls, pool0.full, readTuples(law.holds, generation.tick).map(([, key]) => key), none, generation);
|
|
1761
|
+
const pick = preferMemberInclusions(m, decls, pool0.full, ordinary, 10, generation.tick);
|
|
1762
|
+
selection = { chosen: new Set(ids(pick)), cap: Math.min(10, pick.insts.length + 2), previous: pick, decls, reserve: reservationState(goal, [m, ls, goal], pool), stable: stableState([m, ls, goal]) };
|
|
1763
|
+
selections.set(goal.name, selection);
|
|
1764
|
+
}
|
|
1765
|
+
const full = reservePool(goal, decls, pool0, selection.previous, selection.decls, selection.chosen, selection.reserve, pool, reservation).full;
|
|
1766
|
+
const keys = ids(full), lazyRoom = selection.chosen.size < selection.cap;
|
|
1767
|
+
const view = chosenView(full, selection.chosen, selection.cap);
|
|
1768
|
+
const c = withRanges(goal, decls, selectedCertificate(goal, decls, view, selection.stable, lazyRoom), full.reads);
|
|
1769
|
+
const gg = mcGoal(goal.hyps, decls, c), fg = lazyRoom ? mcGoal(goal.hyps, decls, full) : undefined;
|
|
1770
|
+
selection.previous = full;
|
|
1771
|
+
selection.decls = decls;
|
|
1772
|
+
memberSources.set(goal.name, memberHints(m, decls, c, generation.tick));
|
|
1773
|
+
return { goal, decls, c, gg, all: full.reads, pool: fg ? { fg, keys, wits: [...full.picks.map(() => undefined), ...full.insts.map(i => i.wit)], chosen: selection.chosen, cap: selection.cap } : undefined };
|
|
1774
|
+
}
|
|
1775
|
+
let full = pass ? certFor(goal, decls, wide, wide && lazyMode !== '0' ? pool : undefined, undefined, structured) : none;
|
|
1776
|
+
if (pass && m.inputMaps?.length && lazyMode !== '0') {
|
|
1777
|
+
const proposed = admitMemberWitnesses(m, decls, full, members(), wide ? pool : 10, generation.tick);
|
|
1778
|
+
full = proposed.cert;
|
|
1779
|
+
memberSources.set(goal.name, proposed.hints);
|
|
1780
|
+
}
|
|
1781
|
+
if (!pass || lazyMode === '0' || (lazyMode === 'wide' && !wide)) {
|
|
1782
|
+
const c0 = withRanges(goal, decls, full, full.reads);
|
|
1783
|
+
return { goal, decls, c: c0, gg: ptime('encode', () => mcGoal(goal.hyps, decls, c0)), all: full.reads, pool: undefined };
|
|
1784
|
+
}
|
|
489
1785
|
const rd = new Map(full.reads.map(r => [r[0], json([r[1], r[2]])]));
|
|
490
1786
|
const keys = [...full.picks.map(q => `p${json([rd.get(q[0]), q[1]])}`), ...full.insts.map(i => `i${json([i.terms.map(([z, x]) => [z, rd.get(x)]), i.unit, i.below])}`)];
|
|
491
|
-
if (lazyMode === 'wide')
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
1787
|
+
if (lazyMode === 'wide') {
|
|
1788
|
+
const prefix = { ...full, picks: [], insts: full.insts.slice(0, 10) };
|
|
1789
|
+
const initial = memberSources.get(goal.name)?.length ? prefix : preferMemberInclusions(m, decls, full, prefix, 10, generation.tick);
|
|
1790
|
+
for (const inst of initial.insts)
|
|
1791
|
+
chosen.add(keys[full.picks.length + full.insts.indexOf(inst)]);
|
|
1792
|
+
}
|
|
1793
|
+
const c = withRanges(goal, decls, { ...full, picks: full.picks.filter((_, j) => chosen.has(keys[j])), insts: full.insts.filter((_, j) => chosen.has(keys[j + full.picks.length])) }, full.reads);
|
|
495
1794
|
const fg = ptime('encode', () => mcGoal(goal.hyps, decls, full));
|
|
496
|
-
return { goal, decls, c, gg: ptime('encode', () => mcGoal(goal.hyps, decls, c)), pool: fg && keys.length ? { fg, keys, wits: [...full.picks.map(() => undefined), ...full.insts.map(i => i.wit)] } : undefined };
|
|
1795
|
+
return { goal, decls, c, gg: ptime('encode', () => mcGoal(goal.hyps, decls, c)), all: full.reads, pool: fg && keys.length ? { fg, keys, wits: [...full.picks.map(() => undefined), ...full.insts.map(i => i.wit)] } : undefined };
|
|
497
1796
|
});
|
|
1797
|
+
let lastSignature = '';
|
|
1798
|
+
const build = () => {
|
|
1799
|
+
let built = rawBuild();
|
|
1800
|
+
if (pass)
|
|
1801
|
+
while (seedCount < 64 && clock() < attemptEnd) {
|
|
1802
|
+
const step = built.at(-1), hints = step && memberSources.get(step.goal.name);
|
|
1803
|
+
if (!step || !hints?.length)
|
|
1804
|
+
break;
|
|
1805
|
+
// Seed declaration-backed member flags first. Scalar law tuples stay
|
|
1806
|
+
// model-driven rather than crowding the initial goal with field bridges.
|
|
1807
|
+
const seeded = instantiateMemberPremises(m, [], at, step.decls, hints, members(), 64 - seedCount, generation.tick);
|
|
1808
|
+
if (!seeded.added.length)
|
|
1809
|
+
break;
|
|
1810
|
+
at = seeded.at;
|
|
1811
|
+
seedCount += seeded.added.length;
|
|
1812
|
+
countsDump.on?.({ phase: 'member-premises', law: law.name, goal: step.goal.name, pass, added: seeded.added });
|
|
1813
|
+
built = rawBuild();
|
|
1814
|
+
}
|
|
1815
|
+
if (pass && supported)
|
|
1816
|
+
while (seedCount < 64 && clock() < attemptEnd) {
|
|
1817
|
+
const step = built.at(-1);
|
|
1818
|
+
if (!step?.gg)
|
|
1819
|
+
break;
|
|
1820
|
+
const signature = refinementSignature(step.gg, step.c);
|
|
1821
|
+
if (signature === lastSignature)
|
|
1822
|
+
break;
|
|
1823
|
+
lastSignature = signature;
|
|
1824
|
+
const seeds = sparseReadInstances(m, ls.filter(l => l === law || !reads(l.holds, isCount).size), law, at, step.gg, step.c, 64 - seedCount, step.goal.hyps.at(-1), step.decls, sourceMaps, step.goal.hyps.slice(0, -1), generation);
|
|
1825
|
+
if (!seeds.added.length)
|
|
1826
|
+
break;
|
|
1827
|
+
const previous = countSignature(step.c);
|
|
1828
|
+
at = seeds.at;
|
|
1829
|
+
seedCount += seeds.added.length;
|
|
1830
|
+
built = rawBuild();
|
|
1831
|
+
if (countSignature(built.at(-1).c) !== previous && !seeds.summary.foundationBarrier)
|
|
1832
|
+
break;
|
|
1833
|
+
}
|
|
1834
|
+
return built;
|
|
1835
|
+
};
|
|
498
1836
|
// (the pool's hypotheses a model breaks, chosen; whether there were any)
|
|
499
1837
|
// (`strict`, where nothing else is broken or asked: the cells it leaves out at their start alone, as a model whose
|
|
500
1838
|
// completion meets an instance may still meet it only at a witness some law then breaks)
|
|
@@ -503,7 +1841,7 @@ function searchCounted0(m0, g, m, caller, ms) {
|
|
|
503
1841
|
return false;
|
|
504
1842
|
// (broken where no completion of the model meets it: the cells it leaves out at their start, at 1, or one map's
|
|
505
1843
|
// flipped from either, and an instance's witness at each value below 16)
|
|
506
|
-
const { fg, keys, wits } = b.pool, base = fg.hyps.length - keys.length, ids = keys.flatMap((q, j) => (
|
|
1844
|
+
const { fg, keys, wits } = b.pool, active = b.pool.chosen ?? chosen, base = fg.hyps.length - keys.length, ids = keys.flatMap((q, j) => (active.has(q) ? [] : [base + j])), rawJudge = brokenOf(fg), judge = (...args) => withEvaluationAdmission(() => rawJudge(...args));
|
|
507
1845
|
let bad = ids.length ? judge(w, ids) : [];
|
|
508
1846
|
const mps = [...new Set(bad.flatMap(i => [...reads(fg.hyps[i], () => true).values()].map(([mp]) => mp)))], one1 = Object.fromEntries(mps.map(mp => [mp, 1]));
|
|
509
1847
|
for (const d of strict ? [undefined] : [undefined, one1, ...mps.map(mp => ({ [mp]: 1 })), ...mps.map(mp => ({ ...one1, [mp]: 0 }))])
|
|
@@ -517,21 +1855,54 @@ function searchCounted0(m0, g, m, caller, ms) {
|
|
|
517
1855
|
const still = new Set(judge(w2, bad, false, d));
|
|
518
1856
|
bad = bad.filter(i => still.has(i));
|
|
519
1857
|
}
|
|
1858
|
+
if (b.pool.cap !== undefined) {
|
|
1859
|
+
const seen = new Set();
|
|
1860
|
+
bad = bad.filter(i => { const key = keys[i - base]; if (seen.has(key))
|
|
1861
|
+
return false; seen.add(key); return true; }).slice(0, Math.max(0, b.pool.cap - active.size));
|
|
1862
|
+
}
|
|
520
1863
|
for (const i of bad)
|
|
521
|
-
|
|
1864
|
+
active.add(keys[i - base]);
|
|
522
1865
|
tally('#lazy', bad.length);
|
|
523
1866
|
return bad.length > 0;
|
|
524
1867
|
});
|
|
1868
|
+
// Complete only assumptions about count maps the requested law reads.
|
|
1869
|
+
// Unrelated count laws keep their ordinary demand-driven instantiation.
|
|
1870
|
+
const completionMaps = new Set([...reads(law.holds, isCount).values()].map(([map]) => map));
|
|
1871
|
+
let countCompleted = false;
|
|
1872
|
+
const completeCounts = () => {
|
|
1873
|
+
if (!pass || countCompleted || !completionMaps.size)
|
|
1874
|
+
return false;
|
|
1875
|
+
countCompleted = true;
|
|
1876
|
+
const completion = completeCountLawInstances(modelLaws, at, ts, l => reads(l.holds, map => completionMaps.has(map)).size > 0, generation.tick);
|
|
1877
|
+
if (!completion.added.length)
|
|
1878
|
+
return false;
|
|
1879
|
+
at = completion.at;
|
|
1880
|
+
tally('#count-completion', completion.added.length);
|
|
1881
|
+
countsDump.on?.({ law: law.name, pass, phase: 'count-completion', added: completion.added });
|
|
1882
|
+
return true;
|
|
1883
|
+
};
|
|
1884
|
+
// A single-key clause mixing field and count reads can need count premises now.
|
|
1885
|
+
// Concrete goals and isolated or multi-key count targets stay sparse-first:
|
|
1886
|
+
// speculative self-instances can crowd out an already easy proof.
|
|
1887
|
+
if (pass && law.forall && !law.keys?.length && completionMaps.size &&
|
|
1888
|
+
reads(law.holds, map => !isCount(map)).size && [...completionMaps].every(map => !m.counts[map].lo) &&
|
|
1889
|
+
modelLaws.some(other => other.name !== law.name && reads(other.holds, map => completionMaps.has(map)).size))
|
|
1890
|
+
completeCounts();
|
|
1891
|
+
// Stuck-model paths retain the same bounded completion and attempt allowance.
|
|
525
1892
|
let built = build();
|
|
1893
|
+
const observe = (b, phase, witness) => {
|
|
1894
|
+
if (countsDump.on)
|
|
1895
|
+
countsDump.on({ law: law.name, goal: b.goal.name, pass, phase, generation: { ...generation.state }, machine: m, laws: ls, rawGoal: b.goal, decls: b.decls, instances: at, certificateRequest: b.c, hyps: b.gg?.hyps, witness, seedCount });
|
|
1896
|
+
};
|
|
526
1897
|
let decideStep = decisions.get(id);
|
|
527
1898
|
if (!decideStep) {
|
|
528
1899
|
if (decisions.size >= 64)
|
|
529
1900
|
decisions.delete(decisions.keys().next().value);
|
|
530
1901
|
decisions.set(id, (decideStep = modelSequence()));
|
|
531
1902
|
}
|
|
532
|
-
const
|
|
1903
|
+
const more = () => clock() < attemptEnd;
|
|
533
1904
|
// The step goal decided first by the CDCL search for a model (its phases the simplex's point: a model is met where the
|
|
534
|
-
// tree search would split on), within
|
|
1905
|
+
// tree search would split on), within the attempt's remaining allowance:
|
|
535
1906
|
// - refuted: the law's instances cut to those its core reads, and the core's hypotheses grown on their own first,
|
|
536
1907
|
// the tree widened to the goal;
|
|
537
1908
|
// - a model: the instances it asks for (kernel/prove.ts's modelInstances, MBQI: a law or quantified flag broken at a
|
|
@@ -539,39 +1910,85 @@ function searchCounted0(m0, g, m, caller, ms) {
|
|
|
539
1910
|
// up at once (no tree to grow); the rounds within the attempt's time (a second at least, as the kernel's
|
|
540
1911
|
// withModels gives its later rounds), past which the goal is unknown;
|
|
541
1912
|
// - unknown: the goals grown as they are.
|
|
1913
|
+
let preflighted = false;
|
|
542
1914
|
for (;;) {
|
|
1915
|
+
checkWall('counted refinement');
|
|
1916
|
+
if (!more())
|
|
1917
|
+
return { stuck: 'unknown' };
|
|
543
1918
|
let part;
|
|
1919
|
+
let direct;
|
|
544
1920
|
for (;;) {
|
|
1921
|
+
checkWall('counted model loop');
|
|
1922
|
+
if (!more())
|
|
1923
|
+
return { stuck: 'unknown' };
|
|
545
1924
|
const step = built.at(-1);
|
|
546
1925
|
if (!step?.gg)
|
|
547
1926
|
break;
|
|
548
|
-
|
|
549
|
-
|
|
1927
|
+
if (supported && !preflighted && !step.c.insts.length) {
|
|
1928
|
+
preflighted = true;
|
|
1929
|
+
const directSmall = step.gg.hyps.length <= 64, small = directSmall ? step.gg : relevantGoals(step.gg)[0] ?? step.gg, end = Math.min(attemptEnd, clock() + (directSmall ? ms : ms / 6));
|
|
1930
|
+
// Small already-reified goals use direct tree search before model
|
|
1931
|
+
// construction; neither branch may outlive the original attempt. A subset model
|
|
1932
|
+
// says nothing about the whole goal; only a widened tree is reusable.
|
|
1933
|
+
const tree = ptime('preflight', () => withDeadline(end, () => {
|
|
1934
|
+
const quick = grow(small, new Map(), { nodes: 0, until: end });
|
|
1935
|
+
return 'tree' in quick ? widen(small, step.gg, quick.tree) : undefined;
|
|
1936
|
+
}));
|
|
1937
|
+
observe(step, tree ? 'preflight-proven' : 'preflight-miss');
|
|
1938
|
+
if (tree) {
|
|
1939
|
+
direct = { gg: step.gg, tree };
|
|
1940
|
+
break;
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
observe(step, 'query');
|
|
1944
|
+
const q0 = clock(), q = ptime('decide', () => decideStep(step.gg, attemptEnd));
|
|
1945
|
+
observe(step, 'decision:' + ('tree' in q ? 'tree' : q.why === REFUTED ? 'refuted' : q.stuck));
|
|
1946
|
+
if (env.GDP_COUNTS_TRACE?.includes('2'))
|
|
1947
|
+
console.error(`counts: decide ${pass} ${step.goal.name}: ${'tree' in q ? 'proven' : q.stuck} ${step.gg.hyps.length} hyps ${Math.round(clock() - q0)} ms`);
|
|
1948
|
+
if ('tree' in q) {
|
|
1949
|
+
direct = { gg: step.gg, tree: q.tree };
|
|
1950
|
+
break;
|
|
1951
|
+
}
|
|
1952
|
+
if (q.why === REFUTED && q.core) {
|
|
550
1953
|
const gg = step.gg, last = gg.hyps.length - 1, used = new Set(q.core.map(h => json(gg.hyps[h]))), cut = {};
|
|
551
1954
|
for (const [name, ts2] of Object.entries(at)) {
|
|
552
1955
|
const l = ls.find(x => x.name === name), n = l ? 1 + (l.keys?.length ?? 0) : 0;
|
|
553
1956
|
cut[name] = !l ? ts2 : Array.from({ length: ts2.length / n }, (_, t) => ts2.slice(t * n, t * n + n)).filter(t => used.has(json(assumed([l], { [name]: t })[0]))).flat();
|
|
554
1957
|
}
|
|
555
1958
|
at = cut;
|
|
556
|
-
|
|
1959
|
+
// Replay changes the goal, not its proposal pool or complete read set.
|
|
1960
|
+
const beforeReplay = built;
|
|
1961
|
+
built = obligations(at).map(({ goal, decls }, j) => ({ ...built[j], goal, decls, gg: mcGoal(goal.hyps, decls, built[j].c) }));
|
|
1962
|
+
countsDump.on?.({ phase: 'core-replay', law: law.name, pass,
|
|
1963
|
+
readCount: beforeReplay.at(-1).all.length,
|
|
1964
|
+
readsRetained: built.every((b, j) => b.all === beforeReplay[j].all),
|
|
1965
|
+
poolsRetained: built.every((b, j) => b.pool === beforeReplay[j].pool),
|
|
1966
|
+
certificatesRetained: built.every((b, j) => b.c === beforeReplay[j].c) });
|
|
557
1967
|
part = { gg: built.at(-1).gg, core: { name: gg.name, hyps: (q.core.includes(last) ? q.core : [...q.core, last]).map(h => gg.hyps[h]) } };
|
|
558
1968
|
break;
|
|
559
1969
|
}
|
|
560
|
-
if (
|
|
1970
|
+
if (q.stuck !== 'sat' || !q.witness)
|
|
561
1971
|
break;
|
|
1972
|
+
observe(step, 'model', q.witness);
|
|
562
1973
|
if (!more())
|
|
563
1974
|
return { stuck: 'unknown' };
|
|
564
|
-
const asked = ptime('mbqi', () => modelInstances(m,
|
|
1975
|
+
const asked = ptime('mbqi', () => independent(at, modelInstances(m, modelLaws, at, step.gg, q.witness), step.c.insts.map(i => i.wit))), lz = breaks(step, q.witness) || (!asked && breaks(step, q.witness, true));
|
|
565
1976
|
tally('#rounds');
|
|
566
1977
|
tally('#hyps', step.gg.hyps.length);
|
|
567
|
-
|
|
1978
|
+
// (a model with a count above its bound: that count's range instance from now on, the goal made again)
|
|
1979
|
+
const ranged = pass && wantRanges(step.goal, step.decls, step.all, q.witness);
|
|
1980
|
+
if ((lz || ranged) && !asked) {
|
|
568
1981
|
built = build();
|
|
569
1982
|
continue;
|
|
570
1983
|
}
|
|
571
1984
|
if (!asked) {
|
|
572
|
-
if (
|
|
1985
|
+
if (completeCounts()) {
|
|
1986
|
+
built = build();
|
|
1987
|
+
continue;
|
|
1988
|
+
}
|
|
1989
|
+
if (countsDump.on && (pass || env.GDP_COUNTS_DUMP_ALL_PASSES === '1') && dumped < Number(env.GDP_COUNTS_DUMP_N ?? 3)) {
|
|
573
1990
|
dumped++;
|
|
574
|
-
countsDump.on({ law: law.name, goal: step.goal.name, ls: ls.map(l => l.name), stuck: 'sat', witness: q.witness, reads: step.c.reads, insts: step.c.insts, hyps: step.gg.hyps });
|
|
1991
|
+
countsDump.on({ law: law.name, goal: step.goal.name, ls: ls.map(l => l.name), stuck: 'sat', witness: q.witness, reads: step.c.reads, insts: step.c.insts, hyps: step.gg.hyps, base: step.goal, decls: step.decls, cert: step.c, at, laws: ls, wide, pass });
|
|
575
1992
|
}
|
|
576
1993
|
if (pass && !wide && houdini && 'loose' in step.c && (step.c.loose || isCaller) && more()) {
|
|
577
1994
|
wide = true;
|
|
@@ -579,38 +1996,52 @@ function searchCounted0(m0, g, m, caller, ms) {
|
|
|
579
1996
|
built = build();
|
|
580
1997
|
continue;
|
|
581
1998
|
}
|
|
582
|
-
return refuted(step.gg, q.witness);
|
|
1999
|
+
return refuted(step.gg, q.witness, at);
|
|
583
2000
|
}
|
|
584
2001
|
at = asked;
|
|
585
2002
|
built = build();
|
|
586
2003
|
}
|
|
2004
|
+
// A wide pool can obscure a short subset proof. Retry only ordinary
|
|
2005
|
+
// witness-bearing certificates with the warmed law instances; the final
|
|
2006
|
+
// checkCountedLaws gate is unchanged; the same bounded finite-input default applies.
|
|
2007
|
+
if (pass && wide && focusEnabled && clock() < attemptEnd) {
|
|
2008
|
+
defer(() => ptime('focused', () => proveFocusedCounts(m, ls, law, at, Math.min(attemptEnd, clock() + Math.min(ms, 5000)), (g, ds) => certFor(g, ds, true, pool, undefined, structured))));
|
|
2009
|
+
}
|
|
587
2010
|
// (whether a goal reads a count: if none does, pass 1's goals are pass 0's)
|
|
588
2011
|
if (!pass)
|
|
589
2012
|
counted = built.some(b => certFor(b.goal, b.decls).reads.length);
|
|
590
2013
|
const certs = {};
|
|
591
2014
|
let again = false;
|
|
592
|
-
for (const { goal, c, gg } of built) {
|
|
2015
|
+
for (const { goal, decls, c, gg } of built) {
|
|
593
2016
|
const t0 = clock(), viaPart = gg && part?.gg === gg ? ptime('part', () => {
|
|
594
|
-
const o1 = grow(part.core, new Map(), { nodes: 0, until:
|
|
2017
|
+
const o1 = grow(part.core, new Map(), { nodes: 0, until: attemptEnd }), w = 'tree' in o1 ? widen(part.core, gg, o1.tree) : undefined;
|
|
595
2018
|
return w ? { tree: w, nodes: 0 } : undefined;
|
|
596
2019
|
}) : undefined;
|
|
597
|
-
const o = viaPart ?? (gg && ptime(`grow${(gg.hyps.length > 300 ? '>300' : '')}`, () => grow(gg, new Map(), { nodes: 0, until:
|
|
2020
|
+
const o = (direct && direct.gg === gg ? { tree: direct.tree, nodes: 0 } : undefined) ?? viaPart ?? (gg && ptime(`grow${(gg.hyps.length > 300 ? '>300' : '')}`, () => grow(gg, new Map(), { nodes: 0, until: attemptEnd })));
|
|
2021
|
+
if (gg && o && !('tree' in o))
|
|
2022
|
+
observe(built.find(b => b.gg === gg), o.stuck, 'witness' in o ? o.witness : undefined);
|
|
598
2023
|
if (countsDump.on && gg && o && !('tree' in o) && gg.hyps.length > Number(env.GDP_COUNTS_DUMP_MIN ?? 300) && dumped < Number(env.GDP_COUNTS_DUMP_N ?? 3)) {
|
|
599
2024
|
dumped++;
|
|
600
|
-
countsDump.on({ law: law.name, goal: goal.name, ls: ls.map(l => l.name), stuck: o.stuck, hyps: gg.hyps });
|
|
2025
|
+
countsDump.on({ law: law.name, goal: goal.name, ls: ls.map(l => l.name), stuck: o.stuck, hyps: gg.hyps, base: goal, decls, cert: c, at, laws: ls, wide, pass, ...('witness' in o ? { witness: o.witness } : {}) });
|
|
601
2026
|
}
|
|
602
2027
|
if (env.GDP_COUNTS_TRACE?.includes('2'))
|
|
603
2028
|
console.error(`counts: ${ls.length === 1 ? 'alone' : `with ${ls.length}`} ${pass} ${goal.name}: ${o && 'tree' in o ? 'proven' : gg ? o.stuck : 'no read'} ${gg?.hyps.length ?? 0} hyps (insts ${'insts' in c ? c.insts.length : 0} picks ${'picks' in c ? c.picks.length : 0}${wide ? ' wide' : ''}${built.find(b => b.gg === gg)?.pool ? ` of ${built.find(b => b.gg === gg).pool.keys.length}` : ''}) ${Math.round(clock() - t0)} ms`);
|
|
604
2029
|
// (the tree search's model of the step goal: the instances it asks for, as the CDCL search's, and the goals again)
|
|
605
2030
|
if (gg && o && !('tree' in o) && o.stuck === 'sat' && o.witness && gg === built.at(-1).gg && more()) {
|
|
606
|
-
const asked = ptime('mbqi', () => modelInstances(m,
|
|
607
|
-
|
|
2031
|
+
const last = built.at(-1), asked = ptime('mbqi', () => independent(at, modelInstances(m, modelLaws, at, gg, o.witness), c.insts.map(i => i.wit))), lz = breaks(last, o.witness) || (!asked && breaks(last, o.witness, true));
|
|
2032
|
+
const ranged = pass && wantRanges(last.goal, last.decls, last.all, o.witness);
|
|
2033
|
+
if (asked || lz || ranged) {
|
|
608
2034
|
if (asked)
|
|
609
2035
|
at = asked;
|
|
610
2036
|
built = build();
|
|
611
2037
|
again = true;
|
|
612
2038
|
break;
|
|
613
2039
|
}
|
|
2040
|
+
if (completeCounts()) {
|
|
2041
|
+
built = build();
|
|
2042
|
+
again = true;
|
|
2043
|
+
break;
|
|
2044
|
+
}
|
|
614
2045
|
}
|
|
615
2046
|
if (gg && o && !('tree' in o) && o.stuck === 'sat' && o.witness && gg === built.at(-1).gg && pass && !wide && houdini && 'loose' in c && (c.loose || isCaller) && more()) {
|
|
616
2047
|
wide = true;
|
|
@@ -620,7 +2051,7 @@ function searchCounted0(m0, g, m, caller, ms) {
|
|
|
620
2051
|
break;
|
|
621
2052
|
}
|
|
622
2053
|
if (gg && o && !('tree' in o) && o.stuck === 'sat' && o.witness && gg === built.at(-1).gg)
|
|
623
|
-
return refuted(gg, o.witness);
|
|
2054
|
+
return refuted(gg, o.witness, at);
|
|
624
2055
|
if (!o || !('tree' in o))
|
|
625
2056
|
return { stuck: gg ? o.stuck ?? '' : '' };
|
|
626
2057
|
certs[goal.name] = { reads: c.reads, insts: c.insts, tree: o.tree, ...('picks' in c && c.picks.length ? { picks: c.picks } : {}) };
|
|
@@ -629,59 +2060,142 @@ function searchCounted0(m0, g, m, caller, ms) {
|
|
|
629
2060
|
return { proof: { instances: at, certs } };
|
|
630
2061
|
}
|
|
631
2062
|
};
|
|
632
|
-
const
|
|
633
|
-
const
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
2063
|
+
const attempt = (law, ls, pass, ms, strategyAllowed = true) => {
|
|
2064
|
+
const end = Math.min(until, clock() + ms);
|
|
2065
|
+
const result = withDeadline(end, () => {
|
|
2066
|
+
let remaining = ms;
|
|
2067
|
+
if (strategyAllowed && !pass && env.GDP_COUNT_STRATEGIES === '1' && (!strategyOnly.size || strategyOnly.has(law))) {
|
|
2068
|
+
const proof = ptime('strategies', () => (tiers?.active && finalCountStepDeferralEnabled() ? proposeCountStrategiesForClosing : proveCountStrategies)(m, ls, law, end, (goal, decls) => certFor(goal, decls, false, 0, () => clock() < end, structured), event => countsDump.on?.({ phase: 'count-strategy', law: law.name, pass, end, ...event }), workAllowance, shapeFamily));
|
|
2069
|
+
countsDump.on?.({ phase: 'count-strategy-result', law: law.name, pass, end, checked: !!proof && proof.status !== 'unchecked', ...(proof?.status === 'unchecked' ? { proposed: true, status: 'unchecked' } : {}) });
|
|
2070
|
+
if (proof)
|
|
2071
|
+
return { proof };
|
|
2072
|
+
if (strategyOnly.has(law))
|
|
2073
|
+
return { stuck: 'strategy declined' };
|
|
2074
|
+
remaining = Math.max(0, end - clock());
|
|
2075
|
+
if (!remaining)
|
|
2076
|
+
return { stuck: 'unknown' };
|
|
2077
|
+
}
|
|
2078
|
+
return withDeferredCountRecovery(end, defer => ordinaryAttempt(law, ls, pass, remaining, end, defer), () => !!pass || !counted);
|
|
2079
|
+
});
|
|
2080
|
+
if (!pass) {
|
|
2081
|
+
const failures = plainFailures.get(law) ?? new WeakSet();
|
|
2082
|
+
if (!('proof' in result) && !result.refuted)
|
|
2083
|
+
failures.add(ls);
|
|
2084
|
+
else
|
|
2085
|
+
failures.delete(ls);
|
|
2086
|
+
plainFailures.set(law, failures);
|
|
2087
|
+
}
|
|
2088
|
+
return result;
|
|
637
2089
|
};
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
2090
|
+
const traced = (law, ls, pass, ms, strategyAllowed = true) => {
|
|
2091
|
+
const t0 = clock(), w0 = countedSearchNow(), p0 = { ...cprof };
|
|
2092
|
+
let r;
|
|
2093
|
+
try {
|
|
2094
|
+
const end = Math.min(until, clock() + ms);
|
|
2095
|
+
if (tiers?.active) {
|
|
2096
|
+
r = countPremiseSearch(ls, end, localEnd => [false, true].flatMap(guardReads => {
|
|
2097
|
+
const context = countPremiseContext(m, ls, law, localEnd, guardReads);
|
|
2098
|
+
return context ? [context] : [];
|
|
2099
|
+
}), (local, probeEnd) => attempt(law, local, pass, Math.max(0, probeEnd - clock()), strategyAllowed), (context, proposed, localEnd) => {
|
|
2100
|
+
if (!('proof' in proposed))
|
|
2101
|
+
return;
|
|
2102
|
+
const localGoals = countedObligations(m, context.laws, { [law.name]: proposed.proof.instances }, context.laws.indexOf(law));
|
|
2103
|
+
const wholeGoals = countedObligations(m, ls, { [law.name]: proposed.proof.instances }, ls.indexOf(law));
|
|
2104
|
+
if (localGoals.length !== wholeGoals.length)
|
|
2105
|
+
return;
|
|
2106
|
+
const certs = {};
|
|
2107
|
+
for (let i = 0; i < wholeGoals.length; i++) {
|
|
2108
|
+
const part = localGoals[i], whole = wholeGoals[i], cert = proposed.proof.certs[part.goal.name];
|
|
2109
|
+
if (!cert || clock() >= localEnd)
|
|
2110
|
+
return;
|
|
2111
|
+
const from = mcGoal(part.goal.hyps, part.decls, cert), to = mcGoal(whole.goal.hyps, whole.decls, cert);
|
|
2112
|
+
const lifted = from && to && transportCountCertificate(from, to, cert, wallAt(), { declarations: { from: part.decls, to: whole.decls }, diagnostic: { member: law.name, obligation: whole.goal.name, route: 'strategy-proposal' } });
|
|
2113
|
+
if (!lifted || (!(finalCountStepDeferralEnabled() && proposed.proof.status === 'unchecked') && !checkMC(whole.goal.hyps, whole.decls, lifted)))
|
|
2114
|
+
return;
|
|
2115
|
+
certs[whole.goal.name] = lifted;
|
|
2116
|
+
}
|
|
2117
|
+
return { proof: { instances: proposed.proof.instances, certs, ...(proposed.proof.status === 'unchecked' ? { status: 'unchecked' } : {}) } };
|
|
2118
|
+
}, event => countsDump.on?.({ ...event, law: law.name, pass }), error => error instanceof UnsupportedCountProposal);
|
|
2119
|
+
}
|
|
2120
|
+
else {
|
|
2121
|
+
// Probe only strict subsets, within the existing attempt's allowance. A
|
|
2122
|
+
// subset model is not a verdict: failure always widens to the full set.
|
|
2123
|
+
// Kept certificates must be lifted to that full set's exact row layout.
|
|
2124
|
+
const focused = pass && ls.some(l => support.has(l)) && (reads(law.holds, isCount).size || !caller.includes(law) && !!law.keys?.length) ? sourceContext(m, ls, law, support) : ls;
|
|
2125
|
+
const contexts = [...(focused.length < ls.length ? [{ local: focused, fraction: 1, kind: 'source-context' }] : []), ...(env.GDP_COUNTS_RELEVANCE === '1' ? relevantLaws(m, ls, law, support).map(local => ({ local, fraction: 1 / 6, kind: 'relevance' })) : [])];
|
|
2126
|
+
for (const { local, fraction, kind } of contexts) {
|
|
2127
|
+
const slice = Math.max(0, Math.min(ms * fraction, end - clock()));
|
|
2128
|
+
if (!slice)
|
|
2129
|
+
break;
|
|
2130
|
+
let probe;
|
|
2131
|
+
try {
|
|
2132
|
+
probe = withDeadline(clock() + slice, () => attempt(law, local, pass, slice, strategyAllowed));
|
|
2133
|
+
}
|
|
2134
|
+
catch (error) {
|
|
2135
|
+
if (!(error instanceof UnsupportedCountProposal))
|
|
2136
|
+
throw error;
|
|
2137
|
+
continue;
|
|
2138
|
+
}
|
|
2139
|
+
if (!('proof' in probe))
|
|
2140
|
+
continue;
|
|
2141
|
+
const localGoals = countedObligations(m, local, { [law.name]: probe.proof.instances }, local.indexOf(law));
|
|
2142
|
+
const wholeGoals = countedObligations(m, ls, { [law.name]: probe.proof.instances }, ls.indexOf(law));
|
|
2143
|
+
const certs = {};
|
|
2144
|
+
let complete = true;
|
|
2145
|
+
for (let i = 0; i < wholeGoals.length; i++) {
|
|
2146
|
+
const part = localGoals[i], whole = wholeGoals[i], c = probe.proof.certs[part.goal.name];
|
|
2147
|
+
if (!c) {
|
|
2148
|
+
complete = false;
|
|
2149
|
+
break;
|
|
2150
|
+
}
|
|
2151
|
+
const pg = mcGoal(part.goal.hyps, part.decls, c), wg = mcGoal(whole.goal.hyps, whole.decls, c);
|
|
2152
|
+
const lifted = pg && wg && withDeadline(end, () => transportCountCertificate(pg, wg, c, wallAt(), { declarations: { from: part.decls, to: whole.decls }, diagnostic: { member: law.name, obligation: whole.goal.name, route: 'strategy-probe' } }));
|
|
2153
|
+
if (!lifted) {
|
|
2154
|
+
complete = false;
|
|
2155
|
+
break;
|
|
2156
|
+
}
|
|
2157
|
+
if (!checkMC(whole.goal.hyps, whole.decls, lifted)) {
|
|
2158
|
+
complete = false;
|
|
2159
|
+
break;
|
|
2160
|
+
}
|
|
2161
|
+
certs[whole.goal.name] = lifted;
|
|
2162
|
+
}
|
|
2163
|
+
if (complete) {
|
|
2164
|
+
r = { proof: { instances: probe.proof.instances, certs } };
|
|
2165
|
+
countsDump.on?.({ phase: kind + '-proof', law: law.name, local: local.length, whole: ls.length });
|
|
2166
|
+
return r;
|
|
2167
|
+
}
|
|
666
2168
|
}
|
|
667
|
-
|
|
668
|
-
instances[law.name] = r.proof.instances;
|
|
669
|
-
Object.assign(certs, r.proof.certs);
|
|
2169
|
+
r = attempt(law, ls, pass, Math.max(0, end - clock()), strategyAllowed);
|
|
670
2170
|
}
|
|
671
|
-
if (env.GDP_COUNTS_TRACE)
|
|
672
|
-
console.error(`counts: round ${round}: ${set.length} laws, ${kept.size} kept, ${carried.size} carried, failed ${[...failed].join('; ').slice(0, 600)}`);
|
|
673
|
-
if (!failed.size)
|
|
674
|
-
return finish(set, { instances, certs });
|
|
675
|
-
const next = set.filter(l => !failed.has(l.name) || caller.includes(l));
|
|
676
|
-
// (only callers fail: drop nothing more, give up)
|
|
677
|
-
if (next.length === set.length)
|
|
678
|
-
return { proven: false, laws: set, m, why: `not proven: ${[...failed].join(', ')}` };
|
|
679
|
-
// (a proof that assumes no law dropped at any key is one over the rest: its goals are the same; the kernel checks all)
|
|
680
|
-
const dropped = set.filter(l => !next.includes(l));
|
|
681
|
-
carried = new Map([...proofs].filter(([, pr]) => dropped.every(d => d.forall && !pr.instances[d.name]?.length)));
|
|
682
|
-
set = next;
|
|
683
2171
|
}
|
|
684
|
-
|
|
2172
|
+
catch (error) {
|
|
2173
|
+
// A local tier deadline expires this attempt, not the whole enclosing search.
|
|
2174
|
+
// Invalid or captured proposals are likewise never assumptions.
|
|
2175
|
+
if (!(error instanceof UnsupportedCountProposal) && !(error instanceof WallExpired) && !(tiers?.active && isLocalCountExpiration(error, enclosingEnd)))
|
|
2176
|
+
throw error;
|
|
2177
|
+
countsDump.on?.({ law: law.name, pass, phase: 'rejected proposal', error: String(error) });
|
|
2178
|
+
r = shapeFamily ? { stuck: 'unknown', expired: error instanceof BudgetExpired, reason: String(error) } : { stuck: 'unknown' };
|
|
2179
|
+
}
|
|
2180
|
+
if (env.GDP_COUNTS_TRACE?.includes('3'))
|
|
2181
|
+
console.error(`counts: try ${law.name.slice(0, 50)} | ls ${ls.length} pass ${pass} ms ${Math.round(ms)} took ${Math.round(clock() - t0)} wall ${Math.round(countedSearchNow() - w0)} [${Object.entries(cprof).filter(([k2, x]) => x - (p0[k2] ?? 0) >= 1).map(([k2, x]) => `${k2} ${Math.round(x - (p0[k2] ?? 0))}`).join(' ')}] -> ${'proof' in r ? 'kept' : r.stuck}`);
|
|
2182
|
+
return r;
|
|
2183
|
+
};
|
|
2184
|
+
// One bounded non-lifted strategy recipe, without ordinary-search fallback.
|
|
2185
|
+
// The explicit lifted lease dispatcher intentionally rejects row/guard kinds.
|
|
2186
|
+
const strategyProposal = (law, ls, kind) => {
|
|
2187
|
+
if (env.GDP_COUNT_STRATEGIES !== '1' || strategyOnly.size && !strategyOnly.has(law))
|
|
2188
|
+
return undefined;
|
|
2189
|
+
const end = withinDeadline(until);
|
|
2190
|
+
return ptime('strategies', () => (tiers?.active && finalCountStepDeferralEnabled() ? proposeCountStrategyKindForClosing : proveCountStrategyKind)(kind, m, ls, law, end, (goal, decls) => certFor(goal, decls, false, 0, () => clock() < end, structured), event => countsDump.on?.({ phase: 'count-strategy', law: law.name, pass: 0, ...event }), workAllowance, shapeFamily));
|
|
2191
|
+
};
|
|
2192
|
+
// Explicit seam for the persistent section46 controller. The legacy traced
|
|
2193
|
+
// path remains unchanged; no plan is inferred from ms, clock or remaining work.
|
|
2194
|
+
const exactStrategy = (law, ls, plan) => {
|
|
2195
|
+
assertLiftedWorkLease(plan);
|
|
2196
|
+
if (env.GDP_COUNT_STRATEGIES !== '1' || strategyOnly.size && !strategyOnly.has(law))
|
|
2197
|
+
return undefined;
|
|
2198
|
+
return ptime('strategies', () => (tiers?.active && finalCountStepDeferralEnabled() ? proposeCountStrategiesForClosing : proveCountStrategies)(m, ls, law, Infinity, (goal, decls) => certFor(goal, decls, false, 0, () => true, structured), event => countsDump.on?.({ phase: 'count-strategy', law: law.name, pass: 0, ...event }), workAllowance, shapeFamily, plan));
|
|
685
2199
|
};
|
|
686
|
-
return
|
|
2200
|
+
return { traced, exactStrategy, strategyProposal, countermodel: (law) => models.get(`1 ${law.name}`)?.w ?? models.get(`0 ${law.name}`)?.w, get counted() { return counted; }, set houdini(value) { houdini = value; } };
|
|
687
2201
|
}
|