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/dsl.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { searchNow as countedSearchNow } from "./wall.js";
|
|
1
2
|
// Typed builders for machines, decisions and loops: names are declared once and come back as typed values, so a
|
|
2
3
|
// misspelled name, a law that reads a request, or a step that sets an undeclared variable is a TypeScript error, and
|
|
3
4
|
// the input kinds the kernel would otherwise see as hand encodings (a flag, an optional fact, a choice among values)
|
|
@@ -16,12 +17,20 @@
|
|
|
16
17
|
// A step returns its updates as one object: every right-hand side reads the state before the step, as the kernel and
|
|
17
18
|
// both runtimes do.
|
|
18
19
|
import { candidates, cone, searchCounted } from "./counts.js";
|
|
20
|
+
import { inheritSource, translationVerdict } from "./source-check.js";
|
|
19
21
|
import { env as knobs } from "./solver.js";
|
|
20
|
-
import { argsKey, machineTerms, part, tuple, carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, seeded, withArithmetic } from "./machine.js";
|
|
22
|
+
import { argsKey, bindDirect, directOf, machineTerms, part, tuple, carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, fnCall, hasFinite, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, seeded, sourceFreeFn, withArithmetic } from "./machine.js";
|
|
21
23
|
import { allowed, keysOf, requestEnv, watch, watchWork } from "./watch.js";
|
|
22
24
|
import { ghostOf, proveSome, skolemOf, someHolds, substVars, substVarsE, witnessSupport } from "./exists.js";
|
|
23
25
|
import { check, mapArities, checkRecur, foldObligations, ghostedMachine, loopObligations, someOfGhostsOk, substC, sumMachine } from "../kernel/kernel.js";
|
|
24
|
-
import { certLoop, clock, counted, factsFor, fullRate, grow, pastWall, proveLaw, proveLaws, proveLiveness, proveSetFast, proveStepLaws, usualProof,
|
|
26
|
+
import { certLoop, clock, counted, factsFor, fullRate, grow, pastWall, proveLaw, proveLaws, proveLiveness, proveSetFast, proveStepLaws, usualProof, withWall } from "../kernel/prove.js";
|
|
27
|
+
import { WallExpired, checkWall, checkWorkEndpoint, searchWall, withBudget, BudgetExpired } from "./wall.js";
|
|
28
|
+
import { completeWorkProfile } from "./work-profile.js";
|
|
29
|
+
import { workLedger } from "./work-admission.js";
|
|
30
|
+
import { withStageAllowance, withStageDeadline, withStageWall } from "./dsl-deadline.js";
|
|
31
|
+
import { withPublicSearchPolicy } from "./search-policy.js";
|
|
32
|
+
import { workRefusalWhy } from "./work-refusal.js";
|
|
33
|
+
import { workDivide, workFromNumber, workToNumber } from "./work-amount.js";
|
|
25
34
|
import { certCyclic, certOn, crossCyclic, cyclicOn, foldNodes, proveCyclic, quietly, recurNodes, translatedProof, uncovered } from "./cyclic.js";
|
|
26
35
|
import { discover } from "./discover.js";
|
|
27
36
|
import { inferLaws, inferRates } from "./infer.js";
|
|
@@ -1057,6 +1066,41 @@ export class SeqTable {
|
|
|
1057
1066
|
}
|
|
1058
1067
|
// f at every key below n: what bookkeeping a request carries meets, row by row (where each grant went, say).
|
|
1059
1068
|
export const everyBelow = (n, f) => everyKey(k => k.lt(n).implies(f(k)));
|
|
1069
|
+
// Explicit finite-domain opt-in. The guard, not the label, carries its semantics.
|
|
1070
|
+
// A size is over immutable params; the kernel validates that when it scopes the rule.
|
|
1071
|
+
// Unlike everyBelow's legacy breakpoint route, every/some enumerate every element.
|
|
1072
|
+
export function sizedSort(name, size) {
|
|
1073
|
+
if (!name)
|
|
1074
|
+
throw new Error('a sized sort needs a name');
|
|
1075
|
+
const below = termOf(size);
|
|
1076
|
+
const every = (f) => {
|
|
1077
|
+
const key = `k$${++boundCounter}`;
|
|
1078
|
+
const body = f(v(key));
|
|
1079
|
+
if (body.ex?.length || hasAll(body.c))
|
|
1080
|
+
throw new Error('a finite sort body must be unquantified in this slice');
|
|
1081
|
+
const c = { op: 'all', key, finite: name, c: { op: 'or', xs: [{ op: 'not', x: { op: '<', a: v(key).e, b: below } }, body.c] } };
|
|
1082
|
+
const n = valOf(size);
|
|
1083
|
+
if (n !== undefined)
|
|
1084
|
+
naturalConst(n);
|
|
1085
|
+
checkWall('finite sort enumeration');
|
|
1086
|
+
let ok = n === undefined ? undefined : true;
|
|
1087
|
+
if (n !== undefined)
|
|
1088
|
+
for (let k = 0; k < n; k++) {
|
|
1089
|
+
if ((k & 255) === 0)
|
|
1090
|
+
checkWall('finite sort enumeration');
|
|
1091
|
+
const holds = f(keyTerm(k)).ok;
|
|
1092
|
+
if (holds === false) {
|
|
1093
|
+
ok = false;
|
|
1094
|
+
break;
|
|
1095
|
+
}
|
|
1096
|
+
if (holds === undefined)
|
|
1097
|
+
ok = undefined;
|
|
1098
|
+
}
|
|
1099
|
+
return new Cond(c, ok);
|
|
1100
|
+
};
|
|
1101
|
+
return { name, size: new Term(below, valOf(size)), has: (key) => new Term(termOf(key), valOf(key)).lt(size),
|
|
1102
|
+
every, some: (f) => every(k => f(k).not()).not() };
|
|
1103
|
+
}
|
|
1060
1104
|
const when_ = (c, then, otherwise) => new Term({ op: 'if', c: c.c, then: termOf(then), else: termOf(otherwise) }, c.ok === undefined ? undefined : valOf(c.ok ? then : otherwise));
|
|
1061
1105
|
const isPartsWrite = (u) => typeof u === 'object' && u !== null && 'parts' in u;
|
|
1062
1106
|
// The parts of a value written at a cell, by the names of the maps they go to.
|
|
@@ -1188,7 +1232,7 @@ export class CarriedList {
|
|
|
1188
1232
|
const item = (i) => this.kind.build(this.name, p => new Term({ op: 'get', map: fname(p), key: i.e }));
|
|
1189
1233
|
// Every item is a value of the kind (its own laws, as a fact of the first part's function).
|
|
1190
1234
|
const kindFact = this.kind.invariant(this.kind.value(this.name)).length ? { 'every item is a value of its kind': forall(k => all(...this.kind.invariant(item(k)))) } : {};
|
|
1191
|
-
const fns = Object.fromEntries(parts.map((p, j) => [fname(p), fn(1, 'x => 0', j === 0 ? { facts: () => kindFact } : {})]));
|
|
1235
|
+
const fns = Object.fromEntries(parts.map((p, j) => [fname(p), { ...fn(1, 'x => 0', j === 0 ? { facts: () => kindFact } : {}), direct: bindDirect({ js: 'x => 0' }, { kind: 'const', value: 0 }) }]));
|
|
1192
1236
|
const folds = Object.entries(this.folds);
|
|
1193
1237
|
const r = rule(`${this.name}'s folds, by induction`).params(Object.fromEntries(this.paramKinds)).fns(fns).inputs({})
|
|
1194
1238
|
.state({ i: 0, ...Object.fromEntries(folds.map(([f, d]) => [`acc$${f}`, typeof d.from === 'number' ? d.from : (p) => d.from(p)])) })
|
|
@@ -1435,7 +1479,7 @@ class Hoister {
|
|
|
1435
1479
|
const outer = bound.filter(key => namesIn(q).includes(key));
|
|
1436
1480
|
if (outer.length)
|
|
1437
1481
|
throw new Error(`a condition at every key reads ${outer[0]}, a key bound outside it: two keys at once are named together (everyKey((i, j) => ...))`);
|
|
1438
|
-
const inner = perStep(q.c), keys = q.keys?.length ? { keys: q.keys } : {};
|
|
1482
|
+
const inner = perStep(q.c), keys = { ...(q.keys?.length ? { keys: q.keys } : {}), ...(q.finite === undefined ? {} : { finite: q.finite }) };
|
|
1439
1483
|
if (!inner) {
|
|
1440
1484
|
const f = name ?? `${this.prefix}${++this.n}`;
|
|
1441
1485
|
this.flags[f] = { op: 'all', key: q.key, ...keys, c: q.c };
|
|
@@ -1471,6 +1515,8 @@ export function nameQuantifiers(m) {
|
|
|
1471
1515
|
const hasForall = (c, positive = true) => c.op === 'all' ? positive || hasForall(c.c, positive) : c.op === 'not' ? hasForall(c.x, !positive) : c.op === 'and' || c.op === 'or' ? c.xs.some(y => hasForall(y, positive)) : false;
|
|
1472
1516
|
const hasAll = (c) => JSON.stringify(c).includes('"op":"all"');
|
|
1473
1517
|
function prenex(c, what, key) {
|
|
1518
|
+
if (hasFinite(c) && (what.startsWith('step law') || (c.op !== 'all' && hasForall(c))))
|
|
1519
|
+
throw new Error(`${what}: a finite universal is one whole law in this slice (not nested or a step law)`);
|
|
1474
1520
|
let found = false;
|
|
1475
1521
|
const walk = (d, positive) => {
|
|
1476
1522
|
switch (d.op) {
|
|
@@ -1501,6 +1547,8 @@ function prenex(c, what, key) {
|
|
|
1501
1547
|
return found ? out : undefined;
|
|
1502
1548
|
}
|
|
1503
1549
|
const substKey = (c, from, to) => JSON.parse(JSON.stringify(c).replaceAll(`"op":"var","name":"${from}"`, `"op":"var","name":"${to}"`));
|
|
1550
|
+
// The definitions actually flattened into a rule may have changed since recur captured its inlined helpers.
|
|
1551
|
+
const sourceFreeDef = (d) => sourceFreeFn(d) && Object.values(d.uses ?? {}).every(sourceFreeDef);
|
|
1504
1552
|
export const fn = (arity, js, opts = {}) => {
|
|
1505
1553
|
if (!Number.isInteger(arity) || arity < 1)
|
|
1506
1554
|
throw new Error('a function takes one argument or more');
|
|
@@ -1511,23 +1559,26 @@ export const fn = (arity, js, opts = {}) => {
|
|
|
1511
1559
|
export const divBy = (c) => {
|
|
1512
1560
|
if (!Number.isSafeInteger(c) || c < 1)
|
|
1513
1561
|
throw new RangeError('divBy takes a whole number at least 1');
|
|
1514
|
-
return fn(1, `x => Math.floor(x / ${c})`, { lean: `fun x => x / ${c}`, facts: f => ({
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1562
|
+
return { ...fn(1, `x => Math.floor(x / ${c})`, { lean: `fun x => x / ${c}`, facts: f => ({
|
|
1563
|
+
[`${c}·q(x) <= x`]: forall(x => f(x).times(c).atMost(x)),
|
|
1564
|
+
[`x < ${c}·q(x) + ${c}`]: forall(x => x.lt(f(x).times(c).plus(c))),
|
|
1565
|
+
}) }), direct: bindDirect({ js: `x => Math.floor(x / ${c})` }, { kind: 'div', divisor: c }) };
|
|
1518
1566
|
};
|
|
1519
1567
|
export const modBy = (c) => {
|
|
1520
1568
|
if (!Number.isSafeInteger(c) || c < 1)
|
|
1521
1569
|
throw new RangeError('modBy takes a whole number at least 1');
|
|
1522
1570
|
// x mod c is below c, and x less it is a multiple of c: x ∸ r = c·q for the q that divBy(c) gives; as facts about r
|
|
1523
1571
|
// alone, r <= x, r < c, and r(x + c) = r(x).
|
|
1524
|
-
return fn(1, `x => x % ${c}`, { lean: `fun x => x % ${c}`, facts: f => ({
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1572
|
+
return { ...fn(1, `x => x % ${c}`, { lean: `fun x => x % ${c}`, facts: f => ({
|
|
1573
|
+
[`r(x) < ${c}`]: forall(x => f(x).lt(c)),
|
|
1574
|
+
[`r(x) <= x`]: forall(x => f(x).atMost(x)),
|
|
1575
|
+
[`r(x + ${c}) = r(x)`]: forall(x => f(x.plus(c)).eq(f(x))),
|
|
1576
|
+
}) }), direct: bindDirect({ js: `x => x % ${c}` }, { kind: 'mod', divisor: c }) };
|
|
1529
1577
|
};
|
|
1530
1578
|
const reservedInRecur = ['x', 'fx', 'y', 'fy', 'prev', 'x0', 'fx0'];
|
|
1579
|
+
// No dynamic parser is needed for library-generated source. Reject reserved bindings and the globals used by
|
|
1580
|
+
// recurJs (including by inlined helpers), which an argument would otherwise shadow only in compiled mode.
|
|
1581
|
+
const unsafeJsName = new Set(('await break case catch class const continue debugger default delete do else enum export extends false finally for function if implements import in instanceof interface let new null package private protected public return static super switch this throw true try typeof var void while with yield eval arguments Math Number RangeError').split(' '));
|
|
1531
1582
|
export const recur = (name, def, lemmas = {}, between = {}) => {
|
|
1532
1583
|
const plain = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
1533
1584
|
if (!plain.test(name))
|
|
@@ -1536,6 +1587,9 @@ export const recur = (name, def, lemmas = {}, between = {}) => {
|
|
|
1536
1587
|
for (const n of [...args, ...uses.map(([u]) => u)])
|
|
1537
1588
|
if (!plain.test(n) || reservedInRecur.includes(n) || n === name)
|
|
1538
1589
|
throw new Error(`recur ${name}: ${n} can't name an argument or a function here (${reservedInRecur.join(', ')} and ${name} are taken)`);
|
|
1590
|
+
for (const n of args)
|
|
1591
|
+
if (unsafeJsName.has(n))
|
|
1592
|
+
throw new Error(`recur ${name}: ${n} can't name an argument (it shadows JavaScript syntax or a runtime global)`);
|
|
1539
1593
|
distinctNames(`recur ${name}`, [...args, ...uses.map(([u]) => u)]);
|
|
1540
1594
|
// A rule reads the function at its arguments paired, which the kernel multiplies out: with five further arguments that
|
|
1541
1595
|
// is a polynomial of degree 32, past what it can hold.
|
|
@@ -1588,15 +1642,15 @@ export const recur = (name, def, lemmas = {}, between = {}) => {
|
|
|
1588
1642
|
.step((env) => ({ x: env.x.plus(1), fx: def.next(env.x, env.fx, envAt(args.map(a => env[a]))) }));
|
|
1589
1643
|
const laws = Object.entries(lemmas).map(([n, f]) => r.law(n, (env) => f(env.x, env.fx, envAt(args.map(a => env[a])))));
|
|
1590
1644
|
// (Its machine's proof timed alone: the recurrence is compared below as its own instance.)
|
|
1591
|
-
const t0 =
|
|
1645
|
+
const t0 = countedSearchNow();
|
|
1592
1646
|
usualProof.last = undefined;
|
|
1593
1647
|
verdict = quietly(() => proveRule(r, laws, { search: false }));
|
|
1594
1648
|
lemmaProof = usualProof.last;
|
|
1595
1649
|
if (cyclicOn())
|
|
1596
|
-
crossCyclic('recurrence', name, verdict.proven && verdict.checked, () => { const { facts, specs } = recurNodes(recurCase([])); return proveCyclic(facts, specs); },
|
|
1650
|
+
crossCyclic('recurrence', name, verdict.proven && verdict.checked, () => { const { facts, specs } = recurNodes(recurCase([])); return proveCyclic(facts, specs); }, countedSearchNow() - t0, translatedRecur({ lemmas: lemmaProof }));
|
|
1597
1651
|
// (the usual trees checked already, inside quietly: where no cyclic proof is made they are the certificate)
|
|
1598
1652
|
if (certOn() && verdict.proven && verdict.checked) {
|
|
1599
|
-
const c = certCyclic('recurrence', name, translatedRecur({ lemmas: lemmaProof }), () => { const { facts, specs } = recurNodes(recurCase([])); return proveCyclic(facts, specs); },
|
|
1653
|
+
const c = certCyclic('recurrence', name, translatedRecur({ lemmas: lemmaProof }), () => { const { facts, specs } = recurNodes(recurCase([])); return proveCyclic(facts, specs); }, countedSearchNow() - t0);
|
|
1600
1654
|
if (!c.checked)
|
|
1601
1655
|
uncovered('recurrence', name, c.why);
|
|
1602
1656
|
}
|
|
@@ -1623,7 +1677,8 @@ export const recur = (name, def, lemmas = {}, between = {}) => {
|
|
|
1623
1677
|
...(withBetween ? Object.fromEntries(Object.entries(between).map(([n, l]) => [n, keysOf(2 + args.length)((k, j, ...as) => k.atMost(j).implies(l(k, f(k, ...as), j, f(j, ...as), env(as))))])) : {}),
|
|
1624
1678
|
};
|
|
1625
1679
|
};
|
|
1626
|
-
const
|
|
1680
|
+
const direct = bindDirect({ js, arity: 1 + args.length }, { kind: 'recur', name, args: [...args], zero, next, uses: Object.fromEntries(uses.map(([u, d]) => [u, runtimeFn(u, d, false)])) });
|
|
1681
|
+
const base = { arity: 1 + args.length, js, direct, lean: `Recur.${name}`, recur: recurrence, ...(uses.length ? { uses: def.fns } : {}) };
|
|
1627
1682
|
// The laws between two points: y counting up from x and fy from fx, a value at x that meets the lemmas (as f(x)
|
|
1628
1683
|
// does: they are given of it, as facts of the params), each law a law of that machine beside the lemmas at y. What
|
|
1629
1684
|
// holds there for every such fx holds for f(x), and fy is f(y) by the recurrence; the machine reads no f at all.
|
|
@@ -1637,7 +1692,7 @@ export const recur = (name, def, lemmas = {}, between = {}) => {
|
|
|
1637
1692
|
const laws = [...Object.entries(lemmas).map(([n, l]) => r.law(`${n} at y`, (env) => l(env.y, env.fy, envAt(at(env))))),
|
|
1638
1693
|
...Object.entries(between).map(([n, l]) => r.law(n, (env) => l(env.x, env.fx, env.y, env.fy, envAt(at(env)))))];
|
|
1639
1694
|
usualProof.last = undefined;
|
|
1640
|
-
const t0 =
|
|
1695
|
+
const t0 = countedSearchNow(), v = quietly(() => proveRule(r, laws, { search: false })), usualMs = countedSearchNow() - t0, betweenProof = usualProof.last;
|
|
1641
1696
|
if (cyclicOn())
|
|
1642
1697
|
crossCyclic('recurrence, between', name, v.proven && v.checked, () => { const { facts, specs } = recurNodes(recurCase(pairs)); return proveCyclic(facts, specs); }, usualMs, betweenProof && translatedRecur({ lemmas: lemmaProof, between: betweenProof }));
|
|
1643
1698
|
if (certOn() && v.proven && v.checked) {
|
|
@@ -1692,7 +1747,7 @@ const recurJs = (name, args, zero, next, uses) => {
|
|
|
1692
1747
|
case 'all': throw new Error('a recurrence takes no flag or quantifier');
|
|
1693
1748
|
}
|
|
1694
1749
|
};
|
|
1695
|
-
const inlined = uses.map(([u, d], i) => `const $f${i} = (${fnSource(u, d)}); ${d.arity > 1 ? `const $g${i} = (${jsOf(d)}); ` : ''}`).join('');
|
|
1750
|
+
const inlined = uses.map(([u, d], i) => `const $f${i} = (${fnSource(u, d, false)}); ${d.arity > 1 ? `const $g${i} = (${jsOf(d)}); ` : ''}`).join('');
|
|
1696
1751
|
// The last value computed at each tuple of further arguments is kept, so reading f at x after f at a smaller x takes
|
|
1697
1752
|
// only the steps between (a rule that reads f at a count that grows costs one step a request).
|
|
1698
1753
|
return `(() => { ${inlined}const $memo = new Map(); return (x, ${args.map(a => `${a}, `).join('')}) => { const $k = ${args.length ? `[${args.join(', ')}].join()` : "''"}; let $at = $memo.get($k); if (!$at || $at[0] > x) $at = [0, ${js(zero)}]; let x0 = $at[0], prev = $at[1]; for (; x0 < x; x0++) { prev = ((x, prev) => ${js(next)})(x0, prev); if (!Number.isSafeInteger(prev)) throw new RangeError(${JSON.stringify(`${name} passes the safe integers`)}); } if ($memo.size > 4096) $memo.clear(); $memo.set($k, [x, prev]); return prev; }; })()`;
|
|
@@ -1704,33 +1759,52 @@ const flatFns = (defs) => defs.flatMap(([n, d]) => {
|
|
|
1704
1759
|
});
|
|
1705
1760
|
// A function's JavaScript as one function of its key: its arguments unpaired (left-nested, as argsKey pairs them).
|
|
1706
1761
|
const jsOf = (d) => (typeof d.js === 'string' ? d.js : String(d.js));
|
|
1707
|
-
const fnSource = (name, d) => {
|
|
1762
|
+
const fnSource = (name, d, validate = true) => {
|
|
1708
1763
|
const src = jsOf(d);
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1764
|
+
if (validate && !sourceFreeDef(d)) {
|
|
1765
|
+
try {
|
|
1766
|
+
const f = compileFunction([], `return (${src})`)();
|
|
1767
|
+
f(...Array.from({ length: d.arity }, () => 0));
|
|
1768
|
+
fnValues.set(d, { js: d.js, arity: d.arity, direct: directOf(d), value: f });
|
|
1769
|
+
}
|
|
1770
|
+
catch (e) {
|
|
1771
|
+
throw new Error(`function ${name}: its js must be a function of its arguments that reads nothing else (${e.message})`);
|
|
1772
|
+
}
|
|
1716
1773
|
}
|
|
1717
1774
|
if (d.arity === 1)
|
|
1718
1775
|
return src;
|
|
1719
1776
|
return `(() => { const $fn = (${src}); return k => { const u = z => { let s = Math.floor(Math.sqrt(z)); while (s * s > z) s--; while ((s + 1) * (s + 1) <= z) s++; return [s - (z - s * s), z - s * s]; }; const a = []; let z = k; for (let i = 1; i < ${d.arity}; i++) { const [p, q] = u(z); a.unshift(q); z = p; } a.unshift(z); return $fn(...a); }; })()`;
|
|
1720
1777
|
};
|
|
1778
|
+
// Materialize runtime metadata without evaluating generated source during helper construction.
|
|
1779
|
+
const runtimeFn = (name, d, validate = true) => {
|
|
1780
|
+
const out = { js: fnSource(name, d, validate),
|
|
1781
|
+
...(d.arity > 1 ? { arity: d.arity, call: jsOf(d) } : {}), ...(d.lean ? { lean: d.lean } : {}),
|
|
1782
|
+
...(d.recur ? { recur: d.recur } : {}) };
|
|
1783
|
+
const direct = directOf(d);
|
|
1784
|
+
if (direct)
|
|
1785
|
+
out.direct = bindDirect(out, direct);
|
|
1786
|
+
return out;
|
|
1787
|
+
};
|
|
1721
1788
|
const fnTerm = (name, d) => (...args) => {
|
|
1722
1789
|
if (args.length !== d.arity)
|
|
1723
1790
|
throw new Error(`function ${name} takes ${d.arity} argument${d.arity === 1 ? '' : 's'}`);
|
|
1724
1791
|
const vals = known(args.map(valOf));
|
|
1725
|
-
return new Term({ op: 'get', map: name, key: argsKey(args.map(termOf)) }, vals && fnValueOf(d)(...vals));
|
|
1792
|
+
return new Term({ op: 'get', map: name, key: argsKey(args.map(termOf)) }, vals && fnValueOf(d)?.(...vals));
|
|
1726
1793
|
};
|
|
1727
1794
|
// A function's JavaScript on its arguments themselves (not through the pairing the kernel reads them by).
|
|
1728
1795
|
const fnValues = new WeakMap();
|
|
1729
1796
|
const fnValueOf = (d) => {
|
|
1730
|
-
|
|
1797
|
+
const cached = fnValues.get(d);
|
|
1798
|
+
let f = cached?.js === d.js && cached.arity === d.arity && cached.direct === directOf(d) && (!cached.direct || sourceFreeDef(d)) ? cached.value : undefined;
|
|
1731
1799
|
if (!f) {
|
|
1732
|
-
|
|
1733
|
-
|
|
1800
|
+
if (sourceFreeDef(d)) {
|
|
1801
|
+
const fn = runtimeFn('constant', d, false);
|
|
1802
|
+
f = (...args) => fnCall(fn, args);
|
|
1803
|
+
}
|
|
1804
|
+
// User source (including callbacks) may be folded only after materialization validated it, never invoked just
|
|
1805
|
+
// to build a term before the runtime's explicit compilation guard.
|
|
1806
|
+
if (f)
|
|
1807
|
+
fnValues.set(d, { js: d.js, arity: d.arity, direct: directOf(d), value: f });
|
|
1734
1808
|
}
|
|
1735
1809
|
return f;
|
|
1736
1810
|
};
|
|
@@ -1765,8 +1839,9 @@ export class Rule {
|
|
|
1765
1839
|
spec;
|
|
1766
1840
|
constructor(spec) {
|
|
1767
1841
|
this.spec = spec;
|
|
1842
|
+
inheritSource(spec, this);
|
|
1768
1843
|
}
|
|
1769
|
-
with(more) {
|
|
1844
|
+
with(more) { const next = new Rule({ ...this.spec, ...more }); inheritSource(this, next, Object.keys(more).every(k => k === 'arith' || k === 'sumsRead')); return next; }
|
|
1770
1845
|
get name() { return this.spec.name; }
|
|
1771
1846
|
// For core/discover.ts: the functions and carried lists the rule reads, and the same rule with functions made again
|
|
1772
1847
|
// and lemmas added to its lists' folds (each proven here, as carriesList proves its own).
|
|
@@ -1987,9 +2062,11 @@ export class Rule {
|
|
|
1987
2062
|
const key = `key$${++keyCounter}`;
|
|
1988
2063
|
if (out instanceof Cond) {
|
|
1989
2064
|
const p = prenex(out.c, `law ${name}`, key);
|
|
1990
|
-
return this.divides(this.someOf(name, out, p ? { name, forall: key, holds: p } : { name, holds: out.c }));
|
|
2065
|
+
return this.divides(this.someOf(name, out, p ? { name, forall: key, holds: p, ...(out.c.op === 'all' && out.c.finite !== undefined ? { finite: out.c.finite } : {}) } : { name, holds: out.c }));
|
|
1991
2066
|
}
|
|
1992
2067
|
const [k1, more] = keysFor(out), inner = out.forall(v(k1), ...more.map(v)), holds = inner.c;
|
|
2068
|
+
if (hasFinite(holds))
|
|
2069
|
+
throw new Error(`law ${name}: a finite universal is one whole law, not inside forall`);
|
|
1993
2070
|
return this.divides(this.someOf(name, inner, more.length ? { name, forall: k1, keys: more, holds } : { name, forall: k1, holds: prenex(holds, `law ${name}`, k1) ?? holds }));
|
|
1994
2071
|
}
|
|
1995
2072
|
// A law's existentials (exists), pulled out before it: `some` its naturals, `witness` the ones given (a ghost's step
|
|
@@ -2366,7 +2443,7 @@ export class Rule {
|
|
|
2366
2443
|
// Functions, and their facts: each function's own (named after it), then the rule's.
|
|
2367
2444
|
// The functions a function reads come first, each named <function>.<use>.
|
|
2368
2445
|
const flat = flatFns(s.fns ?? []);
|
|
2369
|
-
const fns = Object.fromEntries(flat.map(([n, d]) => [n,
|
|
2446
|
+
const fns = Object.fromEntries(flat.map(([n, d]) => [n, runtimeFn(n, d)]));
|
|
2370
2447
|
const facts = [
|
|
2371
2448
|
...flat.flatMap(([n, d, uses]) => Object.entries(d.facts?.(fnTerm(n, d), uses) ?? {}).map(([name, f]) => this.lawOf(`${n}: ${name}`, f))),
|
|
2372
2449
|
...(s.facts ?? []).flatMap(f => Object.entries(f(pEnv)).map(([name, out]) => this.lawOf(name, out))),
|
|
@@ -2565,29 +2642,85 @@ export class Rule {
|
|
|
2565
2642
|
// with requests drawn by their kinds (or `draw`), must hold the same values as the compiled rule (decoded: integers and
|
|
2566
2643
|
// decimals as numbers) for every field the reference's state has, after every step of `trials` runs of `depth`.
|
|
2567
2644
|
compare(reference, opts = {}) {
|
|
2568
|
-
const s = this.spec, rand = opts.rand ?? seeded(5), bound = opts.bound ?? 100,
|
|
2569
|
-
|
|
2645
|
+
const s = this.spec, rand = opts.rand ?? seeded(5), bound = compareCount(opts.bound ?? 100, 'bound'), trials = compareCount(opts.trials ?? 200, 'trials');
|
|
2646
|
+
const depth = compareCount(opts.depth ?? 10, 'depth', 1), cap = compareCount(opts.maxCases ?? 100_000, 'maxCases', 1), m = this.machine, gen = this.compiled(), run = interpret(m);
|
|
2647
|
+
const paramsDomain = opts.params || opts.draw ? undefined : finiteFields(s.params, cap);
|
|
2648
|
+
const inputsDomain = paramsDomain && !s.carried?.length && !s.seqs?.length && !s.seqTables?.length && !s.lists2?.length ? finiteFields(s.inputs, Math.floor(cap / paramsDomain.size)) : undefined;
|
|
2649
|
+
const exhaustive = !!(paramsDomain && inputsDomain);
|
|
2650
|
+
let checked = 0, skipped = 0, skippedParams = 0;
|
|
2570
2651
|
const sample = (kinds) => Object.fromEntries(kinds.map(([n, k]) => [n, k.sample(rand, bound)]));
|
|
2571
|
-
|
|
2572
|
-
const
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
continue;
|
|
2580
|
-
ours = gen.step(ps, ours, encoded);
|
|
2581
|
-
theirs = reference.step(params, theirs, request);
|
|
2652
|
+
const checkRun = (params, requests, chunks) => {
|
|
2653
|
+
const ps = this.encodeParams(params);
|
|
2654
|
+
if (m.pre && !evalC(m.pre, ps, { scalars: {}, maps: {} }, m)) {
|
|
2655
|
+
skippedParams++;
|
|
2656
|
+
return undefined;
|
|
2657
|
+
}
|
|
2658
|
+
let ours = gen.init(ps), theirs = reference.init(compareCopy(params)), at = 0, trace = [];
|
|
2659
|
+
const mismatch = (where) => {
|
|
2582
2660
|
const got = this.decode(ours);
|
|
2583
|
-
for (const [field, want] of Object.entries(theirs))
|
|
2584
|
-
checked++;
|
|
2661
|
+
for (const [field, want] of Object.entries(compareFields(theirs)))
|
|
2585
2662
|
if (!sameRaw(got[field], want))
|
|
2586
|
-
return
|
|
2663
|
+
return `${s.name}, params ${JSON.stringify(params)}, ${where}, trace ${JSON.stringify(trace)}: ${field} is ${shown(got[field])} here, ${shown(want)} in the code it describes`;
|
|
2664
|
+
return undefined;
|
|
2665
|
+
};
|
|
2666
|
+
let failure = mismatch('at init');
|
|
2667
|
+
if (failure)
|
|
2668
|
+
return failure;
|
|
2669
|
+
for (const request0 of requests) {
|
|
2670
|
+
if (chunks && at === depth) {
|
|
2671
|
+
ours = gen.init(ps);
|
|
2672
|
+
theirs = reference.init(compareCopy(params));
|
|
2673
|
+
at = 0;
|
|
2674
|
+
trace = [];
|
|
2675
|
+
failure = mismatch('at init');
|
|
2676
|
+
if (failure)
|
|
2677
|
+
return failure;
|
|
2678
|
+
}
|
|
2679
|
+
const request = compareCopy(request0), encoded = this.encodeInput(request, params);
|
|
2680
|
+
at++;
|
|
2681
|
+
if (!allowed(m, run, ps, ours, encoded)) {
|
|
2682
|
+
skipped++;
|
|
2683
|
+
continue;
|
|
2587
2684
|
}
|
|
2685
|
+
trace.push(compareCopy(request));
|
|
2686
|
+
ours = gen.step(ps, ours, encoded);
|
|
2687
|
+
theirs = reference.step(compareCopy(params), theirs, compareCopy(request));
|
|
2688
|
+
checked++;
|
|
2689
|
+
failure = mismatch(`after ${JSON.stringify(request)}`);
|
|
2690
|
+
if (failure)
|
|
2691
|
+
return failure;
|
|
2692
|
+
}
|
|
2693
|
+
return undefined;
|
|
2694
|
+
};
|
|
2695
|
+
if (exhaustive) {
|
|
2696
|
+
const supplied = opts.edges ?? [], edges = supplied.filter((edge, i) => !supplied.slice(0, i).some(old => sameRaw(old, edge)));
|
|
2697
|
+
function* requests() {
|
|
2698
|
+
for (const edge of edges)
|
|
2699
|
+
yield compareCopy(edge);
|
|
2700
|
+
for (const value of inputsDomain.values())
|
|
2701
|
+
if (!edges.some(edge => sameRaw(edge, value)))
|
|
2702
|
+
yield value;
|
|
2703
|
+
}
|
|
2704
|
+
for (const value of paramsDomain.values()) {
|
|
2705
|
+
const failure = checkRun(value, requests(), true);
|
|
2706
|
+
if (failure)
|
|
2707
|
+
return compareResult(checked, false, skipped, skippedParams, failure);
|
|
2588
2708
|
}
|
|
2589
2709
|
}
|
|
2590
|
-
|
|
2710
|
+
else {
|
|
2711
|
+
for (let trial = 0; trial < trials; trial++) {
|
|
2712
|
+
const params = compareCopy((opts.params?.(rand) ?? sample(s.params))), edges = trial === 0 ? opts.edges ?? [] : [];
|
|
2713
|
+
function* requests() {
|
|
2714
|
+
yield* edges;
|
|
2715
|
+
for (let i = 0; i < depth; i++)
|
|
2716
|
+
yield opts.draw?.(rand) ?? sample(s.inputs);
|
|
2717
|
+
}
|
|
2718
|
+
const failure = checkRun(params, requests(), false);
|
|
2719
|
+
if (failure)
|
|
2720
|
+
return compareResult(checked, false, skipped, skippedParams, failure);
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
return compareResult(checked, exhaustive, skipped, skippedParams);
|
|
2591
2724
|
}
|
|
2592
2725
|
// --- running it -----------------------------------------------------------------------------------------------------
|
|
2593
2726
|
// Runtime values (numbers, booleans, choice names, null for a missing value) to the variables the machine reads.
|
|
@@ -2706,7 +2839,11 @@ export class Rule {
|
|
|
2706
2839
|
}
|
|
2707
2840
|
// The prune order's variable, if the history is pruned (a runtime must send it nondecreasing).
|
|
2708
2841
|
get orderedBy() { return this.spec.prune ? new Map(this.spec.inputs).get(this.spec.prune.order).vars(this.spec.prune.order)[0] : undefined; }
|
|
2709
|
-
interpreter(
|
|
2842
|
+
interpreter(options = {}) {
|
|
2843
|
+
if (this.spec.fns?.some(([, d]) => !sourceFreeDef(d)) && !options.compileHelpers)
|
|
2844
|
+
throw new Error(`${this.name}: interpreter() does not compile declared helper source; use compiled() or explicitly pass {compileHelpers: true}`);
|
|
2845
|
+
return interpret(this.machine);
|
|
2846
|
+
}
|
|
2710
2847
|
compiled() {
|
|
2711
2848
|
return loadJs(this.machine);
|
|
2712
2849
|
}
|
|
@@ -2761,18 +2898,44 @@ export class Fun {
|
|
|
2761
2898
|
// check for an encoding: that the terms here are what the real function computes, on its real inputs.
|
|
2762
2899
|
// cap.compare(({left, local}) => ({out: realCap(left, local)}), {edges: [{left: 2 ** 32 + 5, local: 10}]})
|
|
2763
2900
|
compare(reference, opts = {}) {
|
|
2764
|
-
const rand = opts.rand ?? seeded(5), bound = opts.bound ?? 1000,
|
|
2765
|
-
|
|
2766
|
-
const
|
|
2767
|
-
|
|
2768
|
-
|
|
2901
|
+
const rand = opts.rand ?? seeded(5), bound = compareCount(opts.bound ?? 1000, 'bound'), trials = compareCount(opts.trials ?? 2000, 'trials');
|
|
2902
|
+
const cap = compareCount(opts.maxCases ?? 100_000, 'maxCases', 1), params = compareCopy((opts.params ?? {})), kinds = this.r['spec'].inputs;
|
|
2903
|
+
const parameterKinds = this.r['spec'].params, finiteParams = !!finiteFields(parameterKinds, cap);
|
|
2904
|
+
const domain = opts.draw ? undefined : finiteFields(kinds, cap), r = this.rule, m = r.machine, run = r.interpreter({ compileHelpers: true }), ps = r.encodeParams(params), execute = this.compiled();
|
|
2905
|
+
let checked = 0, skipped = 0;
|
|
2906
|
+
const finish = (exhaustive, skippedParams = 0, failure) => ({
|
|
2907
|
+
...compareResult(checked, exhaustive && finiteParams, skipped, skippedParams, failure),
|
|
2908
|
+
...(parameterKinds.length ? { parameterScope: { kind: 'fixed', values: compareCopy(params) } } : {}),
|
|
2909
|
+
});
|
|
2910
|
+
if (m.pre && !evalC(m.pre, ps, { scalars: {}, maps: {} }, m))
|
|
2911
|
+
return finish(false, 1);
|
|
2912
|
+
const initial = run.init(ps), supplied = opts.edges ?? [];
|
|
2913
|
+
const edges = domain ? supplied.filter((edge, i) => !supplied.slice(0, i).some(old => sameRaw(old, edge))) : supplied;
|
|
2914
|
+
function* draws() {
|
|
2915
|
+
for (const edge of edges)
|
|
2916
|
+
yield compareCopy(edge);
|
|
2917
|
+
if (domain) {
|
|
2918
|
+
for (const value of domain.values())
|
|
2919
|
+
if (!edges.some(edge => sameRaw(edge, value)))
|
|
2920
|
+
yield value;
|
|
2921
|
+
}
|
|
2922
|
+
else
|
|
2923
|
+
for (let i = 0; i < trials; i++)
|
|
2924
|
+
yield opts.draw?.(rand) ?? Object.fromEntries(kinds.map(([n, k]) => [n, k.sample(rand, bound)]));
|
|
2925
|
+
}
|
|
2926
|
+
for (const values of draws()) {
|
|
2927
|
+
if (!allowed(m, run, ps, initial, r.encodeInput(values, params))) {
|
|
2928
|
+
skipped++;
|
|
2929
|
+
continue;
|
|
2930
|
+
}
|
|
2931
|
+
const ours = execute(values, params), theirs = compareFields(reference(compareCopy(values), compareCopy(params)));
|
|
2932
|
+
checked++;
|
|
2769
2933
|
for (const [field, want] of Object.entries(theirs)) {
|
|
2770
|
-
checked++;
|
|
2771
2934
|
if (!sameRaw(ours[field], want))
|
|
2772
|
-
return
|
|
2935
|
+
return finish(false, 0, `${this.name}, params ${JSON.stringify(params)}, at ${JSON.stringify(values)}: ${field} is ${shown(ours[field])} here, ${shown(want)} in the code it describes`);
|
|
2773
2936
|
}
|
|
2774
2937
|
}
|
|
2775
|
-
return
|
|
2938
|
+
return finish(!!domain);
|
|
2776
2939
|
}
|
|
2777
2940
|
// The one-step rule it compiles to: the result's fields are its state (named out.<field>, apart from the arguments).
|
|
2778
2941
|
get rule() {
|
|
@@ -2781,15 +2944,31 @@ export class Fun {
|
|
|
2781
2944
|
return this.r.state(Object.fromEntries(fields.map(([k, t]) => { const kind = kindOf(t); return [name(k), kind.from(kind.empty())]; })))
|
|
2782
2945
|
.step(env => Object.fromEntries(Object.entries(this.result(env)).map(([k, t]) => [name(k), t])));
|
|
2783
2946
|
}
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2947
|
+
runtimeRule;
|
|
2948
|
+
runners = {};
|
|
2949
|
+
runner(mode) {
|
|
2950
|
+
const cached = this.runners[mode];
|
|
2951
|
+
if (cached)
|
|
2952
|
+
return cached;
|
|
2953
|
+
// Custom helpers are source code, including callbacks serialized by fnSource. Refuse before materializing a
|
|
2954
|
+
// machine rather than implicitly invoking Function in a runtime which the caller chose to interpret.
|
|
2955
|
+
const helpers = this.r['spec'].fns;
|
|
2956
|
+
if (mode === 'interpreted' && helpers?.some(([, d]) => !sourceFreeDef(d)))
|
|
2957
|
+
throw new Error(`${this.name}: run() does not compile declared helper source (${helpers.map(([name]) => name).join(', ')}); use compiled() explicitly`);
|
|
2958
|
+
this.runtimeRule ??= { rule: this.rule, fields: Object.keys(this.result(this.r['env']({ flags: false, state: false, queries: false }))) };
|
|
2959
|
+
const { rule, fields } = this.runtimeRule, gen = mode === 'compiled' ? rule.compiled() : rule.interpreter();
|
|
2960
|
+
const execute = (values, params = {}) => {
|
|
2961
|
+
const ps = rule.encodeParams(params);
|
|
2962
|
+
const st = rule.decode(gen.step(ps, gen.init(ps), rule.encodeInput(values, params)));
|
|
2963
|
+
return Object.fromEntries(fields.map(k => [k, st[`out.${k}`]]));
|
|
2964
|
+
};
|
|
2965
|
+
this.runners[mode] = execute;
|
|
2966
|
+
return execute;
|
|
2792
2967
|
}
|
|
2968
|
+
// The default runtime interprets terms without generating JavaScript.
|
|
2969
|
+
run(values, params = {}) { return this.runner('interpreted')(values, params); }
|
|
2970
|
+
// Explicit dynamic-code opt-in. Cache this callable at startup; it has run()'s argument and result types.
|
|
2971
|
+
compiled() { return this.runner('compiled'); }
|
|
2793
2972
|
}
|
|
2794
2973
|
export const fun = (name) => new Fun(rule(name));
|
|
2795
2974
|
// The function a law was stated about. Variants of one function share its arguments, so a law's terms alone don't say
|
|
@@ -2797,6 +2976,76 @@ export const fun = (name) => new Fun(rule(name));
|
|
|
2797
2976
|
const lawsOfFuns = new WeakMap();
|
|
2798
2977
|
const lawOfFun = (f, d) => { lawsOfFuns.set(d, f); return d; };
|
|
2799
2978
|
export const funOf = (d) => lawsOfFuns.get(d);
|
|
2979
|
+
const compareCount = (value, name, minimum = 0) => {
|
|
2980
|
+
if (!Number.isSafeInteger(value) || value < minimum)
|
|
2981
|
+
throw new RangeError(`${name} must be a safe integer at least ${minimum}`);
|
|
2982
|
+
return value;
|
|
2983
|
+
};
|
|
2984
|
+
// Determine cardinality before allocating or enumerating; custom and unbounded kinds sample instead.
|
|
2985
|
+
const finiteKind = (kind, cap) => {
|
|
2986
|
+
if (kind instanceof NatKind) {
|
|
2987
|
+
if (kind.maxValue === undefined || kind.maxValue >= cap)
|
|
2988
|
+
return undefined;
|
|
2989
|
+
const size = kind.maxValue + 1;
|
|
2990
|
+
return { size, values: function* () { for (let i = 0; i < size; i++)
|
|
2991
|
+
yield i; } };
|
|
2992
|
+
}
|
|
2993
|
+
if (kind instanceof BoolKind)
|
|
2994
|
+
return cap < 2 ? undefined : { size: 2, values: () => [false, true] };
|
|
2995
|
+
if (kind instanceof OneOfKind)
|
|
2996
|
+
return kind.values.length > cap ? undefined : { size: kind.values.length, values: () => kind.values };
|
|
2997
|
+
if (kind instanceof MaybeKind) {
|
|
2998
|
+
const inner = finiteKind(kind.of, cap - 1);
|
|
2999
|
+
return inner && { size: inner.size + 1, values: function* () { yield null; yield* inner.values(); } };
|
|
3000
|
+
}
|
|
3001
|
+
if (kind instanceof RecordKind)
|
|
3002
|
+
return finiteFields(Object.entries(kind.fields), cap);
|
|
3003
|
+
if (kind instanceof VariantKind) {
|
|
3004
|
+
let size = 0;
|
|
3005
|
+
const cases = [];
|
|
3006
|
+
for (const name of kind.names) {
|
|
3007
|
+
const domain = finiteFields(Object.entries(kind.cases[name]), cap - size);
|
|
3008
|
+
if (!domain)
|
|
3009
|
+
return undefined;
|
|
3010
|
+
size += domain.size;
|
|
3011
|
+
cases.push([name, domain]);
|
|
3012
|
+
}
|
|
3013
|
+
return { size, values: function* () { for (const [name, domain] of cases)
|
|
3014
|
+
for (const fields of domain.values())
|
|
3015
|
+
yield { [kind.tagKey]: name, ...fields }; } };
|
|
3016
|
+
}
|
|
3017
|
+
return undefined;
|
|
3018
|
+
};
|
|
3019
|
+
const finiteFields = (fields, cap) => {
|
|
3020
|
+
if (cap < 1)
|
|
3021
|
+
return undefined;
|
|
3022
|
+
let size = 1;
|
|
3023
|
+
const domains = [];
|
|
3024
|
+
for (const [name, kind] of fields) {
|
|
3025
|
+
const domain = finiteKind(kind, Math.floor(cap / size));
|
|
3026
|
+
if (!domain)
|
|
3027
|
+
return undefined;
|
|
3028
|
+
size *= domain.size;
|
|
3029
|
+
domains.push([name, domain]);
|
|
3030
|
+
}
|
|
3031
|
+
function* at(index, entries) {
|
|
3032
|
+
if (index === domains.length) {
|
|
3033
|
+
yield Object.fromEntries(entries);
|
|
3034
|
+
return;
|
|
3035
|
+
}
|
|
3036
|
+
const [name, domain] = domains[index];
|
|
3037
|
+
for (const value of domain.values())
|
|
3038
|
+
yield* at(index + 1, [...entries, [name, value]]);
|
|
3039
|
+
}
|
|
3040
|
+
return { size, values: () => at(0, []) };
|
|
3041
|
+
};
|
|
3042
|
+
const compareCopy = (value) => structuredClone(value);
|
|
3043
|
+
const compareFields = (value) => {
|
|
3044
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || typeof value.then === 'function')
|
|
3045
|
+
throw new TypeError('compare reference must return a synchronous object');
|
|
3046
|
+
return value;
|
|
3047
|
+
};
|
|
3048
|
+
const compareResult = (checked, exhaustive, skipped, skippedParams = 0, failure) => ({ checked, exhaustive: exhaustive && checked > 0 && !skipped && !skippedParams && !failure, ...(skipped ? { skipped } : {}), ...(skippedParams ? { skippedParams } : {}), ...(failure ? { failure } : {}) });
|
|
2800
3049
|
// A loop runs `body` while `while` holds, each turn with fresh inputs; it halts if a rank over the state and params
|
|
2801
3050
|
// (or a tuple of them, compared in order) drops on every turn.
|
|
2802
3051
|
export class LoopRule {
|
|
@@ -2910,6 +3159,10 @@ function guidesOf(m) {
|
|
|
2910
3159
|
} }];
|
|
2911
3160
|
});
|
|
2912
3161
|
}
|
|
3162
|
+
// Model-only negative evidence for inference: never a source-law verdict.
|
|
3163
|
+
export function refuteModelByRuns(r, laws, stepLaws = []) {
|
|
3164
|
+
return refuteByRuns(r, laws, stepLaws);
|
|
3165
|
+
}
|
|
2913
3166
|
function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
|
|
2914
3167
|
const m = r.machine;
|
|
2915
3168
|
const run = interpret(m), rand = seeded(budget.seed ?? 13), bound = budget.bound, shown = shownRequest, guides = budget.mixed ? guidesOf(m) : [];
|
|
@@ -2917,12 +3170,19 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
|
|
|
2917
3170
|
const facts = (m.facts ?? []).filter(f => !isArithmetic(f.name.slice(0, f.name.indexOf(':'))));
|
|
2918
3171
|
const holds = (f, params) => {
|
|
2919
3172
|
const names = f.forall ? [f.forall, ...(f.keys ?? [])] : [], top = names.length > 1 ? bound : 2 * bound;
|
|
2920
|
-
const at = (env, i) =>
|
|
2921
|
-
|
|
3173
|
+
const at = (env, i) => {
|
|
3174
|
+
checkWorkEndpoint('refutation fact bindings');
|
|
3175
|
+
return i === names.length ? evalC(f.holds, env, { scalars: {}, maps: {} }, m)
|
|
3176
|
+
: Array.from({ length: top + 1 }, (_, key) => key).every(key => at({ ...env, [names[i]]: key }, i + 1));
|
|
3177
|
+
};
|
|
2922
3178
|
try {
|
|
2923
3179
|
return at(params, 0);
|
|
2924
3180
|
}
|
|
2925
|
-
catch {
|
|
3181
|
+
catch (e) {
|
|
3182
|
+
if (e instanceof WallExpired)
|
|
3183
|
+
throw e;
|
|
3184
|
+
if (e instanceof BudgetExpired)
|
|
3185
|
+
checkWorkEndpoint(e.phase);
|
|
2926
3186
|
return false;
|
|
2927
3187
|
}
|
|
2928
3188
|
};
|
|
@@ -2933,7 +3193,7 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
|
|
|
2933
3193
|
&& facts.filter(readsParams).every(f => holds(f, params));
|
|
2934
3194
|
const cap = watchWork.n + perTrial * budget.trials;
|
|
2935
3195
|
try {
|
|
2936
|
-
const late = () => pastWall() || budget.until !== undefined &&
|
|
3196
|
+
const late = () => { checkWorkEndpoint('refutation poll'); return pastWall() || budget.until !== undefined && countedSearchNow() > budget.until; };
|
|
2937
3197
|
for (let trial = 0; trial < budget.trials && watchWork.n <= cap && !late(); trial++) {
|
|
2938
3198
|
// (`mixed`: the trials in turn at bounds 1 to 4, every fourth near)
|
|
2939
3199
|
const bound = budget.mixed ? 1 + trial % 4 : budget.bound, guided = guides, near = budget.mixed && trial % 4 ? undefined : budget.near;
|
|
@@ -3007,7 +3267,11 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
|
|
|
3007
3267
|
return { goal: `${l.name} @step`, witness: witness() };
|
|
3008
3268
|
}
|
|
3009
3269
|
}
|
|
3010
|
-
catch {
|
|
3270
|
+
catch (e) {
|
|
3271
|
+
if (e instanceof WallExpired)
|
|
3272
|
+
throw e;
|
|
3273
|
+
if (e instanceof BudgetExpired)
|
|
3274
|
+
checkWorkEndpoint(e.phase);
|
|
3011
3275
|
return undefined;
|
|
3012
3276
|
}
|
|
3013
3277
|
return undefined;
|
|
@@ -3019,10 +3283,70 @@ const refutedVerdict = (out) => ({ proven: false, checked: false, goal: out.goal
|
|
|
3019
3283
|
// another instance of the same rule (a factory called twice).
|
|
3020
3284
|
const noting = (r, ...xs) => { const ks = divisorsIn(xs); if (ks.size)
|
|
3021
3285
|
r.dividesBy(...ks); return r; };
|
|
3286
|
+
function workPlan(opts) {
|
|
3287
|
+
const explicit = typeof opts.search === 'object' ? opts.search.work : undefined;
|
|
3288
|
+
const ms = typeof opts.search === 'object' ? opts.search.ms : undefined;
|
|
3289
|
+
if (explicit !== undefined && ms !== undefined)
|
|
3290
|
+
throw new RangeError('choose a work budget or a legacy ms budget, not both');
|
|
3291
|
+
const work = explicit ?? (completeWorkProfile.enabled ? ms === undefined ? completeWorkProfile.defaultUnits : ms * fullRate : undefined);
|
|
3292
|
+
if (work === undefined || opts.search === false)
|
|
3293
|
+
return { work, opts };
|
|
3294
|
+
const search = typeof opts.search === 'object' ? { ...opts.search } : {};
|
|
3295
|
+
delete search.work;
|
|
3296
|
+
// Compatibility scheduling hint only; withBudget below receives the exact
|
|
3297
|
+
// original amount. This display must never become the root's authority.
|
|
3298
|
+
search.ms = typeof work === 'number' ? work / fullRate : workToNumber(workDivide(work, workFromNumber(fullRate)));
|
|
3299
|
+
return { work, opts: { ...opts, search } };
|
|
3300
|
+
}
|
|
3301
|
+
function workVerdict(opts, supported, run) {
|
|
3302
|
+
const plan = workPlan(opts);
|
|
3303
|
+
// An implicit child inherits the owner's hard allowance, not a fresh default.
|
|
3304
|
+
// Keep workPlan's validation and scheduling hint; let the owner's refusal
|
|
3305
|
+
// propagate to its handler rather than becoming this child's unknown verdict.
|
|
3306
|
+
const implicit = typeof opts.search !== 'object' || (opts.search.work === undefined && opts.search.ms === undefined);
|
|
3307
|
+
if (completeWorkProfile.enabled && workLedger.inBudget() && implicit)
|
|
3308
|
+
return run(plan.opts);
|
|
3309
|
+
if (plan.work === undefined)
|
|
3310
|
+
return run(plan.opts);
|
|
3311
|
+
if (!completeWorkProfile.enabled && !supported)
|
|
3312
|
+
return { proven: false, checked: false, stuck: 'unknown', why: 'work mode: plain-path migration pending' };
|
|
3313
|
+
try {
|
|
3314
|
+
return withBudget(plan.work, () => run(plan.opts));
|
|
3315
|
+
}
|
|
3316
|
+
catch (error) {
|
|
3317
|
+
if (!(error instanceof BudgetExpired))
|
|
3318
|
+
throw error;
|
|
3319
|
+
return { proven: false, checked: false, stuck: 'unknown', why: workRefusalWhy(error) };
|
|
3320
|
+
}
|
|
3321
|
+
}
|
|
3022
3322
|
export function proveRule(r, laws, opts = {}) {
|
|
3323
|
+
const hasCounts = !!Object.keys(r.machine.counts ?? {}).length;
|
|
3324
|
+
return workVerdict(opts, hasCounts, plan => withPublicSearchPolicy(hasCounts, () => proveRuleWall(r, laws, plan)));
|
|
3325
|
+
}
|
|
3326
|
+
function proveRuleWall(r, laws, opts) {
|
|
3327
|
+
const ms = typeof opts.search === 'object' ? opts.search.ms : undefined;
|
|
3328
|
+
const run = () => {
|
|
3329
|
+
try {
|
|
3330
|
+
checkWall('rule preflight');
|
|
3331
|
+
const out = proveRuleIn(r, laws, opts);
|
|
3332
|
+
checkWall('rule result');
|
|
3333
|
+
return out;
|
|
3334
|
+
}
|
|
3335
|
+
catch (e) {
|
|
3336
|
+
if (!(e instanceof WallExpired))
|
|
3337
|
+
throw e;
|
|
3338
|
+
return { proven: false, checked: false, stuck: 'unknown', why: e.message };
|
|
3339
|
+
}
|
|
3340
|
+
};
|
|
3341
|
+
// One absolute wall for setup, sampling, generation and proof, not a fresh
|
|
3342
|
+
// allowance for each phase. Nested callers can only shorten it.
|
|
3343
|
+
return translationVerdict(r, laws, ms === undefined ? run() : withWall(searchWall(ms), run));
|
|
3344
|
+
}
|
|
3345
|
+
function proveRuleIn(r, laws, opts) {
|
|
3023
3346
|
r = r.withSumsOf(laws);
|
|
3024
3347
|
noting(r, laws);
|
|
3025
3348
|
const refuted = refuteByRuns(r, laws);
|
|
3349
|
+
checkWorkEndpoint('refutation result');
|
|
3026
3350
|
// A state the laws allow whose step breaks one, with no run to it (a wide rule's: what the kernel's step goal would end
|
|
3027
3351
|
// at), is a counterexample to induction: the laws may still hold, so the search goes on from it, as from the kernel's.
|
|
3028
3352
|
// (A step law broken so is refused, proveSteps below: it holds from every state the laws allow, reached or not.)
|
|
@@ -3043,21 +3367,37 @@ export function proveRule(r, laws, opts = {}) {
|
|
|
3043
3367
|
// Quantified witness preflight needs a counted allocation: a slow attempt must
|
|
3044
3368
|
// not seed different memoized decisions. Other laws keep their existing budget;
|
|
3045
3369
|
// inference's query rate is not calibrated for their whole-set preflight.
|
|
3046
|
-
const out = ms === undefined ? given() :
|
|
3047
|
-
const v = { ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) }
|
|
3370
|
+
const out = ms === undefined ? given() : withStageWall(countedSearchNow() + ms / share, () => share === 1 ? given() : counted(inferRates.work, () => withStageDeadline(clock() + ms / share, given, () => undefined)), () => undefined);
|
|
3371
|
+
const v = out ? { ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) }
|
|
3372
|
+
: { proven: false, checked: false, stuck: 'unknown' };
|
|
3048
3373
|
return searched(r, laws, [], v, opts);
|
|
3049
3374
|
}
|
|
3050
3375
|
export function proveSteps(r, laws, stepLaws, opts = {}) {
|
|
3376
|
+
return workVerdict(opts, false, plan => proveStepsWall(r, laws, stepLaws, plan));
|
|
3377
|
+
}
|
|
3378
|
+
function proveStepsWall(r, laws, stepLaws, opts) {
|
|
3051
3379
|
const ms = typeof opts.search === 'object' ? opts.search.ms : undefined;
|
|
3052
3380
|
// From any state, the caller's budget includes preflight runs and all initial
|
|
3053
3381
|
// goals, not a fresh budget per goal. Keep reachable-state search unchanged.
|
|
3054
|
-
|
|
3055
|
-
|
|
3382
|
+
const run = () => {
|
|
3383
|
+
try {
|
|
3384
|
+
return proveStepsIn(r, laws, stepLaws, opts);
|
|
3385
|
+
}
|
|
3386
|
+
catch (e) {
|
|
3387
|
+
if (!(e instanceof WallExpired))
|
|
3388
|
+
throw e;
|
|
3389
|
+
return { proven: false, checked: false, stuck: 'unknown', why: e.message };
|
|
3390
|
+
}
|
|
3391
|
+
};
|
|
3392
|
+
const verdict = opts.from !== 'any' || ms === undefined ? run()
|
|
3393
|
+
: withWall(countedSearchNow() + ms, run);
|
|
3394
|
+
return translationVerdict(r, [...laws, ...stepLaws], verdict);
|
|
3056
3395
|
}
|
|
3057
3396
|
function proveStepsIn(r, laws, stepLaws, opts) {
|
|
3058
3397
|
r = r.withSumsOf(laws, stepLaws);
|
|
3059
3398
|
noting(r, laws, stepLaws);
|
|
3060
3399
|
const refuted = refuteByRuns(r, laws, stepLaws);
|
|
3400
|
+
checkWorkEndpoint('refutation result');
|
|
3061
3401
|
// (a step law broken from a state the laws allow, with no run to it: the laws may need an invariant there, or the run
|
|
3062
3402
|
// be further than these runs go; the search goes on from it, as from the kernel's)
|
|
3063
3403
|
if (refuted)
|
|
@@ -3101,7 +3441,7 @@ function searched(r, laws, stepLaws, v, opts) {
|
|
|
3101
3441
|
// The deeper runs; then runs over small values (keys that meet, small params), whose requests meet their
|
|
3102
3442
|
// assumption's equalities and clocks, or near the counterexample the verdict ends at.
|
|
3103
3443
|
// (the three within the search's budget again, on the wall: past it they stop, and the search starts as it would)
|
|
3104
|
-
const ms = typeof opts.search === 'object' && opts.search.ms !== undefined ? opts.search.ms : 10_000, runsUntil =
|
|
3444
|
+
const ms = typeof opts.search === 'object' && opts.search.ms !== undefined ? opts.search.ms : 10_000, runsUntil = countedSearchNow() + ms;
|
|
3105
3445
|
for (const b of [deeperBudget, { ...deeperBudget, bound: 1, seed: 31, states: false }, { ...deeperBudget, trials: 1200, seed: 41, states: false, mixed: true, ...(v.witness ? { near: v.witness } : {}) }]) {
|
|
3106
3446
|
const deeper = refuteByRuns(r, laws, stepLaws, { ...b, until: runsUntil });
|
|
3107
3447
|
if (deeper?.run)
|
|
@@ -3118,7 +3458,7 @@ function searched(r, laws, stepLaws, v, opts) {
|
|
|
3118
3458
|
}
|
|
3119
3459
|
const until = clock() + (typeof opts.search === 'object' && opts.search.ms !== undefined ? opts.search.ms : 10_000);
|
|
3120
3460
|
// (the search's end on the wall too: kernel/prove.ts's withWall, past which every goal is unknown)
|
|
3121
|
-
return
|
|
3461
|
+
return withStageWall(countedSearchNow() + Math.max(0, until - clock()), () => searchedUntil(r, laws, stepLaws, v, opts, until), () => v);
|
|
3122
3462
|
}
|
|
3123
3463
|
// Two machines alike up to the names of the keys their quantified flags and writes at every key bind (the rule builds
|
|
3124
3464
|
// fresh ones each time it is read): each bound name by its place of first binding.
|
|
@@ -3142,7 +3482,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3142
3482
|
const ghosted = stepGhosts(r.machine, stepLaws);
|
|
3143
3483
|
// (with the step laws' ghosts, a wall stop too, at the budget: their goals cost the cost model more than its clock
|
|
3144
3484
|
// counts, a wide rule's past twice its wall time; and the last runs always, the search's tail on the wall too)
|
|
3145
|
-
const bounded = (ms, from, wall = !!ghosted) => counted(fullRate, () => findBoundedRun(ghosted?.machine ?? r.machine, [...laws, ...(ghosted?.laws ?? [])], { ms, from, steps: true, ...(wall ? { wall:
|
|
3485
|
+
const bounded = (ms, from, wall = !!ghosted) => counted(fullRate, () => withStageAllowance(ms, () => findBoundedRun(ghosted?.machine ?? r.machine, [...laws, ...(ghosted?.laws ?? [])], { ms, from, steps: true, ...(wall ? { wall: countedSearchNow() + ms } : {}), progress: k => { reached = k; } }), () => undefined), true);
|
|
3146
3486
|
const refutedBy = (b) => refutedVerdict({ goal: `${b.law} @step (a run of ${b.depth} steps from the start)`, witness: b.witness, run: { params: b.params, trace: b.trace.map(shownRequest) } });
|
|
3147
3487
|
const shallow = bounded(Math.min(250, total / 40), 1);
|
|
3148
3488
|
if (shallow)
|
|
@@ -3151,24 +3491,24 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3151
3491
|
// within a twentieth of the budget (at most 500 ms, counted so too).
|
|
3152
3492
|
if (!any && !stepLaws.length && laws.every(l => !l.forall && !l.keys?.length && !l.some?.length)) {
|
|
3153
3493
|
const ms = Math.min(500, total / 20), kinds = withKinds(r, []).filter(k => !laws.some(l => l.name === k.name));
|
|
3154
|
-
const kd = counted(fullRate, () => proveKInduction(r.machine, kinds, conjunction(laws), { ms }), true);
|
|
3155
|
-
if (kd
|
|
3494
|
+
const kd = counted(fullRate, () => withStageAllowance(ms, () => proveKInduction(r.machine, kinds, conjunction(laws), { ms }), () => undefined), true);
|
|
3495
|
+
if (kd?.proven && kd.checked)
|
|
3156
3496
|
return { proven: true, checked: true, k: kd.k, assumes: { states: 'reachable', laws: [] } };
|
|
3157
3497
|
}
|
|
3158
3498
|
let rule = r, lemmas;
|
|
3159
3499
|
const { fns, lists } = r.parts;
|
|
3160
3500
|
if (lists.length || fns.some(([, d]) => recurOf(d))) {
|
|
3161
|
-
const d =
|
|
3162
|
-
if (d
|
|
3501
|
+
const d = withStageDeadline(until, () => discover(r, laws, stepLaws, v), () => undefined);
|
|
3502
|
+
if (d?.verdict.proven && d.verdict.checked)
|
|
3163
3503
|
return { ...d.verdict, found: { lemmas: d.found } };
|
|
3164
|
-
if (Object.keys(d.found).length)
|
|
3504
|
+
if (d && Object.keys(d.found).length)
|
|
3165
3505
|
(rule = d.rule, lemmas = d.found);
|
|
3166
3506
|
}
|
|
3167
3507
|
// Functions known by their facts alone (not a recurrence): lemmas about them, fitted to their values and proven from
|
|
3168
3508
|
// the facts as cyclic claims, the laws proven with them as facts.
|
|
3169
3509
|
if ((typeof opts.search !== 'object' || opts.search.cycles !== false) && fns.some(([, d]) => !recurOf(d)) && rule.machine.facts?.length && until - clock() > 500) {
|
|
3170
|
-
const c =
|
|
3171
|
-
if (c
|
|
3510
|
+
const c = withStageDeadline(until, () => cycleLemmas(rule.machine, withKinds(rule, laws), stepLaws, { ms: (until - clock()) / 2 }), () => undefined);
|
|
3511
|
+
if (c?.proven && c.checked)
|
|
3172
3512
|
return { proven: true, checked: true, found: { ...(lemmas ? { lemmas } : {}), facts: c.found.map(f => f.text) } };
|
|
3173
3513
|
}
|
|
3174
3514
|
// Laws about the ids a counter hands out (core/fresh.ts), within a tenth of what is left: the laws with them, then
|
|
@@ -3179,11 +3519,11 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3179
3519
|
let fresh = [];
|
|
3180
3520
|
if (Object.keys(rule.machine.maps ?? {}).length && until - clock() - tail > 1000) {
|
|
3181
3521
|
const fm = rule.machine, share = (until - clock() - tail) / 10;
|
|
3182
|
-
fresh =
|
|
3522
|
+
fresh = withStageDeadline(clock() + share, () => freshLaws(fm, rule.kindLaws(), { params: (rand, bound) => rule.randomParams(rand, bound), input: (rand, bound, ps) => rule.randomInput(rand, bound, ps) }, { ms: share }), () => []);
|
|
3183
3523
|
if (fresh.length) {
|
|
3184
3524
|
// (counted, as the laws' own search: the same verdict on any machine)
|
|
3185
|
-
const given = [...withKinds(rule, laws), ...fresh.map(f => f.law)], out = counted(fullRate, () =>
|
|
3186
|
-
if (out
|
|
3525
|
+
const given = [...withKinds(rule, laws), ...fresh.map(f => f.law)], out = counted(fullRate, () => withStageDeadline(clock() + share, () => (stepLaws.length ? proveStepLaws(fm, given, stepLaws) : proveLaws(fm, given)), () => undefined), true);
|
|
3526
|
+
if (out?.proven && out.checked)
|
|
3187
3527
|
return { proven: true, checked: true, found: { laws: fresh, ...(lemmas ? { lemmas } : {}) }, assumes: reachableBy(fresh) };
|
|
3188
3528
|
}
|
|
3189
3529
|
}
|
|
@@ -3194,9 +3534,11 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3194
3534
|
if (!stepLaws.length && laws.some(l => l.some?.length) && laws.every(l => !l.some?.length || !l.forall)) {
|
|
3195
3535
|
let c;
|
|
3196
3536
|
try {
|
|
3197
|
-
c =
|
|
3537
|
+
c = withStageWall(countedSearchNow() + ms / 2, () => withStageDeadline(clock() + ms / 2, () => someCone(rule, laws, ms / 2), () => undefined), () => undefined);
|
|
3198
3538
|
}
|
|
3199
3539
|
catch (e) {
|
|
3540
|
+
if (e instanceof BudgetExpired)
|
|
3541
|
+
throw e;
|
|
3200
3542
|
if (knobs.GDP_EXISTS_LOG === '1')
|
|
3201
3543
|
console.error(`exists: cone failed: ${String(e.stack ?? e).slice(0, 600)}`);
|
|
3202
3544
|
}
|
|
@@ -3206,7 +3548,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3206
3548
|
return v;
|
|
3207
3549
|
}
|
|
3208
3550
|
// (the search's own wall ends where the tail begins: the last bounded runs keep it)
|
|
3209
|
-
const tailAt = () =>
|
|
3551
|
+
const tailAt = () => countedSearchNow() + Math.max(0, until - tail - clock());
|
|
3210
3552
|
// (a law about every key with "there exists": the search over its plain form, the value at its ghost map's cell, the
|
|
3211
3553
|
// ghosts' own laws beside it, on the rule with the ghosts (exists.ts's skolemOf), its verdict `back`'s; no join, whose
|
|
3212
3554
|
// convex forms can't state a cell read at a key a ghost holds: the engine alone (the join's first whole-set query on
|
|
@@ -3255,15 +3597,15 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3255
3597
|
return counted(fullRate, () => {
|
|
3256
3598
|
const end = clock() + budget;
|
|
3257
3599
|
if (!native)
|
|
3258
|
-
return !
|
|
3600
|
+
return !withStageDeadline(end, () => proveLaw(tm, ls, ls.indexOf(c)), () => undefined)?.proven;
|
|
3259
3601
|
// Try local provenance before instantiating every witness. All three
|
|
3260
3602
|
// attempts share the same existing support-query allocation.
|
|
3261
|
-
if (round === 0 &&
|
|
3603
|
+
if (round === 0 && withStageDeadline(Math.min(end, clock() + 500), () => proveSetFast(tm, [c]), () => undefined)?.proven)
|
|
3262
3604
|
return false;
|
|
3263
3605
|
const local = witnessSupport(tm, helpers, c, Object.keys(sk.maps));
|
|
3264
|
-
if (
|
|
3606
|
+
if (withStageDeadline(Math.min(end, clock() + 1_000), () => proveLaw(tm, local, local.indexOf(c)), () => undefined)?.proven)
|
|
3265
3607
|
return false;
|
|
3266
|
-
return !
|
|
3608
|
+
return !withStageDeadline(end, () => proveLaw(tm, ls, ls.indexOf(c)), () => undefined)?.proven;
|
|
3267
3609
|
}, true);
|
|
3268
3610
|
});
|
|
3269
3611
|
if (clock() >= hUntil)
|
|
@@ -3274,7 +3616,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3274
3616
|
for (const l of native ? sought : []) {
|
|
3275
3617
|
const local = witnessSupport(tm, ls, l);
|
|
3276
3618
|
if (local.length < ls.length)
|
|
3277
|
-
|
|
3619
|
+
withStageDeadline(Math.min(hUntil, clock() + 3_000), () => proveLaw(tm, local, local.indexOf(l)), () => undefined);
|
|
3278
3620
|
}
|
|
3279
3621
|
const b = back(target, keep.map(law => ({ law })), native);
|
|
3280
3622
|
if (knobs.GDP_EXISTS_LOG === '1')
|
|
@@ -3288,14 +3630,14 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3288
3630
|
keep = keep.filter(c => !drop.includes(c));
|
|
3289
3631
|
}
|
|
3290
3632
|
}
|
|
3291
|
-
const inf =
|
|
3292
|
-
if (!(inf
|
|
3633
|
+
const inf = withStageWall(tailAt(), () => inferLaws(target, [...fresh.map(f => f.law), ...sought], stepLaws, { ms, ...((rule === r && !fresh.length) || sk ? { first: v } : {}), ...(sk ? { join: 0 } : {}) }), () => undefined);
|
|
3634
|
+
if (!(inf?.proven && inf.checked)) {
|
|
3293
3635
|
// The sum of each map the step writes (withMapSums): the search again over the rule with them, within half of what
|
|
3294
3636
|
// is left (at most 20 s), where a law of cells against a total needs one (no ERC20 balance past the supply).
|
|
3295
3637
|
const summed = target.withMapSums();
|
|
3296
3638
|
if (summed && until - clock() - tail > 1000) {
|
|
3297
|
-
const inf2 =
|
|
3298
|
-
if (inf2
|
|
3639
|
+
const inf2 = withStageWall(tailAt(), () => inferLaws(summed, [...fresh.map(f => f.law), ...sought], stepLaws, { ms: Math.min(20_000, (until - clock() - tail) / 2) }), () => undefined);
|
|
3640
|
+
if (inf2?.proven && inf2.checked) {
|
|
3299
3641
|
const { found, stats: _s2, ...verdict } = inf2;
|
|
3300
3642
|
void _s2;
|
|
3301
3643
|
const b = back(summed, found);
|
|
@@ -3307,7 +3649,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3307
3649
|
const deep = bounded(Math.max(0, Math.min(until - clock(), ghosted && !laws.length ? 10_000 : Infinity)), Math.max(1, reached), true);
|
|
3308
3650
|
if (deep)
|
|
3309
3651
|
return refutedBy(deep);
|
|
3310
|
-
return { ...v, why: [v.why, `the search found nothing that proves it in ${Math.round(inf.stats.ms)} ms`].filter(Boolean).join('; ') };
|
|
3652
|
+
return { ...v, why: [v.why, inf ? `the search found nothing that proves it in ${Math.round(inf.stats.ms)} ms` : 'the search reached its stage deadline'].filter(Boolean).join('; ') };
|
|
3311
3653
|
}
|
|
3312
3654
|
const { found, stats: _stats, ...verdict } = inf;
|
|
3313
3655
|
void _stats;
|
|
@@ -3338,10 +3680,12 @@ function someCone(r, laws0, ms) {
|
|
|
3338
3680
|
// (a cube the kernel refuses to state, one past its key rules, is never kept)
|
|
3339
3681
|
const plain = (law, ls, ms2) => {
|
|
3340
3682
|
try {
|
|
3341
|
-
const o =
|
|
3342
|
-
return o.proven ? { proof: true } : { stuck: o.stuck };
|
|
3683
|
+
const o = withStageDeadline(Math.min(until, clock() + ms2), () => proveLaw(m, ls, ls.indexOf(law)), () => undefined);
|
|
3684
|
+
return o ? o.proven ? { proof: true } : { stuck: o.stuck } : { stuck: 'unknown' };
|
|
3343
3685
|
}
|
|
3344
|
-
catch {
|
|
3686
|
+
catch (e) {
|
|
3687
|
+
if (e instanceof BudgetExpired)
|
|
3688
|
+
throw e;
|
|
3345
3689
|
return { stuck: '' };
|
|
3346
3690
|
}
|
|
3347
3691
|
};
|
|
@@ -3359,6 +3703,9 @@ const withAssumes = (found) => (found.length ? { assumes: reachableBy(found) } :
|
|
|
3359
3703
|
// The rule a keyed liveness is proven on: the rule with its key as one more param (a natural), any other rule as it is.
|
|
3360
3704
|
export const keyed = (r, l) => (l.forall ? r.params({ [l.forall]: nat }) : r);
|
|
3361
3705
|
export function proveLeadsTo(r, laws, l, opts = {}) {
|
|
3706
|
+
return translationVerdict(r, [...laws, l], proveLeadsToIn(r, laws, l, opts));
|
|
3707
|
+
}
|
|
3708
|
+
function proveLeadsToIn(r, laws, l, opts) {
|
|
3362
3709
|
r = keyed(r, l).withSumsOf(laws, l);
|
|
3363
3710
|
noting(r, laws, l);
|
|
3364
3711
|
if (laws.some(law => law.some?.length))
|
|
@@ -3367,7 +3714,7 @@ export function proveLeadsTo(r, laws, l, opts = {}) {
|
|
|
3367
3714
|
const until = clock() + (opts.ms ?? 10_000), draws = { params: (rand, bound) => r.randomParams(rand, bound), input: (rand, bound, ps) => r.randomInput(rand, bound, ps) };
|
|
3368
3715
|
// (the laws about the keys a counter hands out or a high-water mark bounds, core/fresh.ts, within a twentieth: given
|
|
3369
3716
|
// to both searches, each proven again with the rank)
|
|
3370
|
-
const share = (until - clock()) / 20, fresh = Object.keys(r.machine.maps ?? {}).length ?
|
|
3717
|
+
const share = (until - clock()) / 20, fresh = Object.keys(r.machine.maps ?? {}).length ? withStageDeadline(clock() + share, () => freshLaws(r.machine, r.kindLaws(), draws, { ms: share }), () => []) : [];
|
|
3371
3718
|
laws = [...laws, ...fresh.map(x => x.law)];
|
|
3372
3719
|
let f = findLeadsTo(r.machine, withKinds(r, laws), l, { ...draws, rule: r }, { ms: until - clock() });
|
|
3373
3720
|
// Where the rank fitted to the runs isn't the one: a rank of the rule's own terms (core/live.ts), in the time left.
|
|
@@ -3408,7 +3755,7 @@ export function refuteLeadsTo(r, laws, l, opts = {}) {
|
|
|
3408
3755
|
// prover reads (the counted one inside a counted search): past it the verdict is unknown.
|
|
3409
3756
|
export const proveDecision = (d, opts = {}) => {
|
|
3410
3757
|
const go = () => (d.steps ? proveSteps(d.steps.rule, [], [d.steps.law], { search: false }) : goalsVerdict([d.goal]));
|
|
3411
|
-
return opts.ms === undefined ? go() :
|
|
3758
|
+
return translationVerdict(d.rule, [d.goal], opts.ms === undefined ? go() : withStageDeadline(clock() + opts.ms, go, () => ({ proven: false, checked: false, stuck: 'unknown' })));
|
|
3412
3759
|
};
|
|
3413
3760
|
// A decision's callbacks against its condition, on random params and requests: `given` and `then` each run with every
|
|
3414
3761
|
// value known, against what the interpreter evaluates of the decision built from them.
|
|
@@ -3443,15 +3790,15 @@ export function crossCheckDecision(d, opts = {}) {
|
|
|
3443
3790
|
// usual trees, which are then its input and not checked again); where none is made, the usual trees, checked.
|
|
3444
3791
|
export const proveLoop = (l, laws, opts = {}) => {
|
|
3445
3792
|
if (l.hasRank) {
|
|
3446
|
-
const t0 =
|
|
3793
|
+
const t0 = countedSearchNow(), goals = loopObligations(l.loop, laws, l.rankTerms), v = goalsVerdict(goals, !certOn());
|
|
3447
3794
|
if (!v.proven)
|
|
3448
3795
|
return v;
|
|
3449
|
-
const c = certLoop(l.loop, laws, l.rankTerms, v.trees,
|
|
3796
|
+
const c = certLoop(l.loop, laws, l.rankTerms, v.trees, countedSearchNow() - t0);
|
|
3450
3797
|
return c && !c.checked && certOn() ? { ...v, checked: goals.every(g => check(g, v.trees[g.name])) } : v;
|
|
3451
3798
|
}
|
|
3452
|
-
const t0 =
|
|
3799
|
+
const t0 = countedSearchNow(), out = findRank(l.loop, laws, opts);
|
|
3453
3800
|
if (out.proven && out.checked && out.rank && out.trees)
|
|
3454
|
-
certLoop(l.loop, [...laws, ...(out.laws ?? [])], out.rank, out.trees,
|
|
3801
|
+
certLoop(l.loop, [...laws, ...(out.laws ?? [])], out.rank, out.trees, countedSearchNow() - t0);
|
|
3455
3802
|
return { proven: out.proven, checked: out.checked, ...(out.trees ? { trees: out.trees } : {}), ...(out.goal ? { goal: out.goal, stuck: out.stuck } : {}), ...(out.witness ? { witness: out.witness } : {}), ...(out.why ? { why: out.why } : {}),
|
|
3456
3803
|
...(out.found ? { found: { rank: out.found.rank, ...(out.laws?.length ? { laws: out.laws.map((law, i) => ({ law, text: out.found.laws[i] ?? law.name })) } : {}) } } : {}) };
|
|
3457
3804
|
};
|
|
@@ -3579,7 +3926,7 @@ export const fold = (name) => new FoldRule({ name, params: [], inputs: [], pre:
|
|
|
3579
3926
|
export const proveFold = (f, laws) => {
|
|
3580
3927
|
// (by default the certificate a cyclic proof, core/cyclic.ts's certCyclic, the usual trees its input; where none is
|
|
3581
3928
|
// made, the usual trees checked)
|
|
3582
|
-
const all = [...(f.lemmas ?? []), ...laws], t0 =
|
|
3929
|
+
const all = [...(f.lemmas ?? []), ...laws], t0 = countedSearchNow(), v = goalsVerdict(foldObligations(f.fold, all), !certOn()), usualMs = countedSearchNow() - t0;
|
|
3583
3930
|
if (cyclicOn())
|
|
3584
3931
|
crossCyclic('fold', f.fold.name, v.proven && v.checked, () => { const { facts, specs } = foldNodes(f.fold, all); return proveCyclic(facts, specs); }, usualMs, v.trees && (st => translatedProof(() => JSON.stringify(['fold', f.fold, all]), () => foldNodes(f.fold, all, v.trees, st), st)));
|
|
3585
3932
|
if (certOn() && v.proven) {
|