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,10 +1,4 @@
|
|
|
1
|
-
// Ported from Isabelle2025's Provers/blast.ML. Copyright (c) 1986-2025 University of Cambridge,
|
|
2
|
-
// Technische Universitaet Muenchen, and contributors, see LICENSE.
|
|
3
|
-
//
|
|
4
|
-
// The tableau prover, based on leanTaP. It works on a list of branches, each with its unexpanded
|
|
5
|
-
// formulae, its literals and a bound on unsafe expansions. Every inference records the tactic
|
|
6
|
-
// that replays it; once all branches close, the continuation reconstructs the proof. Each
|
|
7
|
-
// recursion level that can be backtracked to owns a token, and a choice point raises it.
|
|
1
|
+
// Ported from Isabelle2025's Provers/blast.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
|
|
8
2
|
|
|
9
3
|
import type { Seq } from "../../pure/seq";
|
|
10
4
|
import type { GoalTactic } from "../../pure/tactical";
|
|
@@ -46,13 +40,10 @@ import {
|
|
|
46
40
|
type VarRef,
|
|
47
41
|
} from "./term";
|
|
48
42
|
|
|
49
|
-
// The tactics that replay the inferences so far, latest first.
|
|
50
43
|
type Tactics = List<GoalTactic> | undefined;
|
|
51
44
|
|
|
52
45
|
export type Continuation = (tactics: Tactics, choices: Choices) => Seq<Thm>;
|
|
53
46
|
|
|
54
|
-
// A step either finishes the search or continues the same branches without a choice point, which
|
|
55
|
-
// blast.ML does by a tail call. prv loops on the latter, so a long search can't exhaust the stack.
|
|
56
47
|
type Step =
|
|
57
48
|
| { readonly kind: "done"; readonly result: Seq<Thm> }
|
|
58
49
|
| {
|
|
@@ -76,7 +67,6 @@ export const prove = (
|
|
|
76
67
|
const safeList = [context.claset.safe0, context.claset.safep];
|
|
77
68
|
const unsafeList = [context.claset.unsafe];
|
|
78
69
|
|
|
79
|
-
// Applies a safe rule only, possibly allowing instantiation; defers any unsafe formulae.
|
|
80
70
|
const safeStep = (tactics: Tactics, choices: Choices, brs: readonly Branch[]): Step => {
|
|
81
71
|
const token = {};
|
|
82
72
|
const branch = brs[0];
|
|
@@ -90,7 +80,6 @@ export const prove = (
|
|
|
90
80
|
const nxtVars = nextVars(rest);
|
|
91
81
|
const formula = norm(head.safe[0].term);
|
|
92
82
|
const rules = netMkRules(state, formula, branch.vars, safeList);
|
|
93
|
-
// Makes the new branches, decrementing lim if instantiations occur.
|
|
94
83
|
const newBr = (vars: readonly VarRef[], lim: number, prems: TableauRule["prems"]): Branch[] => [
|
|
95
84
|
...prems.map((prem): Branch => {
|
|
96
85
|
const level = { safe: joinMd(md, prem), unsafe: [] };
|
|
@@ -105,14 +94,11 @@ export const prove = (
|
|
|
105
94
|
}),
|
|
106
95
|
...rest,
|
|
107
96
|
];
|
|
108
|
-
// Seeks a matching rule; if unifiable, adds its premises to the branch. Undefined is
|
|
109
|
-
// NEWBRANCHES.
|
|
110
97
|
const deeper = (): Seq<Thm> | undefined => {
|
|
111
98
|
for (let position = 0; position < rules.length; position += 1) {
|
|
112
99
|
const rule = rules[position];
|
|
113
100
|
if (!unify(state, addTermVars(rule.major, []), rule.major, formula)) continue;
|
|
114
101
|
const isUpdated = ntrl < state.trail.length;
|
|
115
|
-
// Discourages branching updates.
|
|
116
102
|
const lim = isUpdated ? branch.lim - (1 + log4(rules.length)) : branch.lim;
|
|
117
103
|
const vars = addPremsVars(rule.prems, varsInVars(branch.vars));
|
|
118
104
|
const nextChoices = cons({ ntrl, nbrs, token }, choices);
|
|
@@ -120,7 +106,6 @@ export const prove = (
|
|
|
120
106
|
try {
|
|
121
107
|
if (rule.prems.length === 0)
|
|
122
108
|
return prv(nextTactics, prune(state, nbrs, nxtVars, nextChoices), rest);
|
|
123
|
-
// Faster to kill all the alternatives.
|
|
124
109
|
if (lim < 0) {
|
|
125
110
|
clearTo(state, ntrl);
|
|
126
111
|
return undefined;
|
|
@@ -128,15 +113,12 @@ export const prove = (
|
|
|
128
113
|
return prv(nextTactics, nextChoices, newBr(vars, lim, rule.prems));
|
|
129
114
|
} catch (error) {
|
|
130
115
|
if (!isBacktrackTo(error, token)) throw error;
|
|
131
|
-
// Backtracks at this level, resetting variables and trying another rule, or to the
|
|
132
|
-
// previous level.
|
|
133
116
|
if (!isUpdated) return backtrack(choices);
|
|
134
117
|
clearTo(state, ntrl);
|
|
135
118
|
}
|
|
136
119
|
}
|
|
137
120
|
return undefined;
|
|
138
121
|
};
|
|
139
|
-
// Tries to close the branch by unifying the formula with a literal. Undefined is CLOSEF.
|
|
140
122
|
const closeF = (literals: readonly BlastTerm[]): Seq<Thm> | undefined => {
|
|
141
123
|
for (const literal of literals) {
|
|
142
124
|
const tactic = tryClose(state, formula, literal);
|
|
@@ -151,7 +133,6 @@ export const prove = (
|
|
|
151
133
|
}
|
|
152
134
|
return undefined;
|
|
153
135
|
};
|
|
154
|
-
// Tries to unify a queued formula, safe or unsafe, with the formula.
|
|
155
136
|
const closeFl = (levels: readonly Level[]): Seq<Thm> | undefined => {
|
|
156
137
|
for (const level of levels) {
|
|
157
138
|
const closed =
|
|
@@ -173,7 +154,6 @@ export const prove = (
|
|
|
173
154
|
const closed = closeF(branch.lits) ?? closeFl(pairs) ?? deeper();
|
|
174
155
|
if (closed !== undefined) return done(closed);
|
|
175
156
|
if (netMkRules(state, formula, branch.vars, unsafeList).length === 0)
|
|
176
|
-
// There are no plausible unsafe rules: the formula becomes a literal.
|
|
177
157
|
return {
|
|
178
158
|
kind: "next",
|
|
179
159
|
tactics,
|
|
@@ -183,7 +163,6 @@ export const prove = (
|
|
|
183
163
|
...rest,
|
|
184
164
|
],
|
|
185
165
|
};
|
|
186
|
-
// The formula admits some unsafe rules: try them later.
|
|
187
166
|
const deferred: Formula = { term: negOfGoal(state, formula), md };
|
|
188
167
|
return {
|
|
189
168
|
kind: "next",
|
|
@@ -201,7 +180,6 @@ export const prove = (
|
|
|
201
180
|
};
|
|
202
181
|
};
|
|
203
182
|
|
|
204
|
-
// No safe steps are possible at any level: applies an unsafe rule.
|
|
205
183
|
const unsafeStep = (tactics: Tactics, choices: Choices, brs: readonly Branch[]): Step => {
|
|
206
184
|
const token = {};
|
|
207
185
|
const branch = brs[0];
|
|
@@ -212,7 +190,6 @@ export const prove = (
|
|
|
212
190
|
const formula = norm(queued[0].term);
|
|
213
191
|
const ntrl = state.trail.length;
|
|
214
192
|
const rules = netMkRules(state, formula, branch.vars, unsafeList);
|
|
215
|
-
// The new premises of unsafe rules may not be duplicated.
|
|
216
193
|
const newPrem = (
|
|
217
194
|
vars: readonly VarRef[],
|
|
218
195
|
pattern: BlastTerm,
|
|
@@ -223,8 +200,6 @@ export const prove = (
|
|
|
223
200
|
const safe = prem.map((term) => ({ term, md: false }));
|
|
224
201
|
const unsafe = isDup ? [...others, { term: negOfGoal(state, formula), md }] : others;
|
|
225
202
|
return {
|
|
226
|
-
// A premise recursive in the rule makes no new stack frame: its unsafe premises end up at
|
|
227
|
-
// the back of the queue, preventing the exclusion of others.
|
|
228
203
|
pairs: prem.some((term) => match(state, pattern, term))
|
|
229
204
|
? [{ safe, unsafe }]
|
|
230
205
|
: [
|
|
@@ -243,16 +218,10 @@ export const prove = (
|
|
|
243
218
|
const isUpdated = ntrl < state.trail.length;
|
|
244
219
|
const vars = varsInVars(branch.vars);
|
|
245
220
|
const newVars = addPremsVars(rule.prems, vars);
|
|
246
|
-
// Duplicates the formula if md permits.
|
|
247
221
|
const isDup = md;
|
|
248
|
-
// Decrements lim extra if updates occur.
|
|
249
222
|
const lim = isUpdated ? branch.lim - (1 + log4(rules.length)) : branch.lim - 1;
|
|
250
|
-
// Allows backtracking from a rule application if other matching rules exist, if the rule
|
|
251
|
-
// updated variables, or if it introduced no new variables, so that it is not a standard
|
|
252
|
-
// gamma-rule. This emulates fast_tac, which allows all unsafe steps to be undone.
|
|
253
223
|
const mayUndo = position + 1 < rules.length || isUpdated || sameVars(vars, newVars);
|
|
254
224
|
const tactic = rule.tactic(isUpdated, isDup, true);
|
|
255
|
-
// Faster to kill all the alternatives.
|
|
256
225
|
if (lim < 0 && rule.prems.length > 0) {
|
|
257
226
|
clearTo(state, ntrl);
|
|
258
227
|
return undefined;
|
|
@@ -273,7 +242,6 @@ export const prove = (
|
|
|
273
242
|
if (branch.lim < 1) return backtrack(choices);
|
|
274
243
|
const closed = deeper();
|
|
275
244
|
if (closed !== undefined) return done(closed);
|
|
276
|
-
// If no rule closes the branch, the formula becomes a literal.
|
|
277
245
|
return {
|
|
278
246
|
kind: "next",
|
|
279
247
|
tactics,
|
|
@@ -300,7 +268,6 @@ export const prove = (
|
|
|
300
268
|
let brs = branches;
|
|
301
269
|
for (;;) {
|
|
302
270
|
checkInterrupt(context.limits);
|
|
303
|
-
// All branches closed.
|
|
304
271
|
if (brs.length === 0) return cont(tactics, choices);
|
|
305
272
|
const branch = brs[0];
|
|
306
273
|
const head = branch.pairs[0];
|
|
@@ -319,7 +286,6 @@ export const prove = (
|
|
|
319
286
|
continue;
|
|
320
287
|
}
|
|
321
288
|
if (branch.pairs.length > 1) {
|
|
322
|
-
// No more safe formulae: transfers the unsafe ones down a level.
|
|
323
289
|
const below = branch.pairs[1];
|
|
324
290
|
brs = [
|
|
325
291
|
{
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
// Ported from Isabelle2025's Provers/blast.ML. Copyright (c) 1986-2025 University of Cambridge,
|
|
2
|
-
// Technische Universitaet Muenchen, and contributors, see LICENSE.
|
|
3
|
-
//
|
|
4
|
-
// Conversion of the classical rules to tableau operations, each with the Isabelle tactic that
|
|
5
|
-
// replays it during proof reconstruction.
|
|
1
|
+
// Ported from Isabelle2025's Provers/blast.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 { revcutRl, zeroVarIndexes } from "../../pure/drule";
|
|
@@ -33,6 +29,7 @@ import {
|
|
|
33
29
|
mkBlastSkolem,
|
|
34
30
|
mkBlastVar,
|
|
35
31
|
mkGoal,
|
|
32
|
+
splitGoalPrems,
|
|
36
33
|
stripBlastImpConcl,
|
|
37
34
|
stripBlastImpPrems,
|
|
38
35
|
toTemplate,
|
|
@@ -42,19 +39,12 @@ import {
|
|
|
42
39
|
type VarRef,
|
|
43
40
|
} from "./term";
|
|
44
41
|
|
|
45
|
-
// A tableau rule: the formula it applies to, the formulae of each new branch, and the tactic
|
|
46
|
-
// for the flags upd (the inference updated the branch), dup (duplicate the formula) and rot
|
|
47
|
-
// (rotate the new hypotheses).
|
|
48
42
|
export interface TableauRule {
|
|
49
43
|
readonly major: BlastTerm;
|
|
50
44
|
readonly prems: readonly (readonly BlastTerm[])[];
|
|
51
45
|
readonly tactic: (isUpdated: boolean, isDup: boolean, isRotated: boolean) => GoalTactic;
|
|
52
46
|
}
|
|
53
47
|
|
|
54
|
-
// Blast converts each rule it looks up afresh, with fresh variables and Skolem terms. This
|
|
55
|
-
// converts each rule once, numbering them: concl is the conclusion's variable, which conversion
|
|
56
|
-
// sets to *False*, and skolems counts the Skolem terms, which take fresh names in this order. An
|
|
57
|
-
// ill-formed rule has no major premise, but still takes the names its conversion took.
|
|
58
48
|
export interface RuleTemplate {
|
|
59
49
|
readonly count: number;
|
|
60
50
|
readonly concl: number | undefined;
|
|
@@ -63,8 +53,6 @@ export interface RuleTemplate {
|
|
|
63
53
|
readonly prems: readonly (readonly Template[])[];
|
|
64
54
|
}
|
|
65
55
|
|
|
66
|
-
// The conclusion becomes the goal or the negated assumption *False*: delete it. A premise without
|
|
67
|
-
// it is ill-formed and could make reconstruction fail.
|
|
68
56
|
const deleteConcl = (state: BlastState, prems: readonly BlastTerm[]): BlastTerm[] | undefined => {
|
|
69
57
|
const position = prems.findIndex((prem) => {
|
|
70
58
|
if (prem.kind !== "App" || prem.fun.kind !== "Const") return false;
|
|
@@ -79,8 +67,6 @@ const deleteConcl = (state: BlastState, prems: readonly BlastTerm[]): BlastTerm[
|
|
|
79
67
|
return position === -1 ? undefined : [...prems.slice(0, position), ...prems.slice(position + 1)];
|
|
80
68
|
};
|
|
81
69
|
|
|
82
|
-
// Skolemizes a premise with placeholder Skolem terms, adding them to skolems in the order that
|
|
83
|
-
// blast names them.
|
|
84
70
|
const skoPrem = (skolems: BlastTerm[], prem: BlastTerm): BlastTerm => {
|
|
85
71
|
const body = destConstApp(prem, "Pure.all");
|
|
86
72
|
if (body?.kind !== "Abs") return prem;
|
|
@@ -97,8 +83,6 @@ const illFormed = (skolems: number): RuleTemplate => ({
|
|
|
97
83
|
prems: [],
|
|
98
84
|
});
|
|
99
85
|
|
|
100
|
-
// fromRule's convertRule, which expects an elimination rule to have a formula variable as its
|
|
101
|
-
// conclusion.
|
|
102
86
|
const makeElimTemplate = (state: BlastState, rule: Thm): RuleTemplate => {
|
|
103
87
|
const trueprop = state.context.data.trueprop;
|
|
104
88
|
const term = fromTerm(state.context.consts, rule.prop);
|
|
@@ -111,11 +95,7 @@ const makeElimTemplate = (state: BlastState, rule: Thm): RuleTemplate => {
|
|
|
111
95
|
const skolems: BlastTerm[] = [];
|
|
112
96
|
const converted: BlastTerm[][] = [];
|
|
113
97
|
for (const prem of prems.slice(1)) {
|
|
114
|
-
const
|
|
115
|
-
const deleted = deleteConcl(state, [
|
|
116
|
-
mkGoal(stripBlastImpConcl(trueprop, skolemized)),
|
|
117
|
-
...stripBlastImpPrems(trueprop, skolemized),
|
|
118
|
-
]);
|
|
98
|
+
const deleted = deleteConcl(state, splitGoalPrems(trueprop, skoPrem(skolems, prem)));
|
|
119
99
|
if (deleted === undefined) return illFormed(skolems.length);
|
|
120
100
|
converted.push(deleted);
|
|
121
101
|
}
|
|
@@ -128,20 +108,15 @@ const makeElimTemplate = (state: BlastState, rule: Thm): RuleTemplate => {
|
|
|
128
108
|
};
|
|
129
109
|
};
|
|
130
110
|
|
|
131
|
-
// fromIntrRule's conversion.
|
|
132
111
|
const makeIntroTemplate = (state: BlastState, rule: Thm): RuleTemplate => {
|
|
133
112
|
const trueprop = state.context.data.trueprop;
|
|
134
113
|
const term = fromTerm(state.context.consts, rule.prop);
|
|
135
114
|
const refs: VarRef[] = [];
|
|
136
115
|
toTemplate(refs, [], term);
|
|
137
116
|
const skolems: BlastTerm[] = [];
|
|
138
|
-
const converted = stripBlastImpPrems(trueprop, term).map((prem) =>
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
mkGoal(stripBlastImpConcl(trueprop, skolemized)),
|
|
142
|
-
...stripBlastImpPrems(trueprop, skolemized),
|
|
143
|
-
];
|
|
144
|
-
});
|
|
117
|
+
const converted = stripBlastImpPrems(trueprop, term).map((prem) =>
|
|
118
|
+
splitGoalPrems(trueprop, skoPrem(skolems, prem)),
|
|
119
|
+
);
|
|
145
120
|
return {
|
|
146
121
|
count: refs.length,
|
|
147
122
|
concl: undefined,
|
|
@@ -151,7 +126,6 @@ const makeIntroTemplate = (state: BlastState, rule: Thm): RuleTemplate => {
|
|
|
151
126
|
};
|
|
152
127
|
};
|
|
153
128
|
|
|
154
|
-
// Like dup_elim, but puts the duplicated major premise first.
|
|
155
129
|
const revDupElim = (rule: Thm) => {
|
|
156
130
|
const result = seqHead(assumption(undefined, 2, rsn(rule, 2, revcutRl)));
|
|
157
131
|
if (result === undefined) throw new TlaIsabelleError("ERROR", "rev_dup_elim: Seq.hd");
|
|
@@ -161,7 +135,6 @@ const revDupElim = (rule: Thm) => {
|
|
|
161
135
|
const countNewHyps = (prem: readonly BlastTerm[]) =>
|
|
162
136
|
prem.filter((term) => destConstApp(term, GOAL_NAME) === undefined).length;
|
|
163
137
|
|
|
164
|
-
// Rotates the assumptions in all new subgoals for the LIFO discipline.
|
|
165
138
|
const rotSubgoalsTac =
|
|
166
139
|
(isRotated: boolean, prems: readonly (readonly BlastTerm[])[]): GoalTactic =>
|
|
167
140
|
(index) =>
|
|
@@ -174,8 +147,6 @@ const rotSubgoalsTac =
|
|
|
174
147
|
),
|
|
175
148
|
);
|
|
176
149
|
|
|
177
|
-
// Resolution or matching: if the inference updated the branch, the proof state may be updated.
|
|
178
|
-
// Matching keeps the tactics more deterministic in the presence of variables.
|
|
179
150
|
const emtac = (state: BlastState, isUpdated: boolean, rule: Thm): GoalTactic =>
|
|
180
151
|
isUpdated ? eresolveTac(state.context.limits, [rule]) : ematchTac(state.context.limits, [rule]);
|
|
181
152
|
|
|
@@ -204,9 +175,6 @@ const intrRuleTactic =
|
|
|
204
175
|
rotSubgoalsTac(isRotated, prems)(index),
|
|
205
176
|
);
|
|
206
177
|
|
|
207
|
-
// A tableau rule from a rule's template. Blast tries the rules in order until one's major premise
|
|
208
|
-
// unifies, and often only checks that a rule exists, so this instantiates the template with fresh
|
|
209
|
-
// variables only when the major premise is used, and the premises only when they are.
|
|
210
178
|
class InstantiatedRule implements TableauRule {
|
|
211
179
|
private readonly state: BlastState;
|
|
212
180
|
private readonly rule: Thm;
|
|
@@ -234,7 +202,6 @@ class InstantiatedRule implements TableauRule {
|
|
|
234
202
|
this.skolems = skolems;
|
|
235
203
|
}
|
|
236
204
|
|
|
237
|
-
// Fresh variables for the template's, with the conclusion's set to *False*.
|
|
238
205
|
private getVars() {
|
|
239
206
|
if (this.vars !== undefined) return this.vars;
|
|
240
207
|
const vars: BlastTerm[] = [];
|
|
@@ -264,7 +231,6 @@ class InstantiatedRule implements TableauRule {
|
|
|
264
231
|
return this.instantiatedPrems;
|
|
265
232
|
}
|
|
266
233
|
|
|
267
|
-
// Since unsafe rules are delayed, dup is always false for introduction rules.
|
|
268
234
|
tactic(isUpdated: boolean, isDup: boolean, isRotated: boolean) {
|
|
269
235
|
return (this.isIntro ? intrRuleTactic : elimRuleTactic)(this.state, this.rule, this.prems)(
|
|
270
236
|
isUpdated,
|
|
@@ -274,8 +240,6 @@ class InstantiatedRule implements TableauRule {
|
|
|
274
240
|
}
|
|
275
241
|
}
|
|
276
242
|
|
|
277
|
-
// fromRule or fromIntrRule: undefined for an ill-formed rule. Its Skolem terms take their names
|
|
278
|
-
// now, as blast converts all the rules it looks up at once.
|
|
279
243
|
const instantiateRule = (
|
|
280
244
|
state: BlastState,
|
|
281
245
|
vars: readonly VarRef[],
|
|
@@ -295,7 +259,6 @@ const instantiateRule = (
|
|
|
295
259
|
: new InstantiatedRule(state, rule, isIntro, template, template.major, skolems);
|
|
296
260
|
};
|
|
297
261
|
|
|
298
|
-
// Too flexible assertions or goals, such as those of (!!P. ~P) ==> 0 == 1.
|
|
299
262
|
const isVarForm = (state: BlastState, term: BlastTerm) =>
|
|
300
263
|
term.kind === "Var" || destConstApp(term, state.context.data.notName)?.kind === "Var";
|
|
301
264
|
|
|
@@ -325,6 +288,5 @@ export const netMkRules = (
|
|
|
325
288
|
return rules;
|
|
326
289
|
};
|
|
327
290
|
|
|
328
|
-
// Converts *Goal* to a negated assumption in first position.
|
|
329
291
|
export const negOfGoalTac = (state: BlastState): GoalTactic =>
|
|
330
292
|
thenGoal(resolveTac(state.context.limits, [state.context.data.ccontr]), rotateTac(-1));
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
// Ported from Isabelle2025's Provers/blast.ML. Copyright (c) 1986-2025 University of Cambridge,
|
|
2
|
-
// Technische Universitaet Muenchen, and contributors, see LICENSE.
|
|
3
|
-
//
|
|
4
|
-
// The object logic's data for blast, and the state of one search: the names of its Skolem
|
|
5
|
-
// constants and the trail of variable assignments that backtracking undoes.
|
|
1
|
+
// Ported from Isabelle2025's Provers/blast.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
|
|
6
2
|
|
|
7
3
|
import { bumpInit, bumpString } from "../../pure/name";
|
|
8
4
|
import type { GoalTactic } from "../../pure/tactical";
|
|
@@ -13,19 +9,14 @@ import type { Claset } from "../classical";
|
|
|
13
9
|
import type { RuleTemplate } from "./rules";
|
|
14
10
|
import { blastAconv, varOccur, wkNorm, type BlastTerm, type ConstType, type VarRef } from "./term";
|
|
15
11
|
|
|
16
|
-
// BLAST_DATA, with the two rules of other structures that blast uses.
|
|
17
12
|
export interface BlastData {
|
|
18
13
|
readonly trueprop: string;
|
|
19
14
|
readonly equalityName: string;
|
|
20
15
|
readonly notName: string;
|
|
21
|
-
// ~P ==> P ==> R
|
|
22
16
|
readonly notE: Thm;
|
|
23
|
-
// (~P ==> False) ==> P
|
|
24
17
|
readonly ccontr: Thm;
|
|
25
18
|
readonly hypSubstTac: (limits: Limits) => GoalTactic;
|
|
26
|
-
// The classical reasoner's (~P ==> P) ==> P, which Classical.dup_intr resolves with.
|
|
27
19
|
readonly classical: Thm;
|
|
28
|
-
// The atomize rules of Object_Logic, newest first, for atomize_prems_tac.
|
|
29
20
|
readonly atomize: readonly Thm[];
|
|
30
21
|
}
|
|
31
22
|
|
|
@@ -33,20 +24,16 @@ export interface BlastContext {
|
|
|
33
24
|
readonly limits: Limits;
|
|
34
25
|
readonly claset: Claset;
|
|
35
26
|
readonly data: BlastData;
|
|
36
|
-
// The constants' declared types, for Sign.const_typargs.
|
|
37
27
|
readonly consts: ReadonlyMap<string, ConstType>;
|
|
38
|
-
// The elimination and introduction rules converted to tableau rules so far.
|
|
39
28
|
readonly elimTemplates: WeakMap<Thm, RuleTemplate>;
|
|
40
29
|
readonly introTemplates: WeakMap<Thm, RuleTemplate>;
|
|
41
30
|
}
|
|
42
31
|
|
|
43
|
-
// A formula pending on a branch, with its may-duplicate flag.
|
|
44
32
|
export interface Formula {
|
|
45
33
|
readonly term: BlastTerm;
|
|
46
34
|
readonly md: boolean;
|
|
47
35
|
}
|
|
48
36
|
|
|
49
|
-
// The safe and unsafe formulae of one level of a branch.
|
|
50
37
|
export interface Level {
|
|
51
38
|
readonly safe: readonly Formula[];
|
|
52
39
|
readonly unsafe: readonly Formula[];
|
|
@@ -54,16 +41,11 @@ export interface Level {
|
|
|
54
41
|
|
|
55
42
|
export interface Branch {
|
|
56
43
|
readonly pairs: readonly Level[];
|
|
57
|
-
// Literals: irreducible formulae.
|
|
58
44
|
readonly lits: readonly BlastTerm[];
|
|
59
|
-
// The variables occurring in the branch.
|
|
60
45
|
readonly vars: readonly VarRef[];
|
|
61
|
-
// The resource limit.
|
|
62
46
|
readonly lim: number;
|
|
63
47
|
}
|
|
64
48
|
|
|
65
|
-
// A choice point: the trail length and branch count when it was made, and the token its handler
|
|
66
|
-
// catches. The token is undefined for PROVE, the end of the search.
|
|
67
49
|
export interface Choice {
|
|
68
50
|
readonly ntrl: number;
|
|
69
51
|
readonly nbrs: number;
|
|
@@ -72,14 +54,11 @@ export interface Choice {
|
|
|
72
54
|
|
|
73
55
|
export interface BlastState {
|
|
74
56
|
readonly context: BlastContext;
|
|
75
|
-
// The used names with their latest renaming, a Name.context updated in place.
|
|
76
57
|
readonly names: Map<string, string | undefined>;
|
|
77
|
-
// The assigned variables, latest last, so that the trail's length is ntrail.
|
|
78
58
|
readonly trail: VarRef[];
|
|
79
59
|
}
|
|
80
60
|
|
|
81
|
-
//
|
|
82
|
-
// Error, since backtracking is frequent and needs no stack trace.
|
|
61
|
+
// Not an Error: backtracking is frequent and needs no stack trace.
|
|
83
62
|
class Backtrack {
|
|
84
63
|
readonly token: object | undefined;
|
|
85
64
|
constructor(token: object | undefined) {
|
|
@@ -87,7 +66,6 @@ class Backtrack {
|
|
|
87
66
|
}
|
|
88
67
|
}
|
|
89
68
|
|
|
90
|
-
// The choice points, latest first. The last is PROVE's.
|
|
91
69
|
export type Choices = List<Choice> | undefined;
|
|
92
70
|
|
|
93
71
|
export const isBacktrackTo = (error: unknown, token: object | undefined) =>
|
|
@@ -97,7 +75,6 @@ export const backtrack = (choices: Choices): never => {
|
|
|
97
75
|
throw new Backtrack(choices?.head.token);
|
|
98
76
|
};
|
|
99
77
|
|
|
100
|
-
// Name.variant on the state's names, for names without trailing underscores.
|
|
101
78
|
export const gensym = (state: BlastState, name: string) => {
|
|
102
79
|
const names = state.names;
|
|
103
80
|
if (!names.has(name)) {
|
|
@@ -112,7 +89,6 @@ export const gensym = (state: BlastState, name: string) => {
|
|
|
112
89
|
return current;
|
|
113
90
|
};
|
|
114
91
|
|
|
115
|
-
// Restores the trail to a previous length, for backtracking.
|
|
116
92
|
export const clearTo = (state: BlastState, count: number) => {
|
|
117
93
|
while (state.trail.length > count) {
|
|
118
94
|
const ref = state.trail.pop();
|
|
@@ -120,8 +96,6 @@ export const clearTo = (state: BlastState, count: number) => {
|
|
|
120
96
|
}
|
|
121
97
|
};
|
|
122
98
|
|
|
123
|
-
// First-order unification with bound variables. The variables of vars are local to a rule: their
|
|
124
|
-
// assignments are not trailed.
|
|
125
99
|
const updateVar = (
|
|
126
100
|
state: BlastState,
|
|
127
101
|
vars: readonly VarRef[],
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
// Ported from Isabelle2025's Provers/blast.ML. Copyright (c) 1986-2025 University of Cambridge,
|
|
2
|
-
// Technische Universitaet Muenchen, and contributors, see LICENSE.
|
|
3
|
-
//
|
|
4
|
-
// Blast's prototerms: untyped terms whose variables are mutable references, so that unification
|
|
5
|
-
// updates them in place and backtracking resets them from the trail. Constants carry their type
|
|
6
|
-
// arguments as terms, so that overloading is tracked faithfully.
|
|
1
|
+
// Ported from Isabelle2025's Provers/blast.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
|
|
7
2
|
|
|
8
3
|
import { typargs, type TypargPosition } from "../../pure/consts";
|
|
9
4
|
import {
|
|
@@ -17,14 +12,11 @@ import {
|
|
|
17
12
|
type Typ,
|
|
18
13
|
} from "../../pure/term";
|
|
19
14
|
|
|
20
|
-
// A variable's assignment: term option Unsynchronized.ref, compared by identity.
|
|
21
15
|
export interface VarRef {
|
|
22
16
|
value: BlastTerm | undefined;
|
|
23
17
|
}
|
|
24
18
|
|
|
25
|
-
//
|
|
26
|
-
// doesn't use undefined, and the constructors below list them in this order. So all prototerms
|
|
27
|
-
// share one object layout, and V8 compiles the many switches on kind to monomorphic loads.
|
|
19
|
+
// Every prototerm lists every field in this order, unused ones undefined, so V8 sees one object layout.
|
|
28
20
|
interface Fields {
|
|
29
21
|
readonly name: string;
|
|
30
22
|
readonly typargs: readonly BlastTerm[];
|
|
@@ -140,7 +132,6 @@ export const mkBlastApp = (fun: BlastTerm, arg: BlastTerm): BlastTerm => ({
|
|
|
140
132
|
export const listBlastComb = (head: BlastTerm, args: readonly BlastTerm[]) =>
|
|
141
133
|
args.reduce((result, arg) => mkBlastApp(result, arg), head);
|
|
142
134
|
|
|
143
|
-
// Const (c, _) $ t: the argument of a constant applied to one term, if the term is one.
|
|
144
135
|
export const destConstApp = (term: BlastTerm, name: string): BlastTerm | undefined =>
|
|
145
136
|
term.kind === "App" && term.fun.kind === "Const" && term.fun.name === name ? term.arg : undefined;
|
|
146
137
|
|
|
@@ -148,7 +139,6 @@ export const mkGoal = (term: BlastTerm) => mkBlastApp(mkBlastConst(GOAL_NAME), t
|
|
|
148
139
|
|
|
149
140
|
export const isGoal = (term: BlastTerm) => destConstApp(term, GOAL_NAME) !== undefined;
|
|
150
141
|
|
|
151
|
-
// Tests whether two terms are alpha-convertible, chasing instantiations.
|
|
152
142
|
export const blastAconv = (left: BlastTerm, right: BlastTerm): boolean => {
|
|
153
143
|
if (left === right) return true;
|
|
154
144
|
if (left.kind === "Const" && right.kind === "Const")
|
|
@@ -169,21 +159,15 @@ export const blastAconv = (left: BlastTerm, right: BlastTerm): boolean => {
|
|
|
169
159
|
const blastAconvs = (lefts: readonly BlastTerm[], rights: readonly BlastTerm[]) =>
|
|
170
160
|
lefts.length === rights.length && lefts.every((left, index) => blastAconv(left, rights[index]));
|
|
171
161
|
|
|
172
|
-
const memTerm = (term: BlastTerm, terms: readonly BlastTerm[]) =>
|
|
173
|
-
terms.some((other) => blastAconv(term, other));
|
|
174
|
-
|
|
175
162
|
export const insTerm = (term: BlastTerm, terms: readonly BlastTerm[]) =>
|
|
176
|
-
|
|
163
|
+
terms.some((other) => blastAconv(term, other)) ? terms : [term, ...terms];
|
|
177
164
|
|
|
178
165
|
export const sameVars = (left: readonly VarRef[], right: readonly VarRef[]) =>
|
|
179
166
|
left.length === right.length && left.every((ref, index) => ref === right[index]);
|
|
180
167
|
|
|
181
|
-
const memVar = (ref: VarRef, refs: readonly VarRef[]) => refs.includes(ref);
|
|
182
|
-
|
|
183
168
|
const insVar = (ref: VarRef, refs: readonly VarRef[]) =>
|
|
184
|
-
|
|
169
|
+
refs.includes(ref) ? refs : [ref, ...refs];
|
|
185
170
|
|
|
186
|
-
// Accumulates the unassigned variables of a term, suppressing duplicates.
|
|
187
171
|
export const addTermVars = (term: BlastTerm, refs: readonly VarRef[]): readonly VarRef[] => {
|
|
188
172
|
switch (term.kind) {
|
|
189
173
|
case "Skolem":
|
|
@@ -213,7 +197,6 @@ const addVarsVars = (vars: readonly VarRef[], refs: readonly VarRef[]) =>
|
|
|
213
197
|
refs,
|
|
214
198
|
);
|
|
215
199
|
|
|
216
|
-
// Chases the assignments of the variables, returning the unassigned ones.
|
|
217
200
|
export const varsInVars = (refs: readonly VarRef[]) => addVarsVars(refs, []);
|
|
218
201
|
|
|
219
202
|
const incrBv = (increment: number, level: number, term: BlastTerm): BlastTerm => {
|
|
@@ -232,7 +215,6 @@ const incrBv = (increment: number, level: number, term: BlastTerm): BlastTerm =>
|
|
|
232
215
|
export const incrBlastBoundvars = (increment: number, term: BlastTerm) =>
|
|
233
216
|
increment === 0 ? term : incrBv(increment, 0, term);
|
|
234
217
|
|
|
235
|
-
// member (op =) (loose_bnos term) 0, which does not chase variables.
|
|
236
218
|
export const hasLooseBound0 = (term: BlastTerm, level = 0): boolean => {
|
|
237
219
|
switch (term.kind) {
|
|
238
220
|
case "Bound":
|
|
@@ -262,8 +244,6 @@ const substBoundAt = (arg: BlastTerm, level: number, term: BlastTerm): BlastTerm
|
|
|
262
244
|
|
|
263
245
|
export const blastSubstBound = (arg: BlastTerm, body: BlastTerm) => substBoundAt(arg, 0, body);
|
|
264
246
|
|
|
265
|
-
// Normalizes, but not the bodies of abstractions. Returns the very same term where nothing
|
|
266
|
-
// changes, so normalizing a normal formula allocates nothing.
|
|
267
247
|
export const norm = (term: BlastTerm): BlastTerm => {
|
|
268
248
|
switch (term.kind) {
|
|
269
249
|
case "Skolem": {
|
|
@@ -319,7 +299,6 @@ const wkNormAux = (term: BlastTerm): BlastTerm => {
|
|
|
319
299
|
}
|
|
320
300
|
};
|
|
321
301
|
|
|
322
|
-
// Weak, one-level normalization for unification; eta-contracts where it can.
|
|
323
302
|
export const wkNorm = (term: BlastTerm): BlastTerm => {
|
|
324
303
|
const head = blastHeadOf(term);
|
|
325
304
|
return head.kind === "Const" || head.kind === "Skolem" || head.kind === "Free"
|
|
@@ -327,7 +306,6 @@ export const wkNorm = (term: BlastTerm): BlastTerm => {
|
|
|
327
306
|
: wkNormAux(term);
|
|
328
307
|
};
|
|
329
308
|
|
|
330
|
-
// Does variable ref occur in term? Dangling bound variables count as occurrences too.
|
|
331
309
|
const occurs = (ref: VarRef, level: number, term: BlastTerm): boolean => {
|
|
332
310
|
switch (term.kind) {
|
|
333
311
|
case "Var":
|
|
@@ -351,14 +329,12 @@ const occurs = (ref: VarRef, level: number, term: BlastTerm): boolean => {
|
|
|
351
329
|
|
|
352
330
|
export const varOccur = (ref: VarRef, term: BlastTerm) => occurs(ref, 0, term);
|
|
353
331
|
|
|
354
|
-
// An entry of the association lists from schematic variables to prototerms that fromTerm keeps.
|
|
355
332
|
export interface VarEntry {
|
|
356
333
|
readonly name: string;
|
|
357
334
|
readonly index: number;
|
|
358
335
|
readonly term: BlastTerm;
|
|
359
336
|
}
|
|
360
337
|
|
|
361
|
-
// AList.lookup, adding a fresh variable for a new one.
|
|
362
338
|
const lookupVar = (entries: VarEntry[], name: string, index: number): BlastTerm => {
|
|
363
339
|
const known = entries.find((entry) => entry.index === index && entry.name === name);
|
|
364
340
|
if (known !== undefined) return known.term;
|
|
@@ -384,7 +360,6 @@ export const fromConst = (
|
|
|
384
360
|
type: Typ,
|
|
385
361
|
) => {
|
|
386
362
|
const declared = consts.get(name);
|
|
387
|
-
// Sign.const_typargs. Constants the map lacks are the ones a theory declares, which have none.
|
|
388
363
|
return declared === undefined || declared.typargs.length === 0
|
|
389
364
|
? mkBlastConst(name)
|
|
390
365
|
: mkBlastConst(
|
|
@@ -425,12 +400,9 @@ const fromTermAux = (
|
|
|
425
400
|
}
|
|
426
401
|
};
|
|
427
402
|
|
|
428
|
-
// Converts a real term to a prototerm, eta-contracting it.
|
|
429
403
|
export const fromTerm = (consts: ReadonlyMap<string, ConstType>, term: Term): BlastTerm =>
|
|
430
404
|
fromTermAux(consts, [], [], term);
|
|
431
405
|
|
|
432
|
-
// A prototerm with its variables and Skolem terms numbered, so that instantiating it with fresh
|
|
433
|
-
// ones gives a copy that shares the parts without them, which blast never updates.
|
|
434
406
|
export type Template =
|
|
435
407
|
| { readonly kind: "ground"; readonly term: BlastTerm }
|
|
436
408
|
| { readonly kind: "var"; readonly index: number }
|
|
@@ -441,7 +413,6 @@ export type Template =
|
|
|
441
413
|
|
|
442
414
|
const isGround = (template: Template) => template.kind === "ground";
|
|
443
415
|
|
|
444
|
-
// Numbers the variables in refs, adding new ones, and the Skolem terms by their place in skolems.
|
|
445
416
|
export const toTemplate = (
|
|
446
417
|
refs: VarRef[],
|
|
447
418
|
skolems: readonly BlastTerm[],
|
|
@@ -507,7 +478,6 @@ export const instantiateTemplate = (
|
|
|
507
478
|
|
|
508
479
|
const dummyVar = mkVar("etc", 0, dummyT);
|
|
509
480
|
|
|
510
|
-
// Converts a prototerm to a real term with dummy types for net lookup, stopping at depth.
|
|
511
481
|
export const toTerm = (depth: number, term: BlastTerm): Term => {
|
|
512
482
|
if (depth === 0) return dummyVar;
|
|
513
483
|
switch (term.kind) {
|
|
@@ -527,7 +497,6 @@ export const toTerm = (depth: number, term: BlastTerm): Term => {
|
|
|
527
497
|
|
|
528
498
|
const stripTrueprop = (trueprop: string, term: BlastTerm) => destConstApp(term, trueprop) ?? term;
|
|
529
499
|
|
|
530
|
-
// A1 ==> ... ==> An ==> B goes to [A1, ..., An], where B is not an implication.
|
|
531
500
|
export const stripBlastImpPrems = (trueprop: string, term: BlastTerm): BlastTerm[] =>
|
|
532
501
|
term.kind === "App" &&
|
|
533
502
|
term.fun.kind === "App" &&
|
|
@@ -536,7 +505,6 @@ export const stripBlastImpPrems = (trueprop: string, term: BlastTerm): BlastTerm
|
|
|
536
505
|
? [stripTrueprop(trueprop, term.fun.arg), ...stripBlastImpPrems(trueprop, term.arg)]
|
|
537
506
|
: [];
|
|
538
507
|
|
|
539
|
-
// A1 ==> ... ==> An ==> B goes to B, where B is not an implication.
|
|
540
508
|
export const stripBlastImpConcl = (trueprop: string, term: BlastTerm): BlastTerm =>
|
|
541
509
|
term.kind === "App" &&
|
|
542
510
|
term.fun.kind === "App" &&
|
|
@@ -544,3 +512,8 @@ export const stripBlastImpConcl = (trueprop: string, term: BlastTerm): BlastTerm
|
|
|
544
512
|
term.fun.fun.name === "Pure.imp"
|
|
545
513
|
? stripBlastImpConcl(trueprop, term.arg)
|
|
546
514
|
: stripTrueprop(trueprop, term);
|
|
515
|
+
|
|
516
|
+
export const splitGoalPrems = (trueprop: string, term: BlastTerm): BlastTerm[] => [
|
|
517
|
+
mkGoal(stripBlastImpConcl(trueprop, term)),
|
|
518
|
+
...stripBlastImpPrems(trueprop, term),
|
|
519
|
+
];
|