tla-ts 0.0.9 → 0.0.10-dev.63a6693bd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -1
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +29 -29
- package/dist/deciders.js +42 -42
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +106 -10
- package/dist/index.d.ts +106 -10
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +117 -37
- package/dist/prove.js +116 -36
- package/dist/run.cjs +143 -31
- package/dist/run.js +143 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +129 -104
- package/dist/transfer.js +129 -104
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +3 -1
- package/src/ast.ts +48 -62
- package/src/bags.ts +99 -102
- package/src/builtins.ts +28 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check-failure.ts +116 -0
- package/src/check-trace.ts +282 -0
- package/src/check.ts +599 -754
- package/src/cli/options.ts +12 -32
- package/src/cli/run.ts +0 -2
- package/src/cli/runtime-invariants.ts +136 -0
- package/src/cli/shared.ts +19 -12
- package/src/cli/tlapm.ts +14 -25
- package/src/cli/tlc-arguments.ts +652 -0
- package/src/cli/tlc-output.ts +687 -0
- package/src/cli/tlc-usage.ts +361 -0
- package/src/cli/tlc.ts +309 -658
- package/src/cli/typescript.ts +23 -0
- package/src/cli/xml-exporter.ts +27 -49
- package/src/cli.ts +0 -1
- package/src/codegen.ts +196 -74
- package/src/config.ts +140 -109
- package/src/coverage.ts +830 -0
- package/src/dependencies.ts +14 -53
- package/src/dfid.ts +618 -0
- package/src/environment-config.ts +315 -0
- package/src/environment.ts +169 -335
- package/src/errors.ts +71 -55
- package/src/evaluate.ts +598 -340
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +75 -11
- package/src/index.ts +3 -0
- package/src/instances.ts +126 -21
- package/src/java-hash.ts +7 -0
- package/src/java-overrides.ts +4 -19
- package/src/json-reader.ts +455 -0
- package/src/json.ts +252 -139
- package/src/levels.ts +46 -58
- package/src/lexer.ts +80 -100
- package/src/liveness-checker.ts +103 -153
- package/src/liveness.ts +150 -109
- package/src/obligations/action.ts +8 -39
- package/src/obligations/anonymize.ts +88 -82
- package/src/obligations/equality.ts +1 -1
- package/src/obligations/expression.ts +20 -21
- package/src/obligations/format.ts +1 -9
- package/src/obligations/generate.ts +46 -49
- package/src/obligations/index.ts +2 -13
- package/src/obligations/levels.ts +4 -8
- package/src/obligations/module.ts +28 -53
- package/src/obligations/normalize.ts +7 -25
- package/src/obligations/operators.ts +1 -2
- package/src/obligations/pragma.ts +1 -10
- package/src/obligations/printer.ts +47 -46
- package/src/obligations/proof.ts +1 -5
- package/src/obligations/regroup.ts +1 -4
- package/src/obligations/simplify.ts +42 -58
- package/src/obligations/source.ts +48 -78
- package/src/obligations/subexpression.ts +5 -11
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +13 -19
- package/src/obligations/tuples.ts +3 -9
- package/src/parallel-worker.ts +30 -60
- package/src/parallel.ts +57 -71
- package/src/parser.ts +584 -316
- package/src/pcal/ast.ts +53 -86
- package/src/pcal/parse.ts +144 -219
- package/src/pcal/tokenize.ts +91 -131
- package/src/pcal/translate.ts +83 -130
- package/src/pcal/validate.ts +48 -68
- package/src/pretty-print.ts +7 -8
- package/src/prover/decide-pool.ts +8 -13
- package/src/prover/deciders.ts +3 -7
- package/src/prover/first-order.ts +0 -11
- package/src/prover/isabelle/decide.ts +0 -6
- package/src/prover/isabelle/encode.ts +11 -23
- package/src/prover/isabelle/isar/inner-syntax.ts +114 -115
- package/src/prover/isabelle/isar/method.ts +29 -53
- package/src/prover/isabelle/isar/proof.ts +1 -10
- package/src/prover/isabelle/isar/statement.ts +1 -6
- package/src/prover/isabelle/isar/theory.ts +26 -36
- package/src/prover/isabelle/isar/type-check.ts +17 -31
- package/src/prover/isabelle/provers/blast/blast.ts +17 -104
- package/src/prover/isabelle/provers/blast/branch.ts +1 -32
- package/src/prover/isabelle/provers/blast/prove.ts +1 -35
- package/src/prover/isabelle/provers/blast/rules.ts +6 -44
- package/src/prover/isabelle/provers/blast/state.ts +2 -28
- package/src/prover/isabelle/provers/blast/term.ts +9 -36
- package/src/prover/isabelle/provers/clasimp.ts +1 -13
- package/src/prover/isabelle/provers/classical.ts +14 -42
- package/src/prover/isabelle/provers/hypsubst.ts +28 -51
- package/src/prover/isabelle/pure/bicompose.ts +25 -38
- package/src/prover/isabelle/pure/consts.ts +1 -7
- package/src/prover/isabelle/pure/conv.ts +3 -17
- package/src/prover/isabelle/pure/drule.ts +33 -42
- package/src/prover/isabelle/pure/envir.ts +3 -52
- package/src/prover/isabelle/pure/goal.ts +1 -7
- package/src/prover/isabelle/pure/interrupt.ts +0 -5
- package/src/prover/isabelle/pure/list.ts +0 -3
- package/src/prover/isabelle/pure/logic.ts +2 -15
- package/src/prover/isabelle/pure/name.ts +2 -9
- package/src/prover/isabelle/pure/net.ts +3 -59
- package/src/prover/isabelle/pure/object-logic.ts +3 -10
- package/src/prover/isabelle/pure/pattern.ts +2 -19
- package/src/prover/isabelle/pure/raw-simplifier.ts +17 -62
- package/src/prover/isabelle/pure/rewriter.ts +31 -67
- package/src/prover/isabelle/pure/search.ts +3 -10
- package/src/prover/isabelle/pure/seq.ts +1 -10
- package/src/prover/isabelle/pure/simplifier.ts +4 -12
- package/src/prover/isabelle/pure/table.ts +3 -32
- package/src/prover/isabelle/pure/tactic.ts +12 -22
- package/src/prover/isabelle/pure/tactical.ts +48 -47
- package/src/prover/isabelle/pure/term-ord.ts +2 -6
- package/src/prover/isabelle/pure/term.ts +2 -43
- package/src/prover/isabelle/pure/thm.ts +27 -47
- package/src/prover/isabelle/pure/type.ts +2 -15
- package/src/prover/isabelle/pure/unify.ts +20 -30
- package/src/prover/isabelle/pure/variable.ts +3 -7
- package/src/prover/isabelle/tla/classical-setup.ts +17 -24
- package/src/prover/isabelle/tla/context.ts +15 -18
- package/src/prover/isabelle/tla/logic.ts +14 -32
- package/src/prover/isabelle/tla/simpdata.ts +46 -43
- package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
- package/src/prover/ocaml.ts +0 -6
- package/src/prover/prep/action.ts +14 -54
- package/src/prover/prep/enabled-axioms.ts +12 -19
- package/src/prover/prep/fingerprint.ts +2 -21
- package/src/prover/prep/level-comparison.ts +8 -12
- package/src/prover/prep/md5.ts +0 -2
- package/src/prover/prep/methods.ts +33 -39
- package/src/prover/prep/normalize.ts +4 -28
- package/src/prover/prove-worker.ts +0 -2
- package/src/prover/prove.ts +87 -100
- package/src/prover/ptl/decide.ts +7 -12
- package/src/prover/ptl/encode.ts +14 -36
- package/src/prover/ptl/sat.ts +24 -32
- package/src/prover/ptl/tableau.ts +12 -26
- package/src/prover/smt/axioms.ts +0 -7
- package/src/prover/smt/context.ts +20 -28
- package/src/prover/smt/data.ts +433 -424
- package/src/prover/smt/encode.ts +43 -52
- package/src/prover/smt/extensionality.ts +0 -10
- package/src/prover/smt/flatten.ts +3 -22
- package/src/prover/smt/format.ts +5 -10
- package/src/prover/smt/instances.ts +0 -10
- package/src/prover/smt/rewrite.ts +663 -667
- package/src/prover/smt/solver/act-cache.ts +0 -15
- package/src/prover/smt/solver/arith-rewriter.ts +3 -48
- package/src/prover/smt/solver/array.ts +1 -3
- package/src/prover/smt/solver/asserted-formulas.ts +1 -43
- package/src/prover/smt/solver/ast-lt.ts +1 -11
- package/src/prover/smt/solver/ast-util.ts +1 -6
- package/src/prover/smt/solver/ast.ts +1 -165
- package/src/prover/smt/solver/auf-solver.ts +8 -44
- package/src/prover/smt/solver/case-split-queue.ts +1 -9
- package/src/prover/smt/solver/cg-table.ts +1 -18
- package/src/prover/smt/solver/clause.ts +1 -27
- package/src/prover/smt/solver/conflict-resolution.ts +0 -9
- package/src/prover/smt/solver/context.ts +7 -64
- package/src/prover/smt/solver/ctx-simplify.ts +14 -41
- package/src/prover/smt/solver/der.ts +2 -21
- package/src/prover/smt/solver/dyn-ack.ts +1 -11
- package/src/prover/smt/solver/e-matching.ts +4 -35
- package/src/prover/smt/solver/enode.ts +1 -21
- package/src/prover/smt/solver/expr-ref.ts +1 -5
- package/src/prover/smt/solver/expr-safe-replace.ts +1 -6
- package/src/prover/smt/solver/fingerprints.ts +1 -12
- package/src/prover/smt/solver/flat-literals.ts +1 -9
- package/src/prover/smt/solver/goal.ts +2 -14
- package/src/prover/smt/solver/hash.ts +0 -8
- package/src/prover/smt/solver/hashtable.ts +1 -12
- package/src/prover/smt/solver/internalizer.ts +7 -100
- package/src/prover/smt/solver/lbool.ts +1 -2
- package/src/prover/smt/solver/literal.ts +0 -3
- package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
- package/src/prover/smt/solver/lp/constraints.ts +2 -8
- package/src/prover/smt/solver/lp/containers.ts +12 -30
- package/src/prover/smt/solver/lp/core-solver.ts +10 -31
- package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
- package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
- package/src/prover/smt/solver/lp/dependency.ts +1 -4
- package/src/prover/smt/solver/lp/dioph-eq.ts +9 -102
- package/src/prover/smt/solver/lp/explanation.ts +1 -6
- package/src/prover/smt/solver/lp/gomory.ts +9 -22
- package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
- package/src/prover/smt/solver/lp/hnf.ts +11 -26
- package/src/prover/smt/solver/lp/int-cube.ts +15 -36
- package/src/prover/smt/solver/lp/int-solver.ts +4 -34
- package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
- package/src/prover/smt/solver/lp/lar-term.ts +1 -5
- package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
- package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
- package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
- package/src/prover/smt/solver/lp/nex.ts +1 -6
- package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
- package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
- package/src/prover/smt/solver/lp/nla-core.ts +36 -135
- package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
- package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
- package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
- package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
- package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
- package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
- package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
- package/src/prover/smt/solver/lp/nla-order.ts +2 -13
- package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
- package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
- package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
- package/src/prover/smt/solver/lp/nla-types.ts +1 -11
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
- package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
- package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
- package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
- package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
- package/src/prover/smt/solver/lp/pdd.ts +7 -70
- package/src/prover/smt/solver/lp/random-updater.ts +1 -8
- package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
- package/src/prover/smt/solver/lp/union-find.ts +1 -6
- package/src/prover/smt/solver/mam-compiler.ts +18 -58
- package/src/prover/smt/solver/mam-interpreter.ts +1 -21
- package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
- package/src/prover/smt/solver/model-checker.ts +3 -37
- package/src/prover/smt/solver/model-evaluator.ts +3 -29
- package/src/prover/smt/solver/model-finder.ts +15 -32
- package/src/prover/smt/solver/model-generator.ts +1 -12
- package/src/prover/smt/solver/model-macro-solver.ts +23 -88
- package/src/prover/smt/solver/nlsat/algebraic.ts +63 -159
- package/src/prover/smt/solver/nlsat/atoms.ts +25 -23
- package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
- package/src/prover/smt/solver/nlsat/explain.ts +10 -69
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
- package/src/prover/smt/solver/nlsat/levelwise.ts +49 -135
- package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +29 -159
- package/src/prover/smt/solver/nlsat/solver.ts +18 -90
- package/src/prover/smt/solver/nlsat/types.ts +1 -8
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +2 -45
- package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
- package/src/prover/smt/solver/nnf.ts +3 -38
- package/src/prover/smt/solver/pattern-inference.ts +2 -15
- package/src/prover/smt/solver/poly-rewriter.ts +3 -23
- package/src/prover/smt/solver/propagate-values.ts +1 -10
- package/src/prover/smt/solver/proto-model.ts +3 -52
- package/src/prover/smt/solver/pull-quant.ts +1 -12
- package/src/prover/smt/solver/qe-lite-der.ts +1 -29
- package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
- package/src/prover/smt/solver/qe-lite.ts +3 -33
- package/src/prover/smt/solver/qi-queue.ts +1 -16
- package/src/prover/smt/solver/quant-tactics.ts +5 -22
- package/src/prover/smt/solver/quantifier-analyzer.ts +27 -47
- package/src/prover/smt/solver/quantifier-manager.ts +2 -13
- package/src/prover/smt/solver/random-gen.ts +1 -2
- package/src/prover/smt/solver/rational.ts +1 -8
- package/src/prover/smt/solver/ref-vector.ts +1 -6
- package/src/prover/smt/solver/relevancy.ts +2 -15
- package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
- package/src/prover/smt/solver/rewriter.ts +3 -85
- package/src/prover/smt/solver/rlimit.ts +2 -20
- package/src/prover/smt/solver/smtlib-parser.ts +80 -131
- package/src/prover/smt/solver/solver.ts +23 -34
- package/src/prover/smt/solver/sort.ts +1 -5
- package/src/prover/smt/solver/sticky-generations.ts +0 -5
- package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
- package/src/prover/smt/solver/theory-lra-bounds.ts +1 -7
- package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
- package/src/prover/smt/solver/theory-lra-internalize.ts +6 -43
- package/src/prover/smt/solver/theory-lra-model.ts +4 -19
- package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
- package/src/prover/smt/solver/theory-lra-state.ts +3 -8
- package/src/prover/smt/solver/theory-lra.ts +1 -8
- package/src/prover/smt/solver/var-subst.ts +2 -26
- package/src/prover/smt/table.ts +0 -8
- package/src/prover/tlapm/cache.ts +45 -40
- package/src/prover/tlapm/ocaml-marshal.ts +19 -21
- package/src/prover/tlapm/tlapm.ts +21 -20
- package/src/prover/verdict.ts +7 -2
- package/src/prover/zenon/check/check.ts +1 -11
- package/src/prover/zenon/check/definitions.ts +5 -15
- package/src/prover/zenon/check/equality.ts +0 -8
- package/src/prover/zenon/check/functions.ts +0 -4
- package/src/prover/zenon/check/keys.ts +0 -7
- package/src/prover/zenon/check/propositional.ts +0 -3
- package/src/prover/zenon/check/records.ts +1 -6
- package/src/prover/zenon/check/relations.ts +2 -14
- package/src/prover/zenon/check/rewrites.ts +2 -21
- package/src/prover/zenon/check/sets.ts +40 -61
- package/src/prover/zenon/check/terms.ts +1 -19
- package/src/prover/zenon/check/tla.ts +0 -6
- package/src/prover/zenon/decide.ts +0 -12
- package/src/prover/zenon/encode.ts +1 -8
- package/src/prover/zenon/eqrel.ts +2 -13
- package/src/prover/zenon/equality-rules.ts +0 -4
- package/src/prover/zenon/expr.ts +8 -26
- package/src/prover/zenon/index-table.ts +26 -57
- package/src/prover/zenon/isar-case.ts +9 -19
- package/src/prover/zenon/isar.ts +36 -64
- package/src/prover/zenon/limits.ts +0 -4
- package/src/prover/zenon/llproof.ts +2 -20
- package/src/prover/zenon/mltoll.ts +66 -104
- package/src/prover/zenon/node.ts +1 -11
- package/src/prover/zenon/ocaml.ts +1 -17
- package/src/prover/zenon/parse.ts +4 -12
- package/src/prover/zenon/phrase.ts +1 -11
- package/src/prover/zenon/proof.ts +0 -9
- package/src/prover/zenon/propositional-rules.ts +0 -5
- package/src/prover/zenon/rules.ts +2 -6
- package/src/prover/zenon/search.ts +5 -31
- package/src/prover/zenon/tla/functions.ts +59 -31
- package/src/prover/zenon/tla/llproof.ts +67 -76
- package/src/prover/zenon/tla/records.ts +57 -33
- package/src/prover/zenon/tla/rewrites.ts +12 -19
- package/src/prover/zenon/tla/sets.ts +83 -53
- package/src/prover/zenon/tla/terms.ts +0 -6
- package/src/prover/zenon/tla/tla.ts +66 -64
- package/src/randomization.ts +81 -35
- package/src/resolve.ts +67 -184
- package/src/runtime.ts +22 -22
- package/src/sany/builtins.ts +2 -5
- package/src/sany/generation.ts +394 -0
- package/src/sany/generator-def-entries.ts +210 -0
- package/src/sany/generator-definitions.ts +686 -0
- package/src/sany/generator-expressions.ts +1100 -0
- package/src/sany/generator-proofs.ts +662 -0
- package/src/sany/generator.ts +191 -2764
- package/src/sany/levels.ts +6 -34
- package/src/sany/lexer.ts +58 -77
- package/src/sany/linter.ts +1 -9
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +5 -43
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +32 -69
- package/src/sany/selectors.ts +49 -76
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +35 -117
- package/src/search.ts +541 -163
- package/src/simulate.ts +709 -0
- package/src/spec-description.ts +192 -100
- package/src/standard-definitions.ts +0 -4
- package/src/standard-modules.ts +264 -95
- package/src/state-graph.ts +52 -31
- package/src/subexpressions.ts +69 -52
- package/src/substitution-levels.ts +7 -7
- package/src/successors.ts +266 -99
- package/src/symmetry.ts +33 -25
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +183 -67
- package/src/tlc/jar-data.ts +112 -6
- package/src/tlc/messages.ts +125 -54
- package/src/tlc/order.ts +39 -69
- package/src/tlc/random.ts +37 -49
- package/src/tlc/replay.ts +553 -228
- package/src/tlc/summary.ts +36 -47
- package/src/tlc/tlc-operators.ts +78 -44
- package/src/tlc/tlcext-operators.ts +139 -122
- package/src/tlc/trace-spec.ts +249 -0
- package/src/tlc/value-stream.ts +139 -0
- package/src/tlc/version.ts +1 -4
- package/src/transfer.ts +22 -25
- package/src/typescript/actions.ts +479 -0
- package/src/typescript/collections.ts +614 -0
- package/src/typescript/compile.ts +63 -0
- package/src/typescript/context.ts +94 -0
- package/src/typescript/emit.ts +121 -0
- package/src/typescript/expressions.ts +496 -0
- package/src/typescript/formula.ts +154 -0
- package/src/typescript/functions.ts +284 -0
- package/src/typescript/model.ts +162 -0
- package/src/typescript/names.ts +114 -0
- package/src/typescript/program.ts +48 -0
- package/src/typescript/properties.ts +139 -0
- package/src/typescript/scope.ts +112 -0
- package/src/typescript/steps.ts +167 -0
- package/src/typescript/types.ts +171 -0
- package/src/values.ts +832 -484
- package/src/worker.ts +7 -8
package/src/prover/prove.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// Proves a module's obligations with tla-ts's own backends, in tlapm's order, or with tlapm.
|
|
2
|
-
|
|
3
1
|
import { TlaProverError, TlaUnsupportedError } from "../errors";
|
|
4
2
|
import { getChildren, mapHyp, type Expr, type Hyp, type Sequent } from "../obligations/expression";
|
|
5
3
|
import { getObligations, type PrintedObligation } from "../obligations";
|
|
@@ -17,14 +15,14 @@ import {
|
|
|
17
15
|
normalizeExpand,
|
|
18
16
|
normalizeSequent,
|
|
19
17
|
} from "./prep/normalize";
|
|
20
|
-
import { findMethods, type Method } from "./prep/methods";
|
|
18
|
+
import { findMethods, getBudget, type Method } from "./prep/methods";
|
|
21
19
|
import { encodePtl } from "./ptl/encode";
|
|
22
20
|
import { encodeSmt } from "./smt/encode";
|
|
23
21
|
import type { EncodingSession } from "./smt/rewrite";
|
|
24
22
|
import { encodeZenon } from "./zenon/encode";
|
|
25
23
|
import type { TlapmResult } from "./tlapm/tlapm";
|
|
26
24
|
import { TLAPS_MODULE } from "./tlaps-module";
|
|
27
|
-
import type
|
|
25
|
+
import { isBackend, type Backend, type Verdict } from "./verdict";
|
|
28
26
|
|
|
29
27
|
interface ObligationBase {
|
|
30
28
|
id: number;
|
|
@@ -65,71 +63,63 @@ export interface ProveOptions {
|
|
|
65
63
|
workers?: number;
|
|
66
64
|
}
|
|
67
65
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
method: Method
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
reason?: string;
|
|
74
|
-
verdict?: Verdict;
|
|
75
|
-
timeUsedMs?: number;
|
|
76
|
-
}
|
|
66
|
+
export type ProofAttempt =
|
|
67
|
+
| { kind: "decided"; method: Method; verdict: Verdict; timeUsedMs: number }
|
|
68
|
+
| { kind: "error"; method: Method }
|
|
69
|
+
| { kind: "skipped"; method: Method; reason: string }
|
|
70
|
+
| { kind: "stored" | "reused"; method: Method; isProved: boolean; reason?: string };
|
|
77
71
|
|
|
78
72
|
interface ProofReport {
|
|
79
73
|
obligation: ProofObligation;
|
|
80
74
|
attempts: ProofAttempt[];
|
|
81
75
|
}
|
|
82
76
|
|
|
83
|
-
// Why a method left an obligation unproved: a prover decided so, or tla-ts couldn't try it.
|
|
84
77
|
interface MethodFailure {
|
|
85
78
|
reason: string;
|
|
86
79
|
isDecided: boolean;
|
|
87
80
|
}
|
|
88
81
|
|
|
89
|
-
// The SMT encoder numbers the CASE errors it standardizes across the run, so an obligation it
|
|
90
|
-
// encodes one in waits for every earlier obligation and starts from the count they leave.
|
|
91
82
|
interface ObligationTask {
|
|
83
|
+
report: Promise<ProofReport>;
|
|
92
84
|
done: Promise<void>;
|
|
85
|
+
isSettled: boolean;
|
|
93
86
|
session: { initial: number; current: EncodingSession } | undefined;
|
|
94
87
|
}
|
|
95
88
|
|
|
96
|
-
// What tlapm keeps across one run's obligations. An obligation waits for the last earlier one with
|
|
97
|
-
// its fingerprint, so obligations prove concurrently as they would in turn.
|
|
98
89
|
interface ProveRun {
|
|
99
90
|
tasks: ObligationTask[];
|
|
100
91
|
results: Map<string, Map<string, ProofAttempt>>;
|
|
101
92
|
isFingerprinted: (obligation: PrintedObligation) => boolean;
|
|
102
93
|
isProving: boolean;
|
|
103
|
-
lastByFingerprint: Map<string,
|
|
94
|
+
lastByFingerprint: Map<string, number>;
|
|
104
95
|
decide: DecidePool["decide"];
|
|
105
96
|
}
|
|
106
97
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
98
|
+
interface Encoder {
|
|
99
|
+
encode: (id: number, sequent: Sequent, method: Method, session: EncodingSession) => string;
|
|
100
|
+
isCaseNumbered?: boolean;
|
|
101
|
+
}
|
|
110
102
|
|
|
111
|
-
// Action.process_obligation, the frontend for every backend but LS4, Isabelle included, then
|
|
112
|
-
// Prep.flatten.
|
|
113
103
|
const shipFirstOrder = (sequent: Sequent) => flatten(processObligation(sequent));
|
|
114
104
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
105
|
+
const SMT_ENCODER: Encoder = {
|
|
106
|
+
encode: (_id, sequent, method, session) =>
|
|
107
|
+
(method.rlimit === undefined ? "" : `(set-option :rlimit ${method.rlimit})\n`) +
|
|
108
|
+
encodeSmt(shipFirstOrder(sequent), session),
|
|
109
|
+
isCaseNumbered: true,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const ENCODERS: Record<Backend, Encoder> = {
|
|
113
|
+
smt: SMT_ENCODER,
|
|
114
|
+
z3: SMT_ENCODER,
|
|
115
|
+
zenon: { encode: (id, sequent) => encodeZenon(id, shipFirstOrder(sequent)) },
|
|
116
|
+
isabelle: {
|
|
117
|
+
encode: (id, sequent, method) =>
|
|
118
|
+
encodeIsabelle(id, shipFirstOrder(sequent), method.tactic ?? "auto"),
|
|
119
|
+
},
|
|
120
|
+
ls4: { encode: (_id, sequent) => encodePtl(sequent) },
|
|
129
121
|
};
|
|
130
122
|
|
|
131
|
-
// The frontends and Prep.flatten add no CASE without OTHER, so the SMT encoder standardizes one
|
|
132
|
-
// only in an obligation that has one after Prep.normalize_expand.
|
|
133
123
|
const hasIncompleteCase = (expression: Expr): boolean =>
|
|
134
124
|
(expression.kind === "Case" && expression.other === undefined) ||
|
|
135
125
|
getChildren(expression).some(hasIncompleteCase);
|
|
@@ -168,8 +158,23 @@ const getUnprovedReport = (
|
|
|
168
158
|
attempts: ProofAttempt[] = [],
|
|
169
159
|
): ProofReport => ({ obligation: { ...getObligationBase(obligation), status, reason }, attempts });
|
|
170
160
|
|
|
171
|
-
|
|
172
|
-
|
|
161
|
+
export const isProvedAttempt = (attempt: ProofAttempt) =>
|
|
162
|
+
attempt.kind === "decided"
|
|
163
|
+
? attempt.verdict === "unsat"
|
|
164
|
+
: (attempt.kind === "stored" || attempt.kind === "reused") && attempt.isProved;
|
|
165
|
+
|
|
166
|
+
export const getFailureReason = (attempt: ProofAttempt) => {
|
|
167
|
+
switch (attempt.kind) {
|
|
168
|
+
case "decided":
|
|
169
|
+
if (attempt.verdict === "unsat") return undefined;
|
|
170
|
+
return attempt.timeUsedMs >= attempt.method.timeLimitMs ? "timeout" : "false";
|
|
171
|
+
case "error":
|
|
172
|
+
return "false";
|
|
173
|
+
default:
|
|
174
|
+
return attempt.reason;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
173
178
|
export const formatNormalized = (obligation: PrintedObligation, isReused: boolean) =>
|
|
174
179
|
`${formatObligation(
|
|
175
180
|
isReused
|
|
@@ -177,7 +182,6 @@ export const formatNormalized = (obligation: PrintedObligation, isReused: boolea
|
|
|
177
182
|
: normalizeExpand(obligation),
|
|
178
183
|
)}\n`;
|
|
179
184
|
|
|
180
|
-
// The theory of the proofs Isabelle found. tlapm also writes Zenon's proofs there.
|
|
181
185
|
export const encodeProofTheory = (
|
|
182
186
|
name: string,
|
|
183
187
|
reports: ProofReport[],
|
|
@@ -189,7 +193,9 @@ export const encodeProofTheory = (
|
|
|
189
193
|
report.attempts
|
|
190
194
|
.filter(
|
|
191
195
|
(attempt) =>
|
|
192
|
-
attempt.method.prover === "isabelle" &&
|
|
196
|
+
attempt.method.prover === "isabelle" &&
|
|
197
|
+
attempt.kind === "decided" &&
|
|
198
|
+
attempt.verdict === "unsat",
|
|
193
199
|
)
|
|
194
200
|
.map((attempt) => ({
|
|
195
201
|
id: report.obligation.id,
|
|
@@ -199,24 +205,24 @@ export const encodeProofTheory = (
|
|
|
199
205
|
),
|
|
200
206
|
);
|
|
201
207
|
|
|
202
|
-
// The text one backend receives for an obligation, for comparing with tlapm's.
|
|
203
208
|
export const encodeForBackend = (
|
|
204
209
|
obligation: PrintedObligation,
|
|
205
|
-
prover:
|
|
210
|
+
prover: Backend,
|
|
206
211
|
session: EncodingSession,
|
|
207
212
|
) => {
|
|
208
|
-
const encode = ENCODERS[prover];
|
|
209
|
-
if (!encode) throw new TlaUnsupportedError(`the ${prover} backend`);
|
|
210
213
|
const methods = findMethods(obligation);
|
|
211
214
|
const method = methods.provers.find((candidate) => candidate.prover === prover) ?? {
|
|
212
215
|
prover,
|
|
213
216
|
timeLimitMs: Infinity,
|
|
214
217
|
};
|
|
215
|
-
return encode(
|
|
218
|
+
return ENCODERS[prover].encode(
|
|
219
|
+
obligation.id,
|
|
220
|
+
normalizeExpand(obligation, methods),
|
|
221
|
+
method,
|
|
222
|
+
session,
|
|
223
|
+
);
|
|
216
224
|
};
|
|
217
225
|
|
|
218
|
-
// The SMT encoder's session for an obligation, from the count of CASE errors every earlier
|
|
219
|
-
// obligation leaves.
|
|
220
226
|
const getSession = async (run: ProveRun, index: number) => {
|
|
221
227
|
const task = run.tasks[index];
|
|
222
228
|
if (task.session) return task.session.current;
|
|
@@ -232,10 +238,6 @@ const getSession = async (run: ProveRun, index: number) => {
|
|
|
232
238
|
return task.session.current;
|
|
233
239
|
};
|
|
234
240
|
|
|
235
|
-
// Prep.ship: the provers the step cites, or tlapm's default ones when it cites none, each tried in
|
|
236
|
-
// turn until one proves the obligation. Prep.already_processed reuses what a prover concluded for
|
|
237
|
-
// an earlier obligation with the same fingerprint: a proof, or a failure within at least as much
|
|
238
|
-
// time. Unless the first prover's proof is reused, a trivial obligation needs no prover.
|
|
239
241
|
const proveWithBackends = async (
|
|
240
242
|
obligation: PrintedObligation,
|
|
241
243
|
index: number,
|
|
@@ -247,24 +249,26 @@ const proveWithBackends = async (
|
|
|
247
249
|
const methods = findMethods(obligation);
|
|
248
250
|
const fingerprint = getFingerprint(obligation.sequent);
|
|
249
251
|
const earlier = run.lastByFingerprint.get(fingerprint);
|
|
250
|
-
run.lastByFingerprint.set(fingerprint,
|
|
251
|
-
await earlier;
|
|
252
|
+
run.lastByFingerprint.set(fingerprint, index);
|
|
253
|
+
await (earlier === undefined ? undefined : run.tasks[earlier].done);
|
|
252
254
|
const attempts: ProofAttempt[] = [];
|
|
253
255
|
const failures: MethodFailure[] = [];
|
|
254
256
|
const getProvedReport = (prover: string): ProofReport => ({
|
|
255
257
|
obligation: { ...getObligationBase(obligation), status: "proved", prover },
|
|
256
258
|
attempts,
|
|
257
259
|
});
|
|
258
|
-
// Prep.already_processed, which forgets the fingerprint's results on each call under --nofp.
|
|
259
260
|
const getPrior = (method: Method) => {
|
|
260
261
|
if (!run.isFingerprinted(obligation)) run.results.delete(fingerprint);
|
|
261
262
|
const prior = run.results.get(fingerprint)?.get(method.prover);
|
|
262
263
|
return prior?.method.tactic === method.tactic ? prior : undefined;
|
|
263
264
|
};
|
|
264
|
-
// Fpfile.get_timeout.
|
|
265
|
-
const getBudget = (method: Method) => method.rlimit ?? method.timeLimitMs / 1000;
|
|
266
265
|
const reuse = (prior: ProofAttempt) =>
|
|
267
|
-
attempts.push({
|
|
266
|
+
attempts.push({
|
|
267
|
+
kind: "reused",
|
|
268
|
+
method: prior.method,
|
|
269
|
+
isProved: isProvedAttempt(prior),
|
|
270
|
+
reason: getFailureReason(prior),
|
|
271
|
+
});
|
|
268
272
|
const record = (attempt: ProofAttempt) => {
|
|
269
273
|
attempts.push(attempt);
|
|
270
274
|
run.results.set(
|
|
@@ -273,23 +277,22 @@ const proveWithBackends = async (
|
|
|
273
277
|
);
|
|
274
278
|
};
|
|
275
279
|
const skip = (method: Method, reason: string) => {
|
|
276
|
-
attempts.push({
|
|
280
|
+
attempts.push({ kind: "skipped", method, reason });
|
|
277
281
|
failures.push({ reason, isDecided: false });
|
|
278
282
|
};
|
|
279
283
|
const firstPrior = getPrior(methods.provers[0]);
|
|
280
|
-
if (firstPrior
|
|
284
|
+
if (firstPrior && isProvedAttempt(firstPrior)) {
|
|
281
285
|
reuse(firstPrior);
|
|
282
286
|
return getProvedReport(firstPrior.method.prover);
|
|
283
287
|
}
|
|
284
288
|
const sequent = normalizeExpand(obligation, methods);
|
|
285
|
-
// Fpfile.fp_writes keeps no trivial result, but adds the fingerprint.
|
|
286
289
|
if (obligation.kind.kind === "Support" && isTrivial(sequent)) {
|
|
287
290
|
run.results.set(fingerprint, run.results.get(fingerprint) ?? new Map());
|
|
288
291
|
return { obligation: { ...getObligationBase(obligation), status: "trivial" }, attempts };
|
|
289
292
|
}
|
|
290
293
|
for (const method of methods.provers) {
|
|
291
294
|
const prior = getPrior(method);
|
|
292
|
-
if (prior
|
|
295
|
+
if (prior && isProvedAttempt(prior)) {
|
|
293
296
|
reuse(prior);
|
|
294
297
|
return getProvedReport(method.prover);
|
|
295
298
|
}
|
|
@@ -302,41 +305,30 @@ const proveWithBackends = async (
|
|
|
302
305
|
continue;
|
|
303
306
|
}
|
|
304
307
|
if (!run.isProving) continue;
|
|
305
|
-
// Prep.prove_with: the Trivial method proves anything.
|
|
306
308
|
if (method.prover === "trivial") return getProvedReport(method.prover);
|
|
307
|
-
|
|
308
|
-
if (!encode) {
|
|
309
|
+
if (!isBackend(method.prover)) {
|
|
309
310
|
skip(method, `tla-ts has no ${method.prover} backend`);
|
|
310
311
|
continue;
|
|
311
312
|
}
|
|
312
313
|
try {
|
|
314
|
+
const encoder = ENCODERS[method.prover];
|
|
313
315
|
const isCaseNumbered =
|
|
314
|
-
|
|
316
|
+
encoder.isCaseNumbered &&
|
|
315
317
|
(sequent.context.some(isIncompleteCaseHyp) || hasIncompleteCase(sequent.active));
|
|
316
318
|
const session = isCaseNumbered ? await getSession(run, index) : { caseErrors: 0 };
|
|
317
|
-
const text = encode(obligation.id, sequent, method, session);
|
|
319
|
+
const text = encoder.encode(obligation.id, sequent, method, session);
|
|
318
320
|
const decision = await run.decide(
|
|
319
321
|
method.prover,
|
|
320
322
|
text,
|
|
321
323
|
{ timeLimitMs: method.timeLimitMs, signal },
|
|
322
324
|
index,
|
|
323
325
|
);
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
method,
|
|
327
|
-
isProved,
|
|
328
|
-
isReused: false,
|
|
329
|
-
...(!isProved && {
|
|
330
|
-
reason: decision.timeUsedMs >= method.timeLimitMs ? "timeout" : "false",
|
|
331
|
-
}),
|
|
332
|
-
verdict: decision.verdict,
|
|
333
|
-
timeUsedMs: decision.timeUsedMs,
|
|
334
|
-
});
|
|
335
|
-
if (isProved) return getProvedReport(method.prover);
|
|
326
|
+
record({ kind: "decided", method, ...decision });
|
|
327
|
+
if (decision.verdict === "unsat") return getProvedReport(method.prover);
|
|
336
328
|
failures.push({ reason: `${method.prover} answered ${decision.verdict}`, isDecided: true });
|
|
337
329
|
} catch (error) {
|
|
338
330
|
if (error instanceof TlaProverError) {
|
|
339
|
-
record({
|
|
331
|
+
record({ kind: "error", method });
|
|
340
332
|
failures.push({ reason: `${method.prover} failed: ${error.message}`, isDecided: true });
|
|
341
333
|
continue;
|
|
342
334
|
}
|
|
@@ -352,8 +344,6 @@ const proveWithBackends = async (
|
|
|
352
344
|
);
|
|
353
345
|
};
|
|
354
346
|
|
|
355
|
-
// An error that escapes proveWithBackends: what tla-ts can't handle is unsupported, and what tlapm
|
|
356
|
-
// refuses, as a frontend's soundness check, fails.
|
|
357
347
|
const getErrorReport = (obligation: PrintedObligation, error: unknown) => {
|
|
358
348
|
if (error instanceof TlaUnsupportedError)
|
|
359
349
|
return getUnprovedReport(obligation, "unsupported", error.message);
|
|
@@ -367,9 +357,7 @@ interface ObligationsOptions {
|
|
|
367
357
|
signal?: AbortSignal;
|
|
368
358
|
onReport?: (report: ProofReport, obligation: PrintedObligation) => void;
|
|
369
359
|
results?: Map<string, Map<string, ProofAttempt>>;
|
|
370
|
-
// --nofp and --nofpl.
|
|
371
360
|
isFingerprinted?: (obligation: PrintedObligation) => boolean;
|
|
372
|
-
// --noproving.
|
|
373
361
|
isProving?: boolean;
|
|
374
362
|
}
|
|
375
363
|
|
|
@@ -391,16 +379,13 @@ export const proveObligations = async (
|
|
|
391
379
|
decide:
|
|
392
380
|
pool?.decide ?? (async (prover, text, decideOptions) => decide(prover, text, decideOptions)),
|
|
393
381
|
};
|
|
394
|
-
// A few obligations per worker prove at once, and each reports once every earlier one has.
|
|
395
382
|
const limit = pool ? workerCount * 4 : 1;
|
|
396
|
-
const pending: Promise<ProofReport>[] = [];
|
|
397
|
-
const isSettled: boolean[] = [];
|
|
398
383
|
const running = new Set<Promise<void>>();
|
|
399
384
|
const reports: ProofReport[] = [];
|
|
400
385
|
const reportSettled = async () => {
|
|
401
|
-
while (
|
|
386
|
+
while (reports.length < run.tasks.length && run.tasks[reports.length].isSettled) {
|
|
402
387
|
options.signal?.throwIfAborted();
|
|
403
|
-
const report = await
|
|
388
|
+
const report = await run.tasks[reports.length].report;
|
|
404
389
|
reports.push(report);
|
|
405
390
|
options.onReport?.(report, obligations[reports.length - 1]);
|
|
406
391
|
// HACK: backends on this thread run synchronously, so yield to let an abort land.
|
|
@@ -410,19 +395,21 @@ export const proveObligations = async (
|
|
|
410
395
|
try {
|
|
411
396
|
for (const [index, obligation] of obligations.entries()) {
|
|
412
397
|
options.signal?.throwIfAborted();
|
|
413
|
-
const done = Promise.withResolvers<void>();
|
|
414
|
-
run.tasks.push({ done: done.promise, session: undefined });
|
|
415
398
|
const report = proveWithBackends(obligation, index, run, options.signal).catch(
|
|
416
399
|
(error: unknown) => getErrorReport(obligation, error),
|
|
417
400
|
);
|
|
418
|
-
pending.push(report);
|
|
419
|
-
running.add(done.promise);
|
|
420
401
|
const settle = () => {
|
|
421
|
-
isSettled
|
|
422
|
-
running.delete(done
|
|
423
|
-
|
|
402
|
+
task.isSettled = true;
|
|
403
|
+
running.delete(task.done);
|
|
404
|
+
};
|
|
405
|
+
const task: ObligationTask = {
|
|
406
|
+
report,
|
|
407
|
+
done: report.then(settle, settle),
|
|
408
|
+
isSettled: false,
|
|
409
|
+
session: undefined,
|
|
424
410
|
};
|
|
425
|
-
|
|
411
|
+
run.tasks.push(task);
|
|
412
|
+
running.add(task.done);
|
|
426
413
|
if (running.size >= limit) await Promise.race(running);
|
|
427
414
|
await reportSettled();
|
|
428
415
|
}
|
package/src/prover/ptl/decide.ts
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
// Decides the text tlapm sends LS4, as LS4 does: unsat when the negated obligation has no model,
|
|
2
|
-
// which proves the obligation.
|
|
3
|
-
|
|
4
1
|
import { TlaSyntaxError } from "../../errors";
|
|
5
2
|
import type { DecideOptions, Verdict } from "../verdict";
|
|
6
3
|
import { getSatisfiability, type PtlFormula } from "./tableau";
|
|
7
4
|
|
|
8
|
-
// LS4's input syntax, as tlapm writes it: every operator is parenthesized except the facts of a
|
|
9
|
-
// sequent, which are joined by & before ->.
|
|
10
5
|
const parseLs4 = (text: string): PtlFormula => {
|
|
11
6
|
const tokens = text.match(/<->|->|[()~&|]|[\w']+|\S/g) ?? [];
|
|
12
|
-
|
|
7
|
+
let position = 0;
|
|
13
8
|
const take = (expected?: string) => {
|
|
14
|
-
const token = tokens[
|
|
9
|
+
const token = tokens[position++];
|
|
15
10
|
if (token === undefined || (expected !== undefined && token !== expected))
|
|
16
11
|
throw new TlaSyntaxError(
|
|
17
12
|
`Expected ${expected ?? "a formula"} in LS4 input, found ${token ?? "the end"}`,
|
|
@@ -35,7 +30,7 @@ const parseLs4 = (text: string): PtlFormula => {
|
|
|
35
30
|
};
|
|
36
31
|
const parseJunction = (operator: string, kind: "And" | "Or", parseOperand: () => PtlFormula) => {
|
|
37
32
|
const operands = [parseOperand()];
|
|
38
|
-
while (tokens[
|
|
33
|
+
while (tokens[position] === operator) {
|
|
39
34
|
take();
|
|
40
35
|
operands.push(parseOperand());
|
|
41
36
|
}
|
|
@@ -43,19 +38,19 @@ const parseLs4 = (text: string): PtlFormula => {
|
|
|
43
38
|
};
|
|
44
39
|
const parseImplies = (): PtlFormula => {
|
|
45
40
|
const left = parseJunction("|", "Or", () => parseJunction("&", "And", parseUnary));
|
|
46
|
-
if (tokens[
|
|
41
|
+
if (tokens[position] !== "->") return left;
|
|
47
42
|
take();
|
|
48
43
|
return { kind: "Implies", left, right: parseImplies() };
|
|
49
44
|
};
|
|
50
45
|
const parseEquiv = (): PtlFormula => {
|
|
51
46
|
const left = parseImplies();
|
|
52
|
-
if (tokens[
|
|
47
|
+
if (tokens[position] !== "<->") return left;
|
|
53
48
|
take();
|
|
54
49
|
return { kind: "Equiv", left, right: parseEquiv() };
|
|
55
50
|
};
|
|
56
51
|
const formula = parseEquiv();
|
|
57
|
-
if (
|
|
58
|
-
throw new TlaSyntaxError(`Expected the end of LS4 input, found ${tokens[
|
|
52
|
+
if (position < tokens.length)
|
|
53
|
+
throw new TlaSyntaxError(`Expected the end of LS4 input, found ${tokens[position]}`);
|
|
59
54
|
return formula;
|
|
60
55
|
};
|
|
61
56
|
|
package/src/prover/ptl/encode.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
// tlapm's PTL backend up to the text it sends LS4 (Pltl.process_obligation, Prep.flatten, and
|
|
2
|
-
// Ls4's printer): temporal operators reduce to [], <> and prime, assumptions that hold
|
|
3
|
-
// always get a [], and every other subformula becomes an atom named by a hash of its printed form.
|
|
4
|
-
// The text is the negated obligation.
|
|
5
|
-
|
|
6
1
|
import {
|
|
7
2
|
bumpBy,
|
|
8
3
|
shift,
|
|
@@ -27,9 +22,6 @@ import { getLevelInfo } from "../../obligations/levels";
|
|
|
27
22
|
import { expandAction, expandFairness, expandLeadsto, getTime } from "../../obligations/temporal";
|
|
28
23
|
import { getHashName, LEVEL_NUMBER_PREFIXES, LEVEL_PREFIXES } from "../prep/action";
|
|
29
24
|
|
|
30
|
-
// Coalesce.rename_with_loc: each declared name gets its kind in front, or its level for a definition,
|
|
31
|
-
// as in VARIABLE_x_ and CONSTANT_i_, so atoms print with the names tlapm hashes. A variable a
|
|
32
|
-
// temporal quantifier binds keeps its name.
|
|
33
25
|
const renameSequent = (scope: Scope | undefined, sequent: Sequent): Sequent => {
|
|
34
26
|
const [inner, context] = mapAccumulate(
|
|
35
27
|
scope,
|
|
@@ -93,38 +85,30 @@ const renameDeclarations = (scope: Scope | undefined, expression: Expr): Expr =>
|
|
|
93
85
|
}
|
|
94
86
|
};
|
|
95
87
|
|
|
96
|
-
interface PreparedHyps {
|
|
97
|
-
scope: Scope | undefined;
|
|
98
|
-
substitution: Substitution;
|
|
99
|
-
context: Hyp[];
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Pltl.expand_domains and Pltl.box_assumptions: NEW x \in S becomes NEW x and the fact x \in S, and
|
|
103
|
-
// each visible fact that holds always gets a [].
|
|
104
88
|
const prepareHyps = (scope: Scope | undefined, expression: Expr): Expr => {
|
|
105
89
|
if (expression.kind !== "Sequent")
|
|
106
90
|
return mapScoped(scope, expression, prepareHyps, adjoin, "all");
|
|
107
|
-
|
|
91
|
+
let innerScope = scope;
|
|
92
|
+
let substitution: Substitution = shift(0);
|
|
93
|
+
const context: Hyp[] = [];
|
|
108
94
|
const push = (hyp: Hyp) => {
|
|
109
95
|
const prepared =
|
|
110
96
|
hyp.kind === "Fact" && hyp.visibility === "Visible" && hyp.time === "Always"
|
|
111
97
|
? { ...hyp, expression: applyBuiltin("BoxTrue", [hyp.expression], hyp.expression) }
|
|
112
98
|
: hyp;
|
|
113
|
-
|
|
114
|
-
|
|
99
|
+
context.push(prepared);
|
|
100
|
+
innerScope = adjoin(innerScope, prepared);
|
|
115
101
|
};
|
|
116
102
|
for (const original of expression.sequent.context) {
|
|
117
|
-
const hyp = substituteHyp(
|
|
103
|
+
const hyp = substituteHyp(substitution, original);
|
|
118
104
|
if (hyp.kind !== "Fresh" || !hyp.domain || original.kind !== "Fresh" || !original.domain) {
|
|
119
105
|
push(
|
|
120
|
-
hyp.kind === "Fact"
|
|
121
|
-
? { ...hyp, expression: prepareHyps(state.scope, hyp.expression) }
|
|
122
|
-
: hyp,
|
|
106
|
+
hyp.kind === "Fact" ? { ...hyp, expression: prepareHyps(innerScope, hyp.expression) } : hyp,
|
|
123
107
|
);
|
|
124
|
-
|
|
108
|
+
substitution = bumpBy(1, substitution);
|
|
125
109
|
continue;
|
|
126
110
|
}
|
|
127
|
-
const domain = prepareHyps(
|
|
111
|
+
const domain = prepareHyps(innerScope, hyp.domain);
|
|
128
112
|
push({ ...hyp, domain: undefined });
|
|
129
113
|
// tlapm judges the time of the domain as written, one hypothesis too deep.
|
|
130
114
|
push({
|
|
@@ -135,19 +119,19 @@ const prepareHyps = (scope: Scope | undefined, expression: Expr): Expr => {
|
|
|
135
119
|
domain,
|
|
136
120
|
),
|
|
137
121
|
visibility: hyp.domainVisibility,
|
|
138
|
-
time: hyp.level === "Constant" ? getTime(
|
|
122
|
+
time: hyp.level === "Constant" ? getTime(innerScope, original.domain) : "Now",
|
|
139
123
|
location: hyp.location,
|
|
140
124
|
});
|
|
141
|
-
|
|
125
|
+
substitution = {
|
|
142
126
|
kind: "Compose",
|
|
143
127
|
outer: shift(1),
|
|
144
|
-
inner: bumpBy(1,
|
|
128
|
+
inner: bumpBy(1, substitution),
|
|
145
129
|
};
|
|
146
130
|
}
|
|
147
|
-
const active = substituteExpr(
|
|
131
|
+
const active = substituteExpr(substitution, expression.sequent.active);
|
|
148
132
|
return {
|
|
149
133
|
...expression,
|
|
150
|
-
sequent: { context
|
|
134
|
+
sequent: { context, active: prepareHyps(innerScope, active) },
|
|
151
135
|
};
|
|
152
136
|
};
|
|
153
137
|
|
|
@@ -166,8 +150,6 @@ const UNARY: Partial<Record<Builtin, string>> = {
|
|
|
166
150
|
Prime: "next",
|
|
167
151
|
};
|
|
168
152
|
|
|
169
|
-
// Prep.flatten, which tlapm applies after Pltl.process_obligation has made every equality an atom:
|
|
170
|
-
// TRUE drops out of the conjunctions of each visible fact, and a fact left with nothing disappears.
|
|
171
153
|
const removeTrue = (expression: Expr): Expr | undefined => {
|
|
172
154
|
if (expression.kind === "Internal" && expression.builtin === "TRUE") return undefined;
|
|
173
155
|
if (expression.kind === "List" && expression.bullet !== "Or") {
|
|
@@ -189,10 +171,7 @@ const removeTrue = (expression: Expr): Expr | undefined => {
|
|
|
189
171
|
|
|
190
172
|
const TRUE_TEXT = "(cc | ~ cc)";
|
|
191
173
|
|
|
192
|
-
// The text tlapm sends LS4 for an obligation after Prep.normalize_expand.
|
|
193
174
|
export const encodePtl = (sequent: Sequent): string => {
|
|
194
|
-
// Ls4's printer. A sequent becomes an implication from its visible facts, joined by &, and
|
|
195
|
-
// Prep.flatten applies to the facts of the outermost one.
|
|
196
175
|
const print = (hyps: Hyp[], expression: Expr, isOutermost = false): string => {
|
|
197
176
|
const recurse = (inner: Expr) => print(hyps, inner);
|
|
198
177
|
switch (expression.kind) {
|
|
@@ -235,7 +214,6 @@ export const encodePtl = (sequent: Sequent): string => {
|
|
|
235
214
|
return facts.length === 0 ? goal : `(${facts.join(" & ")} -> ${goal})`;
|
|
236
215
|
}
|
|
237
216
|
}
|
|
238
|
-
// Pltl.coalesce_fol names an atom as Coalesce does.
|
|
239
217
|
return getHashName(hyps, expression);
|
|
240
218
|
};
|
|
241
219
|
const renamed = renameDeclarations(undefined, { kind: "Sequent", sequent });
|
package/src/prover/ptl/sat.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
// A conflict-driven clause learning SAT solver for the clauses of one tableau node. A literal is a
|
|
2
|
-
// variable number, negated when below zero. The solver keeps what it learns across calls, which add
|
|
3
|
-
// clauses or assume literals. It decides each open variable false first, so a model sets few
|
|
4
|
-
// variables, and a model holds 1 for each true variable and -1 for each false one. It gives up at
|
|
5
|
-
// the first conflict after isExpired turns true.
|
|
6
|
-
|
|
7
1
|
const getIndex = (literal: number) => (literal > 0 ? 2 * literal : -2 * literal + 1);
|
|
8
2
|
|
|
9
3
|
export const createSolver = (variableCount: number, isExpired: () => boolean) => {
|
|
@@ -15,7 +9,9 @@ export const createSolver = (variableCount: number, isExpired: () => boolean) =>
|
|
|
15
9
|
const watches: number[][][] = Array.from({ length: 2 * variableCount + 2 }, () => []);
|
|
16
10
|
const trail: number[] = [];
|
|
17
11
|
const levelStarts: number[] = [];
|
|
18
|
-
|
|
12
|
+
let head = 0;
|
|
13
|
+
let bump = 1;
|
|
14
|
+
let isUnsatisfiable = false;
|
|
19
15
|
const getValue = (literal: number) => (literal > 0 ? values[literal] : -values[-literal]);
|
|
20
16
|
const assign = (literal: number, reason: number[] | undefined) => {
|
|
21
17
|
const variable = Math.abs(literal);
|
|
@@ -28,11 +24,9 @@ export const createSolver = (variableCount: number, isExpired: () => boolean) =>
|
|
|
28
24
|
watches[getIndex(clause[0])].push(clause);
|
|
29
25
|
watches[getIndex(clause[1])].push(clause);
|
|
30
26
|
};
|
|
31
|
-
// Moves each watch off a literal that turned false, and returns the clause of a conflict. The
|
|
32
|
-
// literal a clause implies sits first in it.
|
|
33
27
|
const propagate = () => {
|
|
34
|
-
for (;
|
|
35
|
-
const falsified = -trail[
|
|
28
|
+
for (; head < trail.length; head++) {
|
|
29
|
+
const falsified = -trail[head];
|
|
36
30
|
const watching = watches[getIndex(falsified)];
|
|
37
31
|
for (let position = 0; position < watching.length; position++) {
|
|
38
32
|
const clause = watching[position];
|
|
@@ -59,39 +53,38 @@ export const createSolver = (variableCount: number, isExpired: () => boolean) =>
|
|
|
59
53
|
const size = levelStarts[level];
|
|
60
54
|
while (trail.length > size) values[Math.abs(trail.pop() ?? 0)] = 0;
|
|
61
55
|
levelStarts.length = level;
|
|
62
|
-
|
|
56
|
+
head = trail.length;
|
|
63
57
|
};
|
|
64
|
-
// Resolves the conflict back to the first literal of the current level that all its paths pass
|
|
65
|
-
// through, and returns the learned clause with that literal first.
|
|
66
58
|
const analyze = (conflict: number[]) => {
|
|
67
59
|
const learned = [0];
|
|
68
60
|
const current = levelStarts.length;
|
|
69
|
-
|
|
61
|
+
let pendingCount = 0;
|
|
62
|
+
let resolved = 0;
|
|
63
|
+
let trailIndex = trail.length - 1;
|
|
70
64
|
for (let clause: number[] | undefined = conflict; ;) {
|
|
71
|
-
for (const literal of clause?.slice(
|
|
65
|
+
for (const literal of clause?.slice(resolved === 0 ? 0 : 1) ?? []) {
|
|
72
66
|
const variable = Math.abs(literal);
|
|
73
67
|
if (seen[variable] || levels[variable] === 0) continue;
|
|
74
68
|
seen[variable] = 1;
|
|
75
|
-
activities[variable] +=
|
|
76
|
-
if (levels[variable] === current)
|
|
69
|
+
activities[variable] += bump;
|
|
70
|
+
if (levels[variable] === current) pendingCount++;
|
|
77
71
|
else learned.push(literal);
|
|
78
72
|
}
|
|
79
|
-
while (!seen[Math.abs(trail[
|
|
80
|
-
|
|
81
|
-
seen[Math.abs(
|
|
82
|
-
clause = reasons[Math.abs(
|
|
83
|
-
if (--
|
|
73
|
+
while (!seen[Math.abs(trail[trailIndex])]) trailIndex--;
|
|
74
|
+
resolved = trail[trailIndex--];
|
|
75
|
+
seen[Math.abs(resolved)] = 0;
|
|
76
|
+
clause = reasons[Math.abs(resolved)];
|
|
77
|
+
if (--pendingCount === 0) break;
|
|
84
78
|
}
|
|
85
|
-
learned[0] = -
|
|
79
|
+
learned[0] = -resolved;
|
|
86
80
|
learned.forEach((literal) => (seen[Math.abs(literal)] = 0));
|
|
87
|
-
|
|
81
|
+
bump *= 1.05;
|
|
88
82
|
return learned;
|
|
89
83
|
};
|
|
90
|
-
// Literals false for good are dropped, since the solver adds clauses only at level 0.
|
|
91
84
|
const addClause = (clause: number[]) => {
|
|
92
85
|
backtrack(0);
|
|
93
86
|
const literals = [...new Set(clause)];
|
|
94
|
-
if (
|
|
87
|
+
if (isUnsatisfiable || literals.some((literal) => getValue(literal) > 0)) return;
|
|
95
88
|
if (literals.some((literal) => literals.includes(-literal))) return;
|
|
96
89
|
const open = literals.filter((literal) => getValue(literal) === 0);
|
|
97
90
|
if (open.length > 1) {
|
|
@@ -99,21 +92,20 @@ export const createSolver = (variableCount: number, isExpired: () => boolean) =>
|
|
|
99
92
|
return;
|
|
100
93
|
}
|
|
101
94
|
if (open.length === 0) {
|
|
102
|
-
|
|
95
|
+
isUnsatisfiable = true;
|
|
103
96
|
return;
|
|
104
97
|
}
|
|
105
98
|
assign(open[0], undefined);
|
|
106
|
-
if (propagate())
|
|
99
|
+
if (propagate()) isUnsatisfiable = true;
|
|
107
100
|
};
|
|
108
|
-
// A model of the clauses in which every assumed literal holds, or unsat when there is none.
|
|
109
101
|
const solve = (assumptions: number[]): Int8Array | "unsat" | "unknown" => {
|
|
110
102
|
backtrack(0);
|
|
111
|
-
if (
|
|
103
|
+
if (isUnsatisfiable) return "unsat";
|
|
112
104
|
for (;;) {
|
|
113
105
|
const conflict = propagate();
|
|
114
106
|
if (conflict) {
|
|
115
107
|
if (levelStarts.length === 0) {
|
|
116
|
-
|
|
108
|
+
isUnsatisfiable = true;
|
|
117
109
|
return "unsat";
|
|
118
110
|
}
|
|
119
111
|
if (isExpired()) return "unknown";
|