tla-ts 0.0.8 → 0.0.9-dev.0493be549
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 +30 -0
- 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 +98 -19
- package/dist/index.d.ts +98 -19
- 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 -106
- package/dist/transfer.js +128 -106
- 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 +605 -311
- package/src/cli/options.ts +12 -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 +545 -218
- 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 -69
- package/src/config.ts +140 -109
- package/src/coverage.ts +837 -0
- package/src/dependencies.ts +314 -24
- package/src/dfid.ts +618 -0
- package/src/environment.ts +263 -129
- package/src/errors.ts +70 -55
- package/src/evaluate.ts +734 -980
- 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 +150 -70
- package/src/liveness-checker.ts +10 -18
- package/src/liveness.ts +122 -64
- 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 +31 -38
- package/src/parallel.ts +41 -17
- 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 +128 -176
- package/src/sany/levels.ts +6 -30
- package/src/sany/lexer.ts +7 -23
- package/src/sany/linter.ts +31 -29
- 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 +536 -180
- package/src/simulate.ts +694 -0
- package/src/spec-description.ts +167 -49
- 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 +269 -85
- package/src/symmetry.ts +59 -147
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +226 -151
- package/src/tlc/jar-data.ts +113 -6
- package/src/tlc/messages.ts +122 -37
- package/src/tlc/order.ts +56 -82
- package/src/tlc/random.ts +16 -16
- package/src/tlc/replay.ts +564 -212
- 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 +910 -318
- package/src/worker.ts +7 -8
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
// Parses Isabelle's inner syntax, the terms inside quotes, as far as tlapm's theory printer
|
|
2
|
-
// (isabelle.ml) uses it. The notation and its priorities come from Isabelle2025's Pure and from
|
|
3
|
-
// the Isabelle/TLA+ theories that declare it: PredicateLogic, SetTheory, Functions, Tuples,
|
|
4
|
-
// Strings and CaseExpressions. The translations those theories declare apply while parsing, so a
|
|
5
|
-
// term comes out as constants, names, applications and abstractions only.
|
|
6
|
-
|
|
7
1
|
import { TlaIsabelleError } from "../../../errors";
|
|
8
2
|
import { funT, mkType, propT, type Typ } from "../pure/term";
|
|
9
3
|
|
|
10
4
|
const TLA_TYPE = mkType("PredicateLogic.c");
|
|
11
5
|
|
|
12
|
-
// A parsed term before names resolve and types are inferred. A name is a bound or free variable
|
|
13
|
-
// or a constant; a constant comes from notation.
|
|
14
6
|
export type Ast =
|
|
15
7
|
| { readonly kind: "name"; readonly name: string }
|
|
16
8
|
| { readonly kind: "const"; readonly name: string }
|
|
@@ -109,31 +101,30 @@ const tokenize = (text: string): Token[] => {
|
|
|
109
101
|
return tokens;
|
|
110
102
|
};
|
|
111
103
|
|
|
112
|
-
const
|
|
104
|
+
const toConstant = (name: string): Ast => ({ kind: "const", name });
|
|
113
105
|
const apply = (fun: Ast, ...args: Ast[]) =>
|
|
114
106
|
args.reduce<Ast>((result, arg) => ({ kind: "app", fun: result, arg }), fun);
|
|
115
107
|
|
|
116
|
-
|
|
117
|
-
const nibble = (value: number): Ast =>
|
|
108
|
+
const toNibble = (value: number): Ast =>
|
|
118
109
|
value === 0
|
|
119
|
-
?
|
|
120
|
-
: apply(
|
|
110
|
+
? toConstant("Integers.zero")
|
|
111
|
+
: apply(toConstant("Functions.fapply"), toConstant("Integers.succ"), toNibble(value - 1));
|
|
121
112
|
|
|
122
|
-
const
|
|
113
|
+
const toStringTerm = (text: string) =>
|
|
123
114
|
[...text].reduce((tuple, char) => {
|
|
124
115
|
const code = char.charCodeAt(0);
|
|
125
116
|
if (code >= 128) throw new TlaIsabelleError("ERROR", `Non-ASCII symbol: ${char}`);
|
|
126
117
|
return apply(
|
|
127
|
-
|
|
118
|
+
toConstant("Tuples.Append"),
|
|
128
119
|
tuple,
|
|
129
|
-
apply(
|
|
120
|
+
apply(toConstant("Strings.char"), toNibble(code >> 4), toNibble(code & 15)),
|
|
130
121
|
);
|
|
131
|
-
},
|
|
122
|
+
}, toConstant("Tuples.emptySeq"));
|
|
132
123
|
|
|
133
|
-
const
|
|
124
|
+
const toTuple = (elements: readonly Ast[]) =>
|
|
134
125
|
elements.reduce(
|
|
135
|
-
(result, element) => apply(
|
|
136
|
-
|
|
126
|
+
(result, element) => apply(toConstant("Tuples.Append"), result, element),
|
|
127
|
+
toConstant("Tuples.emptySeq"),
|
|
137
128
|
);
|
|
138
129
|
|
|
139
130
|
interface Infix {
|
|
@@ -188,14 +179,17 @@ const PREFIXES = new Map<
|
|
|
188
179
|
["DOMAIN", { constant: "Functions.DOMAIN", argument: 100, priority: 90 }],
|
|
189
180
|
]);
|
|
190
181
|
|
|
191
|
-
// A parse result: the term, its priority, and whether it is a proposition rather than an object
|
|
192
|
-
// of the logic, which Isabelle tells apart by syntactic category.
|
|
193
182
|
interface Parsed {
|
|
194
183
|
readonly ast: Ast;
|
|
195
184
|
readonly priority: number;
|
|
196
185
|
readonly isProp: boolean;
|
|
197
186
|
}
|
|
198
187
|
|
|
188
|
+
interface TypedName {
|
|
189
|
+
readonly name: string;
|
|
190
|
+
readonly type: Typ | undefined;
|
|
191
|
+
}
|
|
192
|
+
|
|
199
193
|
const MAX_PRIORITY = 1000;
|
|
200
194
|
|
|
201
195
|
class Parser {
|
|
@@ -231,23 +225,22 @@ class Parser {
|
|
|
231
225
|
);
|
|
232
226
|
}
|
|
233
227
|
|
|
234
|
-
private
|
|
228
|
+
private parseIdentifier(): string {
|
|
235
229
|
const token = this.next();
|
|
236
230
|
if (token.kind !== "id") throw this.syntaxError();
|
|
237
231
|
return token.text;
|
|
238
232
|
}
|
|
239
233
|
|
|
240
|
-
|
|
234
|
+
isAtEnd() {
|
|
241
235
|
return this.peek().kind === "end";
|
|
242
236
|
}
|
|
243
237
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
const atom = domains === undefined ? this.typeAtom() : undefined;
|
|
238
|
+
parseType(): Typ {
|
|
239
|
+
const domains = this.isDelimiter("[") ? this.parseTypeList() : undefined;
|
|
240
|
+
const atom = domains === undefined ? this.parseTypeAtom() : undefined;
|
|
248
241
|
if (this.isDelimiter("=>") || this.isDelimiter("\\<Rightarrow>")) {
|
|
249
242
|
this.position += 1;
|
|
250
|
-
const range = this.
|
|
243
|
+
const range = this.parseType();
|
|
251
244
|
return (domains ?? [atom ?? TLA_TYPE]).reduceRight(
|
|
252
245
|
(result, domain) => funT(domain, result),
|
|
253
246
|
range,
|
|
@@ -257,75 +250,71 @@ class Parser {
|
|
|
257
250
|
return atom;
|
|
258
251
|
}
|
|
259
252
|
|
|
260
|
-
private
|
|
253
|
+
private parseTypeList(): Typ[] {
|
|
261
254
|
this.expect("[");
|
|
262
|
-
const types = [this.
|
|
255
|
+
const types = [this.parseType()];
|
|
263
256
|
while (this.isDelimiter(",")) {
|
|
264
257
|
this.position += 1;
|
|
265
|
-
types.push(this.
|
|
258
|
+
types.push(this.parseType());
|
|
266
259
|
}
|
|
267
260
|
this.expect("]");
|
|
268
261
|
return types;
|
|
269
262
|
}
|
|
270
263
|
|
|
271
|
-
private
|
|
264
|
+
private parseTypeAtom(): Typ {
|
|
272
265
|
if (this.isDelimiter("(")) {
|
|
273
266
|
this.position += 1;
|
|
274
|
-
const type = this.
|
|
267
|
+
const type = this.parseType();
|
|
275
268
|
this.expect(")");
|
|
276
269
|
return type;
|
|
277
270
|
}
|
|
278
|
-
const name = this.
|
|
271
|
+
const name = this.parseIdentifier();
|
|
279
272
|
if (name === "c") return TLA_TYPE;
|
|
280
273
|
if (name === "prop") return propT;
|
|
281
274
|
throw new TlaIsabelleError("ERROR", `Undefined type name: ${name}`);
|
|
282
275
|
}
|
|
283
276
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const binders: { name: string; type: Typ | undefined }[] = [];
|
|
277
|
+
private parseBinders(isConstrainable: boolean): TypedName[] {
|
|
278
|
+
const binders: TypedName[] = [];
|
|
287
279
|
while (this.peek().kind === "id") {
|
|
288
|
-
const name = this.
|
|
280
|
+
const name = this.parseIdentifier();
|
|
289
281
|
if (isConstrainable && this.isDelimiter("::")) {
|
|
290
282
|
this.position += 1;
|
|
291
|
-
binders.push({ name, type: this.
|
|
283
|
+
binders.push({ name, type: this.parseType() });
|
|
292
284
|
} else binders.push({ name, type: undefined });
|
|
293
285
|
}
|
|
294
286
|
if (binders.length === 0) throw this.syntaxError();
|
|
295
287
|
return binders;
|
|
296
288
|
}
|
|
297
289
|
|
|
298
|
-
private
|
|
290
|
+
private parseCommaList(close: string): Ast[] {
|
|
299
291
|
if (this.isDelimiter(close)) {
|
|
300
292
|
this.position += 1;
|
|
301
293
|
return [];
|
|
302
294
|
}
|
|
303
|
-
const items = [this.
|
|
295
|
+
const items = [this.parseLogic(0)];
|
|
304
296
|
while (this.isDelimiter(",")) {
|
|
305
297
|
this.position += 1;
|
|
306
|
-
items.push(this.
|
|
298
|
+
items.push(this.parseLogic(0));
|
|
307
299
|
}
|
|
308
300
|
this.expect(close);
|
|
309
301
|
return items;
|
|
310
302
|
}
|
|
311
303
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const parsed = this.expression(minimum);
|
|
304
|
+
parseLogic(minimum: number): Ast {
|
|
305
|
+
const parsed = this.parseExpression(minimum);
|
|
315
306
|
if (parsed.isProp)
|
|
316
307
|
throw new TlaIsabelleError("ERROR", "Inner syntax error: proposition in term position");
|
|
317
308
|
return parsed.ast;
|
|
318
309
|
}
|
|
319
310
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const parsed = this.expression(minimum);
|
|
324
|
-
return parsed.isProp ? parsed.ast : apply(constant("PredicateLogic.Trueprop"), parsed.ast);
|
|
311
|
+
parseProp(minimum: number): Ast {
|
|
312
|
+
const parsed = this.parseExpression(minimum);
|
|
313
|
+
return parsed.isProp ? parsed.ast : apply(toConstant("PredicateLogic.Trueprop"), parsed.ast);
|
|
325
314
|
}
|
|
326
315
|
|
|
327
|
-
private
|
|
328
|
-
let left = this.
|
|
316
|
+
private parseExpression(minimum: number): Parsed {
|
|
317
|
+
let left = this.parsePrefix(minimum);
|
|
329
318
|
for (;;) {
|
|
330
319
|
const token = this.peek();
|
|
331
320
|
if (token.kind !== "delimiter") return left;
|
|
@@ -334,9 +323,9 @@ class Parser {
|
|
|
334
323
|
this.position += 1;
|
|
335
324
|
const premise = left.isProp
|
|
336
325
|
? left.ast
|
|
337
|
-
: apply(
|
|
326
|
+
: apply(toConstant("PredicateLogic.Trueprop"), left.ast);
|
|
338
327
|
left = {
|
|
339
|
-
ast: apply(
|
|
328
|
+
ast: apply(toConstant("Pure.imp"), premise, this.parseProp(1)),
|
|
340
329
|
priority: 1,
|
|
341
330
|
isProp: true,
|
|
342
331
|
};
|
|
@@ -347,7 +336,7 @@ class Parser {
|
|
|
347
336
|
if (minimum > 3 || left.priority < 4) return left;
|
|
348
337
|
this.position += 1;
|
|
349
338
|
left = {
|
|
350
|
-
ast: { kind: "constrain", term: left.ast, type: this.
|
|
339
|
+
ast: { kind: "constrain", term: left.ast, type: this.parseType() },
|
|
351
340
|
priority: 3,
|
|
352
341
|
isProp: false,
|
|
353
342
|
};
|
|
@@ -356,7 +345,7 @@ class Parser {
|
|
|
356
345
|
if (token.text === "(") {
|
|
357
346
|
if (left.priority < MAX_PRIORITY) return left;
|
|
358
347
|
this.position += 1;
|
|
359
|
-
const args = this.
|
|
348
|
+
const args = this.parseCommaList(")");
|
|
360
349
|
if (args.length === 0) throw this.syntaxError();
|
|
361
350
|
left = { ast: apply(left.ast, ...args), priority: MAX_PRIORITY, isProp: false };
|
|
362
351
|
continue;
|
|
@@ -364,10 +353,10 @@ class Parser {
|
|
|
364
353
|
if (token.text === "[") {
|
|
365
354
|
if (minimum > 90 || left.priority < 89) return left;
|
|
366
355
|
this.position += 1;
|
|
367
|
-
const index = this.
|
|
356
|
+
const index = this.parseLogic(0);
|
|
368
357
|
this.expect("]");
|
|
369
358
|
left = {
|
|
370
|
-
ast: apply(
|
|
359
|
+
ast: apply(toConstant("Functions.fapply"), left.ast, index),
|
|
371
360
|
priority: 90,
|
|
372
361
|
isProp: false,
|
|
373
362
|
};
|
|
@@ -378,61 +367,61 @@ class Parser {
|
|
|
378
367
|
return left;
|
|
379
368
|
this.position += 1;
|
|
380
369
|
left = {
|
|
381
|
-
ast: apply(
|
|
370
|
+
ast: apply(toConstant(infix.constant), left.ast, this.parseLogic(infix.right)),
|
|
382
371
|
priority: infix.priority,
|
|
383
372
|
isProp: false,
|
|
384
373
|
};
|
|
385
374
|
}
|
|
386
375
|
}
|
|
387
376
|
|
|
388
|
-
private
|
|
377
|
+
private parsePrefix(minimum: number): Parsed {
|
|
389
378
|
const token = this.next();
|
|
390
|
-
const
|
|
379
|
+
const toTerm = (ast: Ast, priority = MAX_PRIORITY): Parsed => ({
|
|
380
|
+
ast,
|
|
381
|
+
priority,
|
|
382
|
+
isProp: false,
|
|
383
|
+
});
|
|
391
384
|
if (token.kind === "end") {
|
|
392
385
|
this.position -= 1;
|
|
393
386
|
throw this.syntaxError();
|
|
394
387
|
}
|
|
395
|
-
if (token.kind === "id") return
|
|
396
|
-
if (token.kind === "string") return
|
|
388
|
+
if (token.kind === "id") return toTerm({ kind: "name", name: token.text });
|
|
389
|
+
if (token.kind === "string") return toTerm(toStringTerm(token.text));
|
|
397
390
|
switch (token.text) {
|
|
398
391
|
case "(": {
|
|
399
|
-
const inner = this.
|
|
392
|
+
const inner = this.parseExpression(0);
|
|
400
393
|
this.expect(")");
|
|
401
394
|
return { ...inner, priority: MAX_PRIORITY };
|
|
402
395
|
}
|
|
403
396
|
case "0":
|
|
404
|
-
return
|
|
397
|
+
return toTerm(toConstant("Integers.zero"));
|
|
405
398
|
case "{":
|
|
406
399
|
if (this.isDelimiter("}")) {
|
|
407
400
|
this.position += 1;
|
|
408
|
-
return
|
|
401
|
+
return toTerm(toConstant("SetTheory.emptyset"), 100);
|
|
409
402
|
}
|
|
410
|
-
return
|
|
411
|
-
this.
|
|
412
|
-
(set, element) => apply(
|
|
413
|
-
|
|
403
|
+
return toTerm(
|
|
404
|
+
this.parseCommaList("}").reduceRight(
|
|
405
|
+
(set, element) => apply(toConstant("SetTheory.addElt"), element, set),
|
|
406
|
+
toConstant("SetTheory.emptyset"),
|
|
414
407
|
),
|
|
415
408
|
);
|
|
416
409
|
case "<<":
|
|
417
|
-
return
|
|
418
|
-
this.isDelimiter(">>")
|
|
419
|
-
? (this.next(), constant("Tuples.emptySeq"))
|
|
420
|
-
: tuple(this.commaList(">>")),
|
|
421
|
-
);
|
|
410
|
+
return toTerm(toTuple(this.parseCommaList(">>")));
|
|
422
411
|
case "\\<langle>":
|
|
423
|
-
return
|
|
412
|
+
return toTerm(toTuple(this.parseCommaList("\\<rangle>")));
|
|
424
413
|
case "[":
|
|
425
|
-
return this.
|
|
414
|
+
return this.parseBracket();
|
|
426
415
|
case "\\<forall>":
|
|
427
416
|
case "\\<exists>":
|
|
428
|
-
return
|
|
417
|
+
return toTerm(this.parseQuantifier(token.text === "\\<forall>"), 10);
|
|
429
418
|
case "%":
|
|
430
419
|
case "\\<lambda>": {
|
|
431
420
|
if (minimum > 3) throw this.syntaxError();
|
|
432
|
-
const binders = this.
|
|
421
|
+
const binders = this.parseBinders(true);
|
|
433
422
|
this.expect(".");
|
|
434
|
-
const body = this.
|
|
435
|
-
return
|
|
423
|
+
const body = this.parseLogic(3);
|
|
424
|
+
return toTerm(
|
|
436
425
|
binders.reduceRight<Ast>(
|
|
437
426
|
(result, binder) => ({
|
|
438
427
|
kind: "abs",
|
|
@@ -447,13 +436,13 @@ class Parser {
|
|
|
447
436
|
}
|
|
448
437
|
case "\\<And>": {
|
|
449
438
|
if (minimum > 0) throw this.syntaxError();
|
|
450
|
-
const binders = this.
|
|
439
|
+
const binders = this.parseBinders(true);
|
|
451
440
|
this.expect(".");
|
|
452
|
-
const body = this.
|
|
441
|
+
const body = this.parseProp(0);
|
|
453
442
|
return {
|
|
454
443
|
ast: binders.reduceRight<Ast>(
|
|
455
444
|
(result, binder) =>
|
|
456
|
-
apply(
|
|
445
|
+
apply(toConstant("Pure.all"), {
|
|
457
446
|
kind: "abs",
|
|
458
447
|
name: binder.name,
|
|
459
448
|
type: binder.type,
|
|
@@ -471,30 +460,32 @@ class Parser {
|
|
|
471
460
|
this.position -= 1;
|
|
472
461
|
throw this.syntaxError();
|
|
473
462
|
}
|
|
474
|
-
return
|
|
463
|
+
return toTerm(
|
|
464
|
+
apply(toConstant(prefix.constant), this.parseLogic(prefix.argument)),
|
|
465
|
+
prefix.priority,
|
|
466
|
+
);
|
|
475
467
|
}
|
|
476
468
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
const names = [this.identifier()];
|
|
469
|
+
private parseQuantifier(isForall: boolean): Ast {
|
|
470
|
+
const names = [this.parseIdentifier()];
|
|
480
471
|
while (this.isDelimiter(",")) {
|
|
481
472
|
this.position += 1;
|
|
482
|
-
names.push(this.
|
|
473
|
+
names.push(this.parseIdentifier());
|
|
483
474
|
}
|
|
484
475
|
if (this.isDelimiter(":")) {
|
|
485
476
|
this.position += 1;
|
|
486
|
-
const body = this.
|
|
487
|
-
const quantifier =
|
|
477
|
+
const body = this.parseLogic(10);
|
|
478
|
+
const quantifier = toConstant(isForall ? "PredicateLogic.All" : "PredicateLogic.Ex");
|
|
488
479
|
return names.reduceRight(
|
|
489
480
|
(result, name) => apply(quantifier, { kind: "abs", name, type: undefined, body: result }),
|
|
490
481
|
body,
|
|
491
482
|
);
|
|
492
483
|
}
|
|
493
484
|
this.expect("\\<in>");
|
|
494
|
-
const domain = this.
|
|
485
|
+
const domain = this.parseLogic(0);
|
|
495
486
|
this.expect(":");
|
|
496
|
-
const body = this.
|
|
497
|
-
const quantifier =
|
|
487
|
+
const body = this.parseLogic(0);
|
|
488
|
+
const quantifier = toConstant(isForall ? "SetTheory.bAll" : "SetTheory.bEx");
|
|
498
489
|
return names.reduceRight(
|
|
499
490
|
(result, name) =>
|
|
500
491
|
apply(quantifier, domain, { kind: "abs", name, type: undefined, body: result }),
|
|
@@ -502,29 +493,32 @@ class Parser {
|
|
|
502
493
|
);
|
|
503
494
|
}
|
|
504
495
|
|
|
505
|
-
|
|
506
|
-
// and [d : r, ...].
|
|
507
|
-
private bracket(): Parsed {
|
|
496
|
+
private parseBracket(): Parsed {
|
|
508
497
|
if (this.peek().kind === "id" && this.isDelimiter("\\<in>", 1)) {
|
|
509
|
-
const name = this.
|
|
498
|
+
const name = this.parseIdentifier();
|
|
510
499
|
this.position += 1;
|
|
511
|
-
const domain = this.
|
|
500
|
+
const domain = this.parseLogic(0);
|
|
512
501
|
this.expect("\\<mapsto>");
|
|
513
|
-
const body = this.
|
|
502
|
+
const body = this.parseLogic(0);
|
|
514
503
|
this.expect("]");
|
|
515
504
|
return {
|
|
516
|
-
ast: apply(
|
|
505
|
+
ast: apply(toConstant("Functions.Fcn"), domain, {
|
|
506
|
+
kind: "abs",
|
|
507
|
+
name,
|
|
508
|
+
type: undefined,
|
|
509
|
+
body,
|
|
510
|
+
}),
|
|
517
511
|
priority: 900,
|
|
518
512
|
isProp: false,
|
|
519
513
|
};
|
|
520
514
|
}
|
|
521
|
-
const first = this.
|
|
515
|
+
const first = this.parseLogic(0);
|
|
522
516
|
if (this.isDelimiter("\\<rightarrow>")) {
|
|
523
517
|
this.position += 1;
|
|
524
|
-
const range = this.
|
|
518
|
+
const range = this.parseLogic(0);
|
|
525
519
|
this.expect("]");
|
|
526
520
|
return {
|
|
527
|
-
ast: apply(
|
|
521
|
+
ast: apply(toConstant("Functions.FuncSet"), first, range),
|
|
528
522
|
priority: 900,
|
|
529
523
|
isProp: false,
|
|
530
524
|
};
|
|
@@ -535,10 +529,10 @@ class Parser {
|
|
|
535
529
|
for (;;) {
|
|
536
530
|
this.expect("!");
|
|
537
531
|
this.expect("[");
|
|
538
|
-
const index = this.
|
|
532
|
+
const index = this.parseLogic(0);
|
|
539
533
|
this.expect("]");
|
|
540
534
|
this.expect("=");
|
|
541
|
-
result = apply(
|
|
535
|
+
result = apply(toConstant("Functions.except"), result, index, this.parseLogic(0));
|
|
542
536
|
if (!this.isDelimiter(",")) break;
|
|
543
537
|
this.position += 1;
|
|
544
538
|
}
|
|
@@ -547,16 +541,16 @@ class Parser {
|
|
|
547
541
|
}
|
|
548
542
|
this.expect(":");
|
|
549
543
|
const domains = [first];
|
|
550
|
-
const ranges = [this.
|
|
544
|
+
const ranges = [this.parseLogic(0)];
|
|
551
545
|
while (this.isDelimiter(",")) {
|
|
552
546
|
this.position += 1;
|
|
553
|
-
domains.push(this.
|
|
547
|
+
domains.push(this.parseLogic(0));
|
|
554
548
|
this.expect(":");
|
|
555
|
-
ranges.push(this.
|
|
549
|
+
ranges.push(this.parseLogic(0));
|
|
556
550
|
}
|
|
557
551
|
this.expect("]");
|
|
558
552
|
return {
|
|
559
|
-
ast: apply(
|
|
553
|
+
ast: apply(toConstant("Tuples.EnumFuncSet"), toTuple(domains), toTuple(ranges)),
|
|
560
554
|
priority: MAX_PRIORITY,
|
|
561
555
|
isProp: false,
|
|
562
556
|
};
|
|
@@ -566,7 +560,7 @@ class Parser {
|
|
|
566
560
|
const parseWith = <Result>(text: string, parse: (parser: Parser) => Result): Result => {
|
|
567
561
|
const parser = new Parser(tokenize(text));
|
|
568
562
|
const result = parse(parser);
|
|
569
|
-
if (!parser.
|
|
563
|
+
if (!parser.isAtEnd())
|
|
570
564
|
throw new TlaIsabelleError(
|
|
571
565
|
"ERROR",
|
|
572
566
|
`Inner syntax error: trailing input in ${text.slice(0, 40)}`,
|
|
@@ -574,6 +568,6 @@ const parseWith = <Result>(text: string, parse: (parser: Parser) => Result): Res
|
|
|
574
568
|
return result;
|
|
575
569
|
};
|
|
576
570
|
|
|
577
|
-
export const parseProp = (text: string) => parseWith(text, (parser) => parser.
|
|
571
|
+
export const parseProp = (text: string) => parseWith(text, (parser) => parser.parseProp(0));
|
|
578
572
|
|
|
579
|
-
export const parseType = (text: string) => parseWith(text, (parser) => parser.
|
|
573
|
+
export const parseType = (text: string) => parseWith(text, (parser) => parser.parseType());
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
// Ported from Isabelle2025's Pure/Isar/method.ML (
|
|
2
|
-
// finish), the assume_rule_tac and norm_hhf_tac of Pure/goal.ML, and the methods the theories
|
|
3
|
-
// tlapm writes use: auto, force and clarsimp (Provers/clasimp.ML), blast (Provers/blast.ML),
|
|
4
|
-
// iprover (Tools/intuitionistic.ML) and intro. Copyright (c) 1986-2025 University of Cambridge,
|
|
5
|
-
// Technische Universitaet Muenchen, and contributors, see LICENSE.
|
|
1
|
+
// Ported from Isabelle2025's Pure/Isar/method.ML and Pure/goal.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
|
|
6
2
|
|
|
7
3
|
import { TlaIsabelleError } from "../../../errors";
|
|
8
4
|
import { asmRl, isNormHhf, normHhfEq, reflexiveThm, termI } from "../pure/drule";
|
|
9
5
|
import { isEquals, stripImpPrems, stripAssumsConcl } from "../pure/logic";
|
|
10
|
-
import {
|
|
6
|
+
import { makeSimpContext, type Simpset } from "../pure/raw-simplifier";
|
|
11
7
|
import { genericRewriteGoalTac } from "../pure/rewriter";
|
|
12
8
|
import { filterSeq, mapsSeq, singleSeq, type Seq } from "../pure/seq";
|
|
13
9
|
import { atomizePremsTac } from "../pure/object-logic";
|
|
@@ -65,13 +61,11 @@ type MethodText =
|
|
|
65
61
|
| { readonly kind: "then"; readonly methods: readonly MethodText[] }
|
|
66
62
|
| { readonly kind: "try"; readonly method: MethodText };
|
|
67
63
|
|
|
68
|
-
// The methods of by: the initial one, and the terminal one that qed runs.
|
|
69
64
|
interface ProofText {
|
|
70
65
|
readonly initial: MethodText;
|
|
71
66
|
readonly terminal: MethodText | undefined;
|
|
72
67
|
}
|
|
73
68
|
|
|
74
|
-
// What a proof method reads from the Isabelle proof context.
|
|
75
69
|
export interface ProofContext {
|
|
76
70
|
readonly limits: Limits;
|
|
77
71
|
readonly simpset: Simpset;
|
|
@@ -89,7 +83,6 @@ const syntaxError = (token: OuterToken | undefined) =>
|
|
|
89
83
|
`Outer syntax error at: ${token === undefined ? "end of input" : token.text}`,
|
|
90
84
|
);
|
|
91
85
|
|
|
92
|
-
// Method.parse for the proof methods of by.
|
|
93
86
|
export const parseProofText = (tokens: readonly OuterToken[]): ProofText => {
|
|
94
87
|
let position = 0;
|
|
95
88
|
const peek = () => tokens[position];
|
|
@@ -100,62 +93,67 @@ export const parseProofText = (tokens: readonly OuterToken[]): ProofText => {
|
|
|
100
93
|
position += 1;
|
|
101
94
|
};
|
|
102
95
|
const isWord = () => peek()?.kind === "word";
|
|
103
|
-
const
|
|
96
|
+
const readWord = () => {
|
|
104
97
|
const token = peek();
|
|
105
98
|
if (token?.kind !== "word") throw syntaxError(token);
|
|
106
99
|
position += 1;
|
|
107
100
|
return token.text;
|
|
108
101
|
};
|
|
109
102
|
const isSectionStart = () => isWord() && isSymbol(":", 1);
|
|
110
|
-
const
|
|
103
|
+
const readFacts = () => {
|
|
111
104
|
const names: string[] = [];
|
|
112
|
-
while (isWord() && !isSectionStart()) names.push(
|
|
105
|
+
while (isWord() && !isSectionStart()) names.push(readWord());
|
|
113
106
|
return names;
|
|
114
107
|
};
|
|
115
|
-
const
|
|
108
|
+
const readModifiers = (): Modifier[] => {
|
|
116
109
|
const result: Modifier[] = [];
|
|
117
110
|
while (isSectionStart()) {
|
|
118
|
-
const kind =
|
|
111
|
+
const kind = readWord();
|
|
119
112
|
position += 1;
|
|
120
113
|
if (kind !== "intro" && kind !== "dest")
|
|
121
114
|
throw new TlaIsabelleError("ERROR", `Unsupported method modifier: ${kind}`);
|
|
122
|
-
result.push({ kind, facts:
|
|
115
|
+
result.push({ kind, facts: readFacts() });
|
|
123
116
|
}
|
|
124
117
|
return result;
|
|
125
118
|
};
|
|
126
|
-
const
|
|
119
|
+
const readMethod = (name: string, hasArgs: boolean): MethodText => {
|
|
127
120
|
switch (name) {
|
|
128
121
|
case "auto":
|
|
129
122
|
case "blast":
|
|
130
123
|
case "force":
|
|
131
124
|
case "clarsimp":
|
|
132
|
-
return { kind: name, modifiers: hasArgs ?
|
|
125
|
+
return { kind: name, modifiers: hasArgs ? readModifiers() : [] };
|
|
133
126
|
case "iprover":
|
|
134
127
|
return { kind: "iprover" };
|
|
135
128
|
case "intro":
|
|
136
|
-
return { kind: "intro", facts: hasArgs ?
|
|
129
|
+
return { kind: "intro", facts: hasArgs ? readFacts() : [] };
|
|
137
130
|
default:
|
|
138
131
|
throw new TlaIsabelleError("ERROR", `Undefined method: ${name}`);
|
|
139
132
|
}
|
|
140
133
|
};
|
|
141
|
-
const
|
|
134
|
+
const readSuffixed = (text: MethodText): MethodText => {
|
|
142
135
|
if (!isSymbol("?")) return text;
|
|
143
136
|
position += 1;
|
|
144
|
-
return
|
|
137
|
+
return readSuffixed({ kind: "try", method: text });
|
|
145
138
|
};
|
|
146
|
-
const
|
|
139
|
+
const readParenthesized = (): MethodText => {
|
|
147
140
|
expectSymbol("(");
|
|
148
|
-
const elements = [
|
|
141
|
+
const elements = [
|
|
142
|
+
readSuffixed(isSymbol("(") ? readParenthesized() : readMethod(readWord(), true)),
|
|
143
|
+
];
|
|
149
144
|
while (isSymbol(",")) {
|
|
150
145
|
position += 1;
|
|
151
|
-
elements.push(
|
|
146
|
+
elements.push(
|
|
147
|
+
readSuffixed(isSymbol("(") ? readParenthesized() : readMethod(readWord(), true)),
|
|
148
|
+
);
|
|
152
149
|
}
|
|
153
150
|
expectSymbol(")");
|
|
154
151
|
return elements.length === 1 ? elements[0] : { kind: "then", methods: elements };
|
|
155
152
|
};
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
const
|
|
153
|
+
const readAtom = () =>
|
|
154
|
+
readSuffixed(isSymbol("(") ? readParenthesized() : readMethod(readWord(), false));
|
|
155
|
+
const initial = readAtom();
|
|
156
|
+
const terminal = position < tokens.length ? readAtom() : undefined;
|
|
159
157
|
if (position !== tokens.length) throw syntaxError(peek());
|
|
160
158
|
return { initial, terminal };
|
|
161
159
|
};
|
|
@@ -163,7 +161,6 @@ export const parseProofText = (tokens: readonly OuterToken[]): ProofText => {
|
|
|
163
161
|
const getFacts = (context: ProofContext, names: readonly string[]) =>
|
|
164
162
|
names.flatMap((name) => context.getFact(name));
|
|
165
163
|
|
|
166
|
-
// Method.sections: the claset the modifiers declare.
|
|
167
164
|
const withModifiers = (context: ProofContext, modifiers: readonly Modifier[]): ClassicalContext =>
|
|
168
165
|
modifiers.reduce(
|
|
169
166
|
(classical, modifier) =>
|
|
@@ -189,7 +186,6 @@ const getClasimp = (context: ProofContext, classical: ClassicalContext): Clasimp
|
|
|
189
186
|
const insertAllTac = (context: ProofContext, facts: readonly Thm[]) =>
|
|
190
187
|
allGoals((index) => insertTac(context.limits, facts, index));
|
|
191
188
|
|
|
192
|
-
// SIMPLE_METHOD'
|
|
193
189
|
const simpleMethodHead = (context: ProofContext, facts: readonly Thm[], tactic: GoalTactic) =>
|
|
194
190
|
thenGoal((index) => insertTac(context.limits, facts, index), tactic)(1);
|
|
195
191
|
|
|
@@ -255,10 +251,8 @@ const evaluate = (context: ProofContext, text: MethodText): Method => {
|
|
|
255
251
|
}
|
|
256
252
|
};
|
|
257
253
|
|
|
258
|
-
// Goal.norm_hhf_tac
|
|
259
254
|
const normHhfTac = (limits: Limits): GoalTactic => {
|
|
260
|
-
const
|
|
261
|
-
const context = { ...empty, simpset: addSimps(empty, [normHhfEq]) };
|
|
255
|
+
const context = makeSimpContext(limits, [normHhfEq]);
|
|
262
256
|
return thenGoal(
|
|
263
257
|
resolveTac(limits, [asmRl]),
|
|
264
258
|
subgoal((goal, index) =>
|
|
@@ -274,12 +268,10 @@ const normHhfTac = (limits: Limits): GoalTactic => {
|
|
|
274
268
|
);
|
|
275
269
|
};
|
|
276
270
|
|
|
277
|
-
// Goal.assume_rule_tac: solves a goal with one of its non-atomic premises.
|
|
278
271
|
const assumeRuleTac = (limits: Limits): GoalTactic =>
|
|
279
272
|
thenGoal(
|
|
280
273
|
normHhfTac(limits),
|
|
281
274
|
subgoal((goal, index) => {
|
|
282
|
-
// Variable.focus_cterm and Variable.export: the parameters become schematic variables.
|
|
283
275
|
const params = stripAllVars(goal);
|
|
284
276
|
const names = variantList(
|
|
285
277
|
addFreeNames(goal, []),
|
|
@@ -309,7 +301,6 @@ const assumeRuleTac = (limits: Limits): GoalTactic =>
|
|
|
309
301
|
}),
|
|
310
302
|
);
|
|
311
303
|
|
|
312
|
-
// Method.assm_tac
|
|
313
304
|
const assmTac = (limits: Limits): GoalTactic => {
|
|
314
305
|
const condRtac = (isRule: (concl: Term) => boolean, rule: Thm) =>
|
|
315
306
|
subgoal((goal, index) =>
|
|
@@ -331,7 +322,6 @@ const assmTac = (limits: Limits): GoalTactic => {
|
|
|
331
322
|
);
|
|
332
323
|
};
|
|
333
324
|
|
|
334
|
-
// Method.all_assm_tac
|
|
335
325
|
const allAssmTac =
|
|
336
326
|
(limits: Limits) =>
|
|
337
327
|
(index: number): Tactic =>
|
|
@@ -343,9 +333,6 @@ const allAssmTac =
|
|
|
343
333
|
allAssmTac(limits)(index + 1),
|
|
344
334
|
)(state);
|
|
345
335
|
|
|
346
|
-
// Proof.local_terminal_proof: by initial terminal runs the initial method with the facts, then
|
|
347
|
-
// the terminal one without them and Method.finish, and succeeds on the first result that leaves
|
|
348
|
-
// no goal.
|
|
349
336
|
export const terminalProof = (
|
|
350
337
|
context: ProofContext,
|
|
351
338
|
text: ProofText,
|