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/lean-kernel/emit.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { atMost, n, not, pointWrite } from "../core/machine.js";
|
|
2
2
|
import { add, k, scale, sub } from "../core/solver.js";
|
|
3
|
-
import { countedGoal, countedObligations, countHyps, mcGoal, postName, boundOf, caseGoals, cellParts, check, checkRecur, checkRecurCases, coverGoal, recurGoal, canon, decided, factorsOf, isCell, isMonomial, columnTerm, stateName, termColumn, truth, historyMachine, sumMachine, sumCovers, sumParts, foldObligations, kInductionStart, kInductionSteps, leafConstraints, loopLiveness, loopMachine, linear, livenessHelpful, livenessParts, livenessLevels, livenessRanks, strongly, loopObligations, trueC, obligations, progressObligations, stepLawObligations, substC, witnessesOf, withProducts } from "../kernel/kernel.js";
|
|
3
|
+
import { framePath, lemmaPath, checkMC, checkCounted, checkCountedLaws, countedGoal, countedObligations, countHyps, mcGoal, postName, boundOf, caseGoals, cellParts, check, checkRecur, checkRecurCases, coverGoal, recurGoal, canon, decided, factorsOf, isCell, isMonomial, columnTerm, stateName, termColumn, truth, historyMachine, sumMachine, sumCovers, sumParts, foldObligations, kInductionStart, kInductionSteps, leafConstraints, loopLiveness, loopMachine, linear, livenessHelpful, livenessParts, livenessLevels, livenessRanks, strongly, loopObligations, trueC, obligations, progressObligations, stepLawObligations, substC, witnessesOf, withProducts } from "../kernel/kernel.js";
|
|
4
4
|
import { chooseLevels, clock, grow, minimal, proveBuilt, proveLaws, proveSetFast, proveStepLaws, withDeadline } from "../kernel/prove.js";
|
|
5
5
|
import { refinement, refinementSides } from "../core/compose.js";
|
|
6
|
-
import { exactNat, leanSurface, leanTerms } from "./lean-terms.js";
|
|
6
|
+
import { exactNat, leanConnective, leanSurface, leanTerms } from "./lean-terms.js";
|
|
7
7
|
import { descentGoal, mainGoal, premiseGoal } from "../kernel/cyclic.js";
|
|
8
8
|
import { allowNode, certMs, closingInsts, reqTS, withWitness, foldNodes, certMode, quietly, uncoveredWhy, hasQuantified, kWhens, machineNodes, proveCyclic, routeOf, searchedStepNodes, skMachine, stepLawNodes, tBack, tSub } from "../core/cyclic.js";
|
|
9
9
|
import { leanLibrary } from "./library.js";
|
|
10
|
+
import { legacyFamilyLibrary } from "./legacy-family-library.js";
|
|
10
11
|
import { proveKInduction } from "../core/kind.js";
|
|
12
|
+
import { quantifiedRenames } from "./qalpha.js";
|
|
13
|
+
import { countsForReads } from "../core/count-facts.js";
|
|
11
14
|
export { leanLibrary };
|
|
12
15
|
// --- to Lean ------------------------------------------------------------------------------------------------------------
|
|
13
16
|
const varsOf = (c) => [...JSON.stringify(c).matchAll(/"op":"var","name":"([^"]+)"/g)].map(m => m[1]);
|
|
@@ -108,7 +111,7 @@ function reachedChoices(goal, leafList) {
|
|
|
108
111
|
}
|
|
109
112
|
return out;
|
|
110
113
|
}
|
|
111
|
-
export function encode(ex, tamper = false, dropStep = true, globalVars, globalMaps, slim = false, reach = false) {
|
|
114
|
+
export function encode(ex, tamper = false, dropStep = true, globalVars, globalMaps, slim = false, reach = false, context = {}) {
|
|
112
115
|
const { goal, tree } = ex;
|
|
113
116
|
// `slim`: the table only has the columns Lean reads. Each row a leaf uses has a hint (where Lean looks for it first),
|
|
114
117
|
// and Lean computes only the hinted hypotheses' linear forms (Kernel.lean's srcRows), so the columns are the
|
|
@@ -118,7 +121,10 @@ export function encode(ex, tamper = false, dropStep = true, globalVars, globalMa
|
|
|
118
121
|
// hypotheses, so its table is a few columns, not every choice of the node's facts.
|
|
119
122
|
// Each leaf with its path and rows, found once (the passes below and the tree's text read them in the same order).
|
|
120
123
|
const leafList = [];
|
|
121
|
-
leaves(tree, new Map(), (leaf, path) => {
|
|
124
|
+
leaves(tree, context.path ?? new Map(), (leaf, path) => {
|
|
125
|
+
const visible = context.frames?.length || context.monos?.length || context.lins?.length ? framePath(context.frames ?? [], context.lemmas ?? [], path, context.monos, context.lins) : lemmaPath(context.lemmas ?? [], path);
|
|
126
|
+
leafList.push({ leaf, path: visible, base: leafConstraints(goal, visible) });
|
|
127
|
+
});
|
|
122
128
|
const reads = new Set(), hintTerms = new Set();
|
|
123
129
|
let whole = !slim;
|
|
124
130
|
if (slim)
|
|
@@ -134,11 +140,11 @@ export function encode(ex, tamper = false, dropStep = true, globalVars, globalMa
|
|
|
134
140
|
hintTerms.add(src.term);
|
|
135
141
|
}
|
|
136
142
|
}
|
|
137
|
-
const readHyps = whole ? goal.hyps : goal.hyps.filter((_, i) => reads.has(i));
|
|
143
|
+
const readHyps = [...(whole ? goal.hyps : goal.hyps.filter((_, i) => reads.has(i))), ...(context.monos ?? []).flatMap(m => m.when), ...(context.lins ?? []).flatMap(l => l.when)];
|
|
138
144
|
const readTerms = whole ? [] : [...hintTerms].map(name => columnTerm(name));
|
|
139
145
|
// Columns: every variable of the hypotheses, then every cell any leaf uses (and the cells inside their keys),
|
|
140
146
|
// shallower cells first so a key reads only earlier columns.
|
|
141
|
-
const vars = globalVars ?? [...new Set(goal.hyps.flatMap(varsOf))];
|
|
147
|
+
const vars = globalVars ?? [...new Set([...goal.hyps.flatMap(varsOf), ...lemmaNames([], context.frames, context.monos, context.lins).vars])];
|
|
142
148
|
const cells = new Set(), terms = new Set();
|
|
143
149
|
// Monomials: every one a leaf's rows or products use, or that a product term has under the leaf's path, with the
|
|
144
150
|
// cells among their factors.
|
|
@@ -224,6 +230,17 @@ export function encode(ex, tamper = false, dropStep = true, globalVars, globalMa
|
|
|
224
230
|
addCell(key);
|
|
225
231
|
}
|
|
226
232
|
}
|
|
233
|
+
// Conditions can name columns a certificate never uses at a leaf; they still need encoding.
|
|
234
|
+
for (const f of context.frames ?? [])
|
|
235
|
+
for (const r of f.when)
|
|
236
|
+
for (const key of Object.keys(r)) {
|
|
237
|
+
if (isMonomial(key))
|
|
238
|
+
addMono(key);
|
|
239
|
+
else if (isCell(key))
|
|
240
|
+
addCell(key);
|
|
241
|
+
else if (key.startsWith('⟦'))
|
|
242
|
+
terms.add(key);
|
|
243
|
+
}
|
|
227
244
|
const depth = (name) => name.split('[').length;
|
|
228
245
|
// Term columns (open choices, each standing for its term's value) before the cells, whose keys may read them; a
|
|
229
246
|
// monomial with a cell among its factors after the cells.
|
|
@@ -245,7 +262,7 @@ export function encode(ex, tamper = false, dropStep = true, globalVars, globalMa
|
|
|
245
262
|
place(cell);
|
|
246
263
|
for (const mono of cellMonos)
|
|
247
264
|
place(mono);
|
|
248
|
-
const cols = [...vars, ...plainMonos, ...[...terms].sort((a, b) => Number(a.slice(1, -1)) - Number(b.slice(1, -1))), ...late];
|
|
265
|
+
const cols = context.cols ?? [...vars, ...plainMonos, ...[...terms].sort((a, b) => Number(a.slice(1, -1)) - Number(b.slice(1, -1))), ...late];
|
|
249
266
|
const col = new Map(cols.map((name, j) => [name, j]));
|
|
250
267
|
const maps = globalMaps ?? [...new Set([...[...cells].map(cellMap), ...goal.hyps.flatMap(h => [...JSON.stringify(h).matchAll(/"op":"get","map":"([^"]+)"/g)].map(m => m[1]))])];
|
|
251
268
|
const dense = (lin) => {
|
|
@@ -326,7 +343,7 @@ export function encode(ex, tamper = false, dropStep = true, globalVars, globalMa
|
|
|
326
343
|
if (!src)
|
|
327
344
|
return '.any';
|
|
328
345
|
if ('atom' in src)
|
|
329
|
-
return `.atom ${path.size - 1 - src.atom}`; // Lean's path has the latest decision first
|
|
346
|
+
return context.path || context.lemmas?.length || context.frames?.length || context.monos?.length || context.lins?.length ? '.any' : `.atom ${path.size - 1 - src.atom}`; // Lean's path has the latest decision first
|
|
330
347
|
if ('fact' in src)
|
|
331
348
|
return `.fact ${src.fact}`;
|
|
332
349
|
const j = 'pair' in src ? pairs.indexOf([...src.pair].sort().join('\n')) : col.get('nat' in src ? src.nat : src.term) ?? -1;
|
|
@@ -340,7 +357,7 @@ export function encode(ex, tamper = false, dropStep = true, globalVars, globalMa
|
|
|
340
357
|
const at2 = list(used.map(u => `(${row(rows[u])}, ${hint(base[u].src)})`)), rest = `${list(steps)} ${list(keepEqs.map(j => eqs[j]))} ${list(prods.map(([i, j]) => `(${idx(i)}, ${idx(j)})`))}`;
|
|
341
358
|
return squares.length ? `.leafSq ${at2} ${list(squares.map(row))} ${rest}` : `.leafAt ${at2} ${rest}`;
|
|
342
359
|
};
|
|
343
|
-
return { tab: list(tab), tabCols: tab, hyps: list(goal.hyps.map(c)), tree: lean(tree), cols, c, e };
|
|
360
|
+
return { tab: list(tab), tabCols: tab, hyps: list(goal.hyps.map(c)), tree: lean(tree), cols, c, e, row };
|
|
344
361
|
}
|
|
345
362
|
export function goalToLean(ex, i, tamper = false, dropStep = true) {
|
|
346
363
|
const { tab, hyps, tree, cols } = encode(ex, tamper, dropStep);
|
|
@@ -363,14 +380,179 @@ theorem ${name} : ∀ env maps, ¬ ∀ c ∈ ${name}_goal.hyps, evalC env maps c
|
|
|
363
380
|
// certificates Lean computes to false, as kernel.ts refuses them.
|
|
364
381
|
const varsOfE = (t) => [...JSON.stringify(t).matchAll(/"op":"var","name":"([^"]+)"/g)].map(m => m[1]);
|
|
365
382
|
const mapsOf = (t) => [...JSON.stringify(t).matchAll(/"op":"get","map":"([^"]+)"/g)].map(m => m[1]);
|
|
383
|
+
// Extra row names may appear only in a lemma. Resolve their column dependencies with the same rules as encode.
|
|
384
|
+
function lemmaNames(lemmas, frames = [], monos = [], lins = []) {
|
|
385
|
+
const vars = new Set(), maps = new Set(), seen = new Set();
|
|
386
|
+
const name = (s) => {
|
|
387
|
+
if (s === '1' || seen.has(s))
|
|
388
|
+
return;
|
|
389
|
+
seen.add(s);
|
|
390
|
+
if (isMonomial(s)) {
|
|
391
|
+
factorsOf(s).forEach(name);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
if (isCell(s)) {
|
|
395
|
+
maps.add(cellMap(s));
|
|
396
|
+
cellKeys(s).forEach(row);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
const term = columnTerm(s);
|
|
400
|
+
if (term) {
|
|
401
|
+
varsOfE(term).forEach(v => vars.add(v));
|
|
402
|
+
mapsOf(term).forEach(m => maps.add(m));
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
vars.add(s);
|
|
406
|
+
};
|
|
407
|
+
const row = (r) => Object.keys(r).forEach(name);
|
|
408
|
+
const tree = (t) => {
|
|
409
|
+
if ('split' in t) {
|
|
410
|
+
row(t.split);
|
|
411
|
+
tree(t.yes);
|
|
412
|
+
tree(t.no);
|
|
413
|
+
}
|
|
414
|
+
else
|
|
415
|
+
t.squares?.forEach(row);
|
|
416
|
+
};
|
|
417
|
+
for (const l of lemmas) {
|
|
418
|
+
l.when.forEach(row);
|
|
419
|
+
row(l.cut);
|
|
420
|
+
tree(l.tree);
|
|
421
|
+
}
|
|
422
|
+
for (const f of frames) {
|
|
423
|
+
f.when.forEach(row);
|
|
424
|
+
name(f.post);
|
|
425
|
+
name(f.pre);
|
|
426
|
+
}
|
|
427
|
+
for (const m of monos) {
|
|
428
|
+
m.when.flatMap(varsOf).forEach(name);
|
|
429
|
+
m.when.flatMap(mapsOf).forEach(v => maps.add(v));
|
|
430
|
+
name(m.post);
|
|
431
|
+
name(m.pre);
|
|
432
|
+
tree(m.tree);
|
|
433
|
+
}
|
|
434
|
+
for (const l of lins) {
|
|
435
|
+
l.when.flatMap(varsOf).forEach(name);
|
|
436
|
+
l.when.flatMap(mapsOf).forEach(v => maps.add(v));
|
|
437
|
+
[...l.pos, ...l.neg].forEach(([, v]) => name(v));
|
|
438
|
+
tree(l.tree);
|
|
439
|
+
}
|
|
440
|
+
return { vars: [...vars], maps: [...maps] };
|
|
441
|
+
}
|
|
442
|
+
// Every independent proof uses one common table, but its own exact slice and initial path. Two passes establish
|
|
443
|
+
// the union of dependency-ordered columns before printing any rows. The old path stays unchanged for no lemmas.
|
|
444
|
+
export function encodeCounted(id, goal, cert, vars, maps) {
|
|
445
|
+
const ls = cert.lemmas ?? [];
|
|
446
|
+
const sources = ls.map((l, i) => {
|
|
447
|
+
const path = new Map();
|
|
448
|
+
let duplicate = 0;
|
|
449
|
+
for (const atom of [{ lin: l.cut, holds: false }, ...l.when.map(lin => ({ lin, holds: true }))]) {
|
|
450
|
+
const key = canon(atom.lin);
|
|
451
|
+
path.set(path.has(key) ? `@${duplicate++}` : key, atom);
|
|
452
|
+
}
|
|
453
|
+
const selected = l.slice === undefined ? goal.hyps : l.slice.map(j => {
|
|
454
|
+
if (!Number.isSafeInteger(j) || j < 0 || j >= goal.hyps.length)
|
|
455
|
+
throw new Error(`${id}: invalid lemma slice`);
|
|
456
|
+
return goal.hyps[j];
|
|
457
|
+
});
|
|
458
|
+
return { ex: { name: `${id}: lemma ${i}`, goal: { ...goal, hyps: selected }, tree: l.tree }, path };
|
|
459
|
+
});
|
|
460
|
+
const main = { name: id, goal, tree: cert.tree };
|
|
461
|
+
const first = encode(main, false, true, vars, maps, false, false, { lemmas: ls, frames: cert.frames, monos: cert.monos, lins: cert.lins });
|
|
462
|
+
if (!ls.length)
|
|
463
|
+
return { ...first, lemmas: '[]', lemmaList: (entries) => {
|
|
464
|
+
if (entries.length)
|
|
465
|
+
throw new Error(`${id}: no source contexts for added lemmas`);
|
|
466
|
+
return '[]';
|
|
467
|
+
} };
|
|
468
|
+
const initial = sources.map(s => encode(s.ex, false, true, vars, maps, false, false, { path: s.path }));
|
|
469
|
+
const cols = [...new Set([first, ...initial].flatMap(e => e.cols))];
|
|
470
|
+
const base = encode(main, false, true, vars, maps, false, false, { lemmas: ls, frames: cert.frames, monos: cert.monos, lins: cert.lins, cols });
|
|
471
|
+
const proofs = sources.map(s => encode(s.ex, false, true, vars, maps, false, false, { path: s.path, cols }));
|
|
472
|
+
const lemmaList = (entries) => list(entries.map((l, i) => {
|
|
473
|
+
const source = sources[i];
|
|
474
|
+
if (!source)
|
|
475
|
+
throw new Error(`${id}: no source context for lemma ${i}`);
|
|
476
|
+
const t = l.tree === ls[i].tree ? proofs[i].tree
|
|
477
|
+
: encode({ ...source.ex, tree: l.tree }, false, true, vars, maps, false, false, { path: source.path, cols }).tree;
|
|
478
|
+
return `⟨${list(l.when.map(base.row))}, ${base.row(l.cut)}, ${t}, ${l.slice === undefined ? 'none' : `some ${list(l.slice.map(String))}`}⟩`;
|
|
479
|
+
}));
|
|
480
|
+
return { ...base, lemmas: lemmaList(ls), lemmaList };
|
|
481
|
+
}
|
|
482
|
+
// The three cut lists of one counted certificate as Lean literals: frames over the certificate's own row encoder, per-key
|
|
483
|
+
// monotone and linear cuts each with the table and tree of its own auxiliary goal. One code path for the single-goal
|
|
484
|
+
// export (mcToLean) and the family export (cmachineToLean).
|
|
485
|
+
function cutLits(id, cert, decls, enc, vars, maps, c, ix) {
|
|
486
|
+
const frames = list((cert.frames ?? []).map(f => `⟨${list(f.when.map(enc.row))}, ${ix(f.post)}, ${ix(f.pre)}⟩`));
|
|
487
|
+
const counts = countsForReads(decls, cert.reads);
|
|
488
|
+
if (!counts)
|
|
489
|
+
throw new Error(`${id}: invalid count reads`);
|
|
490
|
+
const monos = list((cert.monos ?? []).map((m, i) => {
|
|
491
|
+
const post = counts.find(c => c.v === m.post), pre = counts.find(c => c.v === m.pre);
|
|
492
|
+
const auxiliary = { name: `${id}: per-key cut ${i}`, hyps: [...m.when,
|
|
493
|
+
{ op: '<', a: { op: 'var', name: post.key }, b: post.below }, { op: '<', a: pre.body, b: post.body }] };
|
|
494
|
+
const proof = encode({ name: auxiliary.name, goal: auxiliary, tree: m.tree }, false, true, vars, maps);
|
|
495
|
+
return `⟨${list(m.when.map(c))}, ${ix(m.post)}, ${ix(m.pre)}, ${proof.tab}, ${proof.tree}⟩`;
|
|
496
|
+
}));
|
|
497
|
+
const lins = list((cert.lins ?? []).map((l, i) => {
|
|
498
|
+
const first = counts.find(c => c.v === [...l.pos, ...l.neg][0][1]);
|
|
499
|
+
const term = (side) => side.reduceRight((rest, [k, v]) => ({ op: 'add', a: { op: 'mul', k, a: counts.find(c => c.v === v).body }, b: rest }), { op: 'const', value: 0 });
|
|
500
|
+
const auxiliary = { name: `${id}: linear cut ${i}`, hyps: [...l.when,
|
|
501
|
+
{ op: '<', a: { op: 'var', name: first.key }, b: first.below }, { op: '<', a: term(l.neg), b: term(l.pos) }] };
|
|
502
|
+
const proof = encode({ name: auxiliary.name, goal: auxiliary, tree: l.tree }, false, true, vars, maps);
|
|
503
|
+
const side = (xs) => list(xs.map(([k, v]) => `(${k}, ${ix(v)})`));
|
|
504
|
+
return `⟨${list(l.when.map(c))}, ${side(l.pos)}, ${side(l.neg)}, ${proof.tab}, ${proof.tree}⟩`;
|
|
505
|
+
}));
|
|
506
|
+
return { frames, monos, lins };
|
|
507
|
+
}
|
|
508
|
+
// A single counted obligation, including conditional frames. This is a conditional
|
|
509
|
+
// goal theorem through mcF_sound, not a claim that the source machine's INIT or
|
|
510
|
+
// its other operation goals have been proved.
|
|
511
|
+
export function mcToLean(id, hyps, decls, cert) {
|
|
512
|
+
if (!checkMC(hyps, decls, cert))
|
|
513
|
+
throw new Error(`${id}: counted certificate does not check`);
|
|
514
|
+
const goal = mcGoal(hyps, decls, cert);
|
|
515
|
+
const extra = lemmaNames(cert.lemmas ?? [], cert.frames, cert.monos, cert.lins);
|
|
516
|
+
const vars = [...new Set([...extra.vars, ...goal.hyps.flatMap(varsOf),
|
|
517
|
+
...decls.flatMap(d => [d.j, d.lo ?? d.j, d.key, ...varsOfE(d.below), ...varsOfE(d.body)]),
|
|
518
|
+
...cert.reads.flatMap(r => [r[0], ...varsOfE(r[2])]),
|
|
519
|
+
...cert.insts.flatMap(i => [i.wit, ...varsOfE(i.below)]),
|
|
520
|
+
...(cert.picks ?? []).flatMap(([v, ks]) => [v, ...ks.flatMap(varsOfE)])])];
|
|
521
|
+
const maps = [...new Set([...extra.maps, ...goal.hyps.flatMap(mapsOf), ...decls.flatMap(d => [d.map, ...mapsOf(d.below), ...mapsOf(d.body)])])];
|
|
522
|
+
const enc = encodeCounted(id, goal, cert, vars, maps), { e, c } = enc;
|
|
523
|
+
const ix = (name) => { const i = vars.indexOf(name); if (i < 0)
|
|
524
|
+
throw new Error(`${id}: unknown variable ${name}`); return i; };
|
|
525
|
+
const mx = (name) => maps.indexOf(name);
|
|
526
|
+
const { frames, monos, lins } = cutLits(id, cert, decls, enc, vars, maps, c, ix);
|
|
527
|
+
const linRef = cert.lins?.length ? `${id}_lins` : '[]';
|
|
528
|
+
const linDefinition = cert.lins?.length ? `def ${id}_lins : List LinCut := ${lins}\n` : '';
|
|
529
|
+
const monoRef = cert.monos?.length ? `${id}_monos` : '[]';
|
|
530
|
+
const monoDefinition = cert.monos?.length ? `def ${id}_monos : List MonoCut := ${monos}\n` : '';
|
|
531
|
+
return `-- Goal-local counted certificate; no whole-machine reachability claim.
|
|
532
|
+
def ${id}_hyps : List C := ${list(hyps.map(c))}
|
|
533
|
+
-- CDecl.post is unused by checkMCF/GHolds; this packet already contains PRE/POST declarations.
|
|
534
|
+
def ${id}_decls : List CDecl := ${list(decls.map(d => `⟨${mx(d.map)}, ${mx(d.map)}, ${ix(d.j)}, ${ix(d.key)}, ${e(d.below)}, ${e(d.body)}, ${ix(d.lo ?? d.j)}, ${d.base ?? 0}⟩`))}
|
|
535
|
+
def ${id}_cert : CCert := ⟨${id}_hyps,
|
|
536
|
+
${list(cert.reads.map(r => `(${ix(r[0])}, ${mx(r[1])}, ${e(r[2])})`))},
|
|
537
|
+
${list(cert.insts.map(i => `⟨${ix(i.wit)}, ${e(i.below)}, ${list(i.terms.map(([z, v]) => `(${int(z)}, ${ix(v)})`))}, ${int(i.unit)}⟩`))},
|
|
538
|
+
${enc.tab}, ${enc.tree},
|
|
539
|
+
${list((cert.picks ?? []).map(([v, ks]) => `(${ix(v)}, ${list(ks.map(e))})`))}, ${enc.lemmas}⟩
|
|
540
|
+
def ${id}_frames : List FrameCut := ${frames}
|
|
541
|
+
${monoDefinition}${linDefinition}theorem ${id}_check : checkMCF ${id}_hyps ${id}_decls ${id}_cert ${id}_frames ${monoRef}${cert.lins?.length ? ` ${linRef}` : ''} = true := by ${checkBy}
|
|
542
|
+
theorem ${id} (ρ : Nat → Nat) (M : Nat → Nat → Nat) (hd : GHolds ${id}_decls ρ M)
|
|
543
|
+
(hH : ∀ ρw : Nat → Nat, (∀ j, (∀ i ∈ ${id}_cert.insts, i.wit ≠ j) → ρw j = ρ j) →
|
|
544
|
+
∀ h ∈ ${id}_hyps, evalC ρw M h = true) : False :=
|
|
545
|
+
mcF_sound ${id}_hyps ${id}_decls ${id}_cert ${id}_frames ${monoRef} ${linRef} ${id}_check ρ M hd hH`;
|
|
546
|
+
}
|
|
366
547
|
export function countedToLean(id, g, cert, tampered = []) {
|
|
367
548
|
const goal = countedGoal(g, cert.insts);
|
|
368
549
|
if (!goal)
|
|
369
550
|
throw new Error(`${id}: an instance names no count of the goal, or a count of another bound`);
|
|
370
|
-
const
|
|
551
|
+
const extra = lemmaNames(cert.lemmas ?? []);
|
|
552
|
+
const vars = [...new Set([...extra.vars, ...goal.hyps.flatMap(varsOf), ...g.counts.flatMap(cn => [cn.v, cn.key, ...varsOfE(cn.below), ...varsOfE(cn.body)]),
|
|
371
553
|
...[...cert.insts, ...tampered.flatMap(t => t.insts)].flatMap(i => [i.wit, ...varsOfE(i.below)])])];
|
|
372
|
-
const maps = [...new Set([...goal.hyps, ...g.counts.flatMap(cn => [cn.below, cn.body])].flatMap(mapsOf))];
|
|
373
|
-
const enc =
|
|
554
|
+
const maps = [...new Set([...extra.maps, ...[...goal.hyps, ...g.counts.flatMap(cn => [cn.below, cn.body])].flatMap(mapsOf)])];
|
|
555
|
+
const enc = encodeCounted(id, goal, cert, vars, maps), { e, c } = enc;
|
|
374
556
|
const ix = (name) => vars.indexOf(name);
|
|
375
557
|
const instsLit = (is) => list(is.map(i => `⟨${ix(i.wit)}, ${e(i.below)}, ${list(i.terms.map(([z, v2]) => `(${int(z)}, ${ix(v2)})`))}, ${int(i.unit)}⟩`));
|
|
376
558
|
return `-- ${g.name} (variables ${vars.map((v2, j) => `${j} ${v2}`).join(', ')}; maps ${maps.map((m2, j) => `${j} ${m2}`).join(', ')})
|
|
@@ -380,13 +562,14 @@ def ${id}_insts : List CInst := ${instsLit(cert.insts)}
|
|
|
380
562
|
def ${id}_tab : List VDef := ${enc.tab}
|
|
381
563
|
def ${id}_tree : Tree :=
|
|
382
564
|
${enc.tree}
|
|
565
|
+
def ${id}_lemmas : List CutLemma := ${enc.lemmas}
|
|
383
566
|
-- The instances' hypotheses Lean builds are the ones kernel.ts built.
|
|
384
567
|
example : countHyps ${id}_goal.counts ${id}_insts = some ${list(countHyps(g.counts, cert.insts).map(c))} := by ${checkBy}
|
|
385
568
|
/-- ${g.name}: no naturals and maps where each count is its sum satisfy the hypotheses. -/
|
|
386
569
|
theorem ${id} : ∀ ρ M, (∀ cn ∈ ${id}_goal.counts, cn.Holds ρ M) → ¬ ∀ h ∈ ${id}_goal.hyps, evalC ρ M h = true :=
|
|
387
|
-
counted_sound ${id}_goal ${id}_insts ${id}_tab ${id}_tree (by ${checkBy})${tampered.map(t => `
|
|
570
|
+
counted_sound ${id}_goal ${id}_insts ${id}_tab ${id}_tree (lemmas := ${id}_lemmas) (by ${checkBy})${tampered.map(t => `
|
|
388
571
|
-- TAMPERED: ${t.what}. Lean computes the check to false, as kernel.ts refuses it.
|
|
389
|
-
example : checkCounted ${id}_goal ${instsLit(t.insts)} ${id}_tab ${id}_tree = false := by ${checkBy}`).join('')}`;
|
|
572
|
+
example : checkCounted ${id}_goal ${instsLit(t.insts)} ${id}_tab ${id}_tree ${id}_lemmas = false := by ${checkBy}`).join('')}`;
|
|
390
573
|
}
|
|
391
574
|
// A machine with counts through CountMachine.lean's cmachine_sound: Lean builds the goals and the counts they declare;
|
|
392
575
|
// each certificate names the kernel's goal's hypotheses (each one Lean builds), the cells it reads, Count.lean's
|
|
@@ -397,13 +580,19 @@ export function cmachineToLean(id, m, laws, proof, tampers = []) {
|
|
|
397
580
|
const sm = { ...m, counts: undefined, inputMaps: [...(m.inputMaps ?? []), ...counts.map(([cn]) => cn)] };
|
|
398
581
|
const named = machineNames(sm, laws, [], [], {});
|
|
399
582
|
const allCerts = [proof.certs, ...tampers.map(t => t.certs)];
|
|
583
|
+
const extra = allCerts.flatMap(cs => Object.values(cs).map(k => lemmaNames(k.lemmas ?? [], k.frames, k.monos, k.lins)));
|
|
400
584
|
const goals = obl.map(o => { const g = mcGoal(o.goal.hyps, o.decls, proof.certs[o.goal.name]); if (!g)
|
|
401
585
|
throw new Error(`${id}: ${o.goal.name}: a read of no count`); return g; });
|
|
402
586
|
const certVars = allCerts.flatMap(cs => Object.values(cs).flatMap(k => [...k.reads.flatMap(r => [r[0], ...varsOfE(r[2])]), ...k.insts.flatMap(i => [i.wit, ...varsOfE(i.below)]), ...(k.picks ?? []).flatMap(([v2, ks]) => [v2, ...ks.flatMap(varsOfE)])]));
|
|
403
|
-
const vars = [...new Set([...named.vars, ...counts.flatMap(([, d]) => [d.j, d.lo ?? d.j, d.key, ...varsOfE(d.below), ...varsOfE(d.body)]), ...laws.map(l => (l.forall ? `${l.forall}#` : '#')),
|
|
587
|
+
const vars = [...new Set([...named.vars, ...extra.flatMap(n => n.vars), ...counts.flatMap(([, d]) => [d.j, d.lo ?? d.j, d.key, ...varsOfE(d.below), ...varsOfE(d.body)]), ...laws.map(l => (l.forall ? `${l.forall}#` : '#')),
|
|
404
588
|
...goals.flatMap(g => g.hyps.flatMap(varsOf)), ...certVars])];
|
|
405
|
-
const maps = [...new Set([...named.maps, ...counts.flatMap(([cn]) => [cn, postName(cn)]), ...goals.flatMap(g => g.hyps.flatMap(mapsOf)),
|
|
589
|
+
const maps = [...new Set([...named.maps, ...extra.flatMap(n => n.maps), ...counts.flatMap(([cn]) => [cn, postName(cn)]), ...goals.flatMap(g => g.hyps.flatMap(mapsOf)),
|
|
406
590
|
...allCerts.flatMap(cs => Object.values(cs).flatMap(k => [...k.reads.map(r => r[1]), ...(k.picks ?? []).flatMap(([, ks]) => ks.flatMap(mapsOf))]))])];
|
|
591
|
+
// Keep the input machine and proof untouched. Only the machine submitted to Lean's
|
|
592
|
+
// checker alpha-renames colliding local binders; QAlpha proves its original semantics.
|
|
593
|
+
const renames = quantifiedRenames(sm, laws, [...vars, ...maps]);
|
|
594
|
+
vars.push(...renames.map(r => r.fresh));
|
|
595
|
+
const checked = renames.length ? `${id}_checkedMachine` : `${id}_machine`;
|
|
407
596
|
const { e, c } = leanTerms(vars, maps, id);
|
|
408
597
|
const ix = (name) => { const j = vars.indexOf(name); if (j < 0)
|
|
409
598
|
throw new Error(`${id}: no variable for ${name}`); return j; };
|
|
@@ -429,32 +618,53 @@ export function cmachineToLean(id, m, laws, proof, tampers = []) {
|
|
|
429
618
|
const certLit = (name, certs) => {
|
|
430
619
|
// (a tampered certificate keeps the table and tree of the one it tampers with)
|
|
431
620
|
const o = obl.find(o2 => o2.goal.name === name), k = certs[name], k0 = proof.certs[name];
|
|
432
|
-
const tt =
|
|
621
|
+
const tt = encodeCounted(`${id}: ${name}`, mcGoal(o.goal.hyps, o.decls, k0), k0, vars, maps);
|
|
433
622
|
return `⟨${list(o.goal.hyps.map(c))},
|
|
434
623
|
${list(k.reads.map(r => `(${ix(r[0])}, ${mx(r[1])}, ${e(r[2])})`))},
|
|
435
624
|
${list(k.insts.map(i => `⟨${ix(i.wit)}, ${e(i.below)}, ${list(i.terms.map(([z, v2]) => `(${int(z)}, ${ix(v2)})`))}, ${int(i.unit)}⟩`))},
|
|
436
625
|
${tt.tab},
|
|
437
626
|
${tt.tree},
|
|
438
|
-
${list((k.picks ?? []).map(([v2, ks]) => `(${ix(v2)}, ${list(ks.map(e))})`))}
|
|
627
|
+
${list((k.picks ?? []).map(([v2, ks]) => `(${ix(v2)}, ${list(ks.map(e))})`))},
|
|
628
|
+
${tt.lemmaList(k.lemmas ?? [])}⟩`;
|
|
629
|
+
};
|
|
630
|
+
// A certificate's cuts, encoded against the same table as its tree (a tampered certificate keeps the cuts of the one
|
|
631
|
+
// it tampers with, as it keeps its table and tree). Emitted only when some certificate of this export has a cut: an
|
|
632
|
+
// export without cuts is the text it was before.
|
|
633
|
+
const hasCuts = (k) => !!(k.frames?.length || k.monos?.length || k.lins?.length);
|
|
634
|
+
const withAux = allCerts.some(cs => Object.values(cs).some(hasCuts));
|
|
635
|
+
const auxLit = (name, certs) => {
|
|
636
|
+
const o = obl.find(o2 => o2.goal.name === name), k = certs[name], k0 = proof.certs[name];
|
|
637
|
+
if (!hasCuts(k) && !hasCuts(k0))
|
|
638
|
+
return '⟨[], [], []⟩';
|
|
639
|
+
// The table is the original certificate's (as for its tree); the cuts are this certificate's own, so a tamper
|
|
640
|
+
// that drops or alters a cut is exported as altered and Lean computes the check without it.
|
|
641
|
+
const tt = encodeCounted(`${id}: ${name}`, mcGoal(o.goal.hyps, o.decls, k0), k0, vars, maps);
|
|
642
|
+
const cuts = cutLits(`${id}: ${name}`, { ...k0, frames: k.frames, monos: k.monos, lins: k.lins }, o.decls, tt, vars, maps, c, ix);
|
|
643
|
+
return `⟨${cuts.frames}, ${cuts.monos}, ${cuts.lins}⟩`;
|
|
439
644
|
};
|
|
440
645
|
const entries = (certs) => laws.map(law => {
|
|
441
646
|
const inst = proof.instances[law.name] ?? {};
|
|
442
647
|
return `⟨⟨⟨${c(law.holds)}, ${law.forall ? `some ${ix(law.forall)}` : 'none'}⟩, ${ix(law.forall ? `${law.forall}#` : '#')}, ${list((law.keys ?? []).map(key => String(ix(key))))}, ${list(insts(inst))}, ${list(qinsts(inst))}, ${list(finsts(inst))}, ${list(pinsts(inst))}, ${list(pfinsts(inst))},
|
|
443
648
|
([], [], .leaf [] [] [] []), ([], [], .leaf [] [] [] [])⟩,
|
|
444
649
|
${certLit(`${law.name} @start`, certs)},
|
|
445
|
-
${certLit(`${law.name} @step`, certs)}
|
|
650
|
+
${certLit(`${law.name} @step`, certs)}${withAux ? `,
|
|
651
|
+
${auxLit(`${law.name} @start`, certs)},
|
|
652
|
+
${auxLit(`${law.name} @step`, certs)}` : ''}⟩`;
|
|
446
653
|
});
|
|
447
654
|
return `-- ${m.name}: ${laws.map(l => l.name).join('; ')}, with counts ${counts.map(([cn]) => cn).join(', ')}
|
|
448
655
|
-- (variables ${vars.map((v2, j) => `${j} ${v2}`).join(', ')}; maps ${maps.map((v2, j) => `${j} ${v2}`).join(', ')})
|
|
449
|
-
def ${id}_machine : SMachine := ${machineLit(sm, { e, c }, ix, mx)}
|
|
656
|
+
def ${id}_machine : SMachine := ${machineLit(sm, { e, c }, ix, mx)}${renames.length ? `
|
|
657
|
+
-- Local alpha conversion only; validAll is checked by the generic semantic bridge.
|
|
658
|
+
def ${id}_renames : List QAlpha.Rename := ${list(renames.map(r => `⟨${ix(`?${r.flag}`)}, ${ix(r.old)}, ${ix(r.fresh)}⟩`))}
|
|
659
|
+
def ${id}_checkedMachine : SMachine := QAlpha.renameAll ${id}_machine ${id}_renames` : ''}
|
|
450
660
|
def ${id}_decls : List CDecl := ${list(counts.map(([cn, d]) => `⟨${mx(cn)}, ${mx(postName(cn))}, ${ix(d.j)}, ${ix(d.key)}, ${e(d.below)}, ${e(d.body)}, ${ix(d.lo ?? d.j)}, ${d.base ?? 0}⟩`))}
|
|
451
|
-
def ${id}_proof : List CEntry := ${list(entries(proof.certs))}
|
|
452
|
-
theorem ${id}_check : checkCMachine ${
|
|
661
|
+
${withAux ? 'noncomputable ' : ''}def ${id}_proof : List ${withAux ? 'CEntryF' : 'CEntry'} := ${list(entries(proof.certs))}
|
|
662
|
+
theorem ${id}_check : ${withAux ? 'checkCMachineF' : 'checkCMachine'} ${checked} ${id}_decls ${id}_proof = true := by ${checkBy}
|
|
453
663
|
/-- ${laws.map(l => l.name).join('; ')}: each holds in every reachable state, each count map read as the state's count. -/
|
|
454
664
|
theorem ${id}_laws : ∀ ρ M, CReach ${id}_machine ${id}_decls ρ M → ∀ ce ∈ ${id}_proof, ce.e.Holds ρ (withCnt ${id}_decls ρ M) :=
|
|
455
|
-
cmachine_sound ${id}_machine ${id}_decls ${id}_proof ${id}_check${tampers.map(t => `
|
|
665
|
+
${renames.length ? `QAlpha.${withAux ? 'cmachineF_sound' : 'cmachine_sound'} ${id}_machine ${id}_renames ${id}_decls ${id}_proof (by ${checkBy}) ${id}_check` : `${withAux ? 'cmachineF_sound' : 'cmachine_sound'} ${id}_machine ${id}_decls ${id}_proof ${id}_check`}${tampers.map(t => `
|
|
456
666
|
-- TAMPERED: ${t.what}. Lean computes the check to false, as kernel.ts refuses it.
|
|
457
|
-
example : checkCMachine ${
|
|
667
|
+
example : ${withAux ? 'checkCMachineF' : 'checkCMachine'} ${checked} ${id}_decls ${list(entries(t.certs))} = false := by ${checkBy}`).join('')}`;
|
|
458
668
|
}
|
|
459
669
|
// Whole machines through Kern.machine_sound: Lean builds the goals from the machine; the trees are the kernel's.
|
|
460
670
|
export function machineToLean(id, m, laws, corollary) {
|
|
@@ -683,7 +893,7 @@ function sharedTerms(vars, where, plainE) {
|
|
|
683
893
|
case '=': return `.eq (${e(t.a)}) (${e(t.b)})`;
|
|
684
894
|
case 'not': return `.not (${c(t.x)})`;
|
|
685
895
|
case 'and':
|
|
686
|
-
case 'or': return t.
|
|
896
|
+
case 'or': return leanConnective(t.op, t.xs.map(c));
|
|
687
897
|
case 'flag':
|
|
688
898
|
case 'all': return plainC(t);
|
|
689
899
|
}
|
|
@@ -850,10 +1060,15 @@ export function readable(id, laws, vars, maps, reach) {
|
|
|
850
1060
|
throw new Error(`${id}: no variable for ${name}`); return i; };
|
|
851
1061
|
const ws = ex.vars.map((_, i) => `w${i + 1}`), at = (env, vals) => `updAll ${env} [${ex.vars.map((n, i) => `(${ix(n)}, ${vals[i]})`).join(', ')}]`;
|
|
852
1062
|
const P = `(${lit(ex.body)})`, key = law.forall ? ix(law.forall) : undefined;
|
|
853
|
-
|
|
854
|
-
|
|
1063
|
+
// A retained family may carry ex.ghost metadata without exporting the
|
|
1064
|
+
// original/ghosted pair. In that case its theorem is about this machine:
|
|
1065
|
+
// choose its current witness values, not a nonexistent _ghosted.orig.
|
|
1066
|
+
const throughGhosts = ex.ghost && reach.ghosts;
|
|
1067
|
+
const sub = ex.sub ?? (ex.ghost && !throughGhosts ? Object.fromEntries(ex.vars.map(n => [n, { op: 'var', name: n }])) : undefined);
|
|
1068
|
+
const sigma = sub ? `[${ex.vars.map(n => `(${ix(n)}, ${eLit(sub[n])})`).join(', ')}]` : '';
|
|
1069
|
+
const machine = throughGhosts ? `${id}_ghosted.orig` : `${id}_machine`;
|
|
855
1070
|
const head = `theorem some${j} : ∀ ρ μ, SReach ${machine} ρ μ → ${key !== undefined ? '∀ k : Nat, ' : ''}∃ ${ws.join(' ')} : Nat, evalC (${at(key !== undefined ? `(upd ρ ${key} k)` : 'ρ', ws)}) μ ${P} = true`;
|
|
856
|
-
const proof =
|
|
1071
|
+
const proof = throughGhosts
|
|
857
1072
|
? ` intro ρ μ h
|
|
858
1073
|
obtain ⟨ρg, hg⟩ := some_of_ghost ${id}_ghosted ${id}_ghostOk [${ex.vars.map(ix).join(', ')}] ${P} (by ${checkBy}) (fun ρ μ h => by
|
|
859
1074
|
${haveOf(j)}
|
|
@@ -868,7 +1083,7 @@ export function readable(id, laws, vars, maps, reach) {
|
|
|
868
1083
|
theorem law${j} ${reach.binders} (h : SReach ${machine} ρ μ) : ${statement(law)} := by
|
|
869
1084
|
${key !== undefined ? 'intro k\n ' : ''}obtain ⟨${ws.join(', ')}, hg⟩ := some${j} ρ μ h${key !== undefined ? ' k' : ''}
|
|
870
1085
|
exact ⟨${ws.join(', ')}, (evalC_iff (${at(key !== undefined ? `(upd ρ ${key} k)` : 'ρ', ws)}) μ ${P}).mp hg⟩`;
|
|
871
|
-
return `-- ${law.name}: there exists, proven ${
|
|
1086
|
+
return `-- ${law.name}: there exists, proven ${throughGhosts ? 'through ghosts the machine carries' : ex.ghost ? 'with current-machine witness values' : 'with its witness terms in place'}
|
|
872
1087
|
${head} := by
|
|
873
1088
|
${proof}
|
|
874
1089
|
${plain}`;
|
|
@@ -987,7 +1202,10 @@ ${laws.map((law, j) => {
|
|
|
987
1202
|
return someOf(law, j);
|
|
988
1203
|
if (JSON.stringify(law.holds).includes('"op":"if"'))
|
|
989
1204
|
return `-- ${law.name}: its terms read an if, so no plain statement here (${id}_laws holds it)`;
|
|
990
|
-
const hyps = arithBinders(law), names = arithIn(law).map(hypName)
|
|
1205
|
+
const hyps = arithBinders(law), names = arithIn(law).map(hypName);
|
|
1206
|
+
// Proof terms retain neutral Boolean children; surface statements omit them.
|
|
1207
|
+
const surfaceProof = `by simpa [${id}_l${j}, holdsC, evalE, upd] using hl'`;
|
|
1208
|
+
const rw = names.length ? `have hμ : ${statement(law, false)} := ${surfaceProof}\n rw [${names.join(', ')}] at hμ\n exact hμ` : `exact ${surfaceProof}`;
|
|
991
1209
|
const own = law.keys?.length ? `${reach.have ? reach.have(j) : `have hl : ${id}_e${j}.Holds ρ μ := ${reach.call} ${id}_e${j} (by simp [${id}_proof])`}
|
|
992
1210
|
have hl' := fun k ${law.keys.map((_, i) => `k${i + 2}`).join(' ')} => (evalC_iff (upd (${law.keys.reduce((acc, key, i) => `upd (${acc}) ${vars.indexOf(key)} k${i + 2}`, 'ρ')}) ${vars.indexOf(law.forall)} k) μ ${id}_l${j}.holds).mp (hl ${law.keys.map((_, i) => `k${i + 2}`).join(' ')} k)
|
|
993
1211
|
${rw}` : `${reach.have ? reach.have(j) : `have hl : ${id}_l${j}.Holds ρ μ := ${reach.call} ${id}_e${j} (by simp [${id}_proof])`}
|
|
@@ -1609,7 +1827,7 @@ def ${id}_proof : List SEntry := ${list(laws.map((_, j) => `${id}_e${j}`))}
|
|
|
1609
1827
|
theorem ${id}_check : checkSMachine ${id}_machine ${id}_proof = true := by ${checkBy}
|
|
1610
1828
|
theorem ${id}_laws : ∀ ρ M, SReach ${id}_machine ρ M → ∀ e ∈ ${id}_proof, e.Holds ρ M :=
|
|
1611
1829
|
smachine_sound ${id}_machine ${id}_proof ${id}_check
|
|
1612
|
-
${hm ? histBlock() : readable(id, laws, vars, mapNames, { binders: '(ρ : Nat → Nat) (μ : Nat → Nat → Nat)', hyp: `SReach ${id}_machine ρ μ`, call: `${id}_laws ρ μ h`, lit: c, eLit: e })}${sm ? sumsBlock() : ''}${opts.noFacts ? '' : factsProof(id, m, mapNames, vars, opts.simp)}${opts.tamper ? `
|
|
1830
|
+
${hm ? histBlock() : readable(id, laws, vars, mapNames, { binders: '(ρ : Nat → Nat) (μ : Nat → Nat → Nat)', hyp: `SReach ${id}_machine ρ μ`, call: `${id}_laws ρ μ h`, lit: c, eLit: e, ghosts: !rf && !gm && gv.length > 0 })}${sm ? sumsBlock() : ''}${opts.noFacts ? '' : factsProof(id, m, mapNames, vars, opts.simp)}${opts.tamper ? `
|
|
1613
1831
|
-- TAMPERED: ${opts.tamper.what}. Lean computes the check to false.
|
|
1614
1832
|
def ${id}_tampered : SMachine := ${lit(opts.tamper.machine)}
|
|
1615
1833
|
example : checkSMachine ${id}_tampered ${id}_proof = false := by ${checkBy}` : ''}${records.length ? `\n\n${records.join('\n\n')}` : ''}${opts.after ? `\n\n${opts.after(ix, mx, lit)}` : ''}`;
|
|
@@ -1929,7 +2147,7 @@ ${cycProofText(id, p, [], vars, maps)}
|
|
|
1929
2147
|
${okLemmas}
|
|
1930
2148
|
${lawBlocks}
|
|
1931
2149
|
${lawsThm}
|
|
1932
|
-
${hm ? histBlock() : readable(id, laws, vars, maps, { binders: '(ρ : Nat → Nat) (μ : Nat → Nat → Nat)', hyp: `SReach ${id}_machine ρ μ`, call: '', lit: c, eLit: e,
|
|
2150
|
+
${hm ? histBlock() : readable(id, laws, vars, maps, { binders: '(ρ : Nat → Nat) (μ : Nat → Nat → Nat)', hyp: `SReach ${id}_machine ρ μ`, call: '', lit: c, eLit: e, ghosts: !rf && gv.length > 0,
|
|
1933
2151
|
have: j => `have hl : holdsOver ${id}_l${j} μ ${keys2(laws[j])} ρ := cyc_machine_holds (${id}_law${j}_holds ρ μ h)` })}${opts.noFacts ? '' : factsProof(id, m, maps, vars, opts.simp)}${records.length ? `\n\n${records.join('\n\n')}` : ''}${opts.after ? `\n\n${opts.after(ix)}` : ''}` };
|
|
1934
2152
|
}
|
|
1935
2153
|
// A fold from its cyclic proof (Bridge.lean's cyc_fold_sound): the fold numbered as foldToLean numbers it, each law's
|
|
@@ -2268,7 +2486,19 @@ function toLeanWith(items, opts) {
|
|
|
2268
2486
|
}).join('');
|
|
2269
2487
|
for (let item of items) {
|
|
2270
2488
|
const id = ident(item.id), tItem = performance.now();
|
|
2271
|
-
if ('
|
|
2489
|
+
if ('countedGoal' in item) {
|
|
2490
|
+
if (!checkCounted(item.countedGoal, item.certificate))
|
|
2491
|
+
throw new Error(`${item.id}: counted certificate does not check`);
|
|
2492
|
+
parts.push(countedToLean(id, item.countedGoal, item.certificate));
|
|
2493
|
+
theorems.push(id);
|
|
2494
|
+
}
|
|
2495
|
+
else if ('countedMachine' in item) {
|
|
2496
|
+
if (!checkCountedLaws(item.countedMachine, item.laws, item.proof))
|
|
2497
|
+
throw new Error(`${item.id}: counted machine certificate does not check`);
|
|
2498
|
+
parts.push(cmachineToLean(id, item.countedMachine, item.laws, item.proof));
|
|
2499
|
+
theorems.push(`${id}_laws`);
|
|
2500
|
+
}
|
|
2501
|
+
else if ('machine' in item) {
|
|
2272
2502
|
// Laws with "there exists" go in as the kernel proved them (core/exists.ts): the machine with the ghosts their
|
|
2273
2503
|
// witnesses are, each law with its witness terms in place or over its ghosts, each stated again as ∃ (readable).
|
|
2274
2504
|
if (item.laws.some(l => l.some?.length)) {
|
|
@@ -2377,7 +2607,7 @@ function toLeanWith(items, opts) {
|
|
|
2377
2607
|
}
|
|
2378
2608
|
// The file the items need: Live.lean for a liveness or a loop, Sets.lean (which imports Steps.lean) for any machine.
|
|
2379
2609
|
return `import History
|
|
2380
|
-
${items.some(item => 'machine' in item && item.machine.sums && Object.keys(item.machine.sums).length) ? 'import Sums\n' : ''}${items.some(item => 'neverEnds' in item) ? 'import NonTerm\n' : ''}${items.some(item => 'kInduction' in item) ? 'import KInd\n' : ''}${cycTexts ? 'import BridgeRules\n' : ''}${items.some(item => 'cyclic' in item) ? (items.some(item => 'cyclic' in item && (item.bridge || item.recur || item.fold)) ? 'import Bridge\n' : 'import Cyclic\n') : ''}${items.some(item => 'cyclic' in item && item.data) ? 'import Data\n' : ''}import ${items.some(item => 'refinement' in item) ? 'Refine' : items.some(item => 'machine' in item && (item.ghosts?.length || item.laws.some(l => l.some?.length))) ? 'Ghost' : items.some(item => ('machine' in item && item.liveness?.length) || 'loop' in item) ? 'Live' : items.some(item => 'machine' in item) ? 'Sets' : 'Steps'}
|
|
2610
|
+
${items.some(item => 'countedGoal' in item || 'countedMachine' in item) ? 'import QAlpha\n' : ''}${items.some(item => 'machine' in item && item.machine.sums && Object.keys(item.machine.sums).length) ? 'import Sums\n' : ''}${items.some(item => 'neverEnds' in item) ? 'import NonTerm\n' : ''}${items.some(item => 'kInduction' in item) ? 'import KInd\n' : ''}${cycTexts ? 'import BridgeRules\n' : ''}${items.some(item => 'cyclic' in item) ? (items.some(item => 'cyclic' in item && (item.bridge || item.recur || item.fold)) ? 'import Bridge\n' : 'import Cyclic\n') : ''}${items.some(item => 'cyclic' in item && item.data) ? 'import Data\n' : ''}import ${items.some(item => 'refinement' in item) ? 'Refine' : items.some(item => 'machine' in item && (item.ghosts?.length || item.laws.some(l => l.some?.length))) ? 'Ghost' : items.some(item => ('machine' in item && item.liveness?.length) || 'loop' in item) ? 'Live' : items.some(item => 'machine' in item) ? 'Sets' : 'Steps'}
|
|
2381
2611
|
open Kern Cert
|
|
2382
2612
|
set_option maxRecDepth 100000
|
|
2383
2613
|
set_option maxHeartbeats 0
|
|
@@ -2395,9 +2625,13 @@ export { rationalsToLean } from "./qlean.js";
|
|
|
2395
2625
|
// A Lake project that builds the twin and the file: `lake build` in its folder checks every proof.
|
|
2396
2626
|
export function leanProject(file, opts = {}) {
|
|
2397
2627
|
const name = opts.name ?? 'Proofs';
|
|
2398
|
-
|
|
2628
|
+
// Only generated cut-family declarations need the new family library. Merely
|
|
2629
|
+
// mentioning CEntryF in a comment or identifier must not change a cut-free project.
|
|
2630
|
+
const cutFamily = /^(?:noncomputable )?def [^\s:]+ : List CEntryF :=/m.test(file);
|
|
2631
|
+
const library = cutFamily ? leanLibrary : { ...leanLibrary, ...legacyFamilyLibrary };
|
|
2632
|
+
const modules = [...Object.keys(library).map(f => f.replace(/\.lean$/, '')), name];
|
|
2399
2633
|
return {
|
|
2400
|
-
...
|
|
2634
|
+
...library,
|
|
2401
2635
|
[`${name}.lean`]: file,
|
|
2402
2636
|
'lean-toolchain': 'leanprover/lean4:v4.34.0\n',
|
|
2403
2637
|
'lakefile.lean': `import Lake
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type C, type E } from '../core/machine.js';
|
|
2
2
|
export declare const exactNat: (x: number) => string;
|
|
3
|
+
export declare function leanConnective(op: 'and' | 'or', xs: readonly string[]): string;
|
|
3
4
|
export declare function leanTerms(vars: readonly string[], maps: readonly string[], where: string): {
|
|
4
5
|
e: (t: E) => string;
|
|
5
6
|
c: (t: C) => string;
|
|
@@ -7,6 +7,18 @@ import { unreachable } from "../core/machine.js";
|
|
|
7
7
|
// decimal that reads back to it, 10^18 + 128 as 1000000000000000100: Lean would read another number than the kernel and
|
|
8
8
|
// the runtimes do. terra's review of gen/laneQ.)
|
|
9
9
|
export const exactNat = (x) => (Number.isSafeInteger(x) ? String(x) : BigInt(x).toString());
|
|
10
|
+
// Keep a singleton's connective: TS facts can close a contradicted disjunction (or a
|
|
11
|
+
// negated conjunction) directly. Erasing its wrapper preserves truth but loses that row.
|
|
12
|
+
// A neutral binary child preserves both truth and that path-sensitive extraction.
|
|
13
|
+
// Semantic/retained-tree checks: research/verify-all/export-shape.lean.
|
|
14
|
+
export function leanConnective(op, xs) {
|
|
15
|
+
const neutral = op === 'and' ? '.le (.const 0) (.const 0)' : '.lt (.const 0) (.const 0)';
|
|
16
|
+
if (!xs.length)
|
|
17
|
+
return neutral;
|
|
18
|
+
if (xs.length === 1)
|
|
19
|
+
return `.${op} (${xs[0]}) (${neutral})`;
|
|
20
|
+
return xs.reduceRight((acc, y) => `.${op} (${y}) (${acc})`);
|
|
21
|
+
}
|
|
10
22
|
export function leanTerms(vars, maps, where) {
|
|
11
23
|
const ix = (name) => { const j = vars.indexOf(name); if (j < 0)
|
|
12
24
|
throw new Error(`${where}: no variable for ${name}`); return j; };
|
|
@@ -36,11 +48,7 @@ export function leanTerms(vars, maps, where) {
|
|
|
36
48
|
case '=': return `.eq (${e(t.a)}) (${e(t.b)})`;
|
|
37
49
|
case 'not': return `.not (${c(t.x)})`;
|
|
38
50
|
case 'and':
|
|
39
|
-
case 'or':
|
|
40
|
-
if (t.xs.length === 0)
|
|
41
|
-
return t.op === 'and' ? '.le (.const 0) (.const 0)' : '.lt (.const 0) (.const 0)';
|
|
42
|
-
return t.xs.map(c).reduceRight((acc, y) => `.${t.op} (${y}) (${acc})`);
|
|
43
|
-
}
|
|
51
|
+
case 'or': return leanConnective(t.op, t.xs.map(c));
|
|
44
52
|
case 'flag': return `.eq (.var ${ix(`?${t.name}`)}) (.const 1)`;
|
|
45
53
|
case 'all': throw new Error(`${where}: a quantified flag goes to Lean as a flag of its own, not a condition`);
|
|
46
54
|
default: return unreachable(t);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const legacyFamilyLibrary: Readonly<Record<string, string>>;
|