tla-ts 0.0.9 → 0.0.10-dev.b4a856304
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 +28 -28
- package/dist/deciders.js +43 -43
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +72 -10
- package/dist/index.d.ts +72 -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 +116 -36
- 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 +128 -103
- package/dist/transfer.js +128 -103
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +3 -1
- package/src/ast.ts +7 -21
- package/src/bags.ts +99 -99
- package/src/builtins.ts +44 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check.ts +576 -300
- package/src/cli/options.ts +11 -6
- package/src/cli/run.ts +2 -2
- package/src/cli/runtime-invariants.ts +135 -0
- package/src/cli/shared.ts +20 -9
- package/src/cli/tlapm.ts +0 -12
- package/src/cli/tlc-arguments.ts +646 -0
- package/src/cli/tlc-usage.ts +362 -0
- package/src/cli/tlc.ts +538 -220
- package/src/cli/typescript.ts +23 -0
- package/src/cli/xml-exporter.ts +4 -16
- package/src/cli.ts +0 -1
- package/src/codegen.ts +191 -64
- package/src/config.ts +140 -109
- package/src/coverage.ts +837 -0
- package/src/dependencies.ts +6 -40
- package/src/dfid.ts +618 -0
- package/src/environment.ts +240 -118
- package/src/errors.ts +70 -55
- package/src/evaluate.ts +630 -297
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +10 -10
- package/src/index.ts +3 -0
- package/src/instances.ts +79 -11
- package/src/java-overrides.ts +2 -12
- package/src/json-reader.ts +456 -0
- package/src/json.ts +262 -139
- package/src/levels.ts +2 -3
- package/src/lexer.ts +17 -26
- package/src/liveness-checker.ts +10 -18
- package/src/liveness.ts +121 -49
- package/src/obligations/action.ts +4 -28
- package/src/obligations/anonymize.ts +84 -80
- package/src/obligations/equality.ts +1 -1
- package/src/obligations/expression.ts +2 -19
- package/src/obligations/format.ts +1 -9
- package/src/obligations/generate.ts +1 -11
- package/src/obligations/index.ts +0 -11
- package/src/obligations/levels.ts +4 -8
- package/src/obligations/module.ts +1 -15
- package/src/obligations/normalize.ts +5 -24
- 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 +3 -14
- package/src/obligations/source.ts +1 -21
- package/src/obligations/subexpression.ts +5 -11
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +8 -14
- package/src/obligations/tuples.ts +3 -9
- package/src/parallel-worker.ts +29 -39
- package/src/parallel.ts +29 -13
- package/src/parser.ts +436 -90
- package/src/pcal/ast.ts +7 -28
- package/src/pcal/parse.ts +11 -39
- package/src/pcal/tokenize.ts +4 -20
- package/src/pcal/translate.ts +10 -42
- package/src/pcal/validate.ts +3 -21
- package/src/pretty-print.ts +1 -2
- package/src/prover/decide-pool.ts +5 -10
- package/src/prover/deciders.ts +0 -4
- 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 +108 -114
- package/src/prover/isabelle/isar/method.ts +25 -38
- 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 +15 -26
- package/src/prover/isabelle/isar/type-check.ts +11 -25
- package/src/prover/isabelle/provers/blast/blast.ts +10 -41
- 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 +11 -25
- package/src/prover/isabelle/pure/bicompose.ts +16 -13
- package/src/prover/isabelle/pure/consts.ts +1 -7
- package/src/prover/isabelle/pure/conv.ts +1 -9
- package/src/prover/isabelle/pure/drule.ts +24 -40
- 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 +1 -14
- 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 +13 -49
- package/src/prover/isabelle/pure/rewriter.ts +26 -58
- 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 +1 -31
- package/src/prover/isabelle/pure/tactic.ts +12 -22
- package/src/prover/isabelle/pure/tactical.ts +6 -12
- 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 +13 -36
- 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 +9 -19
- package/src/prover/isabelle/tla/context.ts +8 -16
- package/src/prover/isabelle/tla/logic.ts +4 -11
- package/src/prover/isabelle/tla/simpdata.ts +46 -34
- package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
- package/src/prover/ocaml.ts +0 -6
- package/src/prover/prep/action.ts +4 -36
- package/src/prover/prep/enabled-axioms.ts +12 -19
- package/src/prover/prep/fingerprint.ts +0 -16
- package/src/prover/prep/level-comparison.ts +8 -12
- package/src/prover/prep/md5.ts +0 -2
- package/src/prover/prep/methods.ts +9 -36
- package/src/prover/prep/normalize.ts +4 -28
- package/src/prover/prove-worker.ts +0 -2
- package/src/prover/prove.ts +0 -36
- 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 +19 -26
- package/src/prover/smt/data.ts +51 -54
- package/src/prover/smt/encode.ts +14 -35
- 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 +66 -101
- 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 -143
- package/src/prover/smt/solver/auf-solver.ts +6 -39
- 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 +4 -61
- 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 +3 -34
- 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 +0 -5
- 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 +6 -98
- 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 +12 -98
- 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 +35 -130
- 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 +14 -56
- 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 +2 -36
- package/src/prover/smt/solver/model-evaluator.ts +3 -29
- package/src/prover/smt/solver/model-finder.ts +3 -15
- package/src/prover/smt/solver/model-generator.ts +1 -12
- package/src/prover/smt/solver/model-macro-solver.ts +12 -69
- package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
- package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
- package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
- package/src/prover/smt/solver/nlsat/explain.ts +3 -47
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
- package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
- package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
- package/src/prover/smt/solver/nlsat/solver.ts +7 -67
- package/src/prover/smt/solver/nlsat/types.ts +1 -8
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
- 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 -48
- 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 +17 -37
- package/src/prover/smt/solver/quantifier-manager.ts +1 -8
- 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 +2 -37
- 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 +0 -5
- package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
- 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 +20 -25
- package/src/prover/tlapm/ocaml-marshal.ts +19 -21
- package/src/prover/tlapm/tlapm.ts +12 -17
- package/src/prover/verdict.ts +0 -2
- package/src/prover/zenon/check/check.ts +0 -9
- 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 +0 -5
- package/src/prover/zenon/check/relations.ts +0 -13
- package/src/prover/zenon/check/rewrites.ts +0 -6
- package/src/prover/zenon/check/sets.ts +0 -3
- package/src/prover/zenon/check/terms.ts +0 -17
- 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 +0 -13
- package/src/prover/zenon/equality-rules.ts +0 -4
- package/src/prover/zenon/expr.ts +1 -26
- package/src/prover/zenon/index-table.ts +17 -38
- package/src/prover/zenon/isar-case.ts +9 -19
- package/src/prover/zenon/isar.ts +1 -29
- package/src/prover/zenon/limits.ts +0 -4
- package/src/prover/zenon/llproof.ts +0 -9
- package/src/prover/zenon/mltoll.ts +54 -76
- package/src/prover/zenon/node.ts +1 -11
- package/src/prover/zenon/ocaml.ts +1 -17
- package/src/prover/zenon/parse.ts +2 -7
- 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 +1 -17
- package/src/prover/zenon/tla/functions.ts +57 -29
- package/src/prover/zenon/tla/llproof.ts +63 -70
- package/src/prover/zenon/tla/records.ts +56 -27
- package/src/prover/zenon/tla/rewrites.ts +12 -19
- package/src/prover/zenon/tla/sets.ts +68 -39
- package/src/prover/zenon/tla/terms.ts +0 -6
- package/src/prover/zenon/tla/tla.ts +59 -58
- package/src/randomization.ts +84 -35
- package/src/resolve.ts +18 -60
- package/src/runtime.ts +11 -4
- package/src/sany/builtins.ts +3 -4
- package/src/sany/generator.ts +119 -169
- package/src/sany/levels.ts +6 -30
- package/src/sany/lexer.ts +7 -23
- package/src/sany/linter.ts +1 -8
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +0 -31
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +29 -63
- package/src/sany/selectors.ts +15 -39
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +13 -63
- package/src/search.ts +494 -154
- package/src/simulate.ts +694 -0
- package/src/spec-description.ts +166 -48
- package/src/standard-definitions.ts +2 -3
- package/src/standard-modules.ts +264 -68
- package/src/state-graph.ts +51 -18
- package/src/subexpressions.ts +31 -5
- package/src/substitution-levels.ts +2 -3
- package/src/successors.ts +267 -77
- package/src/symmetry.ts +31 -8
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +183 -61
- package/src/tlc/jar-data.ts +113 -6
- package/src/tlc/messages.ts +122 -37
- package/src/tlc/order.ts +33 -38
- package/src/tlc/random.ts +16 -16
- package/src/tlc/replay.ts +563 -211
- package/src/tlc/summary.ts +2 -4
- package/src/tlc/tlc-operators.ts +81 -36
- package/src/tlc/tlcext-operators.ts +138 -117
- package/src/tlc/trace-spec.ts +273 -0
- package/src/tlc/value-stream.ts +143 -0
- package/src/tlc/version.ts +2 -4
- package/src/transfer.ts +22 -25
- package/src/typescript/actions.ts +481 -0
- package/src/typescript/collections.ts +600 -0
- package/src/typescript/compile.ts +65 -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 +152 -0
- package/src/typescript/functions.ts +284 -0
- package/src/typescript/model.ts +163 -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 +165 -0
- package/src/typescript/types.ts +171 -0
- package/src/values.ts +826 -276
- package/src/worker.ts +7 -8
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// The check of unfolding a definition: a real definition from the input, or a pseudo-definition
|
|
2
|
-
// that Zenon reads off a hypothesis.
|
|
3
|
-
|
|
4
1
|
import type { Definition } from "../parse";
|
|
5
2
|
import {
|
|
6
3
|
app,
|
|
@@ -14,8 +11,6 @@ import {
|
|
|
14
11
|
type Term,
|
|
15
12
|
} from "./terms";
|
|
16
13
|
|
|
17
|
-
// Checks that `unfolded` is `folded` with occurrences of the defined symbol replaced by its body,
|
|
18
|
-
// going through applications and negations as Zenon does.
|
|
19
14
|
const isUnfolding = (
|
|
20
15
|
checker: Checker,
|
|
21
16
|
definition: Definition,
|
|
@@ -67,7 +62,6 @@ const getBound = (origin: Term) => {
|
|
|
67
62
|
return { bound, matrix };
|
|
68
63
|
};
|
|
69
64
|
|
|
70
|
-
// A pseudo-definition stands for its hypothesis, \A params : f(params) = body or <=> body.
|
|
71
65
|
const isDefinedBy = (checker: Checker, definition: Definition, origin: Term) => {
|
|
72
66
|
const quantified = getBound(origin);
|
|
73
67
|
const bound = quantified.bound;
|
|
@@ -85,14 +79,13 @@ const isDefinedBy = (checker: Checker, definition: Definition, origin: Term) =>
|
|
|
85
79
|
];
|
|
86
80
|
if (params.length === 0) heads.push(variable(definition.symbol));
|
|
87
81
|
const sides = matrix.args;
|
|
88
|
-
// The parameters are free in the head and the body, so compare them under the same names.
|
|
89
82
|
const env: Env = new Map(bound.map((name, index) => [name, index]));
|
|
90
|
-
const
|
|
91
|
-
const headKeys = heads.map(
|
|
92
|
-
const bodyKey =
|
|
83
|
+
const getBoundKey = (formula: Term) => checker.getKey(formula, env, bound.length);
|
|
84
|
+
const headKeys = heads.map(getBoundKey);
|
|
85
|
+
const bodyKey = getBoundKey(definition.body);
|
|
93
86
|
return (
|
|
94
|
-
(headKeys.includes(
|
|
95
|
-
(headKeys.includes(
|
|
87
|
+
(headKeys.includes(getBoundKey(sides[0])) && getBoundKey(sides[1]) === bodyKey) ||
|
|
88
|
+
(headKeys.includes(getBoundKey(sides[1])) && getBoundKey(sides[0]) === bodyKey)
|
|
96
89
|
);
|
|
97
90
|
};
|
|
98
91
|
|
|
@@ -102,7 +95,6 @@ const getFreeSymbols = (formula: Term, symbols: Set<string>) => {
|
|
|
102
95
|
return symbols;
|
|
103
96
|
};
|
|
104
97
|
|
|
105
|
-
// Real definitions are sound when each symbol has one and they don't refer to themselves.
|
|
106
98
|
const isWellFounded = (definition: Definition, definitions: Definition[]) => {
|
|
107
99
|
const reals = definitions.filter((candidate) => candidate.kind === "real");
|
|
108
100
|
const bySymbol = new Map(reals.map((candidate) => [candidate.symbol, candidate]));
|
|
@@ -130,8 +122,6 @@ export const getDefinitionSpec = (
|
|
|
130
122
|
): RuleSpec => {
|
|
131
123
|
const definitions = checker.context.definitions;
|
|
132
124
|
ensure(definitions.includes(definition));
|
|
133
|
-
// An equivalence only says the two sides have the same truth value, so it unfolds where a
|
|
134
|
-
// formula is expected, not inside a term.
|
|
135
125
|
const isEquivalence =
|
|
136
126
|
definition.kind === "pseudo" && getBound(definition.origin).matrix.kind === "equiv";
|
|
137
127
|
ensure(isUnfolding(checker, definition, args[0], args[1], isEquivalence));
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// The checks of Zenon's rules for equality, strings and the relations that the hypotheses make
|
|
2
|
-
// reflexive, symmetric or transitive.
|
|
3
|
-
|
|
4
1
|
import type { PlainRuleName, Rule, RelationRuleName } from "../proof";
|
|
5
2
|
import {
|
|
6
3
|
app,
|
|
@@ -20,8 +17,6 @@ import {
|
|
|
20
17
|
|
|
21
18
|
const relate = (symbol: string, left: Term, right: Term) => app(symbol, [left, right]);
|
|
22
19
|
|
|
23
|
-
// The two branches that the relation fails to link and the ends differ. The ends come from
|
|
24
|
-
// r(a, b) and ~r(c, d) in the order that Zenon's Trans or Trans_sym takes them.
|
|
25
20
|
const getTransitivitySpec = (
|
|
26
21
|
checker: Checker,
|
|
27
22
|
args: [Term, Term],
|
|
@@ -48,7 +43,6 @@ const getTransitivitySpec = (
|
|
|
48
43
|
};
|
|
49
44
|
};
|
|
50
45
|
|
|
51
|
-
// a = b against ~r(c, d), in the order of Zenon's TransEq, TransEq_sym or TransEq2.
|
|
52
46
|
const getTransitiveEqualitySpec = (
|
|
53
47
|
checker: Checker,
|
|
54
48
|
args: [Term, Term, Term],
|
|
@@ -83,7 +77,6 @@ const getTransitiveEqualitySpec = (
|
|
|
83
77
|
};
|
|
84
78
|
};
|
|
85
79
|
|
|
86
|
-
// Of t1 = s1 and t2 = s2 with distinct strings s1 and s2, in the order of the rule's sides.
|
|
87
80
|
const getStringDifferenceSpec = (args: Term[], sides: "ll" | "lr" | "rl" | "rr"): RuleSpec => {
|
|
88
81
|
const term1 = args[0];
|
|
89
82
|
const string1 = args[1];
|
|
@@ -99,7 +92,6 @@ const getStringDifferenceSpec = (args: Term[], sides: "ll" | "lr" | "rl" | "rr")
|
|
|
99
92
|
};
|
|
100
93
|
};
|
|
101
94
|
|
|
102
|
-
// Of f(a1, ..., an) and ~g(b1, ..., bn) with f and g the same: some argument differs.
|
|
103
95
|
const getArgumentsDifferSpec = (premises: Term[], left: Term, right: Term): RuleSpec => {
|
|
104
96
|
const leftArgs = expectKind(left, "app");
|
|
105
97
|
const rightArgs = expectKind(right, "app");
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// The checks of the TLA+ extension's rules for functions, after the lemmas in Zenon.thy that justify
|
|
2
|
-
// them.
|
|
3
|
-
|
|
4
1
|
import type { PlainRuleName } from "../proof";
|
|
5
2
|
import {
|
|
6
3
|
and,
|
|
@@ -18,7 +15,6 @@ import {
|
|
|
18
15
|
type Term,
|
|
19
16
|
} from "./terms";
|
|
20
17
|
|
|
21
|
-
// ~isAFcn(f) where f is built by a function constructor closes the branch.
|
|
22
18
|
const getNotFunctionSpec = (formula: Term, constructor: string, arity: number) => {
|
|
23
19
|
expectApp(expectApp(expectNot(formula), "TLA.isAFcn", 1)[0], constructor, arity);
|
|
24
20
|
return { premises: [formula], branches: [] };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// Comparing formulas by their own alpha-equivalence: each formula prints to a key in which a bound
|
|
2
|
-
// variable is the number of binders between it and its own.
|
|
3
|
-
|
|
4
1
|
import { term, UncheckedError, variable, type Env, type Operators, type Term } from "./terms";
|
|
5
2
|
|
|
6
3
|
export const createKeys = () => {
|
|
@@ -8,8 +5,6 @@ export const createKeys = () => {
|
|
|
8
5
|
const topKeys = new WeakMap<Term, string>();
|
|
9
6
|
let freshCount = 0;
|
|
10
7
|
|
|
11
|
-
// The variables and applied symbols that a formula doesn't bind, which are the names an
|
|
12
|
-
// environment can change.
|
|
13
8
|
const getFreeNames = (formula: Term): Set<string> => {
|
|
14
9
|
const cached = freeNames.get(formula);
|
|
15
10
|
if (cached !== undefined) return cached;
|
|
@@ -33,7 +28,6 @@ export const createKeys = () => {
|
|
|
33
28
|
return names;
|
|
34
29
|
};
|
|
35
30
|
|
|
36
|
-
// `operators` replaces applied symbols, for definitions whose parameters are operators.
|
|
37
31
|
const getKey = (formula: Term, env: Env, depth: number, operators?: Operators): string => {
|
|
38
32
|
for (const name of getFreeNames(formula))
|
|
39
33
|
if (env.has(name) || operators?.has(name) === true)
|
|
@@ -107,7 +101,6 @@ export const createKeys = () => {
|
|
|
107
101
|
const getTopKey = (formula: Term) => {
|
|
108
102
|
const cached = topKeys.get(formula);
|
|
109
103
|
if (cached !== undefined) return cached;
|
|
110
|
-
// Keys count binders from the variable, so a formula's key doesn't depend on where it sits.
|
|
111
104
|
const key = getEnvKey(formula, new Map(), 0);
|
|
112
105
|
topKeys.set(formula, key);
|
|
113
106
|
return key;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// The checks of Zenon's rules for connectives, quantifiers and the cut.
|
|
2
|
-
|
|
3
1
|
import type { PlainRuleName } from "../proof";
|
|
4
2
|
import {
|
|
5
3
|
and,
|
|
@@ -39,7 +37,6 @@ const getDisjuncts = (formula: Term): Term[] => {
|
|
|
39
37
|
return [formula];
|
|
40
38
|
};
|
|
41
39
|
|
|
42
|
-
// The witness of an existential: Hilbert's epsilon of its body.
|
|
43
40
|
const getWitness = (exists: Term) => instantiate(exists, term("tau", exists.symbol, exists.args));
|
|
44
41
|
|
|
45
42
|
export const PROPOSITIONAL_RULES = {
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// The checks of the TLA+ extension's rules for tuples and records, after the lemmas in Zenon.thy
|
|
2
|
-
// that justify them.
|
|
3
|
-
|
|
4
1
|
import type { PlainRuleName } from "../proof";
|
|
5
2
|
import {
|
|
6
3
|
app,
|
|
@@ -21,7 +18,6 @@ import {
|
|
|
21
18
|
type Term,
|
|
22
19
|
} from "./terms";
|
|
23
20
|
|
|
24
|
-
// The fields of a record or a set of records, whose labels must be distinct string literals.
|
|
25
21
|
export const getFields = (record: Term, constructor: "TLA.record" | "TLA.recordset") => {
|
|
26
22
|
const fields = getPairs(expectApp(record, constructor));
|
|
27
23
|
const labels = fields.map((field) => getStringText(field[0]));
|
|
@@ -49,7 +45,6 @@ const getRecordInequalitySpec = (formula: Term, isRecordRight: boolean): RuleSpe
|
|
|
49
45
|
};
|
|
50
46
|
};
|
|
51
47
|
|
|
52
|
-
// Checks that the formulas list exactly the expected ones, and returns them as branches.
|
|
53
48
|
const expectSameSet = (checker: Checker, given: Term[], expected: Term[]) => {
|
|
54
49
|
const keys = new Set(expected.map(checker.getTopKey));
|
|
55
50
|
ensure(
|
|
@@ -1,25 +1,13 @@
|
|
|
1
|
-
// Whether the hypotheses make a relation reflexive, symmetric or transitive, which Zenon's rules for
|
|
2
|
-
// relations other than = rely on. The property holds when no way for the relation to hold among
|
|
3
|
-
// three elements satisfies the ground instances of the hypotheses and breaks the property.
|
|
4
|
-
|
|
5
1
|
import type { CheckContext, RelationProperty, Term } from "./terms";
|
|
6
2
|
|
|
7
3
|
type Polarity = "positive" | "negative" | "both";
|
|
8
4
|
|
|
9
|
-
// A hypothesis as a test on how a relation holds among three elements: `values` gives the bound
|
|
10
|
-
// variables their elements and bit 3 * i + j of `holds` says whether the relation holds from
|
|
11
|
-
// element i to element j.
|
|
12
5
|
type GroundTest = (values: number[], holds: number) => boolean;
|
|
13
6
|
|
|
14
7
|
const ELEMENTS = [0, 1, 2];
|
|
15
8
|
|
|
16
|
-
// The type Zenon gives a variable that its binder leaves untyped, which ranges over everything.
|
|
17
9
|
const UNTYPED = "zenon_U";
|
|
18
10
|
|
|
19
|
-
// The ground instances of a hypothesis over three elements. A universal quantifier where the
|
|
20
|
-
// hypothesis asserts it, or an existential where it denies it, becomes a test over the three
|
|
21
|
-
// elements, which the hypothesis implies. Undefined when the hypothesis says anything but how the
|
|
22
|
-
// relation holds between bound variables, so that it's left out.
|
|
23
11
|
const getGroundTest = (
|
|
24
12
|
formula: Term,
|
|
25
13
|
symbol: string,
|
|
@@ -92,7 +80,6 @@ const getGroundTest = (
|
|
|
92
80
|
}
|
|
93
81
|
};
|
|
94
82
|
|
|
95
|
-
// = has every property. Another relation has the ones the hypotheses give it.
|
|
96
83
|
export const createRelationProperties = (context: CheckContext) => {
|
|
97
84
|
const cache = new Map<string, boolean>();
|
|
98
85
|
const hasProperty = (symbol: string, property: RelationProperty) => {
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
// The checks of the TLA+ extension's rules that rewrite a subterm in place: evaluating a function
|
|
2
|
-
// application, DOMAIN, IF, CASE, Len, or a formula used as a term. Each rule names the context of
|
|
3
|
-
// the subterm as a lambda, (\x. context).
|
|
4
|
-
|
|
5
1
|
import type { PlainRuleName } from "../proof";
|
|
6
2
|
import { getFields } from "./records";
|
|
7
3
|
import {
|
|
@@ -28,7 +24,6 @@ import {
|
|
|
28
24
|
type Term,
|
|
29
25
|
} from "./terms";
|
|
30
26
|
|
|
31
|
-
// The term that fills the hole of a context to give a formula.
|
|
32
27
|
const getFilled = (lambda: Term, formula: Term) => {
|
|
33
28
|
ensure(lambda.kind === "lam");
|
|
34
29
|
const hole = lambda.args[0].symbol;
|
|
@@ -68,7 +63,6 @@ const getCaseBranches = (lambda: Term, args: Term[], condition: Term): Term[][]
|
|
|
68
63
|
];
|
|
69
64
|
};
|
|
70
65
|
|
|
71
|
-
// A formula used as a term splits into the cases where it equals TRUE and FALSE.
|
|
72
66
|
const getBoolCaseSpec = (
|
|
73
67
|
checker: Checker,
|
|
74
68
|
args: Term[],
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
// What the rule checks share: the formulas they build and take apart, and how a check rejects a
|
|
2
|
-
// proof.
|
|
3
|
-
|
|
4
1
|
import type { ExprKind } from "../expr";
|
|
5
2
|
import type { Definition } from "../parse";
|
|
6
3
|
import type { PlainRuleName, RuleArgs } from "../proof";
|
|
7
4
|
|
|
8
5
|
type TermKind = ExprKind | "subst";
|
|
9
6
|
|
|
10
|
-
// A formula as the checker sees it. The prover's expressions fit this shape. "subst" stands for
|
|
11
|
-
// its first argument with the variable named `symbol` replaced by its second argument.
|
|
12
7
|
export interface Term {
|
|
13
8
|
kind: TermKind;
|
|
14
9
|
symbol: string;
|
|
@@ -20,7 +15,6 @@ export interface CheckContext {
|
|
|
20
15
|
definitions: Definition[];
|
|
21
16
|
}
|
|
22
17
|
|
|
23
|
-
// What a rule needs on its branch: its premises, and the formulas each of its branches adds.
|
|
24
18
|
export interface RuleSpec {
|
|
25
19
|
premises: Term[];
|
|
26
20
|
branches: Term[][];
|
|
@@ -28,34 +22,25 @@ export interface RuleSpec {
|
|
|
28
22
|
|
|
29
23
|
export type RelationProperty = "reflexive" | "symmetric" | "transitive";
|
|
30
24
|
|
|
31
|
-
// What a variable stands for while printing a key: the depth of its binder, or a term substituted
|
|
32
|
-
// for it with the environment where the substitution was made. A substituted term prints where it
|
|
33
|
-
// lands, so its own binders get depths below the binders around it.
|
|
34
25
|
export type Binding = number | { formula: Term; env: Env; operators?: Operators };
|
|
35
26
|
|
|
36
27
|
export type Env = Map<string, Binding>;
|
|
37
28
|
|
|
38
29
|
export type Operators = Map<string, Term>;
|
|
39
30
|
|
|
40
|
-
// One check of a proof, with the caches that last as long as it does.
|
|
41
31
|
export interface Checker {
|
|
42
32
|
context: CheckContext;
|
|
43
|
-
// A canonical text for a formula up to the names of bound variables.
|
|
44
33
|
getKey: (formula: Term, env: Env, depth: number, operators?: Operators) => string;
|
|
45
34
|
getTopKey: (formula: Term) => string;
|
|
46
35
|
isSame: (left: Term, right: Term) => boolean;
|
|
47
|
-
// A binder whose variable can't clash with any name in the input.
|
|
48
36
|
bind: (kind: "all" | "ex", type: string, build: (bound: Term) => Term) => Term;
|
|
49
|
-
// Rejects the proof unless the hypotheses give the relation these properties.
|
|
50
37
|
ensureRelation: (symbol: string, properties: RelationProperty[]) => void;
|
|
51
38
|
}
|
|
52
39
|
|
|
53
|
-
// The check of each rule, given the rule's arguments and the formulas the proof says it uses.
|
|
54
40
|
export type SpecTable<Name extends PlainRuleName> = {
|
|
55
41
|
[Key in Name]: (args: RuleArgs<Key, Term>, checker: Checker, uses: Term[]) => RuleSpec;
|
|
56
42
|
};
|
|
57
43
|
|
|
58
|
-
// Raised inside a rule check to reject the proof.
|
|
59
44
|
export class UncheckedError extends Error {}
|
|
60
45
|
|
|
61
46
|
export const ensure: (condition: boolean) => asserts condition = (condition) => {
|
|
@@ -81,7 +66,6 @@ export const domain = (fcn: Term) => app("TLA.DOMAIN", [fcn]);
|
|
|
81
66
|
export const TRUE = term("true", "", []);
|
|
82
67
|
export const FALSE = term("false", "", []);
|
|
83
68
|
|
|
84
|
-
// Instantiates the body of a binder with a term.
|
|
85
69
|
export const instantiate = (binder: Term, value: Term) =>
|
|
86
70
|
term("subst", binder.args[0].symbol, [binder.args[1], value]);
|
|
87
71
|
|
|
@@ -105,7 +89,6 @@ export const expectNot = (formula: Term) => expectKind(formula, "not")[0];
|
|
|
105
89
|
export const isVariable = (formula: Term, name: string) =>
|
|
106
90
|
formula.kind === "var" && formula.symbol === name;
|
|
107
91
|
|
|
108
|
-
// The text of a string literal. Escapes could spell one string two ways, so they don't count.
|
|
109
92
|
export const getStringText = (formula: Term) => {
|
|
110
93
|
ensure(isApp(formula, "$string", 1) && formula.args[0].kind === "var");
|
|
111
94
|
const text = formula.args[0].symbol;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// The checks of the TLA+ extension's rules for booleans, CHOOSE, natural numbers, bounded
|
|
2
|
-
// quantifiers and equal propositions, after the lemmas in Zenon.thy that justify them.
|
|
3
|
-
|
|
4
1
|
import type { PlainRuleName } from "../proof";
|
|
5
2
|
import {
|
|
6
3
|
ensure,
|
|
@@ -18,8 +15,6 @@ import {
|
|
|
18
15
|
type Term,
|
|
19
16
|
} from "./terms";
|
|
20
17
|
|
|
21
|
-
// From P and a = b, or ~P and a = b, where P is one side: P differs from that side, or the other
|
|
22
|
-
// side holds.
|
|
23
18
|
const getPropositionEqualitySpec = (
|
|
24
19
|
args: Term[],
|
|
25
20
|
isNegated: boolean,
|
|
@@ -77,7 +72,6 @@ export const TLA_RULES = {
|
|
|
77
72
|
);
|
|
78
73
|
return { premises: [args[0]], branches: [[differ]] };
|
|
79
74
|
},
|
|
80
|
-
// Zenon writes ~(P <=> Q) as $notequiv(P, Q).
|
|
81
75
|
notequivdef: (_args, _checker, uses) => {
|
|
82
76
|
ensure(uses.length === 1);
|
|
83
77
|
const sides = expectApp(uses[0], "$notequiv", 2);
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
// Ported from Zenon's main.ml, as shipped in tlapm. Copyright 1997 INRIA, see LICENSE.
|
|
2
|
-
//
|
|
3
|
-
// Runs Zenon on a .znn file as tlapm does, with -oisar. A proof counts only once the independent
|
|
4
|
-
// checker accepts it. tlapm passes -max-time 1d and kills Zenon at its own timeout instead, whether
|
|
5
|
-
// Zenon is still reading, searching or printing the proof.
|
|
6
2
|
|
|
7
3
|
import { TlaZenonError } from "../../errors";
|
|
8
4
|
import type { DecideOptions } from "../verdict";
|
|
@@ -20,11 +16,7 @@ import { getBuiltInDefinitions, PREDEFINED_SYMBOLS } from "./tla/tla";
|
|
|
20
16
|
|
|
21
17
|
interface ZenonRun {
|
|
22
18
|
proof: Proof | undefined;
|
|
23
|
-
// Why Zenon gave up: in the search, or at the limits while it checked or printed the proof.
|
|
24
|
-
// "zenon error" stands for the exceptions that stop Zenon mid-search.
|
|
25
19
|
failure: SearchFailure | "zenon error" | undefined;
|
|
26
|
-
// Zenon's -oisar output, once the checker accepts the proof and the printer ends within the
|
|
27
|
-
// limits.
|
|
28
20
|
isar: string | undefined;
|
|
29
21
|
nodesSearched: number;
|
|
30
22
|
maxBranchFormulas: number;
|
|
@@ -32,8 +24,6 @@ interface ZenonRun {
|
|
|
32
24
|
formulasCreated: number;
|
|
33
25
|
}
|
|
34
26
|
|
|
35
|
-
// The search and its statistics, which match the -stats output of the OCaml Zenon. Throws
|
|
36
|
-
// TlaZenonError when the text isn't a valid .znn file.
|
|
37
27
|
export const runZenon = (text: string, options: DecideOptions): ZenonRun => {
|
|
38
28
|
const limits = { deadline: Date.now() + options.timeLimitMs, signal: options.signal };
|
|
39
29
|
const exprs = createExpressions();
|
|
@@ -99,8 +89,6 @@ export const runZenon = (text: string, options: DecideOptions): ZenonRun => {
|
|
|
99
89
|
|
|
100
90
|
type ZenonDecision = { verdict: "unsat"; proof: string } | { verdict: "unknown" };
|
|
101
91
|
|
|
102
|
-
// Zenon's verdict on a .znn file: "unsat" with the Isar proof that tlapm writes, when Zenon refutes
|
|
103
|
-
// the hypotheses with a proof that the checker accepts and prints it within the time limit.
|
|
104
92
|
export const decideZenon = (text: string, options: DecideOptions): ZenonDecision => {
|
|
105
93
|
const isar = runZenon(text, options).isar;
|
|
106
94
|
return isar === undefined ? { verdict: "unknown" } : { verdict: "unsat", proof: isar };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
// A port of tlapm's Backend.Zenon
|
|
2
|
-
// each visible fact and a $goal, naming identifiers as Isabelle does.
|
|
1
|
+
// A port of tlapm's Backend.Zenon.
|
|
3
2
|
|
|
4
3
|
import { TlapmBugError, TlaProverError, TlaUnsupportedError } from "../../errors";
|
|
5
4
|
import { createContext, getBoundName, popNames, pushName } from "../../obligations/printer";
|
|
@@ -74,9 +73,6 @@ const getSuccessors = (integer: string) => {
|
|
|
74
73
|
return `${"(TLA.fapply TLA.Succ ".repeat(count)}0${")".repeat(count)}`;
|
|
75
74
|
};
|
|
76
75
|
|
|
77
|
-
// pp_print_obligation: the text tlapm writes to the .znn file it hands Zenon, for an obligation
|
|
78
|
-
// that Backend.Prep has shipped. Unsupported in the goal fails the obligation and in a fact omits
|
|
79
|
-
// it.
|
|
80
76
|
export const encodeZenon = (id: number, sequent: Sequent) => {
|
|
81
77
|
const context = createContext();
|
|
82
78
|
const adjoin = (name: string) => pushName(context, pickle(name));
|
|
@@ -85,7 +81,6 @@ export const encodeZenon = (id: number, sequent: Sequent) => {
|
|
|
85
81
|
const delimited = (args: Expr[]) => formatDelimited(args, printExpr, SPACE);
|
|
86
82
|
const nonatomic = (name: string, args: Expr[]) => format("(%s %a)", name, delimited(args));
|
|
87
83
|
|
|
88
|
-
// A binder's name binds in the body, and what comes before prints outside it.
|
|
89
84
|
const printBinder = (name: string, before: Doc, body: Expr) => {
|
|
90
85
|
const bound = adjoin(name);
|
|
91
86
|
const doc = format("%a((%s) %a))", before, bound, printExpr(body));
|
|
@@ -163,7 +158,6 @@ export const encodeZenon = (id: number, sequent: Sequent) => {
|
|
|
163
158
|
);
|
|
164
159
|
};
|
|
165
160
|
|
|
166
|
-
// SetOf and Fcn take one bound, whose domain prints outside it.
|
|
167
161
|
const printOneBound = (name: string, bounds: Bound[], body: Expr, what: string) => {
|
|
168
162
|
if (bounds.length !== 1) throw new TlaUnsupportedError(`${what} (multiple declared constants)`);
|
|
169
163
|
const bound = bounds[0];
|
|
@@ -175,7 +169,6 @@ export const encodeZenon = (id: number, sequent: Sequent) => {
|
|
|
175
169
|
);
|
|
176
170
|
};
|
|
177
171
|
|
|
178
|
-
// A sequent inside an expression, as an implication under quantifiers.
|
|
179
172
|
const printNestedSequent = (sequent: Sequent): Doc => {
|
|
180
173
|
if (sequent.context.length === 0) return printExpr(sequent.active);
|
|
181
174
|
const hyp = sequent.context[0];
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
// Ported from Zenon's eqrel.ml, as shipped in tlapm. Copyright 2004 INRIA, see LICENSE.
|
|
2
|
-
//
|
|
3
|
-
// Finds the hypotheses that make a relation reflexive, symmetric or transitive. The prover then
|
|
4
|
-
// reasons with those properties directly, and drops the hypotheses that only state them. The
|
|
5
|
-
// translation to Isar proves the properties again from the hypotheses that stated them.
|
|
6
2
|
|
|
7
3
|
import { TRUE, type Expr, type Expressions } from "./expr";
|
|
8
4
|
|
|
9
5
|
export type Direction = "left" | "right";
|
|
10
6
|
|
|
11
|
-
// Where a hypothesis states a property: the conjunct at `directions`, with the relation's
|
|
12
|
-
// arguments bound by the quantifiers at `variables`, counted from the outermost.
|
|
13
7
|
export interface Origin {
|
|
14
8
|
formula: Expr;
|
|
15
9
|
directions: Direction[];
|
|
@@ -21,7 +15,6 @@ interface RelationInfo {
|
|
|
21
15
|
symmetric: Origin | undefined;
|
|
22
16
|
transitive: Origin | undefined;
|
|
23
17
|
transitiveSymmetric: Origin | undefined;
|
|
24
|
-
// The type of the relation's arguments.
|
|
25
18
|
type: string;
|
|
26
19
|
}
|
|
27
20
|
|
|
@@ -30,8 +23,6 @@ interface Bound {
|
|
|
30
23
|
type: string;
|
|
31
24
|
}
|
|
32
25
|
|
|
33
|
-
// A conjunct of a hypothesis: the variables quantified around it and the literals of its
|
|
34
|
-
// disjunction, when they all relate two of those variables by the same symbol.
|
|
35
26
|
interface Leaves {
|
|
36
27
|
directions: Direction[];
|
|
37
28
|
env: Bound[];
|
|
@@ -125,7 +116,6 @@ const getPair = (leaf: Expr) => {
|
|
|
125
116
|
return [args[0].symbol, args[1].symbol];
|
|
126
117
|
};
|
|
127
118
|
|
|
128
|
-
// The leaves as Zenon's partition returns them: positive and negative, each reversed.
|
|
129
119
|
const partition = (leaves: Expr[]) => ({
|
|
130
120
|
positive: leaves
|
|
131
121
|
.filter((leaf) => leaf.kind !== "not")
|
|
@@ -137,8 +127,6 @@ const partition = (leaves: Expr[]) => ({
|
|
|
137
127
|
.map(getPair),
|
|
138
128
|
});
|
|
139
129
|
|
|
140
|
-
// Each check returns the variables that the translation instantiates to prove the property, or
|
|
141
|
-
// undefined when the conjunct doesn't state it.
|
|
142
130
|
const getReflexive = (leaves: Expr[]) => {
|
|
143
131
|
if (leaves.length !== 1 || leaves[0].kind === "not") return undefined;
|
|
144
132
|
const pair = getPair(leaves[0]);
|
|
@@ -292,7 +280,6 @@ export const createRelations = (exprs: Expressions) => {
|
|
|
292
280
|
record.transitive !== undefined)
|
|
293
281
|
);
|
|
294
282
|
},
|
|
295
|
-
// Where the hypotheses state a relation's properties, for the translation to Isar.
|
|
296
283
|
get,
|
|
297
284
|
};
|
|
298
285
|
};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
// Ported from Zenon's prove.ml, as shipped in tlapm. Copyright 2002 INRIA, see LICENSE.
|
|
2
|
-
//
|
|
3
|
-
// The rules for equality and other relations: instances that unify a metavariable, matching a
|
|
4
|
-
// literal against its negation, congruence, reflexivity, symmetry and transitivity.
|
|
5
2
|
|
|
6
3
|
import { TlaZenonError } from "../../errors";
|
|
7
4
|
import {
|
|
@@ -50,7 +47,6 @@ const makeInstance = (
|
|
|
50
47
|
]),
|
|
51
48
|
);
|
|
52
49
|
}
|
|
53
|
-
// Zenon hands applications to the extension named by the symbol's prefix, and tla has none.
|
|
54
50
|
if (quantified.kind === "app") return queue;
|
|
55
51
|
throw new TlaZenonError("Zenon: make_inst on a formula that isn't quantified");
|
|
56
52
|
};
|
package/src/prover/zenon/expr.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
// Ported from Zenon's expr.ml, as shipped in tlapm. Copyright 2002 INRIA, see LICENSE.
|
|
2
|
-
//
|
|
3
|
-
// Formulas and terms, hash-consed so that equal expressions are the same object. Like Zenon,
|
|
4
|
-
// equality treats bound variables up to renaming, and a hash ignores the names of bound variables.
|
|
5
|
-
// Each run builds its expressions in its own store, so that fresh names and hashes start over.
|
|
6
2
|
|
|
7
3
|
import { TlaZenonError } from "../../errors";
|
|
8
4
|
import { combine, createHasher, toInt63, type Int63 } from "./ocaml";
|
|
9
5
|
|
|
10
|
-
// What every expression caches about itself.
|
|
11
6
|
interface ExprData {
|
|
12
7
|
id: number;
|
|
13
8
|
hash: number;
|
|
@@ -24,7 +19,6 @@ export interface VarExpr extends ExprData {
|
|
|
24
19
|
args: [];
|
|
25
20
|
}
|
|
26
21
|
|
|
27
|
-
// A metavariable stands for a term that instantiates its quantifier.
|
|
28
22
|
export interface MetaExpr extends ExprData {
|
|
29
23
|
kind: "meta";
|
|
30
24
|
symbol: "";
|
|
@@ -55,7 +49,6 @@ export interface ConstantExpr extends ExprData {
|
|
|
55
49
|
args: [];
|
|
56
50
|
}
|
|
57
51
|
|
|
58
|
-
// `symbol` is the type of the bound variable.
|
|
59
52
|
export interface BinderExpr extends ExprData {
|
|
60
53
|
kind: "all" | "ex" | "tau" | "lam";
|
|
61
54
|
symbol: string;
|
|
@@ -66,7 +59,6 @@ export type Expr = VarExpr | MetaExpr | AppExpr | NotExpr | BinaryExpr | Constan
|
|
|
66
59
|
|
|
67
60
|
export type ExprKind = Expr["kind"];
|
|
68
61
|
|
|
69
|
-
// An application to two arguments, such as an equality or another relation between two terms.
|
|
70
62
|
export type RelationExpr = AppExpr & { args: [Expr, Expr] };
|
|
71
63
|
|
|
72
64
|
export type NegatedRelationExpr = NotExpr & { args: [RelationExpr] };
|
|
@@ -121,8 +113,6 @@ const isBinder = (expression: Expr): expression is BinderExpr =>
|
|
|
121
113
|
expression.kind === "tau" ||
|
|
122
114
|
expression.kind === "lam";
|
|
123
115
|
|
|
124
|
-
// Zenon's str_union: the names of the first list missing from the second, in reverse, then the
|
|
125
|
-
// second. Hashes depend on this order.
|
|
126
116
|
const unionNames = (left: string[], right: string[]) => {
|
|
127
117
|
if (left.length === 0) return right;
|
|
128
118
|
if (right.length === 0) return left;
|
|
@@ -139,7 +129,6 @@ const removeName = (name: string, names: string[]) => {
|
|
|
139
129
|
export const difference = (left: Expr[], right: Expr[]) =>
|
|
140
130
|
left.filter((inner) => !right.includes(inner));
|
|
141
131
|
|
|
142
|
-
// Zenon's union on small sets: the first list's new elements in reverse, then the second list.
|
|
143
132
|
export const union = (left: Expr[], right: Expr[]) => {
|
|
144
133
|
const added = difference(left, right);
|
|
145
134
|
return added.length === 0 ? right : [...added.reverse(), ...right];
|
|
@@ -212,7 +201,6 @@ const isEqualBody = (leftVar: Expr, rightVar: Expr, left: Expr, right: Expr) =>
|
|
|
212
201
|
);
|
|
213
202
|
};
|
|
214
203
|
|
|
215
|
-
// Zenon's HashedExpr.equal on two binders whose children are already hash-consed.
|
|
216
204
|
const isSameBinder = (left: BinderExpr, right: BinderExpr) =>
|
|
217
205
|
left.kind === right.kind &&
|
|
218
206
|
left.symbol === right.symbol &&
|
|
@@ -220,8 +208,6 @@ const isSameBinder = (left: BinderExpr, right: BinderExpr) =>
|
|
|
220
208
|
? left.args[1] === right.args[1]
|
|
221
209
|
: isEqualBody(left.args[0], right.args[0], left.args[1], right.args[1]));
|
|
222
210
|
|
|
223
|
-
// The symbol is part of the narrowed type, so a failed test for one symbol keeps the expression an
|
|
224
|
-
// application for the next test.
|
|
225
211
|
export const isApp = <Symbol extends string>(
|
|
226
212
|
expression: Expr,
|
|
227
213
|
symbol: Symbol,
|
|
@@ -239,7 +225,6 @@ export const isRelation = (expression: Expr): expression is RelationExpr =>
|
|
|
239
225
|
export const isNegatedRelation = (expression: Expr): expression is NegatedRelationExpr =>
|
|
240
226
|
expression.kind === "not" && isRelation(expression.args[0]);
|
|
241
227
|
|
|
242
|
-
// Zenon orders by hash, and only breaks ties structurally.
|
|
243
228
|
export const compareExprs = (left: Expr, right: Expr): number => {
|
|
244
229
|
if (left.hash !== right.hash) return left.hash < right.hash ? -1 : 1;
|
|
245
230
|
if (left === right) return 0;
|
|
@@ -263,20 +248,14 @@ const isIrrelevant = (names: string[], map: Substitution) =>
|
|
|
263
248
|
const hasConflict = (variable: Expr, map: Substitution) =>
|
|
264
249
|
map.some((pair) => pair[1].freeVars.includes(variable.symbol));
|
|
265
250
|
|
|
266
|
-
// The store of one run's expressions, and the operations that build expressions in it.
|
|
267
251
|
export const createExpressions = () => {
|
|
268
252
|
const hasher = createHasher();
|
|
269
|
-
// Binders are hash-consed by hash, since they're equal up to the names of their variables. Other
|
|
270
|
-
// expressions are equal exactly when their kind, symbol and children are, so they're found by
|
|
271
|
-
// those before their hash is computed.
|
|
272
253
|
const binders = new Map<number, BinderExpr[]>();
|
|
273
254
|
const interned = new Map<number, Expr[]>();
|
|
274
|
-
// Numbers for the symbols, so an expression hashes by its symbol and children without strings.
|
|
275
255
|
const symbolIds = new Map<string, number>();
|
|
276
256
|
let nextId = FALSE.id + 1;
|
|
277
257
|
let createdCount = 0;
|
|
278
|
-
// Zenon's Ext_focal takes the first five fresh names
|
|
279
|
-
// definitions, so the first name Zenon gives out is zenon_Vf.
|
|
258
|
+
// Zenon's Ext_focal takes the first five fresh names at startup, so the first name Zenon gives out is zenon_Vf.
|
|
280
259
|
let nameCounter = "e";
|
|
281
260
|
|
|
282
261
|
const create = <Shape extends Pick<Expr, "kind" | "symbol" | "args">>(
|
|
@@ -437,8 +416,6 @@ export const createExpressions = () => {
|
|
|
437
416
|
return evar(VAR_PREFIX + nameCounter);
|
|
438
417
|
};
|
|
439
418
|
|
|
440
|
-
// A binder's variable for a substitution, renamed when the substituted values capture it, and
|
|
441
|
-
// the substitution to apply to its body.
|
|
442
419
|
const enterBinder = (expression: BinderExpr, map: Substitution): [VarExpr, Substitution] => {
|
|
443
420
|
const variable = expression.args[0];
|
|
444
421
|
const rest = map.filter((pair) => pair[0] !== variable);
|
|
@@ -486,8 +463,6 @@ export const createExpressions = () => {
|
|
|
486
463
|
return results;
|
|
487
464
|
};
|
|
488
465
|
|
|
489
|
-
// Zenon's substitute_2nd: also replaces applied symbols bound in the map, for definitions with
|
|
490
|
-
// operator parameters. Undefined stands for Zenon's Higher_order exception.
|
|
491
466
|
const substituteSecondOrder = (map: Substitution, expression: Expr): Expr | undefined => {
|
|
492
467
|
switch (expression.kind) {
|
|
493
468
|
case "var":
|