tla-ts 0.0.9 → 0.0.10-dev.63a6693bd
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 +29 -1
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +29 -29
- package/dist/deciders.js +42 -42
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +106 -10
- package/dist/index.d.ts +106 -10
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +117 -37
- package/dist/prove.js +116 -36
- package/dist/run.cjs +143 -31
- package/dist/run.js +143 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +129 -104
- package/dist/transfer.js +129 -104
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +3 -1
- package/src/ast.ts +48 -62
- package/src/bags.ts +99 -102
- package/src/builtins.ts +28 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check-failure.ts +116 -0
- package/src/check-trace.ts +282 -0
- package/src/check.ts +599 -754
- package/src/cli/options.ts +12 -32
- package/src/cli/run.ts +0 -2
- package/src/cli/runtime-invariants.ts +136 -0
- package/src/cli/shared.ts +19 -12
- package/src/cli/tlapm.ts +14 -25
- package/src/cli/tlc-arguments.ts +652 -0
- package/src/cli/tlc-output.ts +687 -0
- package/src/cli/tlc-usage.ts +361 -0
- package/src/cli/tlc.ts +309 -658
- package/src/cli/typescript.ts +23 -0
- package/src/cli/xml-exporter.ts +27 -49
- package/src/cli.ts +0 -1
- package/src/codegen.ts +196 -74
- package/src/config.ts +140 -109
- package/src/coverage.ts +830 -0
- package/src/dependencies.ts +14 -53
- package/src/dfid.ts +618 -0
- package/src/environment-config.ts +315 -0
- package/src/environment.ts +169 -335
- package/src/errors.ts +71 -55
- package/src/evaluate.ts +598 -340
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +75 -11
- package/src/index.ts +3 -0
- package/src/instances.ts +126 -21
- package/src/java-hash.ts +7 -0
- package/src/java-overrides.ts +4 -19
- package/src/json-reader.ts +455 -0
- package/src/json.ts +252 -139
- package/src/levels.ts +46 -58
- package/src/lexer.ts +80 -100
- package/src/liveness-checker.ts +103 -153
- package/src/liveness.ts +150 -109
- package/src/obligations/action.ts +8 -39
- package/src/obligations/anonymize.ts +88 -82
- package/src/obligations/equality.ts +1 -1
- package/src/obligations/expression.ts +20 -21
- package/src/obligations/format.ts +1 -9
- package/src/obligations/generate.ts +46 -49
- package/src/obligations/index.ts +2 -13
- package/src/obligations/levels.ts +4 -8
- package/src/obligations/module.ts +28 -53
- package/src/obligations/normalize.ts +7 -25
- package/src/obligations/operators.ts +1 -2
- package/src/obligations/pragma.ts +1 -10
- package/src/obligations/printer.ts +47 -46
- package/src/obligations/proof.ts +1 -5
- package/src/obligations/regroup.ts +1 -4
- package/src/obligations/simplify.ts +42 -58
- package/src/obligations/source.ts +48 -78
- package/src/obligations/subexpression.ts +5 -11
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +13 -19
- package/src/obligations/tuples.ts +3 -9
- package/src/parallel-worker.ts +30 -60
- package/src/parallel.ts +57 -71
- package/src/parser.ts +584 -316
- package/src/pcal/ast.ts +53 -86
- package/src/pcal/parse.ts +144 -219
- package/src/pcal/tokenize.ts +91 -131
- package/src/pcal/translate.ts +83 -130
- package/src/pcal/validate.ts +48 -68
- package/src/pretty-print.ts +7 -8
- package/src/prover/decide-pool.ts +8 -13
- package/src/prover/deciders.ts +3 -7
- package/src/prover/first-order.ts +0 -11
- package/src/prover/isabelle/decide.ts +0 -6
- package/src/prover/isabelle/encode.ts +11 -23
- package/src/prover/isabelle/isar/inner-syntax.ts +114 -115
- package/src/prover/isabelle/isar/method.ts +29 -53
- package/src/prover/isabelle/isar/proof.ts +1 -10
- package/src/prover/isabelle/isar/statement.ts +1 -6
- package/src/prover/isabelle/isar/theory.ts +26 -36
- package/src/prover/isabelle/isar/type-check.ts +17 -31
- package/src/prover/isabelle/provers/blast/blast.ts +17 -104
- package/src/prover/isabelle/provers/blast/branch.ts +1 -32
- package/src/prover/isabelle/provers/blast/prove.ts +1 -35
- package/src/prover/isabelle/provers/blast/rules.ts +6 -44
- package/src/prover/isabelle/provers/blast/state.ts +2 -28
- package/src/prover/isabelle/provers/blast/term.ts +9 -36
- package/src/prover/isabelle/provers/clasimp.ts +1 -13
- package/src/prover/isabelle/provers/classical.ts +14 -42
- package/src/prover/isabelle/provers/hypsubst.ts +28 -51
- package/src/prover/isabelle/pure/bicompose.ts +25 -38
- package/src/prover/isabelle/pure/consts.ts +1 -7
- package/src/prover/isabelle/pure/conv.ts +3 -17
- package/src/prover/isabelle/pure/drule.ts +33 -42
- package/src/prover/isabelle/pure/envir.ts +3 -52
- package/src/prover/isabelle/pure/goal.ts +1 -7
- package/src/prover/isabelle/pure/interrupt.ts +0 -5
- package/src/prover/isabelle/pure/list.ts +0 -3
- package/src/prover/isabelle/pure/logic.ts +2 -15
- package/src/prover/isabelle/pure/name.ts +2 -9
- package/src/prover/isabelle/pure/net.ts +3 -59
- package/src/prover/isabelle/pure/object-logic.ts +3 -10
- package/src/prover/isabelle/pure/pattern.ts +2 -19
- package/src/prover/isabelle/pure/raw-simplifier.ts +17 -62
- package/src/prover/isabelle/pure/rewriter.ts +31 -67
- package/src/prover/isabelle/pure/search.ts +3 -10
- package/src/prover/isabelle/pure/seq.ts +1 -10
- package/src/prover/isabelle/pure/simplifier.ts +4 -12
- package/src/prover/isabelle/pure/table.ts +3 -32
- package/src/prover/isabelle/pure/tactic.ts +12 -22
- package/src/prover/isabelle/pure/tactical.ts +48 -47
- package/src/prover/isabelle/pure/term-ord.ts +2 -6
- package/src/prover/isabelle/pure/term.ts +2 -43
- package/src/prover/isabelle/pure/thm.ts +27 -47
- package/src/prover/isabelle/pure/type.ts +2 -15
- package/src/prover/isabelle/pure/unify.ts +20 -30
- package/src/prover/isabelle/pure/variable.ts +3 -7
- package/src/prover/isabelle/tla/classical-setup.ts +17 -24
- package/src/prover/isabelle/tla/context.ts +15 -18
- package/src/prover/isabelle/tla/logic.ts +14 -32
- package/src/prover/isabelle/tla/simpdata.ts +46 -43
- package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
- package/src/prover/ocaml.ts +0 -6
- package/src/prover/prep/action.ts +14 -54
- package/src/prover/prep/enabled-axioms.ts +12 -19
- package/src/prover/prep/fingerprint.ts +2 -21
- package/src/prover/prep/level-comparison.ts +8 -12
- package/src/prover/prep/md5.ts +0 -2
- package/src/prover/prep/methods.ts +33 -39
- package/src/prover/prep/normalize.ts +4 -28
- package/src/prover/prove-worker.ts +0 -2
- package/src/prover/prove.ts +87 -100
- package/src/prover/ptl/decide.ts +7 -12
- package/src/prover/ptl/encode.ts +14 -36
- package/src/prover/ptl/sat.ts +24 -32
- package/src/prover/ptl/tableau.ts +12 -26
- package/src/prover/smt/axioms.ts +0 -7
- package/src/prover/smt/context.ts +20 -28
- package/src/prover/smt/data.ts +433 -424
- package/src/prover/smt/encode.ts +43 -52
- package/src/prover/smt/extensionality.ts +0 -10
- package/src/prover/smt/flatten.ts +3 -22
- package/src/prover/smt/format.ts +5 -10
- package/src/prover/smt/instances.ts +0 -10
- package/src/prover/smt/rewrite.ts +663 -667
- package/src/prover/smt/solver/act-cache.ts +0 -15
- package/src/prover/smt/solver/arith-rewriter.ts +3 -48
- package/src/prover/smt/solver/array.ts +1 -3
- package/src/prover/smt/solver/asserted-formulas.ts +1 -43
- package/src/prover/smt/solver/ast-lt.ts +1 -11
- package/src/prover/smt/solver/ast-util.ts +1 -6
- package/src/prover/smt/solver/ast.ts +1 -165
- package/src/prover/smt/solver/auf-solver.ts +8 -44
- package/src/prover/smt/solver/case-split-queue.ts +1 -9
- package/src/prover/smt/solver/cg-table.ts +1 -18
- package/src/prover/smt/solver/clause.ts +1 -27
- package/src/prover/smt/solver/conflict-resolution.ts +0 -9
- package/src/prover/smt/solver/context.ts +7 -64
- package/src/prover/smt/solver/ctx-simplify.ts +14 -41
- package/src/prover/smt/solver/der.ts +2 -21
- package/src/prover/smt/solver/dyn-ack.ts +1 -11
- package/src/prover/smt/solver/e-matching.ts +4 -35
- package/src/prover/smt/solver/enode.ts +1 -21
- package/src/prover/smt/solver/expr-ref.ts +1 -5
- package/src/prover/smt/solver/expr-safe-replace.ts +1 -6
- package/src/prover/smt/solver/fingerprints.ts +1 -12
- package/src/prover/smt/solver/flat-literals.ts +1 -9
- package/src/prover/smt/solver/goal.ts +2 -14
- package/src/prover/smt/solver/hash.ts +0 -8
- package/src/prover/smt/solver/hashtable.ts +1 -12
- package/src/prover/smt/solver/internalizer.ts +7 -100
- package/src/prover/smt/solver/lbool.ts +1 -2
- package/src/prover/smt/solver/literal.ts +0 -3
- package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
- package/src/prover/smt/solver/lp/constraints.ts +2 -8
- package/src/prover/smt/solver/lp/containers.ts +12 -30
- package/src/prover/smt/solver/lp/core-solver.ts +10 -31
- package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
- package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
- package/src/prover/smt/solver/lp/dependency.ts +1 -4
- package/src/prover/smt/solver/lp/dioph-eq.ts +9 -102
- package/src/prover/smt/solver/lp/explanation.ts +1 -6
- package/src/prover/smt/solver/lp/gomory.ts +9 -22
- package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
- package/src/prover/smt/solver/lp/hnf.ts +11 -26
- package/src/prover/smt/solver/lp/int-cube.ts +15 -36
- package/src/prover/smt/solver/lp/int-solver.ts +4 -34
- package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
- package/src/prover/smt/solver/lp/lar-term.ts +1 -5
- package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
- package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
- package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
- package/src/prover/smt/solver/lp/nex.ts +1 -6
- package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
- package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
- package/src/prover/smt/solver/lp/nla-core.ts +36 -135
- package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
- package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
- package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
- package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
- package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
- package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
- package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
- package/src/prover/smt/solver/lp/nla-order.ts +2 -13
- package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
- package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
- package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
- package/src/prover/smt/solver/lp/nla-types.ts +1 -11
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
- package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
- package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
- package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
- package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
- package/src/prover/smt/solver/lp/pdd.ts +7 -70
- package/src/prover/smt/solver/lp/random-updater.ts +1 -8
- package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
- package/src/prover/smt/solver/lp/union-find.ts +1 -6
- package/src/prover/smt/solver/mam-compiler.ts +18 -58
- package/src/prover/smt/solver/mam-interpreter.ts +1 -21
- package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
- package/src/prover/smt/solver/model-checker.ts +3 -37
- package/src/prover/smt/solver/model-evaluator.ts +3 -29
- package/src/prover/smt/solver/model-finder.ts +15 -32
- package/src/prover/smt/solver/model-generator.ts +1 -12
- package/src/prover/smt/solver/model-macro-solver.ts +23 -88
- package/src/prover/smt/solver/nlsat/algebraic.ts +63 -159
- package/src/prover/smt/solver/nlsat/atoms.ts +25 -23
- package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
- package/src/prover/smt/solver/nlsat/explain.ts +10 -69
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
- package/src/prover/smt/solver/nlsat/levelwise.ts +49 -135
- package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +29 -159
- package/src/prover/smt/solver/nlsat/solver.ts +18 -90
- package/src/prover/smt/solver/nlsat/types.ts +1 -8
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +2 -45
- package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
- package/src/prover/smt/solver/nnf.ts +3 -38
- package/src/prover/smt/solver/pattern-inference.ts +2 -15
- package/src/prover/smt/solver/poly-rewriter.ts +3 -23
- package/src/prover/smt/solver/propagate-values.ts +1 -10
- package/src/prover/smt/solver/proto-model.ts +3 -52
- package/src/prover/smt/solver/pull-quant.ts +1 -12
- package/src/prover/smt/solver/qe-lite-der.ts +1 -29
- package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
- package/src/prover/smt/solver/qe-lite.ts +3 -33
- package/src/prover/smt/solver/qi-queue.ts +1 -16
- package/src/prover/smt/solver/quant-tactics.ts +5 -22
- package/src/prover/smt/solver/quantifier-analyzer.ts +27 -47
- package/src/prover/smt/solver/quantifier-manager.ts +2 -13
- package/src/prover/smt/solver/random-gen.ts +1 -2
- package/src/prover/smt/solver/rational.ts +1 -8
- package/src/prover/smt/solver/ref-vector.ts +1 -6
- package/src/prover/smt/solver/relevancy.ts +2 -15
- package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
- package/src/prover/smt/solver/rewriter.ts +3 -85
- package/src/prover/smt/solver/rlimit.ts +2 -20
- package/src/prover/smt/solver/smtlib-parser.ts +80 -131
- package/src/prover/smt/solver/solver.ts +23 -34
- package/src/prover/smt/solver/sort.ts +1 -5
- package/src/prover/smt/solver/sticky-generations.ts +0 -5
- package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
- package/src/prover/smt/solver/theory-lra-bounds.ts +1 -7
- package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
- package/src/prover/smt/solver/theory-lra-internalize.ts +6 -43
- package/src/prover/smt/solver/theory-lra-model.ts +4 -19
- package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
- package/src/prover/smt/solver/theory-lra-state.ts +3 -8
- package/src/prover/smt/solver/theory-lra.ts +1 -8
- package/src/prover/smt/solver/var-subst.ts +2 -26
- package/src/prover/smt/table.ts +0 -8
- package/src/prover/tlapm/cache.ts +45 -40
- package/src/prover/tlapm/ocaml-marshal.ts +19 -21
- package/src/prover/tlapm/tlapm.ts +21 -20
- package/src/prover/verdict.ts +7 -2
- package/src/prover/zenon/check/check.ts +1 -11
- package/src/prover/zenon/check/definitions.ts +5 -15
- package/src/prover/zenon/check/equality.ts +0 -8
- package/src/prover/zenon/check/functions.ts +0 -4
- package/src/prover/zenon/check/keys.ts +0 -7
- package/src/prover/zenon/check/propositional.ts +0 -3
- package/src/prover/zenon/check/records.ts +1 -6
- package/src/prover/zenon/check/relations.ts +2 -14
- package/src/prover/zenon/check/rewrites.ts +2 -21
- package/src/prover/zenon/check/sets.ts +40 -61
- package/src/prover/zenon/check/terms.ts +1 -19
- package/src/prover/zenon/check/tla.ts +0 -6
- package/src/prover/zenon/decide.ts +0 -12
- package/src/prover/zenon/encode.ts +1 -8
- package/src/prover/zenon/eqrel.ts +2 -13
- package/src/prover/zenon/equality-rules.ts +0 -4
- package/src/prover/zenon/expr.ts +8 -26
- package/src/prover/zenon/index-table.ts +26 -57
- package/src/prover/zenon/isar-case.ts +9 -19
- package/src/prover/zenon/isar.ts +36 -64
- package/src/prover/zenon/limits.ts +0 -4
- package/src/prover/zenon/llproof.ts +2 -20
- package/src/prover/zenon/mltoll.ts +66 -104
- package/src/prover/zenon/node.ts +1 -11
- package/src/prover/zenon/ocaml.ts +1 -17
- package/src/prover/zenon/parse.ts +4 -12
- package/src/prover/zenon/phrase.ts +1 -11
- package/src/prover/zenon/proof.ts +0 -9
- package/src/prover/zenon/propositional-rules.ts +0 -5
- package/src/prover/zenon/rules.ts +2 -6
- package/src/prover/zenon/search.ts +5 -31
- package/src/prover/zenon/tla/functions.ts +59 -31
- package/src/prover/zenon/tla/llproof.ts +67 -76
- package/src/prover/zenon/tla/records.ts +57 -33
- package/src/prover/zenon/tla/rewrites.ts +12 -19
- package/src/prover/zenon/tla/sets.ts +83 -53
- package/src/prover/zenon/tla/terms.ts +0 -6
- package/src/prover/zenon/tla/tla.ts +66 -64
- package/src/randomization.ts +81 -35
- package/src/resolve.ts +67 -184
- package/src/runtime.ts +22 -22
- package/src/sany/builtins.ts +2 -5
- package/src/sany/generation.ts +394 -0
- package/src/sany/generator-def-entries.ts +210 -0
- package/src/sany/generator-definitions.ts +686 -0
- package/src/sany/generator-expressions.ts +1100 -0
- package/src/sany/generator-proofs.ts +662 -0
- package/src/sany/generator.ts +191 -2764
- package/src/sany/levels.ts +6 -34
- package/src/sany/lexer.ts +58 -77
- package/src/sany/linter.ts +1 -9
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +5 -43
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +32 -69
- package/src/sany/selectors.ts +49 -76
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +35 -117
- package/src/search.ts +541 -163
- package/src/simulate.ts +709 -0
- package/src/spec-description.ts +192 -100
- package/src/standard-definitions.ts +0 -4
- package/src/standard-modules.ts +264 -95
- package/src/state-graph.ts +52 -31
- package/src/subexpressions.ts +69 -52
- package/src/substitution-levels.ts +7 -7
- package/src/successors.ts +266 -99
- package/src/symmetry.ts +33 -25
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +183 -67
- package/src/tlc/jar-data.ts +112 -6
- package/src/tlc/messages.ts +125 -54
- package/src/tlc/order.ts +39 -69
- package/src/tlc/random.ts +37 -49
- package/src/tlc/replay.ts +553 -228
- package/src/tlc/summary.ts +36 -47
- package/src/tlc/tlc-operators.ts +78 -44
- package/src/tlc/tlcext-operators.ts +139 -122
- package/src/tlc/trace-spec.ts +249 -0
- package/src/tlc/value-stream.ts +139 -0
- package/src/tlc/version.ts +1 -4
- package/src/transfer.ts +22 -25
- package/src/typescript/actions.ts +479 -0
- package/src/typescript/collections.ts +614 -0
- package/src/typescript/compile.ts +63 -0
- package/src/typescript/context.ts +94 -0
- package/src/typescript/emit.ts +121 -0
- package/src/typescript/expressions.ts +496 -0
- package/src/typescript/formula.ts +154 -0
- package/src/typescript/functions.ts +284 -0
- package/src/typescript/model.ts +162 -0
- package/src/typescript/names.ts +114 -0
- package/src/typescript/program.ts +48 -0
- package/src/typescript/properties.ts +139 -0
- package/src/typescript/scope.ts +112 -0
- package/src/typescript/steps.ts +167 -0
- package/src/typescript/types.ts +171 -0
- package/src/values.ts +832 -484
- package/src/worker.ts +7 -8
|
@@ -1,10 +1,7 @@
|
|
|
1
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
2
|
|
|
6
3
|
import { TlaZenonError } from "../../errors";
|
|
7
|
-
import type { Direction, Origin, Relations } from "./eqrel";
|
|
4
|
+
import type { Direction, Origin, RelationProperty, Relations } from "./eqrel";
|
|
8
5
|
import {
|
|
9
6
|
difference,
|
|
10
7
|
union,
|
|
@@ -13,13 +10,12 @@ import {
|
|
|
13
10
|
type Expressions,
|
|
14
11
|
type VarExpr,
|
|
15
12
|
} from "./expr";
|
|
16
|
-
import {
|
|
13
|
+
import type { Connective, Lemma, LlProof, LlRule } from "./llproof";
|
|
17
14
|
import type { Definition, Phrase } from "./parse";
|
|
18
15
|
import type { Rule } from "./proof";
|
|
19
16
|
import { getTlaLlProof } from "./tla/llproof";
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
export type MlRule = Rule | { name: "notall" | "notallex"; args: [Expr] };
|
|
18
|
+
type MlRule = Rule | { name: "notall" | "notallex"; args: [Expr] };
|
|
23
19
|
|
|
24
20
|
export interface MlProof {
|
|
25
21
|
conclusions: Expr[];
|
|
@@ -27,22 +23,15 @@ export interface MlProof {
|
|
|
27
23
|
subproofs: MlProof[];
|
|
28
24
|
}
|
|
29
25
|
|
|
30
|
-
// A translated proof, with the hypotheses it uses that aren't conclusions of the node.
|
|
31
26
|
export type Translated = [LlProof, Expr[]];
|
|
32
27
|
|
|
33
28
|
interface TranslateContext {
|
|
34
29
|
exprs: Expressions;
|
|
35
|
-
// Zenon's Index.get_number, which also names the formulas in the Isar output.
|
|
36
30
|
getNumber: (expression: Expr) => number;
|
|
37
|
-
// The proofs that the search reused, which Zenon counts in mlrefc.
|
|
38
31
|
sharedProofs: ReadonlySet<MlProof>;
|
|
39
32
|
relations: Relations;
|
|
40
33
|
}
|
|
41
34
|
|
|
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
35
|
type HypothesisKind =
|
|
47
36
|
| { kind: "reflexive"; origin: Origin }
|
|
48
37
|
| { kind: "symmetric"; origin: Origin }
|
|
@@ -61,7 +50,6 @@ export const isMetaName = (name: string) => name.startsWith(META_PREFIX);
|
|
|
61
50
|
|
|
62
51
|
const isAlphanumeric = (char: string) => /^[A-Za-z0-9]$/.test(char);
|
|
63
52
|
|
|
64
|
-
// Zenon's type_to_ident.
|
|
65
53
|
const toIdentifier = (type: string) =>
|
|
66
54
|
[...type]
|
|
67
55
|
.map((char) =>
|
|
@@ -79,7 +67,6 @@ const getSingle = (proof: MlProof) => {
|
|
|
79
67
|
return proof.subproofs[0];
|
|
80
68
|
};
|
|
81
69
|
|
|
82
|
-
// Zenon's Mlproof.make_node: the node's conclusions and those its subproofs leave open.
|
|
83
70
|
const makeNode = (
|
|
84
71
|
conclusions: Expr[],
|
|
85
72
|
rule: MlRule,
|
|
@@ -119,7 +106,6 @@ const isDerived = (rule: MlRule) => {
|
|
|
119
106
|
}
|
|
120
107
|
};
|
|
121
108
|
|
|
122
|
-
// The rules that tr_rule translates directly: the core rules and the extension rules named "".
|
|
123
109
|
const CORE_RULES = new Set<string>([
|
|
124
110
|
"close",
|
|
125
111
|
"false",
|
|
@@ -150,7 +136,6 @@ const CORE_RULES = new Set<string>([
|
|
|
150
136
|
"stringdiffrr",
|
|
151
137
|
]);
|
|
152
138
|
|
|
153
|
-
// Zenon's Mltoll.translate: the lemmas in the order they were made, then the theorem.
|
|
154
139
|
export const translateProof = (
|
|
155
140
|
context: TranslateContext,
|
|
156
141
|
phrases: Phrase[],
|
|
@@ -158,14 +143,11 @@ export const translateProof = (
|
|
|
158
143
|
): Lemma[] => {
|
|
159
144
|
const exprs = context.exprs;
|
|
160
145
|
const translatedExprs = new Map<Expr, Expr>();
|
|
161
|
-
const
|
|
162
|
-
const lemmaTable = new Map<string, [Lemma, Expr[]]>();
|
|
146
|
+
const lemmaTable = new Map<MlProof, [Lemma, Expr[]]>();
|
|
163
147
|
const lemmas: Lemma[] = [];
|
|
164
|
-
const getLemmaName = (number: number) => `${LEMMA_PREFIX}${number}_`;
|
|
165
148
|
|
|
166
149
|
const equal = (left: Expr, right: Expr) => exprs.eapp("=", [left, right]);
|
|
167
150
|
|
|
168
|
-
// Zenon's tr_expr: metavariables become variables named after their quantifier.
|
|
169
151
|
const translateExpr = (expression: Expr): Expr => {
|
|
170
152
|
if (expression.metas.length === 0) return expression;
|
|
171
153
|
const cached = translatedExprs.get(expression);
|
|
@@ -189,13 +171,13 @@ export const translateProof = (
|
|
|
189
171
|
case "imply":
|
|
190
172
|
case "equiv": {
|
|
191
173
|
const right = translateExpr(expression.args[1]);
|
|
192
|
-
return
|
|
174
|
+
return exprs.binary(expression.kind, translateExpr(expression.args[0]), right);
|
|
193
175
|
}
|
|
194
176
|
case "all":
|
|
195
177
|
case "ex":
|
|
196
178
|
case "tau":
|
|
197
179
|
case "lam":
|
|
198
|
-
return
|
|
180
|
+
return exprs.binder(
|
|
199
181
|
expression.kind,
|
|
200
182
|
expression.args[0],
|
|
201
183
|
expression.symbol,
|
|
@@ -209,41 +191,31 @@ export const translateProof = (
|
|
|
209
191
|
return result;
|
|
210
192
|
};
|
|
211
193
|
|
|
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
194
|
const translateRule = (rule: MlRule): LlRule => {
|
|
222
|
-
const tr = translateExpr;
|
|
223
195
|
switch (rule.name) {
|
|
224
196
|
case "close":
|
|
225
|
-
return { kind: "axiom", formula:
|
|
197
|
+
return { kind: "axiom", formula: translateExpr(rule.args[0]) };
|
|
226
198
|
case "close_refl":
|
|
227
|
-
return { kind: "noteq", term:
|
|
199
|
+
return { kind: "noteq", term: translateExpr(rule.args[0]) };
|
|
228
200
|
case "close_sym": {
|
|
229
|
-
const right =
|
|
230
|
-
return { kind: "eqsym", left:
|
|
201
|
+
const right = translateExpr(rule.args[1]);
|
|
202
|
+
return { kind: "eqsym", left: translateExpr(rule.args[0]), right };
|
|
231
203
|
}
|
|
232
204
|
case "false":
|
|
233
205
|
return { kind: "false" };
|
|
234
206
|
case "not_true":
|
|
235
207
|
return { kind: "nottrue" };
|
|
236
208
|
case "not_not":
|
|
237
|
-
return { kind: "notnot", formula:
|
|
209
|
+
return { kind: "notnot", formula: translateExpr(rule.args[0]) };
|
|
238
210
|
case "and":
|
|
239
211
|
case "or":
|
|
240
212
|
case "impl":
|
|
241
213
|
case "equiv": {
|
|
242
|
-
const right =
|
|
214
|
+
const right = translateExpr(rule.args[1]);
|
|
243
215
|
return {
|
|
244
216
|
kind: "connect",
|
|
245
217
|
connective: RULE_CONNECTIVES[rule.name],
|
|
246
|
-
left:
|
|
218
|
+
left: translateExpr(rule.args[0]),
|
|
247
219
|
right,
|
|
248
220
|
};
|
|
249
221
|
}
|
|
@@ -251,57 +223,59 @@ export const translateProof = (
|
|
|
251
223
|
case "not_impl":
|
|
252
224
|
case "not_and":
|
|
253
225
|
case "not_equiv": {
|
|
254
|
-
const right =
|
|
226
|
+
const right = translateExpr(rule.args[1]);
|
|
255
227
|
return {
|
|
256
228
|
kind: "notconnect",
|
|
257
229
|
connective: RULE_CONNECTIVES[rule.name],
|
|
258
|
-
left:
|
|
230
|
+
left: translateExpr(rule.args[0]),
|
|
259
231
|
right,
|
|
260
232
|
};
|
|
261
233
|
}
|
|
262
234
|
case "ex": {
|
|
263
235
|
const quantified = getBinder(rule.args[0], "ex");
|
|
264
|
-
const term =
|
|
265
|
-
|
|
236
|
+
const term = translateExpr(
|
|
237
|
+
exprs.etau(quantified.args[0], quantified.symbol, quantified.args[1]),
|
|
238
|
+
);
|
|
239
|
+
return { kind: "ex", quantified: translateExpr(quantified), term };
|
|
266
240
|
}
|
|
267
241
|
case "all": {
|
|
268
|
-
const term =
|
|
269
|
-
return { kind: "all", quantified:
|
|
242
|
+
const term = translateExpr(rule.args[1]);
|
|
243
|
+
return { kind: "all", quantified: translateExpr(rule.args[0]), term };
|
|
270
244
|
}
|
|
271
245
|
case "not_ex": {
|
|
272
246
|
const negation = rule.args[0];
|
|
273
247
|
if (negation.kind !== "not") throw new TlaZenonError("Zenon: not_ex without a negation");
|
|
274
|
-
const term =
|
|
275
|
-
return { kind: "notex", quantified:
|
|
248
|
+
const term = translateExpr(rule.args[1]);
|
|
249
|
+
return { kind: "notex", quantified: translateExpr(negation.args[0]), term };
|
|
276
250
|
}
|
|
277
251
|
case "p_not_p": {
|
|
278
|
-
const negative =
|
|
279
|
-
return { kind: "pnotp", positive:
|
|
252
|
+
const negative = translateExpr(rule.args[1]);
|
|
253
|
+
return { kind: "pnotp", positive: translateExpr(rule.args[0]), negative };
|
|
280
254
|
}
|
|
281
255
|
case "not_equal": {
|
|
282
|
-
const right =
|
|
283
|
-
return { kind: "notequal", left:
|
|
256
|
+
const right = translateExpr(rule.args[1]);
|
|
257
|
+
return { kind: "notequal", left: translateExpr(rule.args[0]), right };
|
|
284
258
|
}
|
|
285
259
|
case "definition": {
|
|
286
260
|
if (rule.definition.kind !== "real")
|
|
287
261
|
throw new TlaZenonError("Zenon: a pseudo-definition in tr_rule");
|
|
288
|
-
const unfolded =
|
|
262
|
+
const unfolded = translateExpr(rule.args[1]);
|
|
289
263
|
return {
|
|
290
264
|
kind: "definition",
|
|
291
265
|
name: rule.definition.name,
|
|
292
|
-
folded:
|
|
266
|
+
folded: translateExpr(rule.args[0]),
|
|
293
267
|
unfolded,
|
|
294
268
|
};
|
|
295
269
|
}
|
|
296
270
|
case "cut":
|
|
297
|
-
return { kind: "cut", formula:
|
|
271
|
+
return { kind: "cut", formula: translateExpr(rule.args[0]) };
|
|
298
272
|
case "congruence_lr":
|
|
299
273
|
case "congruence_rl": {
|
|
300
|
-
const right =
|
|
301
|
-
const left =
|
|
274
|
+
const right = translateExpr(rule.args[2]);
|
|
275
|
+
const left = translateExpr(rule.args[1]);
|
|
302
276
|
return {
|
|
303
277
|
kind: rule.name === "congruence_lr" ? "congruencelr" : "congruencerl",
|
|
304
|
-
context:
|
|
278
|
+
context: translateExpr(rule.args[0]),
|
|
305
279
|
left,
|
|
306
280
|
right,
|
|
307
281
|
};
|
|
@@ -309,10 +283,10 @@ export const translateProof = (
|
|
|
309
283
|
case "notall": {
|
|
310
284
|
const negation = rule.args[0];
|
|
311
285
|
const quantified = getBinder(negation.kind === "not" ? negation.args[0] : negation, "all");
|
|
312
|
-
const term =
|
|
286
|
+
const term = translateExpr(
|
|
313
287
|
exprs.etau(quantified.args[0], quantified.symbol, exprs.enot(quantified.args[1])),
|
|
314
288
|
);
|
|
315
|
-
return { kind: "notall", quantified:
|
|
289
|
+
return { kind: "notall", quantified: translateExpr(quantified), term };
|
|
316
290
|
}
|
|
317
291
|
case "notallex": {
|
|
318
292
|
const lambda = getBinder(rule.args[0], "lam");
|
|
@@ -344,7 +318,10 @@ export const translateProof = (
|
|
|
344
318
|
case "stringdifflr":
|
|
345
319
|
case "stringdiffrl":
|
|
346
320
|
case "stringdiffrr": {
|
|
347
|
-
const
|
|
321
|
+
const first = rule.args[0];
|
|
322
|
+
const firstValue = rule.args[1];
|
|
323
|
+
const second = rule.args[2];
|
|
324
|
+
const secondValue = rule.args[3];
|
|
348
325
|
const isFirstLeft = rule.name === "stringdiffll" || rule.name === "stringdifflr";
|
|
349
326
|
const isSecondLeft = rule.name === "stringdiffll" || rule.name === "stringdiffrl";
|
|
350
327
|
const firstConclusion = isFirstLeft ? equal(first, firstValue) : equal(firstValue, first);
|
|
@@ -366,7 +343,6 @@ export const translateProof = (
|
|
|
366
343
|
}
|
|
367
344
|
};
|
|
368
345
|
|
|
369
|
-
// Zenon's get_params: the free taus of a lemma's conclusions, each with its type.
|
|
370
346
|
const getParams = (accumulated: [string, Expr][], expression: Expr): [string, Expr][] => {
|
|
371
347
|
const merge = (type: string, term: Expr): [string, Expr][] =>
|
|
372
348
|
accumulated.some((param) => param[1] === term) ? accumulated : [[type, term], ...accumulated];
|
|
@@ -385,8 +361,7 @@ export const translateProof = (
|
|
|
385
361
|
};
|
|
386
362
|
|
|
387
363
|
const getLemmaReference = (proof: MlProof): Translated => {
|
|
388
|
-
const
|
|
389
|
-
const entry = number === undefined ? undefined : lemmaTable.get(getLemmaName(number));
|
|
364
|
+
const entry = lemmaTable.get(proof);
|
|
390
365
|
if (entry === undefined) throw new TlaZenonError("Zenon: a lemma that was never made");
|
|
391
366
|
const lemma = entry[0];
|
|
392
367
|
return [
|
|
@@ -400,19 +375,17 @@ export const translateProof = (
|
|
|
400
375
|
};
|
|
401
376
|
|
|
402
377
|
const makeLemma = (translated: LlProof, extras: Expr[], proof: MlProof) => {
|
|
403
|
-
const number = lemmas.length + 1;
|
|
404
|
-
lemmaNumbers.set(proof, number);
|
|
405
378
|
const lemma = {
|
|
406
|
-
name:
|
|
379
|
+
name: `${LEMMA_PREFIX}${lemmas.length + 1}_`,
|
|
407
380
|
params: translated.conclusions.reduce(getParams, []),
|
|
408
381
|
proof: translated,
|
|
409
382
|
};
|
|
410
|
-
lemmaTable.set(
|
|
383
|
+
lemmaTable.set(proof, [lemma, extras]);
|
|
411
384
|
lemmas.push(lemma);
|
|
412
385
|
};
|
|
413
386
|
|
|
414
387
|
const translate = (proof: MlProof): Translated => {
|
|
415
|
-
if (
|
|
388
|
+
if (lemmaTable.has(proof)) return getLemmaReference(proof);
|
|
416
389
|
const result = isDerived(proof.rule)
|
|
417
390
|
? translateDerived(proof)
|
|
418
391
|
: ((): Translated => {
|
|
@@ -433,9 +406,8 @@ export const translateProof = (
|
|
|
433
406
|
};
|
|
434
407
|
|
|
435
408
|
const isSharedProof = (proof: MlProof) =>
|
|
436
|
-
context.sharedProofs.has(proof) && !
|
|
409
|
+
context.sharedProofs.has(proof) && !lemmaTable.has(proof);
|
|
437
410
|
|
|
438
|
-
// Zenon's get_sub: the subproofs, and the union of their extras from the right.
|
|
439
411
|
const translateAll = (proofs: MlProof[]): [LlProof[], Expr[]] => {
|
|
440
412
|
const translated = proofs.map(translate);
|
|
441
413
|
return [
|
|
@@ -444,7 +416,6 @@ export const translateProof = (
|
|
|
444
416
|
];
|
|
445
417
|
};
|
|
446
418
|
|
|
447
|
-
// A node of recomp_conj, with the formulas it removes from its subproof's conclusions.
|
|
448
419
|
const recompose = (
|
|
449
420
|
conclusion: Expr,
|
|
450
421
|
rule: LlRule,
|
|
@@ -518,12 +489,11 @@ export const translateProof = (
|
|
|
518
489
|
}
|
|
519
490
|
};
|
|
520
491
|
|
|
521
|
-
// Zenon's recomp_disj: consumes the translated subproofs, one for each disjunct.
|
|
522
492
|
const recompDisj = (subs: Translated[], formula: Expr): [LlProof, Expr[], Translated[]] => {
|
|
523
493
|
const node = (
|
|
524
494
|
conclusion: Expr,
|
|
525
495
|
connectiveName: Connective,
|
|
526
|
-
|
|
496
|
+
isNegated: boolean,
|
|
527
497
|
left: Expr,
|
|
528
498
|
right: Expr,
|
|
529
499
|
first: [LlProof, Expr[], Translated[]],
|
|
@@ -540,7 +510,12 @@ export const translateProof = (
|
|
|
540
510
|
difference(second[0].conclusions, [secondRemoved]),
|
|
541
511
|
),
|
|
542
512
|
),
|
|
543
|
-
rule: {
|
|
513
|
+
rule: {
|
|
514
|
+
kind: isNegated ? "notconnect" : "connect",
|
|
515
|
+
connective: connectiveName,
|
|
516
|
+
left,
|
|
517
|
+
right,
|
|
518
|
+
},
|
|
544
519
|
subproofs: [first[0], second[0]],
|
|
545
520
|
},
|
|
546
521
|
difference(union(first[1], second[1]), [extra]),
|
|
@@ -643,7 +618,6 @@ export const translateProof = (
|
|
|
643
618
|
return [subs[0][0], subs[0][1], subs.slice(1)];
|
|
644
619
|
};
|
|
645
620
|
|
|
646
|
-
// The constructors of Zenon's Mlproof, for the proofs that the translation builds.
|
|
647
621
|
const makeClose = (formula: Expr) =>
|
|
648
622
|
makeNode([formula, exprs.enot(formula)], { name: "close", args: [formula] }, [], []);
|
|
649
623
|
const makeCloseRefl = (relation: string, term: Expr) =>
|
|
@@ -704,7 +678,6 @@ export const translateProof = (
|
|
|
704
678
|
const instance = exprs.substitute([[binder.args[0], terms[0]]], binder.args[1]);
|
|
705
679
|
return makeAll(quantified, terms[0], makeAlls(instance, terms.slice(1), subproof));
|
|
706
680
|
};
|
|
707
|
-
// Zenon's make_impls: the implications from `hypotheses` to `conclusion`, and their proof.
|
|
708
681
|
const makeImplies = (
|
|
709
682
|
hypotheses: Expr[],
|
|
710
683
|
conclusion: Expr,
|
|
@@ -737,8 +710,6 @@ export const translateProof = (
|
|
|
737
710
|
[first, second],
|
|
738
711
|
);
|
|
739
712
|
|
|
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
713
|
const relationHypotheses = new Map<string, Expr>();
|
|
743
714
|
const hypothesisKinds = new Map<Expr, HypothesisKind>();
|
|
744
715
|
const getRelationHypothesis = (property: RelationProperty, relation: string) => {
|
|
@@ -795,7 +766,6 @@ export const translateProof = (
|
|
|
795
766
|
return hypothesis;
|
|
796
767
|
};
|
|
797
768
|
|
|
798
|
-
// Zenon's inst_nall: the instance of a negated universal at its counterexample.
|
|
799
769
|
const instantiateNegation = (negation: Expr): [Expr, Expr] => {
|
|
800
770
|
if (negation.kind !== "not") throw new TlaZenonError("Zenon: inst_nall without a negation");
|
|
801
771
|
const binder = getBinder(negation.args[0], "all");
|
|
@@ -804,7 +774,6 @@ export const translateProof = (
|
|
|
804
774
|
return [exprs.substitute([[binder.args[0], witness]], body), witness];
|
|
805
775
|
};
|
|
806
776
|
|
|
807
|
-
// Zenon's decompose_disj: closes each literal of a disjunction with one of `forms`.
|
|
808
777
|
const decomposeDisjunction = (formula: Expr, forms: Expr[]): MlProof => {
|
|
809
778
|
const visit = (disjunct: Expr) => decomposeDisjunction(disjunct, forms);
|
|
810
779
|
const getForm = (form: Expr) => {
|
|
@@ -867,8 +836,6 @@ export const translateProof = (
|
|
|
867
836
|
}
|
|
868
837
|
};
|
|
869
838
|
|
|
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
839
|
const decomposeConjunction = (
|
|
873
840
|
position: number,
|
|
874
841
|
formula: Expr,
|
|
@@ -986,8 +953,6 @@ export const translateProof = (
|
|
|
986
953
|
return decomposeDisjunction(formula, forms);
|
|
987
954
|
};
|
|
988
955
|
|
|
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
956
|
const getRelationProof = (hypothesis: Expr): [MlProof, Expr[]] => {
|
|
992
957
|
const kind = hypothesisKinds.get(hypothesis);
|
|
993
958
|
if (kind === undefined)
|
|
@@ -1124,7 +1089,6 @@ export const translateProof = (
|
|
|
1124
1089
|
|
|
1125
1090
|
const relate = (relation: string, left: Expr, right: Expr) => exprs.eapp(relation, [left, right]);
|
|
1126
1091
|
|
|
1127
|
-
// Zenon's make_direct_trans: r(a, b), r(b, c) / r(a, c) / (proof).
|
|
1128
1092
|
const makeDirectTrans = (relation: string, a: Expr, b: Expr, c: Expr, proof: MlProof) => {
|
|
1129
1093
|
const hypothesis = getRelationHypothesis("transitive", relation);
|
|
1130
1094
|
const ab = relate(relation, a, b);
|
|
@@ -1137,21 +1101,18 @@ export const translateProof = (
|
|
|
1137
1101
|
);
|
|
1138
1102
|
return makeAlls(hypothesis, [a, b, c], implied[1]);
|
|
1139
1103
|
};
|
|
1140
|
-
// Zenon's make_direct_nsym: -r(a, b) / -r(b, a) / (proof).
|
|
1141
1104
|
const makeDirectNotSym = (relation: string, a: Expr, b: Expr, proof: MlProof) => {
|
|
1142
1105
|
const hypothesis = getRelationHypothesis("symmetric", relation);
|
|
1143
1106
|
const ab = relate(relation, a, b);
|
|
1144
1107
|
const ba = relate(relation, b, a);
|
|
1145
1108
|
return makeAlls(hypothesis, [b, a], makeImply(ba, ab, proof, makeClose(ab)));
|
|
1146
1109
|
};
|
|
1147
|
-
// Zenon's make_direct_sym_neq: a != b / b != a / (proof).
|
|
1148
1110
|
const makeSymmetricDisequality = (a: Expr, b: Expr, proof: MlProof) => {
|
|
1149
1111
|
const reflexive = equal(b, b);
|
|
1150
1112
|
const refuted = makeCloseRefl("=", b);
|
|
1151
1113
|
const swapped = makePNotP(reflexive, exprs.enot(equal(a, b)), [proof, refuted]);
|
|
1152
1114
|
return makeCut(reflexive, swapped, refuted);
|
|
1153
1115
|
};
|
|
1154
|
-
// Zenon's make_direct_sym_eq: a = b / b = a / (proof).
|
|
1155
1116
|
const makeSymmetricEquality = (a: Expr, b: Expr, proof: MlProof) => {
|
|
1156
1117
|
const ab = equal(a, b);
|
|
1157
1118
|
return makeCut(equal(b, a), proof, makeSymmetricDisequality(b, a, makeClose(ab)));
|
|
@@ -1265,7 +1226,6 @@ export const translateProof = (
|
|
|
1265
1226
|
return [proof.subproofs[0], proof.subproofs[1], proof.subproofs[2]];
|
|
1266
1227
|
};
|
|
1267
1228
|
|
|
1268
|
-
// A derived rule's expansion, with the hypotheses it relies on that no phrase may state.
|
|
1269
1229
|
const translateWith = (expanded: MlProof, hypotheses: Expr[]): Translated => {
|
|
1270
1230
|
const translated = translate(expanded);
|
|
1271
1231
|
return [translated[0], union(hypotheses, translated[1])];
|
|
@@ -1295,7 +1255,8 @@ export const translateProof = (
|
|
|
1295
1255
|
}
|
|
1296
1256
|
case "close_sym": {
|
|
1297
1257
|
const hypothesis = getRelationHypothesis("symmetric", rule.relation);
|
|
1298
|
-
const
|
|
1258
|
+
const a = rule.args[0];
|
|
1259
|
+
const b = rule.args[1];
|
|
1299
1260
|
const ab = relate(rule.relation, a, b);
|
|
1300
1261
|
const ba = relate(rule.relation, b, a);
|
|
1301
1262
|
const implied = makeImply(ab, ba, makeClose(ab), makeClose(ba));
|
|
@@ -1310,7 +1271,8 @@ export const translateProof = (
|
|
|
1310
1271
|
}
|
|
1311
1272
|
case "refl": {
|
|
1312
1273
|
const hypothesis = getRelationHypothesis("reflexive", rule.relation);
|
|
1313
|
-
const
|
|
1274
|
+
const a = rule.args[0];
|
|
1275
|
+
const b = rule.args[1];
|
|
1314
1276
|
const reflexive = relate(rule.relation, a, a);
|
|
1315
1277
|
const negated = exprs.enot(relate(rule.relation, a, b));
|
|
1316
1278
|
const closed = makePNotP(reflexive, negated, [makeCloseRefl("=", a), getSingle(proof)]);
|
|
@@ -1325,7 +1287,8 @@ export const translateProof = (
|
|
|
1325
1287
|
return translate(makeSymmetricDisequality(negative.args[0], negative.args[1], node));
|
|
1326
1288
|
}
|
|
1327
1289
|
const hypothesis = getRelationHypothesis("symmetric", rule.relation);
|
|
1328
|
-
const
|
|
1290
|
+
const a = positive.args[0];
|
|
1291
|
+
const b = positive.args[1];
|
|
1329
1292
|
const ba = relate(rule.relation, b, a);
|
|
1330
1293
|
const node = makePNotP(ba, rule.args[1], [proof.subproofs[0], proof.subproofs[1]]);
|
|
1331
1294
|
const implied = makeImply(rule.args[0], ba, makeClose(rule.args[0]), node);
|
|
@@ -1335,8 +1298,11 @@ export const translateProof = (
|
|
|
1335
1298
|
case "trans_sym": {
|
|
1336
1299
|
const positive = getRelation(rule.args[0]);
|
|
1337
1300
|
const relation = positive.symbol;
|
|
1338
|
-
const
|
|
1339
|
-
const
|
|
1301
|
+
const a = positive.args[0];
|
|
1302
|
+
const b = positive.args[1];
|
|
1303
|
+
const negative = getRelation(rule.args[1]);
|
|
1304
|
+
const c = negative.args[0];
|
|
1305
|
+
const d = negative.args[1];
|
|
1340
1306
|
const first = proof.subproofs[0];
|
|
1341
1307
|
const second = proof.subproofs[1];
|
|
1342
1308
|
if (relation === "=")
|
|
@@ -1365,7 +1331,8 @@ export const translateProof = (
|
|
|
1365
1331
|
case "trans_eq_sym": {
|
|
1366
1332
|
const negative = getRelation(rule.args[2]);
|
|
1367
1333
|
const relation = negative.symbol;
|
|
1368
|
-
const
|
|
1334
|
+
const c = negative.args[0];
|
|
1335
|
+
const d = negative.args[1];
|
|
1369
1336
|
const a = rule.args[0];
|
|
1370
1337
|
const b = rule.args[1];
|
|
1371
1338
|
const proofs = getThree(proof);
|
|
@@ -1402,7 +1369,6 @@ export const translateProof = (
|
|
|
1402
1369
|
}
|
|
1403
1370
|
};
|
|
1404
1371
|
|
|
1405
|
-
// Zenon's make_ex.
|
|
1406
1372
|
const makeExistential = (existential: Expr, subproof: MlProof) => {
|
|
1407
1373
|
const binder = getBinder(existential, "ex");
|
|
1408
1374
|
const witness = exprs.etau(binder.args[0], binder.symbol, binder.args[1]);
|
|
@@ -1410,7 +1376,6 @@ export const translateProof = (
|
|
|
1410
1376
|
return makeNode([existential], { name: "ex", args: [existential] }, [[instance]], [subproof]);
|
|
1411
1377
|
};
|
|
1412
1378
|
|
|
1413
|
-
// Zenon's find_diff: the context in which two formulas differ, and the two subterms.
|
|
1414
1379
|
const findDiff = (variable: VarExpr, left: Expr, right: Expr): [Expr, Expr, Expr] => {
|
|
1415
1380
|
if (left === right) throw new TlaZenonError("Zenon: find_diff on equal formulas");
|
|
1416
1381
|
if (left.kind === "app" && right.kind === "app" && left.symbol === right.symbol) {
|
|
@@ -1439,10 +1404,10 @@ export const translateProof = (
|
|
|
1439
1404
|
) {
|
|
1440
1405
|
if (left.args[0] === right.args[0]) {
|
|
1441
1406
|
const diff = findDiff(variable, left.args[1], right.args[1]);
|
|
1442
|
-
return [
|
|
1407
|
+
return [exprs.binary(left.kind, left.args[0], diff[0]), diff[1], diff[2]];
|
|
1443
1408
|
}
|
|
1444
1409
|
const diff = findDiff(variable, left.args[0], right.args[0]);
|
|
1445
|
-
return [
|
|
1410
|
+
return [exprs.binary(left.kind, diff[0], left.args[1]), diff[1], diff[2]];
|
|
1446
1411
|
}
|
|
1447
1412
|
if (
|
|
1448
1413
|
left.kind === right.kind &&
|
|
@@ -1452,7 +1417,6 @@ export const translateProof = (
|
|
|
1452
1417
|
return [variable, left, right];
|
|
1453
1418
|
};
|
|
1454
1419
|
|
|
1455
|
-
// Zenon's translate_pseudo_def: instantiates the defining hypothesis, then rewrites with it.
|
|
1456
1420
|
const translatePseudoDefinition = (
|
|
1457
1421
|
proof: MlProof,
|
|
1458
1422
|
definition: Extract<Definition, { kind: "pseudo" }>,
|
|
@@ -1535,8 +1499,6 @@ export const translateProof = (
|
|
|
1535
1499
|
const translated = translate(proof);
|
|
1536
1500
|
const isCharged = (formula: Expr) =>
|
|
1537
1501
|
!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
1502
|
const discharged = translated[1].filter(isCharged).reduce((current: LlProof, extra): LlProof => {
|
|
1541
1503
|
const relationProof = getRelationProof(extra);
|
|
1542
1504
|
const proved = translate(relationProof[0]);
|
package/src/prover/zenon/node.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
// Ported from Zenon's node.ml and heap.ml, as shipped in tlapm. Copyright 2001-2004 INRIA, see
|
|
2
|
-
// LICENSE.
|
|
3
|
-
//
|
|
4
|
-
// Tableau nodes and the queue that orders them. The search keeps the queue of every open branch,
|
|
5
|
-
// so the queue is persistent: inserting or removing returns a new queue and shares the rest.
|
|
1
|
+
// Ported from Zenon's node.ml and heap.ml, as shipped in tlapm. Copyright 2001-2004 INRIA, see LICENSE.
|
|
6
2
|
|
|
7
3
|
import type { Expr } from "./expr";
|
|
8
4
|
import type { Rule } from "./proof";
|
|
@@ -32,7 +28,6 @@ const reverse = <Item>(list: List<Item>) => {
|
|
|
32
28
|
return result;
|
|
33
29
|
};
|
|
34
30
|
|
|
35
|
-
// A node in the instance heap, with the size of the term that instantiates its formula.
|
|
36
31
|
interface Entry {
|
|
37
32
|
node: Node;
|
|
38
33
|
size: number;
|
|
@@ -44,7 +39,6 @@ interface Tree {
|
|
|
44
39
|
right: Tree | undefined;
|
|
45
40
|
}
|
|
46
41
|
|
|
47
|
-
// Zenon's Heap: a persistent binary heap that alternates insertion paths.
|
|
48
42
|
interface Heap {
|
|
49
43
|
tree: Tree | undefined;
|
|
50
44
|
path: number;
|
|
@@ -101,8 +95,6 @@ export interface Queue {
|
|
|
101
95
|
instSize: List<[number, Heap]>;
|
|
102
96
|
instFront: List<Node>;
|
|
103
97
|
instBack: List<Node>;
|
|
104
|
-
// The nodes inserted since the root. Removed nodes still count, because the queues of the
|
|
105
|
-
// branches above keep them.
|
|
106
98
|
insertedCount: number;
|
|
107
99
|
}
|
|
108
100
|
|
|
@@ -212,8 +204,6 @@ const removeAt = (
|
|
|
212
204
|
return [removed[0], cons([list.head[0], removed[1]], list.tail)];
|
|
213
205
|
};
|
|
214
206
|
|
|
215
|
-
// On even states, the smallest instance of the most goal-directed formulas; on odd states, the
|
|
216
|
-
// smallest instance overall.
|
|
217
207
|
const removeByGoalness = (state: number, list: List<[number, Heap]>) => {
|
|
218
208
|
if (state % 2 === 0) return removeAt(0, list);
|
|
219
209
|
let best = 0;
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
// The parts of OCaml's standard library whose exact behavior steers Zenon's search.
|
|
2
|
-
//
|
|
3
|
-
// Hashtbl.hash on the values Zenon hashes: strings, and the (int, string list) pairs that Expr
|
|
4
|
-
// hashes. Zenon orders record fields by these hashes. Ints are 63-bit in OCaml, so an int is a
|
|
5
|
-
// high part in [-2^30, 2^30) and a low part in [0, 2^32).
|
|
6
|
-
|
|
7
1
|
const TWO_32 = 4294967296;
|
|
8
2
|
const TWO_31 = 2147483648;
|
|
9
3
|
const TWO_30 = 1073741824;
|
|
10
4
|
|
|
11
|
-
// A block's header with its color bits cleared: two fields and tag 0, for a pair or a list cell.
|
|
12
5
|
const PAIR_HEADER = 0x800;
|
|
13
6
|
|
|
14
7
|
const MEANINGFUL_LIMIT = 10;
|
|
@@ -28,8 +21,6 @@ const finalMix = (hash: number) => {
|
|
|
28
21
|
return ((second ^ (second >>> 16)) >>> 0) & 0x3fffffff;
|
|
29
22
|
};
|
|
30
23
|
|
|
31
|
-
// A string's UTF-8 bytes as the little-endian words that caml_hash_mix_string mixes, the last one
|
|
32
|
-
// partial.
|
|
33
24
|
interface StringWords {
|
|
34
25
|
words: number[];
|
|
35
26
|
length: number;
|
|
@@ -54,15 +45,12 @@ const mixWords = (hash: number, encoded: StringWords) => {
|
|
|
54
45
|
return mixed ^ encoded.length;
|
|
55
46
|
};
|
|
56
47
|
|
|
57
|
-
// caml_hash_mix_intnat on the tagged value 2n + 1 of the int n.
|
|
58
48
|
const mixInt = (hash: number, high: number, low: number) => {
|
|
59
49
|
const taggedLow = (low * 2 + 1) % TWO_32;
|
|
60
50
|
const taggedHigh = high * 2 + Math.floor((low * 2 + 1) / TWO_32);
|
|
61
51
|
return mix(hash, (taggedHigh ^ (taggedHigh < 0 ? -1 : 0) ^ taggedLow) | 0);
|
|
62
52
|
};
|
|
63
53
|
|
|
64
|
-
// Hashtbl.hash on strings and on (int, string list) pairs. It keeps each string's words and hash,
|
|
65
|
-
// because Zenon hashes the same variable names over and over.
|
|
66
54
|
export const createHasher = () => {
|
|
67
55
|
const stringWords = new Map<string, StringWords>();
|
|
68
56
|
const stringHashes = new Map<string, number>();
|
|
@@ -103,7 +91,6 @@ export interface Int63 {
|
|
|
103
91
|
low: number;
|
|
104
92
|
}
|
|
105
93
|
|
|
106
|
-
// Expr's combine: x + y * 131 + 1, wrapping like OCaml's 63-bit ints.
|
|
107
94
|
export const combine = (left: Int63, right: Int63): Int63 => {
|
|
108
95
|
const product = right.low * 131;
|
|
109
96
|
const productCarry = Math.floor(product / TWO_32);
|
|
@@ -117,8 +104,6 @@ export const combine = (left: Int63, right: Int63): Int63 => {
|
|
|
117
104
|
|
|
118
105
|
export const toInt63 = (value: number): Int63 => ({ high: 0, low: value });
|
|
119
106
|
|
|
120
|
-
// The merges of OCaml's List.stable_sort, on arrays. Each returns its result reversed, as OCaml's
|
|
121
|
-
// rev_merge and rev_merge_rev do.
|
|
122
107
|
const mergeReversed = <Item>(
|
|
123
108
|
first: Item[],
|
|
124
109
|
second: Item[],
|
|
@@ -136,8 +121,7 @@ const mergeReversed = <Item>(
|
|
|
136
121
|
return merged.reverse();
|
|
137
122
|
};
|
|
138
123
|
|
|
139
|
-
// OCaml's List.sort, step for step, so that a comparison that isn't a total order still gives
|
|
140
|
-
// Zenon's result.
|
|
124
|
+
// OCaml's List.sort, step for step, so that a comparison that isn't a total order still gives Zenon's result.
|
|
141
125
|
export const stableSort = <Item>(items: Item[], compare: (left: Item, right: Item) => number) => {
|
|
142
126
|
const sortRun = (count: number, start: number, isReversed: boolean): Item[] => {
|
|
143
127
|
const isBefore = (left: Item, right: Item) =>
|