tla-ts 0.0.4-dev.0be9567 → 0.0.4-dev.22c041b
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 +77 -122
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/deciders.cjs +366 -0
- package/dist/deciders.js +366 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +44 -12
- package/dist/index.d.ts +44 -12
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -4
- package/dist/parallel-worker.js +1 -4
- package/dist/prove-worker.cjs +9 -0
- package/dist/prove-worker.d.cts +9 -0
- package/dist/prove-worker.d.ts +9 -0
- package/dist/prove-worker.js +9 -0
- package/dist/prove.cjs +1006 -0
- package/dist/prove.js +1006 -0
- package/dist/run.cjs +45 -0
- package/dist/run.js +45 -0
- package/dist/tlapm.cjs +10 -0
- package/dist/tlapm.js +10 -0
- package/dist/transfer.cjs +76 -92
- package/dist/transfer.js +76 -92
- package/dist/worker.cjs +21 -0
- package/dist/worker.js +21 -0
- package/package.json +21 -12
- package/src/ast.ts +2 -2
- package/src/bags.ts +22 -23
- package/src/builtins.ts +16 -8
- package/src/check.ts +131 -1153
- package/src/{cli-options.ts → cli/options.ts} +54 -9
- package/src/cli/run.ts +63 -0
- package/src/cli/shared.ts +106 -0
- package/src/cli/tlapm.ts +374 -0
- package/src/{run-cli.ts → cli/tlc.ts} +115 -721
- package/src/cli/xml-exporter.ts +221 -0
- package/src/cli.ts +1 -1
- package/src/codegen.ts +17 -15
- package/src/config.ts +5 -5
- package/src/dependencies.ts +4 -6
- package/src/environment.ts +55 -60
- package/src/errors.ts +97 -35
- package/src/evaluate.ts +135 -120
- package/src/exit-codes.ts +1 -1
- package/src/fingerprints.ts +3 -3
- package/src/index.ts +10 -0
- package/src/instances.ts +56 -46
- package/src/java-overrides.ts +79 -41
- package/src/json.ts +31 -36
- package/src/levels.ts +10 -13
- package/src/{live-check.ts → liveness-checker.ts} +169 -142
- package/src/liveness.ts +38 -34
- package/src/{obligation-action.ts → obligations/action.ts} +248 -74
- package/src/{obligation-anon.ts → obligations/anonymize.ts} +55 -57
- package/src/obligations/equality.ts +260 -0
- package/src/obligations/expression.ts +618 -0
- package/src/{obligation-format.ts → obligations/format.ts} +7 -8
- package/src/obligations/generate.ts +457 -0
- package/src/{obligations.ts → obligations/index.ts} +46 -32
- package/src/{obligation-levels.ts → obligations/levels.ts} +44 -40
- package/src/obligations/module.ts +445 -0
- package/src/obligations/normalize.ts +554 -0
- package/src/obligations/operators.ts +176 -0
- package/src/obligations/pragma.ts +195 -0
- package/src/{obligation-printer.ts → obligations/printer.ts} +65 -230
- package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
- package/src/obligations/regroup.ts +100 -0
- package/src/{obligation-generate.ts → obligations/simplify.ts} +130 -536
- package/src/{obligation-source.ts → obligations/source.ts} +172 -216
- package/src/{obligation-deref.ts → obligations/subexpression.ts} +84 -115
- package/src/obligations/substitution.ts +261 -0
- package/src/obligations/temporal.ts +321 -0
- package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
- package/src/parallel-worker.ts +39 -51
- package/src/parallel.ts +39 -66
- package/src/parser.ts +67 -74
- package/src/{pcal-ast.ts → pcal/ast.ts} +2 -17
- package/src/{pcal-parse.ts → pcal/parse.ts} +28 -64
- package/src/{pcal-tokenize.ts → pcal/tokenize.ts} +10 -39
- package/src/{pcal-translate.ts → pcal/translate.ts} +30 -109
- package/src/{pcal-validate.ts → pcal/validate.ts} +10 -20
- package/src/prover/decide-pool.ts +95 -0
- package/src/prover/deciders.ts +33 -0
- package/src/prover/first-order.ts +175 -0
- package/src/prover/isabelle/LICENSE +36 -0
- package/src/prover/isabelle/LICENSE-tlapm +26 -0
- package/src/prover/isabelle/decide.ts +44 -0
- package/src/prover/isabelle/encode.ts +445 -0
- package/src/prover/isabelle/isar/inner-syntax.ts +579 -0
- package/src/prover/isabelle/isar/method.ts +367 -0
- package/src/prover/isabelle/isar/proof.ts +28 -0
- package/src/prover/isabelle/isar/statement.ts +57 -0
- package/src/prover/isabelle/isar/theory.ts +192 -0
- package/src/prover/isabelle/isar/type-check.ts +278 -0
- package/src/prover/isabelle/provers/blast/blast.ts +258 -0
- package/src/prover/isabelle/provers/blast/branch.ts +322 -0
- package/src/prover/isabelle/provers/blast/prove.ts +347 -0
- package/src/prover/isabelle/provers/blast/rules.ts +330 -0
- package/src/prover/isabelle/provers/blast/state.ts +180 -0
- package/src/prover/isabelle/provers/blast/term.ts +546 -0
- package/src/prover/isabelle/provers/clasimp.ts +150 -0
- package/src/prover/isabelle/provers/classical.ts +389 -0
- package/src/prover/isabelle/provers/hypsubst.ts +433 -0
- package/src/prover/isabelle/pure/bicompose.ts +174 -0
- package/src/prover/isabelle/pure/consts.ts +32 -0
- package/src/prover/isabelle/pure/conv.ts +79 -0
- package/src/prover/isabelle/pure/drule.ts +264 -0
- package/src/prover/isabelle/pure/envir.ts +331 -0
- package/src/prover/isabelle/pure/goal.ts +53 -0
- package/src/prover/isabelle/pure/interrupt.ts +16 -0
- package/src/prover/isabelle/pure/list.ts +12 -0
- package/src/prover/isabelle/pure/logic.ts +330 -0
- package/src/prover/isabelle/pure/name.ts +98 -0
- package/src/prover/isabelle/pure/net.ts +215 -0
- package/src/prover/isabelle/pure/object-logic.ts +41 -0
- package/src/prover/isabelle/pure/pattern.ts +631 -0
- package/src/prover/isabelle/pure/raw-simplifier.ts +338 -0
- package/src/prover/isabelle/pure/rewriter.ts +602 -0
- package/src/prover/isabelle/pure/search.ts +68 -0
- package/src/prover/isabelle/pure/seq.ts +133 -0
- package/src/prover/isabelle/pure/simplifier.ts +106 -0
- package/src/prover/isabelle/pure/table.ts +201 -0
- package/src/prover/isabelle/pure/tactic.ts +168 -0
- package/src/prover/isabelle/pure/tactical.ts +264 -0
- package/src/prover/isabelle/pure/term-ord.ts +105 -0
- package/src/prover/isabelle/pure/term.ts +688 -0
- package/src/prover/isabelle/pure/thm.ts +783 -0
- package/src/prover/isabelle/pure/type.ts +121 -0
- package/src/prover/isabelle/pure/unify.ts +753 -0
- package/src/prover/isabelle/pure/variable.ts +25 -0
- package/src/prover/isabelle/tla/classical-setup.ts +101 -0
- package/src/prover/isabelle/tla/context.ts +74 -0
- package/src/prover/isabelle/tla/logic-data.ts +5 -0
- package/src/prover/isabelle/tla/logic.ts +215 -0
- package/src/prover/isabelle/tla/simpdata.ts +241 -0
- package/src/prover/isabelle/tools/intuitionistic.ts +132 -0
- package/src/prover/ocaml.ts +22 -0
- package/src/prover/prep/action.ts +508 -0
- package/src/prover/prep/enabled-axioms.ts +189 -0
- package/src/prover/prep/fingerprint.ts +388 -0
- package/src/prover/prep/level-comparison.ts +529 -0
- package/src/prover/prep/md5.ts +60 -0
- package/src/prover/prep/methods.ts +221 -0
- package/src/prover/prep/normalize.ts +309 -0
- package/src/prover/prove-worker.ts +22 -0
- package/src/prover/prove.ts +492 -0
- package/src/prover/ptl/decide.ts +68 -0
- package/src/prover/ptl/encode.ts +244 -0
- package/src/prover/ptl/sat.ts +151 -0
- package/src/prover/ptl/tableau.ts +276 -0
- package/src/prover/smt/axioms.ts +209 -0
- package/src/prover/smt/context.ts +108 -0
- package/src/prover/smt/data.ts +636 -0
- package/src/prover/smt/encode.ts +275 -0
- package/src/prover/smt/extensionality.ts +65 -0
- package/src/prover/smt/flatten.ts +112 -0
- package/src/prover/smt/format.ts +154 -0
- package/src/prover/smt/instances.ts +181 -0
- package/src/prover/smt/rewrite.ts +766 -0
- package/src/prover/smt/solver/act-cache.ts +265 -0
- package/src/prover/smt/solver/arith-rewriter.ts +962 -0
- package/src/prover/smt/solver/array.ts +22 -0
- package/src/prover/smt/solver/asserted-formulas.ts +469 -0
- package/src/prover/smt/solver/ast-lt.ts +157 -0
- package/src/prover/smt/solver/ast-util.ts +91 -0
- package/src/prover/smt/solver/ast.ts +1315 -0
- package/src/prover/smt/solver/auf-solver.ts +572 -0
- package/src/prover/smt/solver/case-split-queue.ts +178 -0
- package/src/prover/smt/solver/cg-table.ts +175 -0
- package/src/prover/smt/solver/clause.ts +276 -0
- package/src/prover/smt/solver/conflict-resolution.ts +343 -0
- package/src/prover/smt/solver/context.ts +1292 -0
- package/src/prover/smt/solver/ctx-simplify.ts +334 -0
- package/src/prover/smt/solver/der.ts +224 -0
- package/src/prover/smt/solver/dyn-ack.ts +141 -0
- package/src/prover/smt/solver/e-matching.ts +659 -0
- package/src/prover/smt/solver/enode.ts +259 -0
- package/src/prover/smt/solver/expr-ref.ts +21 -0
- package/src/prover/smt/solver/expr-safe-replace.ts +172 -0
- package/src/prover/smt/solver/fingerprints.ts +92 -0
- package/src/prover/smt/solver/flat-literals.ts +51 -0
- package/src/prover/smt/solver/goal.ts +138 -0
- package/src/prover/smt/solver/hash.ts +173 -0
- package/src/prover/smt/solver/hashtable.ts +166 -0
- package/src/prover/smt/solver/internalizer.ts +1381 -0
- package/src/prover/smt/solver/lbool.ts +5 -0
- package/src/prover/smt/solver/literal.ts +24 -0
- package/src/prover/smt/solver/lp/bound-propagator.ts +391 -0
- package/src/prover/smt/solver/lp/constraints.ts +78 -0
- package/src/prover/smt/solver/lp/containers.ts +296 -0
- package/src/prover/smt/solver/lp/core-solver.ts +504 -0
- package/src/prover/smt/solver/lp/cross-nested.ts +224 -0
- package/src/prover/smt/solver/lp/dep-intervals.ts +642 -0
- package/src/prover/smt/solver/lp/dependency.ts +51 -0
- package/src/prover/smt/solver/lp/dioph-eq.ts +1181 -0
- package/src/prover/smt/solver/lp/explanation.ts +46 -0
- package/src/prover/smt/solver/lp/gomory.ts +255 -0
- package/src/prover/smt/solver/lp/hnf-cutter.ts +125 -0
- package/src/prover/smt/solver/lp/hnf.ts +281 -0
- package/src/prover/smt/solver/lp/int-cube.ts +295 -0
- package/src/prover/smt/solver/lp/int-solver.ts +514 -0
- package/src/prover/smt/solver/lp/lar-solver.ts +816 -0
- package/src/prover/smt/solver/lp/lar-term.ts +62 -0
- package/src/prover/smt/solver/lp/lp-settings.ts +91 -0
- package/src/prover/smt/solver/lp/maximize-term.ts +347 -0
- package/src/prover/smt/solver/lp/nex-creator.ts +381 -0
- package/src/prover/smt/solver/lp/nex.ts +120 -0
- package/src/prover/smt/solver/lp/nla-backoff.ts +43 -0
- package/src/prover/smt/solver/lp/nla-basics.ts +398 -0
- package/src/prover/smt/solver/lp/nla-core.ts +968 -0
- package/src/prover/smt/solver/lp/nla-divisions.ts +332 -0
- package/src/prover/smt/solver/lp/nla-emonics.ts +373 -0
- package/src/prover/smt/solver/lp/nla-factorization.ts +30 -0
- package/src/prover/smt/solver/lp/nla-grobner.ts +904 -0
- package/src/prover/smt/solver/lp/nla-horner.ts +126 -0
- package/src/prover/smt/solver/lp/nla-intervals.ts +265 -0
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +715 -0
- package/src/prover/smt/solver/lp/nla-monotone.ts +59 -0
- package/src/prover/smt/solver/lp/nla-order.ts +307 -0
- package/src/prover/smt/solver/lp/nla-patcher.ts +112 -0
- package/src/prover/smt/solver/lp/nla-tangents.ts +251 -0
- package/src/prover/smt/solver/lp/nla-throttle.ts +85 -0
- package/src/prover/smt/solver/lp/nla-types.ts +124 -0
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +141 -0
- package/src/prover/smt/solver/lp/nra-solver.ts +440 -0
- package/src/prover/smt/solver/lp/numeric-pair.ts +65 -0
- package/src/prover/smt/solver/lp/pdd-interval.ts +31 -0
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +184 -0
- package/src/prover/smt/solver/lp/pdd-solver.ts +408 -0
- package/src/prover/smt/solver/lp/pdd.ts +971 -0
- package/src/prover/smt/solver/lp/random-updater.ts +138 -0
- package/src/prover/smt/solver/lp/static-matrix.ts +246 -0
- package/src/prover/smt/solver/lp/union-find.ts +96 -0
- package/src/prover/smt/solver/mam-compiler.ts +847 -0
- package/src/prover/smt/solver/mam-interpreter.ts +400 -0
- package/src/prover/smt/solver/maximize-ac-sharing.ts +118 -0
- package/src/prover/smt/solver/model-checker.ts +347 -0
- package/src/prover/smt/solver/model-evaluator.ts +262 -0
- package/src/prover/smt/solver/model-finder.ts +155 -0
- package/src/prover/smt/solver/model-generator.ts +97 -0
- package/src/prover/smt/solver/model-macro-solver.ts +728 -0
- package/src/prover/smt/solver/nlsat/algebraic.ts +1161 -0
- package/src/prover/smt/solver/nlsat/atoms.ts +238 -0
- package/src/prover/smt/solver/nlsat/evaluator.ts +303 -0
- package/src/prover/smt/solver/nlsat/explain.ts +607 -0
- package/src/prover/smt/solver/nlsat/interval-set.ts +351 -0
- package/src/prover/smt/solver/nlsat/levelwise.ts +737 -0
- package/src/prover/smt/solver/nlsat/mpbq.ts +161 -0
- package/src/prover/smt/solver/nlsat/polynomial.ts +1722 -0
- package/src/prover/smt/solver/nlsat/solver.ts +911 -0
- package/src/prover/smt/solver/nlsat/types.ts +43 -0
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
- package/src/prover/smt/solver/nlsat/upolynomial.ts +996 -0
- package/src/prover/smt/solver/nnf.ts +469 -0
- package/src/prover/smt/solver/pattern-inference.ts +351 -0
- package/src/prover/smt/solver/poly-rewriter.ts +477 -0
- package/src/prover/smt/solver/propagate-values.ts +83 -0
- package/src/prover/smt/solver/proto-model.ts +551 -0
- package/src/prover/smt/solver/pull-quant.ts +139 -0
- package/src/prover/smt/solver/qe-lite-der.ts +526 -0
- package/src/prover/smt/solver/qe-lite-fm.ts +576 -0
- package/src/prover/smt/solver/qe-lite.ts +381 -0
- package/src/prover/smt/solver/qi-queue.ts +362 -0
- package/src/prover/smt/solver/quant-tactics.ts +117 -0
- package/src/prover/smt/solver/quantifier-analyzer.ts +562 -0
- package/src/prover/smt/solver/quantifier-manager.ts +186 -0
- package/src/prover/smt/solver/random-gen.ts +10 -0
- package/src/prover/smt/solver/rational.ts +165 -0
- package/src/prover/smt/solver/ref-vector.ts +62 -0
- package/src/prover/smt/solver/relevancy.ts +247 -0
- package/src/prover/smt/solver/rewriter-tpl.ts +1159 -0
- package/src/prover/smt/solver/rewriter.ts +843 -0
- package/src/prover/smt/solver/rlimit.ts +79 -0
- package/src/prover/smt/solver/smtlib-parser.ts +526 -0
- package/src/prover/smt/solver/solver.ts +71 -0
- package/src/prover/smt/solver/sort.ts +35 -0
- package/src/prover/smt/solver/sticky-generations.ts +69 -0
- package/src/prover/smt/solver/theory-lra-axioms.ts +340 -0
- package/src/prover/smt/solver/theory-lra-bounds.ts +226 -0
- package/src/prover/smt/solver/theory-lra-final-check.ts +252 -0
- package/src/prover/smt/solver/theory-lra-internalize.ts +476 -0
- package/src/prover/smt/solver/theory-lra-model.ts +243 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +405 -0
- package/src/prover/smt/solver/theory-lra-state.ts +43 -0
- package/src/prover/smt/solver/theory-lra.ts +56 -0
- package/src/prover/smt/solver/var-subst.ts +258 -0
- package/src/prover/smt/solver/z3-license.txt +10 -0
- package/src/prover/smt/table.ts +170 -0
- package/src/prover/tlapm/cache.ts +236 -0
- package/src/prover/tlapm/ocaml-marshal.ts +166 -0
- package/src/prover/tlapm/tlapm.ts +96 -0
- package/src/prover/tlaps-module.ts +510 -0
- package/src/prover/verdict.ts +13 -0
- package/src/prover/zenon/LICENSE +32 -0
- package/src/prover/zenon/check/check.ts +105 -0
- package/src/prover/zenon/check/definitions.ts +144 -0
- package/src/prover/zenon/check/equality.ts +182 -0
- package/src/prover/zenon/check/functions.ts +62 -0
- package/src/prover/zenon/check/keys.ts +125 -0
- package/src/prover/zenon/check/propositional.ts +104 -0
- package/src/prover/zenon/check/records.ts +188 -0
- package/src/prover/zenon/check/relations.ts +121 -0
- package/src/prover/zenon/check/rewrites.ts +224 -0
- package/src/prover/zenon/check/sets.ts +302 -0
- package/src/prover/zenon/check/terms.ts +127 -0
- package/src/prover/zenon/check/tla.ts +126 -0
- package/src/prover/zenon/decide.ts +107 -0
- package/src/prover/zenon/encode.ts +378 -0
- package/src/prover/zenon/eqrel.ts +300 -0
- package/src/prover/zenon/equality-rules.ts +435 -0
- package/src/prover/zenon/expr.ts +551 -0
- package/src/prover/zenon/index-table.ts +350 -0
- package/src/prover/zenon/isar-case.ts +513 -0
- package/src/prover/zenon/isar.ts +1249 -0
- package/src/prover/zenon/limits.ts +15 -0
- package/src/prover/zenon/llproof.ts +173 -0
- package/src/prover/zenon/mltoll.ts +1566 -0
- package/src/prover/zenon/node.ts +297 -0
- package/src/prover/zenon/ocaml.ts +169 -0
- package/src/prover/zenon/parse.ts +247 -0
- package/src/prover/zenon/phrase.ts +191 -0
- package/src/prover/zenon/proof.ts +198 -0
- package/src/prover/zenon/propositional-rules.ts +387 -0
- package/src/prover/zenon/rules.ts +94 -0
- package/src/prover/zenon/search.ts +288 -0
- package/src/prover/zenon/tla/functions.ts +151 -0
- package/src/prover/zenon/tla/llproof.ts +480 -0
- package/src/prover/zenon/tla/records.ts +225 -0
- package/src/prover/zenon/tla/rewrites.ts +447 -0
- package/src/prover/zenon/tla/sets.ts +304 -0
- package/src/prover/zenon/tla/terms.ts +162 -0
- package/src/prover/zenon/tla/tla.ts +506 -0
- package/src/randomization.ts +19 -24
- package/src/resolve.ts +15 -22
- package/src/runtime.ts +8 -8
- package/src/{sany-builtins.ts → sany/builtins.ts} +1 -1
- package/src/{sany-generator.ts → sany/generator.ts} +38 -55
- package/src/{sany-levels.ts → sany/levels.ts} +45 -48
- package/src/{sany-lexer.ts → sany/lexer.ts} +2 -3
- package/src/{sany-linter.ts → sany/linter.ts} +1 -1
- package/src/{sany-modules.ts → sany/modules.ts} +2 -2
- package/src/{sany-nodes.ts → sany/nodes.ts} +2 -2
- package/src/{sany-parse-error.ts → sany/parse-error.ts} +2 -2
- package/src/{sany-report.ts → sany/report.ts} +16 -17
- package/src/{sany-selectors.ts → sany/selectors.ts} +3 -5
- package/src/{sany-source.ts → sany/source.ts} +6 -7
- package/src/{sany-xml.ts → sany/xml.ts} +5 -6
- package/src/search.ts +969 -0
- package/src/spec-description.ts +26 -20
- package/src/{standard-levels.ts → standard-definitions.ts} +118 -2
- package/src/standard-modules.ts +16 -20
- package/src/state-graph.ts +9 -8
- package/src/substitution-levels.ts +2 -2
- package/src/successors.ts +38 -22
- package/src/symmetry.ts +1 -1
- package/src/tableau.ts +6 -7
- package/src/tlc/fingerprint.ts +214 -0
- package/src/{tlc-messages.ts → tlc/messages.ts} +119 -7
- package/src/{tlc-order.ts → tlc/order.ts} +7 -7
- package/src/{tlc-random.ts → tlc/random.ts} +3 -190
- package/src/{tlc-replay.ts → tlc/replay.ts} +40 -36
- package/src/{tlc-module.ts → tlc/tlc-operators.ts} +9 -9
- package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +30 -25
- package/src/{tlc-version.ts → tlc/version.ts} +8 -7
- package/src/transfer.ts +32 -32
- package/src/values.ts +119 -71
- package/src/worker.ts +62 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
- package/dist/run-cli.cjs +0 -55
- package/dist/run-cli.js +0 -55
- package/src/canonical.ts +0 -40
- package/src/obligation-expression.ts +0 -1060
- package/src/obligation-module.ts +0 -1042
- package/src/standard-ranges.ts +0 -116
- package/src/value-sources.ts +0 -29
- /package/src/{tlc-modules.ts → tlc/jar-data.ts} +0 -0
- /package/src/{tlc-summary.ts → tlc/summary.ts} +0 -0
|
@@ -0,0 +1,1566 @@
|
|
|
1
|
+
// Ported from Zenon's mltoll.ml, as shipped in tlapm. Copyright 2004 INRIA, see LICENSE.
|
|
2
|
+
//
|
|
3
|
+
// Translates the proof that the search finds into a low-level proof: the derived rules expand into
|
|
4
|
+
// core rules, and each proof that the search reused becomes a lemma.
|
|
5
|
+
|
|
6
|
+
import { TlaZenonError } from "../../errors";
|
|
7
|
+
import type { Direction, Origin, Relations } from "./eqrel";
|
|
8
|
+
import {
|
|
9
|
+
difference,
|
|
10
|
+
union,
|
|
11
|
+
type BinderExpr,
|
|
12
|
+
type Expr,
|
|
13
|
+
type Expressions,
|
|
14
|
+
type VarExpr,
|
|
15
|
+
} from "./expr";
|
|
16
|
+
import { connect, type Connective, type Lemma, type LlProof, type LlRule } from "./llproof";
|
|
17
|
+
import type { Definition, Phrase } from "./parse";
|
|
18
|
+
import type { Rule } from "./proof";
|
|
19
|
+
import { getTlaLlProof } from "./tla/llproof";
|
|
20
|
+
|
|
21
|
+
// The search's proofs, and the rule that only the translation builds.
|
|
22
|
+
export type MlRule = Rule | { name: "notall" | "notallex"; args: [Expr] };
|
|
23
|
+
|
|
24
|
+
export interface MlProof {
|
|
25
|
+
conclusions: Expr[];
|
|
26
|
+
rule: MlRule;
|
|
27
|
+
subproofs: MlProof[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// A translated proof, with the hypotheses it uses that aren't conclusions of the node.
|
|
31
|
+
export type Translated = [LlProof, Expr[]];
|
|
32
|
+
|
|
33
|
+
interface TranslateContext {
|
|
34
|
+
exprs: Expressions;
|
|
35
|
+
// Zenon's Index.get_number, which also names the formulas in the Isar output.
|
|
36
|
+
getNumber: (expression: Expr) => number;
|
|
37
|
+
// The proofs that the search reused, which Zenon counts in mlrefc.
|
|
38
|
+
sharedProofs: ReadonlySet<MlProof>;
|
|
39
|
+
relations: Relations;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type RelationProperty = "reflexive" | "symmetric" | "transitive";
|
|
43
|
+
|
|
44
|
+
// Zenon's Eqrel.hyp_kind: how to prove a hypothesis about a relation. A relation is also
|
|
45
|
+
// symmetric or transitive when it's reflexive and transitive in the symmetric sense.
|
|
46
|
+
type HypothesisKind =
|
|
47
|
+
| { kind: "reflexive"; origin: Origin }
|
|
48
|
+
| { kind: "symmetric"; origin: Origin }
|
|
49
|
+
| { kind: "transitive"; origin: Origin }
|
|
50
|
+
| {
|
|
51
|
+
kind: "symmetric2" | "transitive2";
|
|
52
|
+
relation: string;
|
|
53
|
+
reflexive: Origin;
|
|
54
|
+
transitiveSymmetric: Origin;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const LEMMA_PREFIX = "zenon_L";
|
|
58
|
+
const META_PREFIX = "zenon_X";
|
|
59
|
+
|
|
60
|
+
export const isMetaName = (name: string) => name.startsWith(META_PREFIX);
|
|
61
|
+
|
|
62
|
+
const isAlphanumeric = (char: string) => /^[A-Za-z0-9]$/.test(char);
|
|
63
|
+
|
|
64
|
+
// Zenon's type_to_ident.
|
|
65
|
+
const toIdentifier = (type: string) =>
|
|
66
|
+
[...type]
|
|
67
|
+
.map((char) =>
|
|
68
|
+
isAlphanumeric(char) ? char : `_${char.charCodeAt(0).toString(16).padStart(2, "0")}`,
|
|
69
|
+
)
|
|
70
|
+
.join("");
|
|
71
|
+
|
|
72
|
+
const getBinder = (expression: Expr, kind: BinderExpr["kind"]) => {
|
|
73
|
+
if (expression.kind !== kind) throw new TlaZenonError(`Zenon: expected a ${kind} binder`);
|
|
74
|
+
return expression;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const getSingle = (proof: MlProof) => {
|
|
78
|
+
if (proof.subproofs.length !== 1) throw new TlaZenonError("Zenon: expected one subproof");
|
|
79
|
+
return proof.subproofs[0];
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// Zenon's Mlproof.make_node: the node's conclusions and those its subproofs leave open.
|
|
83
|
+
const makeNode = (
|
|
84
|
+
conclusions: Expr[],
|
|
85
|
+
rule: MlRule,
|
|
86
|
+
branches: Expr[][],
|
|
87
|
+
subproofs: MlProof[],
|
|
88
|
+
): MlProof => ({
|
|
89
|
+
conclusions: union(
|
|
90
|
+
conclusions,
|
|
91
|
+
subproofs
|
|
92
|
+
.map((subproof, position) => difference(subproof.conclusions, branches[position]))
|
|
93
|
+
.reduce((accumulated, extra) => union(accumulated, extra), []),
|
|
94
|
+
),
|
|
95
|
+
rule,
|
|
96
|
+
subproofs,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const isDerived = (rule: MlRule) => {
|
|
100
|
+
switch (rule.name) {
|
|
101
|
+
case "close_refl":
|
|
102
|
+
case "close_sym":
|
|
103
|
+
return rule.relation !== "=";
|
|
104
|
+
case "definition":
|
|
105
|
+
return rule.definition.kind !== "real";
|
|
106
|
+
case "conj_tree":
|
|
107
|
+
case "disj_tree":
|
|
108
|
+
case "not_all_ex":
|
|
109
|
+
case "refl":
|
|
110
|
+
case "p_not_p_sym":
|
|
111
|
+
case "trans":
|
|
112
|
+
case "trans_sym":
|
|
113
|
+
case "trans_eq":
|
|
114
|
+
case "trans_eq2":
|
|
115
|
+
case "trans_eq_sym":
|
|
116
|
+
return true;
|
|
117
|
+
default:
|
|
118
|
+
return !CORE_RULES.has(rule.name);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// The rules that tr_rule translates directly: the core rules and the extension rules named "".
|
|
123
|
+
const CORE_RULES = new Set<string>([
|
|
124
|
+
"close",
|
|
125
|
+
"false",
|
|
126
|
+
"not_true",
|
|
127
|
+
"not_not",
|
|
128
|
+
"and",
|
|
129
|
+
"not_or",
|
|
130
|
+
"not_impl",
|
|
131
|
+
"ex",
|
|
132
|
+
"all",
|
|
133
|
+
"not_ex",
|
|
134
|
+
"or",
|
|
135
|
+
"impl",
|
|
136
|
+
"not_and",
|
|
137
|
+
"equiv",
|
|
138
|
+
"not_equiv",
|
|
139
|
+
"p_not_p",
|
|
140
|
+
"not_equal",
|
|
141
|
+
"cut",
|
|
142
|
+
"congruence_lr",
|
|
143
|
+
"congruence_rl",
|
|
144
|
+
"notall",
|
|
145
|
+
"notallex",
|
|
146
|
+
"stringequal",
|
|
147
|
+
"stringdiffll",
|
|
148
|
+
"stringdifflr",
|
|
149
|
+
"stringdiffrl",
|
|
150
|
+
"stringdiffrr",
|
|
151
|
+
]);
|
|
152
|
+
|
|
153
|
+
// Zenon's Mltoll.translate: the lemmas in the order they were made, then the theorem.
|
|
154
|
+
export const translateProof = (
|
|
155
|
+
context: TranslateContext,
|
|
156
|
+
phrases: Phrase[],
|
|
157
|
+
proof: MlProof,
|
|
158
|
+
): Lemma[] => {
|
|
159
|
+
const exprs = context.exprs;
|
|
160
|
+
const translatedExprs = new Map<Expr, Expr>();
|
|
161
|
+
const lemmaNumbers = new Map<MlProof, number>();
|
|
162
|
+
const lemmaTable = new Map<string, [Lemma, Expr[]]>();
|
|
163
|
+
const lemmas: Lemma[] = [];
|
|
164
|
+
const getLemmaName = (number: number) => `${LEMMA_PREFIX}${number}_`;
|
|
165
|
+
|
|
166
|
+
const equal = (left: Expr, right: Expr) => exprs.eapp("=", [left, right]);
|
|
167
|
+
|
|
168
|
+
// Zenon's tr_expr: metavariables become variables named after their quantifier.
|
|
169
|
+
const translateExpr = (expression: Expr): Expr => {
|
|
170
|
+
if (expression.metas.length === 0) return expression;
|
|
171
|
+
const cached = translatedExprs.get(expression);
|
|
172
|
+
if (cached !== undefined) return cached;
|
|
173
|
+
const result = ((): Expr => {
|
|
174
|
+
switch (expression.kind) {
|
|
175
|
+
case "meta": {
|
|
176
|
+
const quantified = expression.args[0];
|
|
177
|
+
if (quantified.kind !== "all" && quantified.kind !== "ex")
|
|
178
|
+
throw new TlaZenonError("Zenon: a metavariable without a quantifier");
|
|
179
|
+
return exprs.evar(
|
|
180
|
+
`${META_PREFIX}${context.getNumber(quantified)}_${toIdentifier(quantified.symbol)}`,
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
case "app":
|
|
184
|
+
return exprs.eapp(expression.symbol, expression.args.map(translateExpr));
|
|
185
|
+
case "not":
|
|
186
|
+
return exprs.enot(translateExpr(expression.args[0]));
|
|
187
|
+
case "and":
|
|
188
|
+
case "or":
|
|
189
|
+
case "imply":
|
|
190
|
+
case "equiv": {
|
|
191
|
+
const right = translateExpr(expression.args[1]);
|
|
192
|
+
return connect(exprs, expression.kind, translateExpr(expression.args[0]), right);
|
|
193
|
+
}
|
|
194
|
+
case "all":
|
|
195
|
+
case "ex":
|
|
196
|
+
case "tau":
|
|
197
|
+
case "lam":
|
|
198
|
+
return makeBinder(
|
|
199
|
+
expression.kind,
|
|
200
|
+
expression.args[0],
|
|
201
|
+
expression.symbol,
|
|
202
|
+
translateExpr(expression.args[1]),
|
|
203
|
+
);
|
|
204
|
+
default:
|
|
205
|
+
return expression;
|
|
206
|
+
}
|
|
207
|
+
})();
|
|
208
|
+
translatedExprs.set(expression, result);
|
|
209
|
+
return result;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const makeBinder = (kind: BinderExpr["kind"], variable: VarExpr, type: string, body: Expr) =>
|
|
213
|
+
kind === "all"
|
|
214
|
+
? exprs.eall(variable, type, body)
|
|
215
|
+
: kind === "ex"
|
|
216
|
+
? exprs.eex(variable, type, body)
|
|
217
|
+
: kind === "tau"
|
|
218
|
+
? exprs.etau(variable, type, body)
|
|
219
|
+
: exprs.elam(variable, type, body);
|
|
220
|
+
|
|
221
|
+
const translateRule = (rule: MlRule): LlRule => {
|
|
222
|
+
const tr = translateExpr;
|
|
223
|
+
switch (rule.name) {
|
|
224
|
+
case "close":
|
|
225
|
+
return { kind: "axiom", formula: tr(rule.args[0]) };
|
|
226
|
+
case "close_refl":
|
|
227
|
+
return { kind: "noteq", term: tr(rule.args[0]) };
|
|
228
|
+
case "close_sym": {
|
|
229
|
+
const right = tr(rule.args[1]);
|
|
230
|
+
return { kind: "eqsym", left: tr(rule.args[0]), right };
|
|
231
|
+
}
|
|
232
|
+
case "false":
|
|
233
|
+
return { kind: "false" };
|
|
234
|
+
case "not_true":
|
|
235
|
+
return { kind: "nottrue" };
|
|
236
|
+
case "not_not":
|
|
237
|
+
return { kind: "notnot", formula: tr(rule.args[0]) };
|
|
238
|
+
case "and":
|
|
239
|
+
case "or":
|
|
240
|
+
case "impl":
|
|
241
|
+
case "equiv": {
|
|
242
|
+
const right = tr(rule.args[1]);
|
|
243
|
+
return {
|
|
244
|
+
kind: "connect",
|
|
245
|
+
connective: RULE_CONNECTIVES[rule.name],
|
|
246
|
+
left: tr(rule.args[0]),
|
|
247
|
+
right,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
case "not_or":
|
|
251
|
+
case "not_impl":
|
|
252
|
+
case "not_and":
|
|
253
|
+
case "not_equiv": {
|
|
254
|
+
const right = tr(rule.args[1]);
|
|
255
|
+
return {
|
|
256
|
+
kind: "notconnect",
|
|
257
|
+
connective: RULE_CONNECTIVES[rule.name],
|
|
258
|
+
left: tr(rule.args[0]),
|
|
259
|
+
right,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
case "ex": {
|
|
263
|
+
const quantified = getBinder(rule.args[0], "ex");
|
|
264
|
+
const term = tr(exprs.etau(quantified.args[0], quantified.symbol, quantified.args[1]));
|
|
265
|
+
return { kind: "ex", quantified: tr(quantified), term };
|
|
266
|
+
}
|
|
267
|
+
case "all": {
|
|
268
|
+
const term = tr(rule.args[1]);
|
|
269
|
+
return { kind: "all", quantified: tr(rule.args[0]), term };
|
|
270
|
+
}
|
|
271
|
+
case "not_ex": {
|
|
272
|
+
const negation = rule.args[0];
|
|
273
|
+
if (negation.kind !== "not") throw new TlaZenonError("Zenon: not_ex without a negation");
|
|
274
|
+
const term = tr(rule.args[1]);
|
|
275
|
+
return { kind: "notex", quantified: tr(negation.args[0]), term };
|
|
276
|
+
}
|
|
277
|
+
case "p_not_p": {
|
|
278
|
+
const negative = tr(rule.args[1]);
|
|
279
|
+
return { kind: "pnotp", positive: tr(rule.args[0]), negative };
|
|
280
|
+
}
|
|
281
|
+
case "not_equal": {
|
|
282
|
+
const right = tr(rule.args[1]);
|
|
283
|
+
return { kind: "notequal", left: tr(rule.args[0]), right };
|
|
284
|
+
}
|
|
285
|
+
case "definition": {
|
|
286
|
+
if (rule.definition.kind !== "real")
|
|
287
|
+
throw new TlaZenonError("Zenon: a pseudo-definition in tr_rule");
|
|
288
|
+
const unfolded = tr(rule.args[1]);
|
|
289
|
+
return {
|
|
290
|
+
kind: "definition",
|
|
291
|
+
name: rule.definition.name,
|
|
292
|
+
folded: tr(rule.args[0]),
|
|
293
|
+
unfolded,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
case "cut":
|
|
297
|
+
return { kind: "cut", formula: tr(rule.args[0]) };
|
|
298
|
+
case "congruence_lr":
|
|
299
|
+
case "congruence_rl": {
|
|
300
|
+
const right = tr(rule.args[2]);
|
|
301
|
+
const left = tr(rule.args[1]);
|
|
302
|
+
return {
|
|
303
|
+
kind: rule.name === "congruence_lr" ? "congruencelr" : "congruencerl",
|
|
304
|
+
context: tr(rule.args[0]),
|
|
305
|
+
left,
|
|
306
|
+
right,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
case "notall": {
|
|
310
|
+
const negation = rule.args[0];
|
|
311
|
+
const quantified = getBinder(negation.kind === "not" ? negation.args[0] : negation, "all");
|
|
312
|
+
const term = tr(
|
|
313
|
+
exprs.etau(quantified.args[0], quantified.symbol, exprs.enot(quantified.args[1])),
|
|
314
|
+
);
|
|
315
|
+
return { kind: "notall", quantified: tr(quantified), term };
|
|
316
|
+
}
|
|
317
|
+
case "notallex": {
|
|
318
|
+
const lambda = getBinder(rule.args[0], "lam");
|
|
319
|
+
const variable = lambda.args[0];
|
|
320
|
+
const body = lambda.args[1];
|
|
321
|
+
const conclusion = exprs.enot(exprs.eall(variable, lambda.symbol, body));
|
|
322
|
+
const hypothesis = exprs.eex(variable, lambda.symbol, exprs.enot(body));
|
|
323
|
+
return {
|
|
324
|
+
kind: "extension",
|
|
325
|
+
name: "zenon_notallex",
|
|
326
|
+
args: [lambda],
|
|
327
|
+
conclusions: [conclusion],
|
|
328
|
+
branches: [[hypothesis]],
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
case "stringequal": {
|
|
332
|
+
const first = rule.args[0];
|
|
333
|
+
const second = rule.args[1];
|
|
334
|
+
const conclusion = equal(exprs.eapp("$string", [first]), exprs.eapp("$string", [second]));
|
|
335
|
+
return {
|
|
336
|
+
kind: "extension",
|
|
337
|
+
name: "zenon_stringequal",
|
|
338
|
+
args: [first, second],
|
|
339
|
+
conclusions: [conclusion],
|
|
340
|
+
branches: [],
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
case "stringdiffll":
|
|
344
|
+
case "stringdifflr":
|
|
345
|
+
case "stringdiffrl":
|
|
346
|
+
case "stringdiffrr": {
|
|
347
|
+
const [first, firstValue, second, secondValue] = rule.args;
|
|
348
|
+
const isFirstLeft = rule.name === "stringdiffll" || rule.name === "stringdifflr";
|
|
349
|
+
const isSecondLeft = rule.name === "stringdiffll" || rule.name === "stringdiffrl";
|
|
350
|
+
const firstConclusion = isFirstLeft ? equal(first, firstValue) : equal(firstValue, first);
|
|
351
|
+
const secondConclusion = isSecondLeft
|
|
352
|
+
? equal(second, secondValue)
|
|
353
|
+
: equal(secondValue, second);
|
|
354
|
+
const hypothesis = exprs.enot(equal(first, second));
|
|
355
|
+
return {
|
|
356
|
+
kind: "extension",
|
|
357
|
+
// HACK: Zenon names the last of the four rules after the third.
|
|
358
|
+
name: rule.name === "stringdiffrr" ? "zenon_stringdiffrl" : `zenon_${rule.name}`,
|
|
359
|
+
args: rule.args,
|
|
360
|
+
conclusions: [firstConclusion, secondConclusion],
|
|
361
|
+
branches: [[hypothesis]],
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
default:
|
|
365
|
+
throw new TlaZenonError(`Zenon: the derived rule ${rule.name} in tr_rule`);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
// Zenon's get_params: the free taus of a lemma's conclusions, each with its type.
|
|
370
|
+
const getParams = (accumulated: [string, Expr][], expression: Expr): [string, Expr][] => {
|
|
371
|
+
const merge = (type: string, term: Expr): [string, Expr][] =>
|
|
372
|
+
accumulated.some((param) => param[1] === term) ? accumulated : [[type, term], ...accumulated];
|
|
373
|
+
switch (expression.kind) {
|
|
374
|
+
case "tau":
|
|
375
|
+
return merge(expression.symbol, expression);
|
|
376
|
+
case "all":
|
|
377
|
+
case "ex":
|
|
378
|
+
case "lam":
|
|
379
|
+
return getParams(accumulated, expression.args[1]);
|
|
380
|
+
case "meta":
|
|
381
|
+
throw new TlaZenonError("Zenon: a metavariable in a translated formula");
|
|
382
|
+
default:
|
|
383
|
+
return expression.args.reduce(getParams, accumulated);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
const getLemmaReference = (proof: MlProof): Translated => {
|
|
388
|
+
const number = lemmaNumbers.get(proof);
|
|
389
|
+
const entry = number === undefined ? undefined : lemmaTable.get(getLemmaName(number));
|
|
390
|
+
if (entry === undefined) throw new TlaZenonError("Zenon: a lemma that was never made");
|
|
391
|
+
const lemma = entry[0];
|
|
392
|
+
return [
|
|
393
|
+
{
|
|
394
|
+
conclusions: lemma.proof.conclusions,
|
|
395
|
+
rule: { kind: "lemma", name: lemma.name, args: lemma.params.map((param) => param[1]) },
|
|
396
|
+
subproofs: [],
|
|
397
|
+
},
|
|
398
|
+
entry[1],
|
|
399
|
+
];
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
const makeLemma = (translated: LlProof, extras: Expr[], proof: MlProof) => {
|
|
403
|
+
const number = lemmas.length + 1;
|
|
404
|
+
lemmaNumbers.set(proof, number);
|
|
405
|
+
const lemma = {
|
|
406
|
+
name: getLemmaName(number),
|
|
407
|
+
params: translated.conclusions.reduce(getParams, []),
|
|
408
|
+
proof: translated,
|
|
409
|
+
};
|
|
410
|
+
lemmaTable.set(lemma.name, [lemma, extras]);
|
|
411
|
+
lemmas.push(lemma);
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
const translate = (proof: MlProof): Translated => {
|
|
415
|
+
if (lemmaNumbers.has(proof)) return getLemmaReference(proof);
|
|
416
|
+
const result = isDerived(proof.rule)
|
|
417
|
+
? translateDerived(proof)
|
|
418
|
+
: ((): Translated => {
|
|
419
|
+
const subproofs = translateAll(proof.subproofs);
|
|
420
|
+
const extras = difference(subproofs[1], proof.conclusions);
|
|
421
|
+
return [
|
|
422
|
+
{
|
|
423
|
+
conclusions: [...extras.toReversed(), ...proof.conclusions].map(translateExpr),
|
|
424
|
+
rule: translateRule(proof.rule),
|
|
425
|
+
subproofs: subproofs[0],
|
|
426
|
+
},
|
|
427
|
+
extras,
|
|
428
|
+
];
|
|
429
|
+
})();
|
|
430
|
+
if (!isSharedProof(proof)) return result;
|
|
431
|
+
makeLemma(result[0], result[1], proof);
|
|
432
|
+
return getLemmaReference(proof);
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
const isSharedProof = (proof: MlProof) =>
|
|
436
|
+
context.sharedProofs.has(proof) && !lemmaNumbers.has(proof);
|
|
437
|
+
|
|
438
|
+
// Zenon's get_sub: the subproofs, and the union of their extras from the right.
|
|
439
|
+
const translateAll = (proofs: MlProof[]): [LlProof[], Expr[]] => {
|
|
440
|
+
const translated = proofs.map(translate);
|
|
441
|
+
return [
|
|
442
|
+
translated.map((entry) => entry[0]),
|
|
443
|
+
translated.reduceRight((accumulated: Expr[], entry) => union(entry[1], accumulated), []),
|
|
444
|
+
];
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
// A node of recomp_conj, with the formulas it removes from its subproof's conclusions.
|
|
448
|
+
const recompose = (
|
|
449
|
+
conclusion: Expr,
|
|
450
|
+
rule: LlRule,
|
|
451
|
+
removed: Expr[],
|
|
452
|
+
next: Translated,
|
|
453
|
+
extra: Expr,
|
|
454
|
+
): Translated => [
|
|
455
|
+
{
|
|
456
|
+
conclusions: union([conclusion], difference(next[0].conclusions, removed)),
|
|
457
|
+
rule,
|
|
458
|
+
subproofs: [next[0]],
|
|
459
|
+
},
|
|
460
|
+
difference(next[1], [extra]),
|
|
461
|
+
];
|
|
462
|
+
|
|
463
|
+
const recompConj = (sub: Translated, formula: Expr): Translated => {
|
|
464
|
+
if (formula.kind === "not") return recompConjNegated(sub, formula.args[0]);
|
|
465
|
+
if (formula.kind !== "and") return sub;
|
|
466
|
+
const left = translateExpr(formula.args[0]);
|
|
467
|
+
const right = translateExpr(formula.args[1]);
|
|
468
|
+
const second = recompConj(recompConj(sub, formula.args[0]), formula.args[1]);
|
|
469
|
+
return recompose(
|
|
470
|
+
translateExpr(formula),
|
|
471
|
+
{ kind: "connect", connective: "and", left, right },
|
|
472
|
+
[left, right],
|
|
473
|
+
second,
|
|
474
|
+
formula,
|
|
475
|
+
);
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
const recompConjNegated = (sub: Translated, formula: Expr): Translated => {
|
|
479
|
+
const conclusion = exprs.enot(translateExpr(formula));
|
|
480
|
+
const negation = exprs.enot(formula);
|
|
481
|
+
switch (formula.kind) {
|
|
482
|
+
case "or": {
|
|
483
|
+
const left = translateExpr(formula.args[0]);
|
|
484
|
+
const right = translateExpr(formula.args[1]);
|
|
485
|
+
const second = recompConjNegated(recompConjNegated(sub, formula.args[0]), formula.args[1]);
|
|
486
|
+
return recompose(
|
|
487
|
+
conclusion,
|
|
488
|
+
{ kind: "notconnect", connective: "or", left, right },
|
|
489
|
+
[exprs.enot(left), exprs.enot(right)],
|
|
490
|
+
second,
|
|
491
|
+
negation,
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
case "imply": {
|
|
495
|
+
const left = translateExpr(formula.args[0]);
|
|
496
|
+
const right = translateExpr(formula.args[1]);
|
|
497
|
+
const second = recompConjNegated(recompConj(sub, formula.args[0]), formula.args[1]);
|
|
498
|
+
return recompose(
|
|
499
|
+
conclusion,
|
|
500
|
+
{ kind: "notconnect", connective: "imply", left, right },
|
|
501
|
+
[left, exprs.enot(right)],
|
|
502
|
+
second,
|
|
503
|
+
negation,
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
case "not": {
|
|
507
|
+
const operand = translateExpr(formula.args[0]);
|
|
508
|
+
return recompose(
|
|
509
|
+
conclusion,
|
|
510
|
+
{ kind: "notnot", formula: operand },
|
|
511
|
+
[operand],
|
|
512
|
+
recompConj(sub, formula.args[0]),
|
|
513
|
+
negation,
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
default:
|
|
517
|
+
return sub;
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
// Zenon's recomp_disj: consumes the translated subproofs, one for each disjunct.
|
|
522
|
+
const recompDisj = (subs: Translated[], formula: Expr): [LlProof, Expr[], Translated[]] => {
|
|
523
|
+
const node = (
|
|
524
|
+
conclusion: Expr,
|
|
525
|
+
connectiveName: Connective,
|
|
526
|
+
negated: boolean,
|
|
527
|
+
left: Expr,
|
|
528
|
+
right: Expr,
|
|
529
|
+
first: [LlProof, Expr[], Translated[]],
|
|
530
|
+
firstRemoved: Expr,
|
|
531
|
+
second: [LlProof, Expr[], Translated[]],
|
|
532
|
+
secondRemoved: Expr,
|
|
533
|
+
extra: Expr,
|
|
534
|
+
): [LlProof, Expr[], Translated[]] => [
|
|
535
|
+
{
|
|
536
|
+
conclusions: union(
|
|
537
|
+
[conclusion],
|
|
538
|
+
union(
|
|
539
|
+
difference(first[0].conclusions, [firstRemoved]),
|
|
540
|
+
difference(second[0].conclusions, [secondRemoved]),
|
|
541
|
+
),
|
|
542
|
+
),
|
|
543
|
+
rule: { kind: negated ? "notconnect" : "connect", connective: connectiveName, left, right },
|
|
544
|
+
subproofs: [first[0], second[0]],
|
|
545
|
+
},
|
|
546
|
+
difference(union(first[1], second[1]), [extra]),
|
|
547
|
+
second[2],
|
|
548
|
+
];
|
|
549
|
+
switch (formula.kind) {
|
|
550
|
+
case "or": {
|
|
551
|
+
const left = translateExpr(formula.args[0]);
|
|
552
|
+
const right = translateExpr(formula.args[1]);
|
|
553
|
+
const first = recompDisj(subs, formula.args[0]);
|
|
554
|
+
const second = recompDisj(first[2], formula.args[1]);
|
|
555
|
+
return node(
|
|
556
|
+
translateExpr(formula),
|
|
557
|
+
"or",
|
|
558
|
+
false,
|
|
559
|
+
left,
|
|
560
|
+
right,
|
|
561
|
+
first,
|
|
562
|
+
left,
|
|
563
|
+
second,
|
|
564
|
+
right,
|
|
565
|
+
formula,
|
|
566
|
+
);
|
|
567
|
+
}
|
|
568
|
+
case "imply": {
|
|
569
|
+
const left = translateExpr(formula.args[0]);
|
|
570
|
+
const right = translateExpr(formula.args[1]);
|
|
571
|
+
const first = recompDisjNegated(subs, formula.args[0]);
|
|
572
|
+
const second = recompDisj(first[2], formula.args[1]);
|
|
573
|
+
return node(
|
|
574
|
+
translateExpr(formula),
|
|
575
|
+
"imply",
|
|
576
|
+
false,
|
|
577
|
+
left,
|
|
578
|
+
right,
|
|
579
|
+
first,
|
|
580
|
+
exprs.enot(left),
|
|
581
|
+
second,
|
|
582
|
+
right,
|
|
583
|
+
formula,
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
case "not":
|
|
587
|
+
return recompDisjNegated(subs, formula.args[0]);
|
|
588
|
+
default:
|
|
589
|
+
return takeSub(subs);
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
const recompDisjNegated = (
|
|
594
|
+
subs: Translated[],
|
|
595
|
+
formula: Expr,
|
|
596
|
+
): [LlProof, Expr[], Translated[]] => {
|
|
597
|
+
switch (formula.kind) {
|
|
598
|
+
case "and": {
|
|
599
|
+
const left = translateExpr(formula.args[0]);
|
|
600
|
+
const right = translateExpr(formula.args[1]);
|
|
601
|
+
const first = recompDisjNegated(subs, formula.args[0]);
|
|
602
|
+
const second = recompDisjNegated(first[2], formula.args[1]);
|
|
603
|
+
const negation = exprs.enot(formula);
|
|
604
|
+
return [
|
|
605
|
+
{
|
|
606
|
+
conclusions: union(
|
|
607
|
+
[exprs.enot(translateExpr(formula))],
|
|
608
|
+
union(
|
|
609
|
+
difference(first[0].conclusions, [exprs.enot(left)]),
|
|
610
|
+
difference(second[0].conclusions, [exprs.enot(right)]),
|
|
611
|
+
),
|
|
612
|
+
),
|
|
613
|
+
rule: { kind: "notconnect", connective: "and", left, right },
|
|
614
|
+
subproofs: [first[0], second[0]],
|
|
615
|
+
},
|
|
616
|
+
difference(union(first[1], second[1]), [negation]),
|
|
617
|
+
second[2],
|
|
618
|
+
];
|
|
619
|
+
}
|
|
620
|
+
case "not": {
|
|
621
|
+
const operand = translateExpr(formula.args[0]);
|
|
622
|
+
const first = recompDisj(subs, formula.args[0]);
|
|
623
|
+
return [
|
|
624
|
+
{
|
|
625
|
+
conclusions: union(
|
|
626
|
+
[exprs.enot(translateExpr(formula))],
|
|
627
|
+
difference(first[0].conclusions, [operand]),
|
|
628
|
+
),
|
|
629
|
+
rule: { kind: "notnot", formula: operand },
|
|
630
|
+
subproofs: [first[0]],
|
|
631
|
+
},
|
|
632
|
+
difference(first[1], [exprs.enot(formula)]),
|
|
633
|
+
first[2],
|
|
634
|
+
];
|
|
635
|
+
}
|
|
636
|
+
default:
|
|
637
|
+
return takeSub(subs);
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
const takeSub = (subs: Translated[]): [LlProof, Expr[], Translated[]] => {
|
|
642
|
+
if (subs.length === 0) throw new TlaZenonError("Zenon: a disjunction tree without subproofs");
|
|
643
|
+
return [subs[0][0], subs[0][1], subs.slice(1)];
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
// The constructors of Zenon's Mlproof, for the proofs that the translation builds.
|
|
647
|
+
const makeClose = (formula: Expr) =>
|
|
648
|
+
makeNode([formula, exprs.enot(formula)], { name: "close", args: [formula] }, [], []);
|
|
649
|
+
const makeCloseRefl = (relation: string, term: Expr) =>
|
|
650
|
+
makeNode(
|
|
651
|
+
[exprs.enot(exprs.eapp(relation, [term, term]))],
|
|
652
|
+
{ name: "close_refl", relation, args: [term] },
|
|
653
|
+
[],
|
|
654
|
+
[],
|
|
655
|
+
);
|
|
656
|
+
const makeCloseSym = (relation: string, left: Expr, right: Expr) =>
|
|
657
|
+
makeNode(
|
|
658
|
+
[exprs.eapp(relation, [left, right]), exprs.enot(exprs.eapp(relation, [right, left]))],
|
|
659
|
+
{ name: "close_sym", relation, args: [left, right] },
|
|
660
|
+
[],
|
|
661
|
+
[],
|
|
662
|
+
);
|
|
663
|
+
const makeNotNot = (formula: Expr, subproof: MlProof) =>
|
|
664
|
+
makeNode(
|
|
665
|
+
[exprs.enot(exprs.enot(formula))],
|
|
666
|
+
{ name: "not_not", args: [formula] },
|
|
667
|
+
[[formula]],
|
|
668
|
+
[subproof],
|
|
669
|
+
);
|
|
670
|
+
const makeAnd = (left: Expr, right: Expr, subproof: MlProof) =>
|
|
671
|
+
makeNode(
|
|
672
|
+
[exprs.eand(left, right)],
|
|
673
|
+
{ name: "and", args: [left, right] },
|
|
674
|
+
[[left, right]],
|
|
675
|
+
[subproof],
|
|
676
|
+
);
|
|
677
|
+
const makeImply = (left: Expr, right: Expr, first: MlProof, second: MlProof) =>
|
|
678
|
+
makeNode(
|
|
679
|
+
[exprs.eimply(left, right)],
|
|
680
|
+
{ name: "impl", args: [left, right] },
|
|
681
|
+
[[exprs.enot(left)], [right]],
|
|
682
|
+
[first, second],
|
|
683
|
+
);
|
|
684
|
+
const makeNotAnd = (left: Expr, right: Expr, first: MlProof, second: MlProof) =>
|
|
685
|
+
makeNode(
|
|
686
|
+
[exprs.enot(exprs.eand(left, right))],
|
|
687
|
+
{ name: "not_and", args: [left, right] },
|
|
688
|
+
[[exprs.enot(left)], [exprs.enot(right)]],
|
|
689
|
+
[first, second],
|
|
690
|
+
);
|
|
691
|
+
const makeAll = (quantified: Expr, term: Expr, subproof: MlProof) => {
|
|
692
|
+
const binder = getBinder(quantified, "all");
|
|
693
|
+
const instance = exprs.substitute([[binder.args[0], term]], binder.args[1]);
|
|
694
|
+
return makeNode(
|
|
695
|
+
[quantified],
|
|
696
|
+
{ name: "all", args: [quantified, term] },
|
|
697
|
+
[[instance]],
|
|
698
|
+
[subproof],
|
|
699
|
+
);
|
|
700
|
+
};
|
|
701
|
+
const makeAlls = (quantified: Expr, terms: Expr[], subproof: MlProof): MlProof => {
|
|
702
|
+
if (terms.length === 0) return subproof;
|
|
703
|
+
const binder = getBinder(quantified, "all");
|
|
704
|
+
const instance = exprs.substitute([[binder.args[0], terms[0]]], binder.args[1]);
|
|
705
|
+
return makeAll(quantified, terms[0], makeAlls(instance, terms.slice(1), subproof));
|
|
706
|
+
};
|
|
707
|
+
// Zenon's make_impls: the implications from `hypotheses` to `conclusion`, and their proof.
|
|
708
|
+
const makeImplies = (
|
|
709
|
+
hypotheses: Expr[],
|
|
710
|
+
conclusion: Expr,
|
|
711
|
+
proofs: MlProof[],
|
|
712
|
+
conclusionProof: MlProof,
|
|
713
|
+
): [Expr, MlProof] => {
|
|
714
|
+
if (hypotheses.length === 0) return [conclusion, conclusionProof];
|
|
715
|
+
const rest = makeImplies(hypotheses.slice(1), conclusion, proofs.slice(1), conclusionProof);
|
|
716
|
+
return [
|
|
717
|
+
exprs.eimply(hypotheses[0], rest[0]),
|
|
718
|
+
makeImply(hypotheses[0], rest[0], proofs[0], rest[1]),
|
|
719
|
+
];
|
|
720
|
+
};
|
|
721
|
+
const makePNotP = (positive: Expr, negative: Expr, subproofs: MlProof[]) => {
|
|
722
|
+
if (positive.kind !== "app" || negative.kind !== "not" || negative.args[0].kind !== "app")
|
|
723
|
+
throw new TlaZenonError("Zenon: make_pnp on a formula that isn't an application");
|
|
724
|
+
const negativeArgs = negative.args[0].args;
|
|
725
|
+
return makeNode(
|
|
726
|
+
[positive, negative],
|
|
727
|
+
{ name: "p_not_p", args: [positive, negative] },
|
|
728
|
+
positive.args.map((arg, position) => [exprs.enot(equal(arg, negativeArgs[position]))]),
|
|
729
|
+
subproofs,
|
|
730
|
+
);
|
|
731
|
+
};
|
|
732
|
+
const makeCut = (formula: Expr, first: MlProof, second: MlProof) =>
|
|
733
|
+
makeNode(
|
|
734
|
+
[],
|
|
735
|
+
{ name: "cut", args: [formula] },
|
|
736
|
+
[[formula], [exprs.enot(formula)]],
|
|
737
|
+
[first, second],
|
|
738
|
+
);
|
|
739
|
+
|
|
740
|
+
// Zenon's Eqrel.get_refl_hyp, get_sym_hyp and get_trans_hyp: the hypothesis that states a
|
|
741
|
+
// property of a relation, which the translation proves from the hypotheses that implied it.
|
|
742
|
+
const relationHypotheses = new Map<string, Expr>();
|
|
743
|
+
const hypothesisKinds = new Map<Expr, HypothesisKind>();
|
|
744
|
+
const getRelationHypothesis = (property: RelationProperty, relation: string) => {
|
|
745
|
+
const key = `${property} ${relation}`;
|
|
746
|
+
const existing = relationHypotheses.get(key);
|
|
747
|
+
if (existing !== undefined) return existing;
|
|
748
|
+
const info = context.relations.get(relation);
|
|
749
|
+
if (relation === "=" || info === undefined)
|
|
750
|
+
throw new TlaZenonError(`Zenon: no ${property} hypothesis for ${relation}`);
|
|
751
|
+
const type = info.type;
|
|
752
|
+
const x = exprs.evar("x");
|
|
753
|
+
const y = exprs.evar("y");
|
|
754
|
+
const z = exprs.evar("z");
|
|
755
|
+
const hypothesis =
|
|
756
|
+
property === "reflexive"
|
|
757
|
+
? exprs.eall(x, type, relate(relation, x, x))
|
|
758
|
+
: property === "symmetric"
|
|
759
|
+
? exprs.eall(
|
|
760
|
+
x,
|
|
761
|
+
type,
|
|
762
|
+
exprs.eall(y, type, exprs.eimply(relate(relation, x, y), relate(relation, y, x))),
|
|
763
|
+
)
|
|
764
|
+
: exprs.eall(
|
|
765
|
+
x,
|
|
766
|
+
type,
|
|
767
|
+
exprs.eall(
|
|
768
|
+
y,
|
|
769
|
+
type,
|
|
770
|
+
exprs.eall(
|
|
771
|
+
z,
|
|
772
|
+
type,
|
|
773
|
+
exprs.eimply(
|
|
774
|
+
relate(relation, x, y),
|
|
775
|
+
exprs.eimply(relate(relation, y, z), relate(relation, x, z)),
|
|
776
|
+
),
|
|
777
|
+
),
|
|
778
|
+
),
|
|
779
|
+
);
|
|
780
|
+
relationHypotheses.set(key, hypothesis);
|
|
781
|
+
const direct = info[property];
|
|
782
|
+
const kind = ((): HypothesisKind | undefined => {
|
|
783
|
+
if (direct !== undefined) return { kind: property, origin: direct };
|
|
784
|
+
if (property === "reflexive" || info.reflexive === undefined) return undefined;
|
|
785
|
+
if (info.transitiveSymmetric === undefined) return undefined;
|
|
786
|
+
return {
|
|
787
|
+
kind: property === "symmetric" ? "symmetric2" : "transitive2",
|
|
788
|
+
relation,
|
|
789
|
+
reflexive: info.reflexive,
|
|
790
|
+
transitiveSymmetric: info.transitiveSymmetric,
|
|
791
|
+
};
|
|
792
|
+
})();
|
|
793
|
+
if (kind === undefined) throw new TlaZenonError(`Zenon: ${relation} isn't ${property}`);
|
|
794
|
+
hypothesisKinds.set(hypothesis, kind);
|
|
795
|
+
return hypothesis;
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
// Zenon's inst_nall: the instance of a negated universal at its counterexample.
|
|
799
|
+
const instantiateNegation = (negation: Expr): [Expr, Expr] => {
|
|
800
|
+
if (negation.kind !== "not") throw new TlaZenonError("Zenon: inst_nall without a negation");
|
|
801
|
+
const binder = getBinder(negation.args[0], "all");
|
|
802
|
+
const body = exprs.enot(binder.args[1]);
|
|
803
|
+
const witness = exprs.etau(binder.args[0], binder.symbol, body);
|
|
804
|
+
return [exprs.substitute([[binder.args[0], witness]], body), witness];
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
// Zenon's decompose_disj: closes each literal of a disjunction with one of `forms`.
|
|
808
|
+
const decomposeDisjunction = (formula: Expr, forms: Expr[]): MlProof => {
|
|
809
|
+
const visit = (disjunct: Expr) => decomposeDisjunction(disjunct, forms);
|
|
810
|
+
const getForm = (form: Expr) => {
|
|
811
|
+
if (!forms.includes(form)) throw new TlaZenonError("Zenon: decompose_disj lacks a literal");
|
|
812
|
+
return form;
|
|
813
|
+
};
|
|
814
|
+
switch (formula.kind) {
|
|
815
|
+
case "or":
|
|
816
|
+
return makeNode(
|
|
817
|
+
[formula],
|
|
818
|
+
{ name: "or", args: [formula.args[0], formula.args[1]] },
|
|
819
|
+
[[formula.args[0]], [formula.args[1]]],
|
|
820
|
+
[visit(formula.args[0]), visit(formula.args[1])],
|
|
821
|
+
);
|
|
822
|
+
case "imply": {
|
|
823
|
+
const negated = exprs.enot(formula.args[0]);
|
|
824
|
+
return makeNode(
|
|
825
|
+
[formula],
|
|
826
|
+
{ name: "impl", args: [formula.args[0], formula.args[1]] },
|
|
827
|
+
[[negated], [formula.args[1]]],
|
|
828
|
+
[visit(negated), visit(formula.args[1])],
|
|
829
|
+
);
|
|
830
|
+
}
|
|
831
|
+
case "false":
|
|
832
|
+
return makeNode([formula], { name: "false", args: [] }, [], []);
|
|
833
|
+
case "app":
|
|
834
|
+
return makeNode(
|
|
835
|
+
[formula, getForm(exprs.enot(formula))],
|
|
836
|
+
{ name: "close", args: [formula] },
|
|
837
|
+
[],
|
|
838
|
+
[],
|
|
839
|
+
);
|
|
840
|
+
case "not": {
|
|
841
|
+
const operand = formula.args[0];
|
|
842
|
+
if (operand.kind === "and") {
|
|
843
|
+
const left = exprs.enot(operand.args[0]);
|
|
844
|
+
const right = exprs.enot(operand.args[1]);
|
|
845
|
+
return makeNode(
|
|
846
|
+
[formula],
|
|
847
|
+
{ name: "not_and", args: [operand.args[0], operand.args[1]] },
|
|
848
|
+
[[left], [right]],
|
|
849
|
+
[visit(left), visit(right)],
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
if (operand.kind === "not")
|
|
853
|
+
return makeNode(
|
|
854
|
+
[formula],
|
|
855
|
+
{ name: "not_not", args: [operand.args[0]] },
|
|
856
|
+
[[operand.args[0]]],
|
|
857
|
+
[visit(operand.args[0])],
|
|
858
|
+
);
|
|
859
|
+
if (operand.kind === "true")
|
|
860
|
+
return makeNode([formula], { name: "not_true", args: [] }, [], []);
|
|
861
|
+
if (operand.kind === "app")
|
|
862
|
+
return makeNode([getForm(operand), formula], { name: "close", args: [operand] }, [], []);
|
|
863
|
+
throw new TlaZenonError("Zenon: decompose_disj on an unexpected formula");
|
|
864
|
+
}
|
|
865
|
+
default:
|
|
866
|
+
throw new TlaZenonError("Zenon: decompose_disj on an unexpected formula");
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
// Zenon's decompose_conj: follows `directions` to the conjunct that states a property, and
|
|
871
|
+
// instantiates the quantifiers at `variables` with `witnesses`, the others with metavariables.
|
|
872
|
+
const decomposeConjunction = (
|
|
873
|
+
position: number,
|
|
874
|
+
formula: Expr,
|
|
875
|
+
directions: Direction[],
|
|
876
|
+
variables: number[],
|
|
877
|
+
forms: Expr[],
|
|
878
|
+
witnesses: Expr[],
|
|
879
|
+
): MlProof => {
|
|
880
|
+
const next = (subformula: Expr, rest: Direction[]) =>
|
|
881
|
+
decomposeConjunction(position, subformula, rest, variables, forms, witnesses);
|
|
882
|
+
const direction = directions[0];
|
|
883
|
+
const rest = directions.slice(1);
|
|
884
|
+
const instantiate = (
|
|
885
|
+
quantified: Expr,
|
|
886
|
+
binder: BinderExpr,
|
|
887
|
+
body: (instance: Expr) => Expr,
|
|
888
|
+
name: "all" | "not_ex",
|
|
889
|
+
) => {
|
|
890
|
+
const isWitness = variables[0] === position;
|
|
891
|
+
const term = isWitness ? witnesses[0] : exprs.emeta(binder);
|
|
892
|
+
if (term === undefined) throw new TlaZenonError("Zenon: decompose_conj ran out of witnesses");
|
|
893
|
+
const instance = body(exprs.substitute([[binder.args[0], term]], binder.args[1]));
|
|
894
|
+
const subproof = decomposeConjunction(
|
|
895
|
+
position + 1,
|
|
896
|
+
instance,
|
|
897
|
+
directions,
|
|
898
|
+
isWitness ? variables.slice(1) : variables,
|
|
899
|
+
forms,
|
|
900
|
+
isWitness ? witnesses.slice(1) : witnesses,
|
|
901
|
+
);
|
|
902
|
+
return makeNode([quantified], { name, args: [quantified, term] }, [[instance]], [subproof]);
|
|
903
|
+
};
|
|
904
|
+
if (formula.kind === "and" && direction !== undefined) {
|
|
905
|
+
const branch = direction === "left" ? formula.args[0] : formula.args[1];
|
|
906
|
+
return makeNode(
|
|
907
|
+
[formula],
|
|
908
|
+
{ name: "and", args: [formula.args[0], formula.args[1]] },
|
|
909
|
+
[[branch]],
|
|
910
|
+
[next(branch, rest)],
|
|
911
|
+
);
|
|
912
|
+
}
|
|
913
|
+
if (formula.kind === "all") return instantiate(formula, formula, (instance) => instance, "all");
|
|
914
|
+
if (formula.kind === "equiv" && direction !== undefined) {
|
|
915
|
+
const left = formula.args[0];
|
|
916
|
+
const right = formula.args[1];
|
|
917
|
+
const rule: MlRule = { name: "equiv", args: [left, right] };
|
|
918
|
+
return direction === "left"
|
|
919
|
+
? makeNode(
|
|
920
|
+
[formula],
|
|
921
|
+
rule,
|
|
922
|
+
[[exprs.enot(left)], [right]],
|
|
923
|
+
[decomposeDisjunction(exprs.enot(left), forms), decomposeDisjunction(right, forms)],
|
|
924
|
+
)
|
|
925
|
+
: makeNode(
|
|
926
|
+
[formula],
|
|
927
|
+
rule,
|
|
928
|
+
[[exprs.enot(right)], [left]],
|
|
929
|
+
[decomposeDisjunction(exprs.enot(right), forms), decomposeDisjunction(left, forms)],
|
|
930
|
+
);
|
|
931
|
+
}
|
|
932
|
+
const operand = formula.kind === "not" ? formula.args[0] : undefined;
|
|
933
|
+
if (operand?.kind === "or" && direction !== undefined) {
|
|
934
|
+
const branch = exprs.enot(direction === "left" ? operand.args[0] : operand.args[1]);
|
|
935
|
+
return makeNode(
|
|
936
|
+
[formula],
|
|
937
|
+
{ name: "not_or", args: [operand.args[0], operand.args[1]] },
|
|
938
|
+
[[branch]],
|
|
939
|
+
[next(branch, rest)],
|
|
940
|
+
);
|
|
941
|
+
}
|
|
942
|
+
if (operand?.kind === "imply" && direction !== undefined) {
|
|
943
|
+
const branch = direction === "left" ? operand.args[0] : exprs.enot(operand.args[1]);
|
|
944
|
+
// HACK: Zenon names the right branch of a negated implication not_or.
|
|
945
|
+
const name = direction === "left" ? "not_impl" : "not_or";
|
|
946
|
+
return makeNode(
|
|
947
|
+
[formula],
|
|
948
|
+
{ name, args: [operand.args[0], operand.args[1]] },
|
|
949
|
+
[[branch]],
|
|
950
|
+
[next(branch, rest)],
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
if (operand?.kind === "ex")
|
|
954
|
+
return instantiate(formula, operand, (instance) => exprs.enot(instance), "not_ex");
|
|
955
|
+
if (operand?.kind === "not")
|
|
956
|
+
return makeNode(
|
|
957
|
+
[formula],
|
|
958
|
+
{ name: "not_not", args: [operand.args[0]] },
|
|
959
|
+
[[operand.args[0]]],
|
|
960
|
+
[next(operand.args[0], directions)],
|
|
961
|
+
);
|
|
962
|
+
if (operand?.kind === "equiv" && direction !== undefined) {
|
|
963
|
+
const left = operand.args[0];
|
|
964
|
+
const right = operand.args[1];
|
|
965
|
+
const rule: MlRule = { name: "not_equiv", args: [left, right] };
|
|
966
|
+
// HACK: Zenon's right branch proves its second case from the negation of `right`.
|
|
967
|
+
return direction === "left"
|
|
968
|
+
? makeNode(
|
|
969
|
+
[formula],
|
|
970
|
+
rule,
|
|
971
|
+
[[right], [left]],
|
|
972
|
+
[decomposeDisjunction(right, forms), decomposeDisjunction(left, forms)],
|
|
973
|
+
)
|
|
974
|
+
: makeNode(
|
|
975
|
+
[formula],
|
|
976
|
+
rule,
|
|
977
|
+
[[exprs.enot(left)], [right]],
|
|
978
|
+
[
|
|
979
|
+
decomposeDisjunction(exprs.enot(left), forms),
|
|
980
|
+
decomposeDisjunction(exprs.enot(right), forms),
|
|
981
|
+
],
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
if (directions.length > 0 || variables.length > 0 || witnesses.length > 0)
|
|
985
|
+
throw new TlaZenonError("Zenon: decompose_conj left directions or variables");
|
|
986
|
+
return decomposeDisjunction(formula, forms);
|
|
987
|
+
};
|
|
988
|
+
|
|
989
|
+
// Zenon's Eqrel.get_proof: proves a relation hypothesis from the hypotheses that implied it,
|
|
990
|
+
// and returns the proof with those hypotheses.
|
|
991
|
+
const getRelationProof = (hypothesis: Expr): [MlProof, Expr[]] => {
|
|
992
|
+
const kind = hypothesisKinds.get(hypothesis);
|
|
993
|
+
if (kind === undefined)
|
|
994
|
+
throw new TlaZenonError("Zenon: an extra hypothesis that isn't a relation's");
|
|
995
|
+
const negation = exprs.enot(hypothesis);
|
|
996
|
+
const notAll = (formula: Expr, instance: Expr, subproof: MlProof) =>
|
|
997
|
+
makeNode([formula], { name: "notall", args: [formula] }, [[instance]], [subproof]);
|
|
998
|
+
const decompose = (origin: Origin, forms: Expr[], witnesses: Expr[]) =>
|
|
999
|
+
decomposeConjunction(
|
|
1000
|
+
0,
|
|
1001
|
+
origin.formula,
|
|
1002
|
+
origin.directions,
|
|
1003
|
+
origin.variables,
|
|
1004
|
+
forms,
|
|
1005
|
+
witnesses,
|
|
1006
|
+
);
|
|
1007
|
+
const getImplication = (formula: Expr) => {
|
|
1008
|
+
if (formula.kind !== "not" || formula.args[0].kind !== "imply")
|
|
1009
|
+
throw new TlaZenonError("Zenon: a relation hypothesis that isn't an implication");
|
|
1010
|
+
return formula.args[0];
|
|
1011
|
+
};
|
|
1012
|
+
const first = instantiateNegation(negation);
|
|
1013
|
+
if (kind.kind === "reflexive") {
|
|
1014
|
+
const proof = decompose(kind.origin, [first[0]], [first[1]]);
|
|
1015
|
+
return [notAll(negation, first[0], proof), [kind.origin.formula]];
|
|
1016
|
+
}
|
|
1017
|
+
const second = instantiateNegation(first[0]);
|
|
1018
|
+
if (kind.kind === "symmetric" || kind.kind === "symmetric2") {
|
|
1019
|
+
const implication = getImplication(second[0]);
|
|
1020
|
+
const premise = implication.args[0];
|
|
1021
|
+
const negatedConclusion = exprs.enot(implication.args[1]);
|
|
1022
|
+
const decomposed =
|
|
1023
|
+
kind.kind === "symmetric"
|
|
1024
|
+
? decompose(kind.origin, [premise, negatedConclusion], [first[1], second[1]])
|
|
1025
|
+
: (() => {
|
|
1026
|
+
const reflexive = relate(kind.relation, first[1], first[1]);
|
|
1027
|
+
const negatedReflexive = exprs.enot(reflexive);
|
|
1028
|
+
const fromReflexive = decompose(kind.reflexive, [negatedReflexive], [first[1]]);
|
|
1029
|
+
const fromTransitive = decompose(
|
|
1030
|
+
kind.transitiveSymmetric,
|
|
1031
|
+
[reflexive, premise, negatedConclusion],
|
|
1032
|
+
[first[1], first[1], second[1]],
|
|
1033
|
+
);
|
|
1034
|
+
return makeCut(reflexive, fromTransitive, fromReflexive);
|
|
1035
|
+
})();
|
|
1036
|
+
const proof = notAll(
|
|
1037
|
+
negation,
|
|
1038
|
+
first[0],
|
|
1039
|
+
notAll(
|
|
1040
|
+
first[0],
|
|
1041
|
+
second[0],
|
|
1042
|
+
makeNode(
|
|
1043
|
+
[second[0]],
|
|
1044
|
+
{ name: "not_impl", args: [premise, implication.args[1]] },
|
|
1045
|
+
[[premise, negatedConclusion]],
|
|
1046
|
+
[decomposed],
|
|
1047
|
+
),
|
|
1048
|
+
),
|
|
1049
|
+
);
|
|
1050
|
+
return [
|
|
1051
|
+
proof,
|
|
1052
|
+
kind.kind === "symmetric"
|
|
1053
|
+
? [kind.origin.formula]
|
|
1054
|
+
: [kind.reflexive.formula, kind.transitiveSymmetric.formula],
|
|
1055
|
+
];
|
|
1056
|
+
}
|
|
1057
|
+
const third = instantiateNegation(second[0]);
|
|
1058
|
+
const outer = getImplication(third[0]);
|
|
1059
|
+
const inner = outer.args[1];
|
|
1060
|
+
if (inner.kind !== "imply")
|
|
1061
|
+
throw new TlaZenonError("Zenon: a transitivity hypothesis that isn't an implication");
|
|
1062
|
+
const premise = outer.args[0];
|
|
1063
|
+
const middle = inner.args[0];
|
|
1064
|
+
const negatedConclusion = exprs.enot(inner.args[1]);
|
|
1065
|
+
const decomposed =
|
|
1066
|
+
kind.kind === "transitive"
|
|
1067
|
+
? decompose(
|
|
1068
|
+
kind.origin,
|
|
1069
|
+
[premise, middle, negatedConclusion],
|
|
1070
|
+
[first[1], second[1], third[1]],
|
|
1071
|
+
)
|
|
1072
|
+
: (() => {
|
|
1073
|
+
const reflexive = relate(kind.relation, first[1], first[1]);
|
|
1074
|
+
const negatedReflexive = exprs.enot(reflexive);
|
|
1075
|
+
const swapped = relate(kind.relation, third[1], first[1]);
|
|
1076
|
+
const negatedSwapped = exprs.enot(swapped);
|
|
1077
|
+
const fromSwapped = decompose(
|
|
1078
|
+
kind.transitiveSymmetric,
|
|
1079
|
+
[swapped, reflexive, negatedConclusion],
|
|
1080
|
+
[third[1], first[1], first[1]],
|
|
1081
|
+
);
|
|
1082
|
+
const toSwapped = decompose(
|
|
1083
|
+
kind.transitiveSymmetric,
|
|
1084
|
+
[premise, middle, negatedSwapped],
|
|
1085
|
+
[first[1], second[1], third[1]],
|
|
1086
|
+
);
|
|
1087
|
+
const swappedCut = makeCut(swapped, fromSwapped, toSwapped);
|
|
1088
|
+
const fromReflexive = decompose(kind.reflexive, [negatedReflexive], [first[1]]);
|
|
1089
|
+
return makeCut(reflexive, swappedCut, fromReflexive);
|
|
1090
|
+
})();
|
|
1091
|
+
const proof = notAll(
|
|
1092
|
+
negation,
|
|
1093
|
+
first[0],
|
|
1094
|
+
notAll(
|
|
1095
|
+
first[0],
|
|
1096
|
+
second[0],
|
|
1097
|
+
notAll(
|
|
1098
|
+
second[0],
|
|
1099
|
+
third[0],
|
|
1100
|
+
makeNode(
|
|
1101
|
+
[third[0]],
|
|
1102
|
+
{ name: "not_impl", args: [premise, inner] },
|
|
1103
|
+
[[premise, exprs.enot(inner)]],
|
|
1104
|
+
[
|
|
1105
|
+
// HACK: Zenon concludes the inner implication itself, not its negation.
|
|
1106
|
+
makeNode(
|
|
1107
|
+
[inner],
|
|
1108
|
+
{ name: "not_impl", args: [middle, inner.args[1]] },
|
|
1109
|
+
[[middle, negatedConclusion]],
|
|
1110
|
+
[decomposed],
|
|
1111
|
+
),
|
|
1112
|
+
],
|
|
1113
|
+
),
|
|
1114
|
+
),
|
|
1115
|
+
),
|
|
1116
|
+
);
|
|
1117
|
+
return [
|
|
1118
|
+
proof,
|
|
1119
|
+
kind.kind === "transitive"
|
|
1120
|
+
? [kind.origin.formula]
|
|
1121
|
+
: [kind.reflexive.formula, kind.transitiveSymmetric.formula],
|
|
1122
|
+
];
|
|
1123
|
+
};
|
|
1124
|
+
|
|
1125
|
+
const relate = (relation: string, left: Expr, right: Expr) => exprs.eapp(relation, [left, right]);
|
|
1126
|
+
|
|
1127
|
+
// Zenon's make_direct_trans: r(a, b), r(b, c) / r(a, c) / (proof).
|
|
1128
|
+
const makeDirectTrans = (relation: string, a: Expr, b: Expr, c: Expr, proof: MlProof) => {
|
|
1129
|
+
const hypothesis = getRelationHypothesis("transitive", relation);
|
|
1130
|
+
const ab = relate(relation, a, b);
|
|
1131
|
+
const bc = relate(relation, b, c);
|
|
1132
|
+
const implied = makeImplies(
|
|
1133
|
+
[ab, bc],
|
|
1134
|
+
relate(relation, a, c),
|
|
1135
|
+
[makeClose(ab), makeClose(bc)],
|
|
1136
|
+
proof,
|
|
1137
|
+
);
|
|
1138
|
+
return makeAlls(hypothesis, [a, b, c], implied[1]);
|
|
1139
|
+
};
|
|
1140
|
+
// Zenon's make_direct_nsym: -r(a, b) / -r(b, a) / (proof).
|
|
1141
|
+
const makeDirectNotSym = (relation: string, a: Expr, b: Expr, proof: MlProof) => {
|
|
1142
|
+
const hypothesis = getRelationHypothesis("symmetric", relation);
|
|
1143
|
+
const ab = relate(relation, a, b);
|
|
1144
|
+
const ba = relate(relation, b, a);
|
|
1145
|
+
return makeAlls(hypothesis, [b, a], makeImply(ba, ab, proof, makeClose(ab)));
|
|
1146
|
+
};
|
|
1147
|
+
// Zenon's make_direct_sym_neq: a != b / b != a / (proof).
|
|
1148
|
+
const makeSymmetricDisequality = (a: Expr, b: Expr, proof: MlProof) => {
|
|
1149
|
+
const reflexive = equal(b, b);
|
|
1150
|
+
const refuted = makeCloseRefl("=", b);
|
|
1151
|
+
const swapped = makePNotP(reflexive, exprs.enot(equal(a, b)), [proof, refuted]);
|
|
1152
|
+
return makeCut(reflexive, swapped, refuted);
|
|
1153
|
+
};
|
|
1154
|
+
// Zenon's make_direct_sym_eq: a = b / b = a / (proof).
|
|
1155
|
+
const makeSymmetricEquality = (a: Expr, b: Expr, proof: MlProof) => {
|
|
1156
|
+
const ab = equal(a, b);
|
|
1157
|
+
return makeCut(equal(b, a), proof, makeSymmetricDisequality(b, a, makeClose(ab)));
|
|
1158
|
+
};
|
|
1159
|
+
|
|
1160
|
+
const expandTrans = (
|
|
1161
|
+
relation: string,
|
|
1162
|
+
a: Expr,
|
|
1163
|
+
b: Expr,
|
|
1164
|
+
c: Expr,
|
|
1165
|
+
d: Expr,
|
|
1166
|
+
first: MlProof,
|
|
1167
|
+
second: MlProof,
|
|
1168
|
+
) => {
|
|
1169
|
+
const ca = equal(c, a);
|
|
1170
|
+
const notCa = exprs.enot(ca);
|
|
1171
|
+
const relatedCa = relate(relation, c, a);
|
|
1172
|
+
const notRelatedCa = exprs.enot(relatedCa);
|
|
1173
|
+
const bd = equal(b, d);
|
|
1174
|
+
const notRelatedCd = exprs.enot(relate(relation, c, d));
|
|
1175
|
+
const either = exprs.eand(notCa, notRelatedCa);
|
|
1176
|
+
const closeBd = makeClose(bd);
|
|
1177
|
+
const viaB = makeNotAnd(
|
|
1178
|
+
notCa,
|
|
1179
|
+
notRelatedCa,
|
|
1180
|
+
makeNotNot(ca, makeSymmetricDisequality(a, c, makeClose(ca))),
|
|
1181
|
+
makeNotNot(
|
|
1182
|
+
relatedCa,
|
|
1183
|
+
makeDirectTrans(
|
|
1184
|
+
relation,
|
|
1185
|
+
c,
|
|
1186
|
+
a,
|
|
1187
|
+
b,
|
|
1188
|
+
makePNotP(relate(relation, c, b), notRelatedCd, [makeCloseRefl("=", c), closeBd]),
|
|
1189
|
+
),
|
|
1190
|
+
),
|
|
1191
|
+
);
|
|
1192
|
+
const viaD = makeNotAnd(
|
|
1193
|
+
notCa,
|
|
1194
|
+
notRelatedCa,
|
|
1195
|
+
makeNotNot(ca, makeCloseSym("=", c, a)),
|
|
1196
|
+
makeNotNot(relatedCa, makeDirectTrans(relation, c, a, d, makeClose(relate(relation, c, d)))),
|
|
1197
|
+
);
|
|
1198
|
+
const fromBd = makePNotP(relate(relation, a, b), notRelatedCd, [viaB, closeBd]);
|
|
1199
|
+
const fromBdRelated = makeDirectTrans(
|
|
1200
|
+
relation,
|
|
1201
|
+
a,
|
|
1202
|
+
b,
|
|
1203
|
+
d,
|
|
1204
|
+
makePNotP(relate(relation, a, d), notRelatedCd, [viaD, makeCloseRefl("=", d)]),
|
|
1205
|
+
);
|
|
1206
|
+
const cutBd = makeCut(bd, fromBd, makeCut(relate(relation, b, d), fromBdRelated, second));
|
|
1207
|
+
return makeCut(either, makeAnd(notCa, notRelatedCa, first), cutBd);
|
|
1208
|
+
};
|
|
1209
|
+
|
|
1210
|
+
const expandTransEq = (
|
|
1211
|
+
relation: string,
|
|
1212
|
+
a: Expr,
|
|
1213
|
+
b: Expr,
|
|
1214
|
+
c: Expr,
|
|
1215
|
+
d: Expr,
|
|
1216
|
+
proofs: [MlProof, MlProof, MlProof],
|
|
1217
|
+
) => {
|
|
1218
|
+
const cd = relate(relation, c, d);
|
|
1219
|
+
const bd = relate(relation, b, d);
|
|
1220
|
+
const cb = relate(relation, c, b);
|
|
1221
|
+
const ca = relate(relation, c, a);
|
|
1222
|
+
const ad = relate(relation, a, d);
|
|
1223
|
+
const notCd = exprs.enot(cd);
|
|
1224
|
+
const closeReflC = makeCloseRefl("=", c);
|
|
1225
|
+
const closeAb = makeClose(equal(a, b));
|
|
1226
|
+
const closeReflD = makeCloseRefl("=", d);
|
|
1227
|
+
const toCb = makePNotP(cb, notCd, [
|
|
1228
|
+
closeReflC,
|
|
1229
|
+
makeCut(bd, makeDirectTrans(relation, c, b, d, makeClose(cd)), proofs[2]),
|
|
1230
|
+
]);
|
|
1231
|
+
const fromCb = makePNotP(ca, exprs.enot(cb), [closeReflC, closeAb]);
|
|
1232
|
+
const toAd = makePNotP(ad, notCd, [makeSymmetricDisequality(a, c, proofs[0]), closeReflD]);
|
|
1233
|
+
const fromAd = makePNotP(bd, exprs.enot(ad), [
|
|
1234
|
+
makeSymmetricDisequality(b, a, closeAb),
|
|
1235
|
+
closeReflD,
|
|
1236
|
+
]);
|
|
1237
|
+
return makeCut(
|
|
1238
|
+
ca,
|
|
1239
|
+
makeCut(cb, toCb, fromCb),
|
|
1240
|
+
makeCut(bd, makeCut(ad, toAd, fromAd), proofs[1]),
|
|
1241
|
+
);
|
|
1242
|
+
};
|
|
1243
|
+
|
|
1244
|
+
const expandTransEqual = (
|
|
1245
|
+
a: Expr,
|
|
1246
|
+
b: Expr,
|
|
1247
|
+
c: Expr,
|
|
1248
|
+
d: Expr,
|
|
1249
|
+
first: MlProof,
|
|
1250
|
+
second: MlProof,
|
|
1251
|
+
) => {
|
|
1252
|
+
const symmetric = makeSymmetricDisequality(a, c, first);
|
|
1253
|
+
return makePNotP(equal(a, b), exprs.enot(equal(c, d)), [symmetric, second]);
|
|
1254
|
+
};
|
|
1255
|
+
|
|
1256
|
+
const getRelation = (formula: Expr) => {
|
|
1257
|
+
const atom = formula.kind === "not" ? formula.args[0] : formula;
|
|
1258
|
+
if (atom.kind !== "app" || atom.args.length !== 2)
|
|
1259
|
+
throw new TlaZenonError("Zenon: a transitivity rule on a formula that isn't a relation");
|
|
1260
|
+
return atom;
|
|
1261
|
+
};
|
|
1262
|
+
|
|
1263
|
+
const getThree = (proof: MlProof): [MlProof, MlProof, MlProof] => {
|
|
1264
|
+
if (proof.subproofs.length !== 3) throw new TlaZenonError("Zenon: expected three subproofs");
|
|
1265
|
+
return [proof.subproofs[0], proof.subproofs[1], proof.subproofs[2]];
|
|
1266
|
+
};
|
|
1267
|
+
|
|
1268
|
+
// A derived rule's expansion, with the hypotheses it relies on that no phrase may state.
|
|
1269
|
+
const translateWith = (expanded: MlProof, hypotheses: Expr[]): Translated => {
|
|
1270
|
+
const translated = translate(expanded);
|
|
1271
|
+
return [translated[0], union(hypotheses, translated[1])];
|
|
1272
|
+
};
|
|
1273
|
+
|
|
1274
|
+
const translateDerived = (proof: MlProof): Translated => {
|
|
1275
|
+
const rule = proof.rule;
|
|
1276
|
+
switch (rule.name) {
|
|
1277
|
+
case "definition": {
|
|
1278
|
+
if (rule.definition.kind !== "pseudo")
|
|
1279
|
+
throw new TlaZenonError("Zenon: a real definition in translate_derived");
|
|
1280
|
+
const expanded = translatePseudoDefinition(
|
|
1281
|
+
proof,
|
|
1282
|
+
rule.definition,
|
|
1283
|
+
rule.args[0],
|
|
1284
|
+
rule.args[1],
|
|
1285
|
+
);
|
|
1286
|
+
return translateWith(expanded, [rule.definition.origin]);
|
|
1287
|
+
}
|
|
1288
|
+
case "conj_tree":
|
|
1289
|
+
return recompConj(translate(getSingle(proof)), rule.args[0]);
|
|
1290
|
+
case "disj_tree": {
|
|
1291
|
+
const result = recompDisj(proof.subproofs.map(translate), rule.args[0]);
|
|
1292
|
+
if (result[2].length > 0)
|
|
1293
|
+
throw new TlaZenonError("Zenon: a disjunction tree with extra subproofs");
|
|
1294
|
+
return [result[0], result[1]];
|
|
1295
|
+
}
|
|
1296
|
+
case "close_sym": {
|
|
1297
|
+
const hypothesis = getRelationHypothesis("symmetric", rule.relation);
|
|
1298
|
+
const [a, b] = rule.args;
|
|
1299
|
+
const ab = relate(rule.relation, a, b);
|
|
1300
|
+
const ba = relate(rule.relation, b, a);
|
|
1301
|
+
const implied = makeImply(ab, ba, makeClose(ab), makeClose(ba));
|
|
1302
|
+
return translateWith(makeAlls(hypothesis, [a, b], implied), [hypothesis]);
|
|
1303
|
+
}
|
|
1304
|
+
case "close_refl": {
|
|
1305
|
+
const hypothesis = getRelationHypothesis("reflexive", rule.relation);
|
|
1306
|
+
const a = rule.args[0];
|
|
1307
|
+
return translateWith(makeAll(hypothesis, a, makeClose(relate(rule.relation, a, a))), [
|
|
1308
|
+
hypothesis,
|
|
1309
|
+
]);
|
|
1310
|
+
}
|
|
1311
|
+
case "refl": {
|
|
1312
|
+
const hypothesis = getRelationHypothesis("reflexive", rule.relation);
|
|
1313
|
+
const [a, b] = rule.args;
|
|
1314
|
+
const reflexive = relate(rule.relation, a, a);
|
|
1315
|
+
const negated = exprs.enot(relate(rule.relation, a, b));
|
|
1316
|
+
const closed = makePNotP(reflexive, negated, [makeCloseRefl("=", a), getSingle(proof)]);
|
|
1317
|
+
return translateWith(makeAll(hypothesis, a, closed), [hypothesis]);
|
|
1318
|
+
}
|
|
1319
|
+
case "p_not_p_sym": {
|
|
1320
|
+
const positive = getRelation(rule.args[0]);
|
|
1321
|
+
const negative = getRelation(rule.args[1]);
|
|
1322
|
+
if (rule.relation === "=") {
|
|
1323
|
+
const swapped = exprs.enot(equal(negative.args[1], negative.args[0]));
|
|
1324
|
+
const node = makePNotP(rule.args[0], swapped, [proof.subproofs[1], proof.subproofs[0]]);
|
|
1325
|
+
return translate(makeSymmetricDisequality(negative.args[0], negative.args[1], node));
|
|
1326
|
+
}
|
|
1327
|
+
const hypothesis = getRelationHypothesis("symmetric", rule.relation);
|
|
1328
|
+
const [a, b] = positive.args;
|
|
1329
|
+
const ba = relate(rule.relation, b, a);
|
|
1330
|
+
const node = makePNotP(ba, rule.args[1], [proof.subproofs[0], proof.subproofs[1]]);
|
|
1331
|
+
const implied = makeImply(rule.args[0], ba, makeClose(rule.args[0]), node);
|
|
1332
|
+
return translateWith(makeAlls(hypothesis, [a, b], implied), [hypothesis]);
|
|
1333
|
+
}
|
|
1334
|
+
case "trans":
|
|
1335
|
+
case "trans_sym": {
|
|
1336
|
+
const positive = getRelation(rule.args[0]);
|
|
1337
|
+
const relation = positive.symbol;
|
|
1338
|
+
const [a, b] = positive.args;
|
|
1339
|
+
const [c, d] = getRelation(rule.args[1]).args;
|
|
1340
|
+
const first = proof.subproofs[0];
|
|
1341
|
+
const second = proof.subproofs[1];
|
|
1342
|
+
if (relation === "=")
|
|
1343
|
+
return rule.name === "trans"
|
|
1344
|
+
? translate(expandTransEqual(a, b, c, d, first, second))
|
|
1345
|
+
: translate(
|
|
1346
|
+
makeSymmetricDisequality(c, d, expandTransEqual(a, b, d, c, first, second)),
|
|
1347
|
+
);
|
|
1348
|
+
if (rule.name === "trans")
|
|
1349
|
+
return translateWith(expandTrans(relation, a, b, c, d, first, second), [
|
|
1350
|
+
getRelationHypothesis("transitive", relation),
|
|
1351
|
+
]);
|
|
1352
|
+
const expanded = makeDirectNotSym(
|
|
1353
|
+
relation,
|
|
1354
|
+
c,
|
|
1355
|
+
d,
|
|
1356
|
+
expandTrans(relation, a, b, d, c, first, second),
|
|
1357
|
+
);
|
|
1358
|
+
return translateWith(expanded, [
|
|
1359
|
+
getRelationHypothesis("transitive", relation),
|
|
1360
|
+
getRelationHypothesis("symmetric", relation),
|
|
1361
|
+
]);
|
|
1362
|
+
}
|
|
1363
|
+
case "trans_eq":
|
|
1364
|
+
case "trans_eq2":
|
|
1365
|
+
case "trans_eq_sym": {
|
|
1366
|
+
const negative = getRelation(rule.args[2]);
|
|
1367
|
+
const relation = negative.symbol;
|
|
1368
|
+
const [c, d] = negative.args;
|
|
1369
|
+
const a = rule.args[0];
|
|
1370
|
+
const b = rule.args[1];
|
|
1371
|
+
const proofs = getThree(proof);
|
|
1372
|
+
if (relation === "=" && rule.name === "trans_eq")
|
|
1373
|
+
return translate(expandTransEqual(a, b, c, d, proofs[0], proofs[2]));
|
|
1374
|
+
if (relation === "=" && rule.name === "trans_eq_sym")
|
|
1375
|
+
return translate(
|
|
1376
|
+
makeSymmetricDisequality(c, d, expandTransEqual(a, b, d, c, proofs[0], proofs[2])),
|
|
1377
|
+
);
|
|
1378
|
+
const hypothesis = getRelationHypothesis("transitive", relation);
|
|
1379
|
+
const expanded =
|
|
1380
|
+
rule.name === "trans_eq"
|
|
1381
|
+
? expandTransEq(relation, a, b, c, d, proofs)
|
|
1382
|
+
: rule.name === "trans_eq2"
|
|
1383
|
+
? makeSymmetricEquality(a, b, expandTransEq(relation, b, a, c, d, proofs))
|
|
1384
|
+
: makeDirectNotSym(relation, c, d, expandTransEq(relation, a, b, d, c, proofs));
|
|
1385
|
+
return translateWith(expanded, [hypothesis]);
|
|
1386
|
+
}
|
|
1387
|
+
case "not_all_ex": {
|
|
1388
|
+
const negation = rule.args[0];
|
|
1389
|
+
const quantified = negation.kind === "not" ? negation.args[0] : negation;
|
|
1390
|
+
const binder = getBinder(quantified, "all");
|
|
1391
|
+
const variable = binder.args[0];
|
|
1392
|
+
const body = binder.args[1];
|
|
1393
|
+
const existential = exprs.eex(variable, binder.symbol, exprs.enot(body));
|
|
1394
|
+
const lambda = exprs.elam(variable, binder.symbol, body);
|
|
1395
|
+
const witnessed = makeExistential(existential, getSingle(proof));
|
|
1396
|
+
return translate(
|
|
1397
|
+
makeNode([negation], { name: "notallex", args: [lambda] }, [[existential]], [witnessed]),
|
|
1398
|
+
);
|
|
1399
|
+
}
|
|
1400
|
+
default:
|
|
1401
|
+
return getTlaLlProof(translateExpr, exprs, proof, proof.subproofs.map(translate));
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
|
|
1405
|
+
// Zenon's make_ex.
|
|
1406
|
+
const makeExistential = (existential: Expr, subproof: MlProof) => {
|
|
1407
|
+
const binder = getBinder(existential, "ex");
|
|
1408
|
+
const witness = exprs.etau(binder.args[0], binder.symbol, binder.args[1]);
|
|
1409
|
+
const instance = exprs.substitute([[binder.args[0], witness]], binder.args[1]);
|
|
1410
|
+
return makeNode([existential], { name: "ex", args: [existential] }, [[instance]], [subproof]);
|
|
1411
|
+
};
|
|
1412
|
+
|
|
1413
|
+
// Zenon's find_diff: the context in which two formulas differ, and the two subterms.
|
|
1414
|
+
const findDiff = (variable: VarExpr, left: Expr, right: Expr): [Expr, Expr, Expr] => {
|
|
1415
|
+
if (left === right) throw new TlaZenonError("Zenon: find_diff on equal formulas");
|
|
1416
|
+
if (left.kind === "app" && right.kind === "app" && left.symbol === right.symbol) {
|
|
1417
|
+
const position = left.args.findIndex((arg, index) => arg !== right.args[index]);
|
|
1418
|
+
const diff = findDiff(variable, left.args[position], right.args[position]);
|
|
1419
|
+
return [
|
|
1420
|
+
exprs.eapp(
|
|
1421
|
+
left.symbol,
|
|
1422
|
+
left.args.map((arg, index) => (index === position ? diff[0] : arg)),
|
|
1423
|
+
),
|
|
1424
|
+
diff[1],
|
|
1425
|
+
diff[2],
|
|
1426
|
+
];
|
|
1427
|
+
}
|
|
1428
|
+
if (left.kind === "not" && right.kind === "not") {
|
|
1429
|
+
const diff = findDiff(variable, left.args[0], right.args[0]);
|
|
1430
|
+
return [exprs.enot(diff[0]), diff[1], diff[2]];
|
|
1431
|
+
}
|
|
1432
|
+
// HACK: Zenon compares every binary connective with a conjunction here.
|
|
1433
|
+
if (
|
|
1434
|
+
(left.kind === "and" ||
|
|
1435
|
+
left.kind === "or" ||
|
|
1436
|
+
left.kind === "imply" ||
|
|
1437
|
+
left.kind === "equiv") &&
|
|
1438
|
+
right.kind === "and"
|
|
1439
|
+
) {
|
|
1440
|
+
if (left.args[0] === right.args[0]) {
|
|
1441
|
+
const diff = findDiff(variable, left.args[1], right.args[1]);
|
|
1442
|
+
return [connect(exprs, left.kind, left.args[0], diff[0]), diff[1], diff[2]];
|
|
1443
|
+
}
|
|
1444
|
+
const diff = findDiff(variable, left.args[0], right.args[0]);
|
|
1445
|
+
return [connect(exprs, left.kind, diff[0], left.args[1]), diff[1], diff[2]];
|
|
1446
|
+
}
|
|
1447
|
+
if (
|
|
1448
|
+
left.kind === right.kind &&
|
|
1449
|
+
(left.kind === "all" || left.kind === "ex" || left.kind === "tau" || left.kind === "lam")
|
|
1450
|
+
)
|
|
1451
|
+
throw new TlaZenonError("Zenon: find_diff under a binder");
|
|
1452
|
+
return [variable, left, right];
|
|
1453
|
+
};
|
|
1454
|
+
|
|
1455
|
+
// Zenon's translate_pseudo_def: instantiates the defining hypothesis, then rewrites with it.
|
|
1456
|
+
const translatePseudoDefinition = (
|
|
1457
|
+
proof: MlProof,
|
|
1458
|
+
definition: Extract<Definition, { kind: "pseudo" }>,
|
|
1459
|
+
folded: Expr,
|
|
1460
|
+
unfolded: Expr,
|
|
1461
|
+
): MlProof => {
|
|
1462
|
+
const origin = definition.origin;
|
|
1463
|
+
const diffArgs = (() => {
|
|
1464
|
+
const diff = findDiff(exprs.newVar(), folded, unfolded);
|
|
1465
|
+
if (diff[1].kind === "app") return diff[1].args;
|
|
1466
|
+
if (diff[1].kind === "var") return [];
|
|
1467
|
+
throw new TlaZenonError("Zenon: a pseudo-definition of something other than a symbol");
|
|
1468
|
+
})();
|
|
1469
|
+
const universals: [Expr, Expr][] = [];
|
|
1470
|
+
for (let current = origin; current.kind === "all"; current = current.args[1])
|
|
1471
|
+
universals.push([current.args[0], current]);
|
|
1472
|
+
const actuals = universals.map((entry, position) => {
|
|
1473
|
+
const isRepeated = universals.slice(position + 1).some((later) => later[0] === entry[0]);
|
|
1474
|
+
const index = definition.params.indexOf(entry[0]);
|
|
1475
|
+
return isRepeated || index === -1 ? exprs.emeta(entry[1]) : diffArgs[index];
|
|
1476
|
+
});
|
|
1477
|
+
const build = (hypothesis: Expr, remaining: Expr[]): MlProof => {
|
|
1478
|
+
if (remaining.length > 0) {
|
|
1479
|
+
const binder = getBinder(hypothesis, "all");
|
|
1480
|
+
const instance = exprs.substitute([[binder.args[0], remaining[0]]], binder.args[1]);
|
|
1481
|
+
const sub = build(instance, remaining.slice(1));
|
|
1482
|
+
return makeNode(
|
|
1483
|
+
[hypothesis],
|
|
1484
|
+
{ name: "all", args: [hypothesis, remaining[0]] },
|
|
1485
|
+
[[instance]],
|
|
1486
|
+
[sub],
|
|
1487
|
+
);
|
|
1488
|
+
}
|
|
1489
|
+
const subproof = getSingle(proof);
|
|
1490
|
+
if (hypothesis.kind === "equiv") {
|
|
1491
|
+
const isCrossed = folded.kind === "not" && unfolded.kind === "not";
|
|
1492
|
+
const formula = isCrossed && folded.kind === "not" ? folded.args[0] : folded;
|
|
1493
|
+
const negated = isCrossed ? folded : exprs.enot(folded);
|
|
1494
|
+
const unfoldedFormula = isCrossed && unfolded.kind === "not" ? unfolded.args[0] : unfolded;
|
|
1495
|
+
const unfoldedNegated = isCrossed ? unfolded : exprs.enot(unfolded);
|
|
1496
|
+
const closed = makeClose(formula);
|
|
1497
|
+
const rule: Rule = { name: "equiv", args: [hypothesis.args[0], hypothesis.args[1]] };
|
|
1498
|
+
return isCrossed
|
|
1499
|
+
? makeNode([hypothesis], rule, [[unfoldedNegated], [formula]], [subproof, closed])
|
|
1500
|
+
: makeNode([hypothesis], rule, [[negated], [unfoldedFormula]], [closed, subproof]);
|
|
1501
|
+
}
|
|
1502
|
+
if (hypothesis.kind === "app" && hypothesis.symbol === "=" && hypothesis.args.length === 2) {
|
|
1503
|
+
if (folded === exprs.enot(hypothesis))
|
|
1504
|
+
return makeNode([folded, hypothesis], { name: "close", args: [hypothesis] }, [], []);
|
|
1505
|
+
const isDefinedOnLeft = definesSymbol(hypothesis.args[0], definition.symbol);
|
|
1506
|
+
if (!isDefinedOnLeft && !definesSymbol(hypothesis.args[1], definition.symbol))
|
|
1507
|
+
throw new TlaZenonError("Zenon: a pseudo-definition that doesn't define its symbol");
|
|
1508
|
+
const variable = exprs.newVar();
|
|
1509
|
+
const diff = findDiff(variable, folded, unfolded);
|
|
1510
|
+
const lambda = exprs.elam(variable, "", diff[0]);
|
|
1511
|
+
const a = diff[1];
|
|
1512
|
+
const b = diff[2];
|
|
1513
|
+
return isDefinedOnLeft
|
|
1514
|
+
? makeNode(
|
|
1515
|
+
[exprs.apply(lambda, a), equal(a, b)],
|
|
1516
|
+
{ name: "congruence_lr", args: [lambda, a, b] },
|
|
1517
|
+
[[exprs.apply(lambda, b)]],
|
|
1518
|
+
[subproof],
|
|
1519
|
+
)
|
|
1520
|
+
: makeNode(
|
|
1521
|
+
[exprs.apply(lambda, a), equal(b, a)],
|
|
1522
|
+
{ name: "congruence_rl", args: [lambda, a, b] },
|
|
1523
|
+
[[exprs.apply(lambda, b)]],
|
|
1524
|
+
[subproof],
|
|
1525
|
+
);
|
|
1526
|
+
}
|
|
1527
|
+
throw new TlaZenonError("Zenon: a pseudo-definition of an unexpected shape");
|
|
1528
|
+
};
|
|
1529
|
+
return build(origin, actuals);
|
|
1530
|
+
};
|
|
1531
|
+
|
|
1532
|
+
const definesSymbol = (side: Expr, symbol: string) =>
|
|
1533
|
+
(side.kind === "app" || side.kind === "var") && side.symbol === symbol;
|
|
1534
|
+
|
|
1535
|
+
const translated = translate(proof);
|
|
1536
|
+
const isCharged = (formula: Expr) =>
|
|
1537
|
+
!phrases.some((phrase) => phrase.kind === "hyp" && phrase.formula === formula);
|
|
1538
|
+
// Zenon's discharge_extra: cuts each hypothesis about a relation that the phrases don't state,
|
|
1539
|
+
// and proves it from the hypotheses that do.
|
|
1540
|
+
const discharged = translated[1].filter(isCharged).reduce((current: LlProof, extra): LlProof => {
|
|
1541
|
+
const relationProof = getRelationProof(extra);
|
|
1542
|
+
const proved = translate(relationProof[0]);
|
|
1543
|
+
if (proved[1].length > 0) throw new TlaZenonError("Zenon: a relation proof with extras");
|
|
1544
|
+
const formula = translateExpr(extra);
|
|
1545
|
+
return {
|
|
1546
|
+
conclusions: union(
|
|
1547
|
+
relationProof[1].map(translateExpr),
|
|
1548
|
+
difference(current.conclusions, [formula]),
|
|
1549
|
+
),
|
|
1550
|
+
rule: { kind: "cut", formula },
|
|
1551
|
+
subproofs: [current, proved[0]],
|
|
1552
|
+
};
|
|
1553
|
+
}, translated[0]);
|
|
1554
|
+
return [...lemmas, { name: "zenon_thm", params: [], proof: discharged }];
|
|
1555
|
+
};
|
|
1556
|
+
|
|
1557
|
+
const RULE_CONNECTIVES = {
|
|
1558
|
+
and: "and",
|
|
1559
|
+
or: "or",
|
|
1560
|
+
impl: "imply",
|
|
1561
|
+
equiv: "equiv",
|
|
1562
|
+
not_or: "or",
|
|
1563
|
+
not_impl: "imply",
|
|
1564
|
+
not_and: "and",
|
|
1565
|
+
not_equiv: "equiv",
|
|
1566
|
+
} as const;
|