tla-ts 0.0.4-dev.a297123 → 0.0.4-dev.c4929d7
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 +27 -141
- package/dist/deciders.cjs +366 -0
- package/dist/deciders.js +366 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -4
- package/dist/parallel-worker.js +1 -4
- package/dist/prove-worker.cjs +9 -0
- package/dist/prove-worker.d.cts +9 -0
- package/dist/prove-worker.d.ts +9 -0
- package/dist/prove-worker.js +9 -0
- package/dist/prove.cjs +996 -0
- package/dist/prove.js +996 -0
- package/dist/run-cli.cjs +37 -47
- package/dist/run-cli.js +37 -47
- package/dist/tlapm.cjs +10 -0
- package/dist/tlapm.js +10 -0
- package/dist/transfer.cjs +38 -44
- package/dist/transfer.js +38 -44
- package/dist/worker.cjs +21 -0
- package/dist/worker.js +21 -0
- package/package.json +21 -12
- package/src/check.ts +1 -0
- package/src/codegen.ts +5 -3
- package/src/errors.ts +86 -0
- package/src/evaluate.ts +54 -19
- package/src/index.ts +10 -0
- package/src/{obligation-action.ts → obligations/action.ts} +265 -55
- package/src/{obligation-anon.ts → obligations/anon.ts} +47 -37
- package/src/obligations/ctx.ts +64 -0
- package/src/{obligation-deref.ts → obligations/deref.ts} +38 -61
- package/src/{obligation-expression.ts → obligations/expression.ts} +78 -45
- package/src/{obligation-format.ts → obligations/format.ts} +7 -8
- package/src/{obligation-generate.ts → obligations/generate.ts} +147 -74
- package/src/{obligations.ts → obligations/index.ts} +29 -13
- package/src/{obligation-levels.ts → obligations/levels.ts} +14 -5
- package/src/{obligation-module.ts → obligations/module.ts} +56 -33
- package/src/obligations/pickle.ts +98 -0
- package/src/obligations/pragma.ts +189 -0
- package/src/{obligation-printer.ts → obligations/printer.ts} +22 -80
- package/src/{obligation-proof.ts → obligations/proof.ts} +7 -1
- package/src/{obligation-source.ts → obligations/source.ts} +159 -97
- package/src/obligations/temporal.ts +319 -0
- package/src/{obligation-tuples.ts → obligations/tuples.ts} +1 -1
- package/src/ocaml-marshal.ts +166 -0
- package/src/parallel-worker.ts +2 -18
- package/src/parallel.ts +10 -43
- package/src/prove/decide-pool.ts +100 -0
- package/src/prove/deciders.ts +33 -0
- package/src/prove/isabelle/LICENSE +36 -0
- package/src/prove/isabelle/LICENSE-tlapm +26 -0
- package/src/prove/isabelle/decide.ts +47 -0
- package/src/prove/isabelle/encode.ts +503 -0
- package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
- package/src/prove/isabelle/isar/method.ts +367 -0
- package/src/prove/isabelle/isar/proof.ts +28 -0
- package/src/prove/isabelle/isar/statement.ts +57 -0
- package/src/prove/isabelle/isar/theory.ts +192 -0
- package/src/prove/isabelle/isar/type-check.ts +278 -0
- package/src/prove/isabelle/provers/blast/blast.ts +258 -0
- package/src/prove/isabelle/provers/blast/branch.ts +322 -0
- package/src/prove/isabelle/provers/blast/prove.ts +347 -0
- package/src/prove/isabelle/provers/blast/rules.ts +330 -0
- package/src/prove/isabelle/provers/blast/state.ts +180 -0
- package/src/prove/isabelle/provers/blast/term.ts +547 -0
- package/src/prove/isabelle/provers/clasimp.ts +150 -0
- package/src/prove/isabelle/provers/classical.ts +389 -0
- package/src/prove/isabelle/provers/hypsubst.ts +441 -0
- package/src/prove/isabelle/pure/bicompose.ts +174 -0
- package/src/prove/isabelle/pure/consts.ts +32 -0
- package/src/prove/isabelle/pure/conv.ts +79 -0
- package/src/prove/isabelle/pure/drule.ts +264 -0
- package/src/prove/isabelle/pure/envir.ts +363 -0
- package/src/prove/isabelle/pure/goal.ts +53 -0
- package/src/prove/isabelle/pure/interrupt.ts +16 -0
- package/src/prove/isabelle/pure/list.ts +12 -0
- package/src/prove/isabelle/pure/logic.ts +402 -0
- package/src/prove/isabelle/pure/name.ts +110 -0
- package/src/prove/isabelle/pure/net.ts +262 -0
- package/src/prove/isabelle/pure/object-logic.ts +41 -0
- package/src/prove/isabelle/pure/pattern.ts +650 -0
- package/src/prove/isabelle/pure/raw-simplifier.ts +353 -0
- package/src/prove/isabelle/pure/rewriter.ts +602 -0
- package/src/prove/isabelle/pure/search.ts +68 -0
- package/src/prove/isabelle/pure/seq.ts +156 -0
- package/src/prove/isabelle/pure/simplifier.ts +112 -0
- package/src/prove/isabelle/pure/table.ts +208 -0
- package/src/prove/isabelle/pure/tactic.ts +276 -0
- package/src/prove/isabelle/pure/tactical.ts +347 -0
- package/src/prove/isabelle/pure/term-ord.ts +159 -0
- package/src/prove/isabelle/pure/term.ts +808 -0
- package/src/prove/isabelle/pure/thm.ts +806 -0
- package/src/prove/isabelle/pure/type.ts +133 -0
- package/src/prove/isabelle/pure/unify.ts +753 -0
- package/src/prove/isabelle/pure/variable.ts +25 -0
- package/src/prove/isabelle/tla/classical-setup.ts +101 -0
- package/src/prove/isabelle/tla/context.ts +74 -0
- package/src/prove/isabelle/tla/logic-data.ts +5 -0
- package/src/prove/isabelle/tla/logic.ts +215 -0
- package/src/prove/isabelle/tla/simpdata.ts +241 -0
- package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
- package/src/prove/ocaml.ts +22 -0
- package/src/prove/prep/action.ts +521 -0
- package/src/prove/prep/defs.ts +33 -0
- package/src/prove/prep/elab.ts +156 -0
- package/src/prove/prep/enabled-axioms.ts +189 -0
- package/src/prove/prep/enabled.ts +43 -0
- package/src/prove/prep/fingerprint.ts +388 -0
- package/src/prove/prep/flatten.ts +70 -0
- package/src/prove/prep/level-comparison.ts +557 -0
- package/src/prove/prep/md5.ts +67 -0
- package/src/prove/prep/pragma.ts +221 -0
- package/src/prove/prep/trivial.ts +22 -0
- package/src/prove/prove-worker.ts +25 -0
- package/src/prove/prove.ts +505 -0
- package/src/prove/ptl/decide.ts +68 -0
- package/src/prove/ptl/encode.ts +256 -0
- package/src/prove/ptl/sat.ts +151 -0
- package/src/prove/ptl/tableau.ts +276 -0
- package/src/prove/smt/axiomatize.ts +69 -0
- package/src/prove/smt/axioms.ts +222 -0
- package/src/prove/smt/context.ts +108 -0
- package/src/prove/smt/data.ts +636 -0
- package/src/prove/smt/encode.ts +166 -0
- package/src/prove/smt/extensionality.ts +65 -0
- package/src/prove/smt/flatten.ts +112 -0
- package/src/prove/smt/format.ts +154 -0
- package/src/prove/smt/instances.ts +182 -0
- package/src/prove/smt/rewrite.ts +773 -0
- package/src/prove/smt/simplify.ts +57 -0
- package/src/prove/smt/solver/act-cache.ts +265 -0
- package/src/prove/smt/solver/arith-rewriter.ts +962 -0
- package/src/prove/smt/solver/array.ts +22 -0
- package/src/prove/smt/solver/asserted-formulas.ts +469 -0
- package/src/prove/smt/solver/ast-lt.ts +157 -0
- package/src/prove/smt/solver/ast-util.ts +147 -0
- package/src/prove/smt/solver/ast.ts +1315 -0
- package/src/prove/smt/solver/auf-solver.ts +572 -0
- package/src/prove/smt/solver/case-split-queue.ts +178 -0
- package/src/prove/smt/solver/cg-table.ts +175 -0
- package/src/prove/smt/solver/clause.ts +276 -0
- package/src/prove/smt/solver/conflict-resolution.ts +343 -0
- package/src/prove/smt/solver/context.ts +1292 -0
- package/src/prove/smt/solver/ctx-simplify.ts +334 -0
- package/src/prove/smt/solver/der.ts +224 -0
- package/src/prove/smt/solver/dyn-ack.ts +141 -0
- package/src/prove/smt/solver/e-matching.ts +659 -0
- package/src/prove/smt/solver/enode.ts +259 -0
- package/src/prove/smt/solver/expr-ref.ts +21 -0
- package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
- package/src/prove/smt/solver/fingerprints.ts +92 -0
- package/src/prove/smt/solver/flat-literals.ts +51 -0
- package/src/prove/smt/solver/goal.ts +138 -0
- package/src/prove/smt/solver/hash.ts +173 -0
- package/src/prove/smt/solver/hashtable.ts +166 -0
- package/src/prove/smt/solver/internalizer.ts +1381 -0
- package/src/prove/smt/solver/lbool.ts +5 -0
- package/src/prove/smt/solver/literal.ts +24 -0
- package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
- package/src/prove/smt/solver/lp/constraints.ts +78 -0
- package/src/prove/smt/solver/lp/containers.ts +296 -0
- package/src/prove/smt/solver/lp/core-solver.ts +504 -0
- package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
- package/src/prove/smt/solver/lp/dep-intervals.ts +656 -0
- package/src/prove/smt/solver/lp/dependency.ts +51 -0
- package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
- package/src/prove/smt/solver/lp/explanation.ts +46 -0
- package/src/prove/smt/solver/lp/gomory.ts +255 -0
- package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
- package/src/prove/smt/solver/lp/hnf.ts +281 -0
- package/src/prove/smt/solver/lp/int-cube.ts +295 -0
- package/src/prove/smt/solver/lp/int-solver.ts +514 -0
- package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
- package/src/prove/smt/solver/lp/lar-term.ts +62 -0
- package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
- package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
- package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
- package/src/prove/smt/solver/lp/nex.ts +120 -0
- package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
- package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
- package/src/prove/smt/solver/lp/nla-core.ts +968 -0
- package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
- package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
- package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
- package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
- package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
- package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
- package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
- package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
- package/src/prove/smt/solver/lp/nla-order.ts +307 -0
- package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
- package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
- package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
- package/src/prove/smt/solver/lp/nla-types.ts +124 -0
- package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
- package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
- package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
- package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
- package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
- package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
- package/src/prove/smt/solver/lp/pdd.ts +971 -0
- package/src/prove/smt/solver/lp/random-updater.ts +138 -0
- package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
- package/src/prove/smt/solver/lp/union-find.ts +96 -0
- package/src/prove/smt/solver/mam-compiler.ts +847 -0
- package/src/prove/smt/solver/mam-interpreter.ts +400 -0
- package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
- package/src/prove/smt/solver/model-checker.ts +347 -0
- package/src/prove/smt/solver/model-evaluator.ts +262 -0
- package/src/prove/smt/solver/model-finder.ts +155 -0
- package/src/prove/smt/solver/model-generator.ts +97 -0
- package/src/prove/smt/solver/model-macro-solver.ts +728 -0
- package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
- package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
- package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
- package/src/prove/smt/solver/nlsat/explain.ts +607 -0
- package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
- package/src/prove/smt/solver/nlsat/levelwise.ts +740 -0
- package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
- package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
- package/src/prove/smt/solver/nlsat/solver.ts +911 -0
- package/src/prove/smt/solver/nlsat/types.ts +43 -0
- package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
- package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
- package/src/prove/smt/solver/nnf.ts +469 -0
- package/src/prove/smt/solver/pattern-inference.ts +351 -0
- package/src/prove/smt/solver/poly-rewriter.ts +477 -0
- package/src/prove/smt/solver/propagate-values.ts +83 -0
- package/src/prove/smt/solver/proto-model.ts +551 -0
- package/src/prove/smt/solver/pull-quant.ts +139 -0
- package/src/prove/smt/solver/qe-lite-der.ts +526 -0
- package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
- package/src/prove/smt/solver/qe-lite.ts +381 -0
- package/src/prove/smt/solver/qi-queue.ts +362 -0
- package/src/prove/smt/solver/quant-tactics.ts +117 -0
- package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
- package/src/prove/smt/solver/quantifier-manager.ts +186 -0
- package/src/prove/smt/solver/random-gen.ts +10 -0
- package/src/prove/smt/solver/rational.ts +165 -0
- package/src/prove/smt/solver/ref-vector.ts +62 -0
- package/src/prove/smt/solver/relevancy.ts +247 -0
- package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
- package/src/prove/smt/solver/rewriter.ts +843 -0
- package/src/prove/smt/solver/rlimit.ts +79 -0
- package/src/prove/smt/solver/smtlib-parser.ts +526 -0
- package/src/prove/smt/solver/solver.ts +71 -0
- package/src/prove/smt/solver/sort.ts +35 -0
- package/src/prove/smt/solver/sticky-generations.ts +69 -0
- package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
- package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
- package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
- package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
- package/src/prove/smt/solver/theory-lra-model.ts +243 -0
- package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
- package/src/prove/smt/solver/theory-lra-state.ts +43 -0
- package/src/prove/smt/solver/theory-lra.ts +56 -0
- package/src/prove/smt/solver/var-subst.ts +258 -0
- package/src/prove/smt/solver/z3-license.txt +10 -0
- package/src/prove/smt/table.ts +170 -0
- package/src/prove/tlapm/tlapm.ts +96 -0
- package/src/prove/tlaps-module.ts +510 -0
- package/src/prove/verdict.ts +18 -0
- package/src/prove/zenon/LICENSE +32 -0
- package/src/prove/zenon/check/check.ts +105 -0
- package/src/prove/zenon/check/definitions.ts +144 -0
- package/src/prove/zenon/check/equality.ts +182 -0
- package/src/prove/zenon/check/functions.ts +62 -0
- package/src/prove/zenon/check/keys.ts +125 -0
- package/src/prove/zenon/check/propositional.ts +104 -0
- package/src/prove/zenon/check/records.ts +188 -0
- package/src/prove/zenon/check/relations.ts +121 -0
- package/src/prove/zenon/check/rewrites.ts +224 -0
- package/src/prove/zenon/check/sets.ts +302 -0
- package/src/prove/zenon/check/terms.ts +127 -0
- package/src/prove/zenon/check/tla.ts +126 -0
- package/src/prove/zenon/decide.ts +113 -0
- package/src/prove/zenon/encode.ts +437 -0
- package/src/prove/zenon/eqrel.ts +300 -0
- package/src/prove/zenon/equality-rules.ts +435 -0
- package/src/prove/zenon/expr.ts +551 -0
- package/src/prove/zenon/index-table.ts +350 -0
- package/src/prove/zenon/isar-case.ts +513 -0
- package/src/prove/zenon/isar.ts +1249 -0
- package/src/prove/zenon/limits.ts +15 -0
- package/src/prove/zenon/llproof.ts +173 -0
- package/src/prove/zenon/mltoll.ts +1566 -0
- package/src/prove/zenon/node.ts +297 -0
- package/src/prove/zenon/ocaml.ts +169 -0
- package/src/prove/zenon/parse.ts +247 -0
- package/src/prove/zenon/phrase.ts +191 -0
- package/src/prove/zenon/proof.ts +198 -0
- package/src/prove/zenon/propositional-rules.ts +387 -0
- package/src/prove/zenon/rules.ts +94 -0
- package/src/prove/zenon/search.ts +288 -0
- package/src/prove/zenon/tla/functions.ts +151 -0
- package/src/prove/zenon/tla/llproof.ts +480 -0
- package/src/prove/zenon/tla/records.ts +225 -0
- package/src/prove/zenon/tla/rewrites.ts +447 -0
- package/src/prove/zenon/tla/sets.ts +304 -0
- package/src/prove/zenon/tla/terms.ts +181 -0
- package/src/prove/zenon/tla/tla.ts +506 -0
- package/src/run-cli.ts +334 -75
- package/src/standard-modules.ts +5 -2
- package/src/successors.ts +24 -5
- package/src/tlapm-cache.ts +236 -0
- package/src/tlc-random.ts +55 -32
- package/src/tlc-version.ts +8 -7
- package/src/values.ts +80 -35
- package/src/worker.ts +65 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
// Proves a module's obligations with tla-ts's own backends, in tlapm's order, or with tlapm.
|
|
2
|
+
|
|
3
|
+
import { TlaProverError, TlaUnsupportedError } from "../errors";
|
|
4
|
+
import { getChildren, mapHyp, type Expr, type Hyp, type Sequent } from "../obligations/expression";
|
|
5
|
+
import { getObligations, type PrintedObligation } from "../obligations";
|
|
6
|
+
import { formatObligation } from "../obligations/printer";
|
|
7
|
+
import { isWorkerSupported } from "../worker";
|
|
8
|
+
import { decide } from "./deciders";
|
|
9
|
+
import { createDecidePool, type DecidePool } from "./decide-pool";
|
|
10
|
+
import { encodeIsabelle, encodeIsabelleTheory } from "./isabelle/encode";
|
|
11
|
+
import { processObligation } from "./prep/action";
|
|
12
|
+
import { expandDefs } from "./prep/defs";
|
|
13
|
+
import { normalizeSequent } from "./prep/elab";
|
|
14
|
+
import { expandEnabledCdot } from "./prep/enabled";
|
|
15
|
+
import { getFingerprint } from "./prep/fingerprint";
|
|
16
|
+
import { flatten } from "./prep/flatten";
|
|
17
|
+
import { findMethods, type Method } from "./prep/pragma";
|
|
18
|
+
import { isTrivial } from "./prep/trivial";
|
|
19
|
+
import { encodePtl } from "./ptl/encode";
|
|
20
|
+
import { encodeSmt } from "./smt/encode";
|
|
21
|
+
import type { EncodingSession } from "./smt/rewrite";
|
|
22
|
+
import { encodeZenon } from "./zenon/encode";
|
|
23
|
+
import type { TlapmResult } from "./tlapm/tlapm";
|
|
24
|
+
import { TLAPS_MODULE } from "./tlaps-module";
|
|
25
|
+
import type { Verdict } from "./verdict";
|
|
26
|
+
|
|
27
|
+
interface ObligationBase {
|
|
28
|
+
id: number;
|
|
29
|
+
location: string;
|
|
30
|
+
text: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ProvedObligation extends ObligationBase {
|
|
34
|
+
status: "proved";
|
|
35
|
+
prover: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface TrivialObligation extends ObligationBase {
|
|
39
|
+
status: "trivial";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface UnprovedObligation extends ObligationBase {
|
|
43
|
+
status: "failed" | "unsupported";
|
|
44
|
+
reason: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type ProofObligation = ProvedObligation | TrivialObligation | UnprovedObligation;
|
|
48
|
+
|
|
49
|
+
export type ProofStatus = ProofObligation["status"];
|
|
50
|
+
|
|
51
|
+
export interface ProveResult {
|
|
52
|
+
obligations: ProofObligation[];
|
|
53
|
+
missingProofCount: number;
|
|
54
|
+
omittedProofCount: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const PROVE_BACKENDS = ["tla-ts", "tlapm"] as const;
|
|
58
|
+
|
|
59
|
+
type ProveBackend = (typeof PROVE_BACKENDS)[number];
|
|
60
|
+
|
|
61
|
+
export const isProveBackend = (name: string | undefined): name is ProveBackend =>
|
|
62
|
+
PROVE_BACKENDS.some((backend) => backend === name);
|
|
63
|
+
|
|
64
|
+
export interface ProveOptions {
|
|
65
|
+
source: string;
|
|
66
|
+
loadModule?: (name: string) => string | undefined;
|
|
67
|
+
backend?: ProveBackend;
|
|
68
|
+
signal?: AbortSignal;
|
|
69
|
+
onObligation?: (obligation: ProofObligation) => void;
|
|
70
|
+
workers?: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// What one method concluded about an obligation, as tlapm's toolbox messages report it.
|
|
74
|
+
export interface ProofAttempt {
|
|
75
|
+
method: Method;
|
|
76
|
+
isProved: boolean;
|
|
77
|
+
isReused: boolean;
|
|
78
|
+
reason?: string;
|
|
79
|
+
verdict?: Verdict;
|
|
80
|
+
timeUsedMs?: number;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface ProofReport {
|
|
84
|
+
obligation: ProofObligation;
|
|
85
|
+
attempts: ProofAttempt[];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// The SMT encoder numbers the CASE errors it standardizes across the run, so an obligation it
|
|
89
|
+
// encodes one in waits for every earlier obligation and starts from the count they leave.
|
|
90
|
+
interface ObligationTask {
|
|
91
|
+
done: Promise<void>;
|
|
92
|
+
session: { initial: number; current: EncodingSession } | undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// What tlapm keeps across one run's obligations. An obligation waits for the last earlier one with
|
|
96
|
+
// its fingerprint, so obligations prove concurrently as they would in turn.
|
|
97
|
+
interface ProveRun {
|
|
98
|
+
tasks: ObligationTask[];
|
|
99
|
+
results: Map<string, Map<string, ProofAttempt>>;
|
|
100
|
+
isFingerprinted: (obligation: PrintedObligation) => boolean;
|
|
101
|
+
isProving: boolean;
|
|
102
|
+
lastByFingerprint: Map<string, Promise<void>>;
|
|
103
|
+
decide: DecidePool["decide"];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
interface Backend {
|
|
107
|
+
// The text Prep.ship sends the backend after Prep.normalize_expand. It throws a
|
|
108
|
+
// TlaUnsupportedError for what tla-ts can't encode.
|
|
109
|
+
encode: (id: number, sequent: Sequent, method: Method, session: EncodingSession) => string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Action.process_obligation, the frontend for every backend but LS4, Isabelle included, then
|
|
113
|
+
// Prep.flatten.
|
|
114
|
+
const shipFirstOrder = (sequent: Sequent) => flatten(processObligation(sequent));
|
|
115
|
+
|
|
116
|
+
const SMT: Backend = {
|
|
117
|
+
// Prep.gen_smt_solve writes the resource budget before the encoding.
|
|
118
|
+
encode: (_id, sequent, method, session) =>
|
|
119
|
+
(method.rlimit === undefined ? "" : `(set-option :rlimit ${method.rlimit})\n`) +
|
|
120
|
+
encodeSmt(shipFirstOrder(sequent), session),
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const BACKENDS: Record<string, Backend> = {
|
|
124
|
+
smt: SMT,
|
|
125
|
+
z3: SMT,
|
|
126
|
+
zenon: { encode: (id, sequent) => encodeZenon(id, shipFirstOrder(sequent)) },
|
|
127
|
+
// tlapm names the theory after its temporary file, and tla-ts after the obligation.
|
|
128
|
+
isabelle: {
|
|
129
|
+
encode: (id, sequent, method) =>
|
|
130
|
+
encodeIsabelle(id, shipFirstOrder(sequent), method.tactic ?? "auto", `tlapm_${id}`),
|
|
131
|
+
},
|
|
132
|
+
// Pltl.process_obligation is LS4's frontend.
|
|
133
|
+
ls4: { encode: (_id, sequent) => encodePtl(sequent) },
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// The frontends and Prep.flatten add no CASE without OTHER, so the SMT encoder standardizes one
|
|
137
|
+
// only in an obligation that has one after Prep.normalize_expand.
|
|
138
|
+
const hasIncompleteCase = (expression: Expr): boolean =>
|
|
139
|
+
(expression.kind === "Case" && expression.other === undefined) ||
|
|
140
|
+
getChildren(expression).some(hasIncompleteCase);
|
|
141
|
+
|
|
142
|
+
const incompleteCaseHyps = new WeakMap<Hyp, boolean>();
|
|
143
|
+
|
|
144
|
+
const isIncompleteCaseHyp = (hyp: Hyp) => {
|
|
145
|
+
const known = incompleteCaseHyps.get(hyp);
|
|
146
|
+
if (known !== undefined) return known;
|
|
147
|
+
const expressions: Expr[] = [];
|
|
148
|
+
mapHyp(
|
|
149
|
+
hyp,
|
|
150
|
+
(inner) => {
|
|
151
|
+
expressions.push(inner);
|
|
152
|
+
return inner;
|
|
153
|
+
},
|
|
154
|
+
"all",
|
|
155
|
+
);
|
|
156
|
+
const isIncomplete = expressions.some(hasIncompleteCase);
|
|
157
|
+
incompleteCaseHyps.set(hyp, isIncomplete);
|
|
158
|
+
return isIncomplete;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const getModuleName = (source: string) => /-{4,}\s*MODULE\s+(\w+)/.exec(source)?.[1] ?? "Main";
|
|
162
|
+
|
|
163
|
+
const getBase = (obligation: PrintedObligation): ObligationBase => ({
|
|
164
|
+
id: obligation.id,
|
|
165
|
+
location: obligation.location,
|
|
166
|
+
text: obligation.text,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const getUnproved = (
|
|
170
|
+
obligation: PrintedObligation,
|
|
171
|
+
status: "failed" | "unsupported",
|
|
172
|
+
reason: string,
|
|
173
|
+
): ProofObligation => ({ ...getBase(obligation), status, reason });
|
|
174
|
+
|
|
175
|
+
// Prep.normalize_expand: expand_defs, Elab.normalize, then the frontends the step cites.
|
|
176
|
+
const normalizeExpand = (obligation: PrintedObligation, methods = findMethods(obligation)) =>
|
|
177
|
+
expandEnabledCdot(normalizeSequent(expandDefs(obligation.sequent)), methods.frontends);
|
|
178
|
+
|
|
179
|
+
// A failed obligation as tlapm prints it: Prep.normalize_expand for a new failure, and
|
|
180
|
+
// Toolbox.normalize, which keeps pragmas, for a reused one.
|
|
181
|
+
export const formatNormalized = (obligation: PrintedObligation, isReused: boolean) =>
|
|
182
|
+
`${formatObligation(
|
|
183
|
+
isReused
|
|
184
|
+
? normalizeSequent(expandDefs(obligation.sequent, false))
|
|
185
|
+
: normalizeExpand(obligation),
|
|
186
|
+
)}\n`;
|
|
187
|
+
|
|
188
|
+
// The theory of the proofs Isabelle found. tlapm also writes Zenon's proofs there.
|
|
189
|
+
export const encodeProofTheory = (
|
|
190
|
+
name: string,
|
|
191
|
+
reports: ProofReport[],
|
|
192
|
+
obligations: PrintedObligation[],
|
|
193
|
+
) =>
|
|
194
|
+
encodeIsabelleTheory(
|
|
195
|
+
name,
|
|
196
|
+
reports.flatMap((report, index) =>
|
|
197
|
+
report.attempts
|
|
198
|
+
.filter(
|
|
199
|
+
(attempt) =>
|
|
200
|
+
attempt.method.prover === "isabelle" && attempt.isProved && !attempt.isReused,
|
|
201
|
+
)
|
|
202
|
+
.map((attempt) => ({
|
|
203
|
+
id: report.obligation.id,
|
|
204
|
+
sequent: shipFirstOrder(normalizeExpand(obligations[index])),
|
|
205
|
+
tactic: attempt.method.tactic ?? "auto",
|
|
206
|
+
})),
|
|
207
|
+
),
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
// The text one backend receives for an obligation, for comparing with tlapm's.
|
|
211
|
+
export const encodeForBackend = (
|
|
212
|
+
obligation: PrintedObligation,
|
|
213
|
+
prover: string,
|
|
214
|
+
session: EncodingSession,
|
|
215
|
+
) => {
|
|
216
|
+
const backend = BACKENDS[prover];
|
|
217
|
+
if (!backend) throw new TlaUnsupportedError(`the ${prover} backend`);
|
|
218
|
+
const methods = findMethods(obligation);
|
|
219
|
+
const method = methods.provers.find((candidate) => candidate.prover === prover) ?? {
|
|
220
|
+
prover,
|
|
221
|
+
timeLimitMs: Infinity,
|
|
222
|
+
};
|
|
223
|
+
return backend.encode(obligation.id, normalizeExpand(obligation, methods), method, session);
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// The SMT encoder's session for an obligation, from the count of CASE errors every earlier
|
|
227
|
+
// obligation leaves.
|
|
228
|
+
const getSession = async (run: ProveRun, index: number) => {
|
|
229
|
+
const task = run.tasks[index];
|
|
230
|
+
if (task.session) return task.session.current;
|
|
231
|
+
const earlier = run.tasks.slice(0, index);
|
|
232
|
+
await Promise.all(earlier.map((innerTask) => innerTask.done));
|
|
233
|
+
const initial = earlier.reduce(
|
|
234
|
+
(total, innerTask) =>
|
|
235
|
+
total +
|
|
236
|
+
(innerTask.session ? innerTask.session.current.caseErrors - innerTask.session.initial : 0),
|
|
237
|
+
0,
|
|
238
|
+
);
|
|
239
|
+
task.session = { initial, current: { caseErrors: initial } };
|
|
240
|
+
return task.session.current;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// Prep.ship: the provers the step cites, or tlapm's default ones when it cites none, each tried in
|
|
244
|
+
// turn until one proves the obligation. Prep.already_processed reuses what a prover concluded for
|
|
245
|
+
// an earlier obligation with the same fingerprint: a proof, or a failure within at least as much
|
|
246
|
+
// time. Unless the first prover's proof is reused, a trivial obligation needs no prover.
|
|
247
|
+
const proveWithBackends = async (
|
|
248
|
+
obligation: PrintedObligation,
|
|
249
|
+
index: number,
|
|
250
|
+
run: ProveRun,
|
|
251
|
+
signal: AbortSignal | undefined,
|
|
252
|
+
): Promise<ProofReport> => {
|
|
253
|
+
if (obligation.kind.kind === "Error")
|
|
254
|
+
return { obligation: getUnproved(obligation, "failed", obligation.kind.message), attempts: [] };
|
|
255
|
+
const methods = findMethods(obligation);
|
|
256
|
+
const fingerprint = getFingerprint(obligation.sequent);
|
|
257
|
+
const earlier = run.lastByFingerprint.get(fingerprint);
|
|
258
|
+
run.lastByFingerprint.set(fingerprint, run.tasks[index].done);
|
|
259
|
+
await earlier;
|
|
260
|
+
const attempts: ProofAttempt[] = [];
|
|
261
|
+
const getProved = (prover: string): ProofReport => ({
|
|
262
|
+
obligation: { ...getBase(obligation), status: "proved", prover },
|
|
263
|
+
attempts,
|
|
264
|
+
});
|
|
265
|
+
// Prep.already_processed.
|
|
266
|
+
const getPrior = (method: Method) => {
|
|
267
|
+
if (!run.isFingerprinted(obligation)) run.results.delete(fingerprint);
|
|
268
|
+
const prior = run.results.get(fingerprint)?.get(method.prover);
|
|
269
|
+
return prior?.method.tactic === method.tactic ? prior : undefined;
|
|
270
|
+
};
|
|
271
|
+
// Fpfile.get_timeout.
|
|
272
|
+
const getBudget = (method: Method) => method.rlimit ?? method.timeLimitMs / 1000;
|
|
273
|
+
const reuse = (prior: ProofAttempt) =>
|
|
274
|
+
attempts.push({ ...prior, isReused: true, timeUsedMs: undefined });
|
|
275
|
+
const firstPrior = getPrior(methods.provers[0]);
|
|
276
|
+
if (firstPrior?.isProved) {
|
|
277
|
+
reuse(firstPrior);
|
|
278
|
+
return getProved(firstPrior.method.prover);
|
|
279
|
+
}
|
|
280
|
+
const sequent = normalizeExpand(obligation, methods);
|
|
281
|
+
// Fpfile.fp_writes keeps no trivial result, but adds the fingerprint.
|
|
282
|
+
if (obligation.kind.kind === "Support" && isTrivial(sequent)) {
|
|
283
|
+
run.results.set(fingerprint, run.results.get(fingerprint) ?? new Map());
|
|
284
|
+
return { obligation: { ...getBase(obligation), status: "trivial" }, attempts };
|
|
285
|
+
}
|
|
286
|
+
const reasons: string[] = [];
|
|
287
|
+
const state = { isDecided: false };
|
|
288
|
+
const decideAttempt = (attempt: ProofAttempt) => {
|
|
289
|
+
attempts.push(attempt);
|
|
290
|
+
run.results.set(
|
|
291
|
+
fingerprint,
|
|
292
|
+
(run.results.get(fingerprint) ?? new Map()).set(attempt.method.prover, attempt),
|
|
293
|
+
);
|
|
294
|
+
state.isDecided = true;
|
|
295
|
+
};
|
|
296
|
+
for (const method of methods.provers) {
|
|
297
|
+
const prior = getPrior(method);
|
|
298
|
+
if (prior?.isProved) {
|
|
299
|
+
reuse(prior);
|
|
300
|
+
return getProved(method.prover);
|
|
301
|
+
}
|
|
302
|
+
if (prior && getBudget(prior.method) >= getBudget(method)) {
|
|
303
|
+
reuse(prior);
|
|
304
|
+
state.isDecided = true;
|
|
305
|
+
reasons.push(`${method.prover} failed on an obligation with the same fingerprint`);
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
if (!run.isProving) continue;
|
|
309
|
+
// Prep.prove_with: the Trivial method proves anything.
|
|
310
|
+
if (method.prover === "trivial") return getProved(method.prover);
|
|
311
|
+
const backend = BACKENDS[method.prover];
|
|
312
|
+
if (!backend) {
|
|
313
|
+
const reason = `tla-ts has no ${method.prover} backend`;
|
|
314
|
+
attempts.push({ method, isProved: false, isReused: false, reason });
|
|
315
|
+
reasons.push(reason);
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
try {
|
|
319
|
+
const isCaseNumbered =
|
|
320
|
+
backend === SMT &&
|
|
321
|
+
(sequent.context.some(isIncompleteCaseHyp) || hasIncompleteCase(sequent.active));
|
|
322
|
+
const session = isCaseNumbered ? await getSession(run, index) : { caseErrors: 0 };
|
|
323
|
+
const text = backend.encode(obligation.id, sequent, method, session);
|
|
324
|
+
const decision = await run.decide(
|
|
325
|
+
method.prover,
|
|
326
|
+
text,
|
|
327
|
+
{ timeLimitMs: method.timeLimitMs, signal },
|
|
328
|
+
index,
|
|
329
|
+
);
|
|
330
|
+
const isProved = decision.verdict === "unsat";
|
|
331
|
+
decideAttempt({
|
|
332
|
+
method,
|
|
333
|
+
isProved,
|
|
334
|
+
isReused: false,
|
|
335
|
+
...(!isProved && {
|
|
336
|
+
reason: decision.timeUsedMs >= method.timeLimitMs ? "timeout" : "false",
|
|
337
|
+
}),
|
|
338
|
+
verdict: decision.verdict,
|
|
339
|
+
timeUsedMs: decision.timeUsedMs,
|
|
340
|
+
});
|
|
341
|
+
if (isProved) return getProved(method.prover);
|
|
342
|
+
reasons.push(`${method.prover} answered ${decision.verdict}`);
|
|
343
|
+
} catch (error) {
|
|
344
|
+
if (error instanceof TlaProverError) {
|
|
345
|
+
decideAttempt({ method, isProved: false, isReused: false, reason: "false" });
|
|
346
|
+
reasons.push(`${method.prover} failed: ${error.message}`);
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
if (!(error instanceof TlaUnsupportedError)) throw error;
|
|
350
|
+
const reason = `${method.prover} can't encode ${error.message}`;
|
|
351
|
+
attempts.push({ method, isProved: false, isReused: false, reason });
|
|
352
|
+
reasons.push(reason);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return {
|
|
356
|
+
obligation: getUnproved(
|
|
357
|
+
obligation,
|
|
358
|
+
state.isDecided ? "failed" : "unsupported",
|
|
359
|
+
reasons.join(", "),
|
|
360
|
+
),
|
|
361
|
+
attempts,
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
// The one place an error becomes a result: what tla-ts can't handle is unsupported, and what tlapm
|
|
366
|
+
// refuses, as a frontend's soundness check, fails.
|
|
367
|
+
const getResult = async (
|
|
368
|
+
obligation: PrintedObligation,
|
|
369
|
+
getReport: () => Promise<ProofReport>,
|
|
370
|
+
): Promise<ProofReport> => {
|
|
371
|
+
try {
|
|
372
|
+
return await getReport();
|
|
373
|
+
} catch (error) {
|
|
374
|
+
if (error instanceof TlaUnsupportedError)
|
|
375
|
+
return { obligation: getUnproved(obligation, "unsupported", error.message), attempts: [] };
|
|
376
|
+
if (error instanceof TlaProverError)
|
|
377
|
+
return { obligation: getUnproved(obligation, "failed", error.message), attempts: [] };
|
|
378
|
+
throw error;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
interface ObligationsOptions {
|
|
383
|
+
workers?: number;
|
|
384
|
+
signal?: AbortSignal;
|
|
385
|
+
onReport?: (report: ProofReport, obligation: PrintedObligation) => void;
|
|
386
|
+
results?: Map<string, Map<string, ProofAttempt>>;
|
|
387
|
+
// --nofp and --nofpl.
|
|
388
|
+
isFingerprinted?: (obligation: PrintedObligation) => boolean;
|
|
389
|
+
// --noproving.
|
|
390
|
+
isProving?: boolean;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export const proveObligations = async (
|
|
394
|
+
obligations: PrintedObligation[],
|
|
395
|
+
options: ObligationsOptions,
|
|
396
|
+
) => {
|
|
397
|
+
const count = options.workers ?? 1;
|
|
398
|
+
const pool = count > 1 && isWorkerSupported() ? await createDecidePool(count) : undefined;
|
|
399
|
+
const onAbort = () => pool?.terminate(options.signal?.reason);
|
|
400
|
+
options.signal?.addEventListener("abort", onAbort);
|
|
401
|
+
const run: ProveRun = {
|
|
402
|
+
tasks: [],
|
|
403
|
+
results: options.results ?? new Map(),
|
|
404
|
+
isFingerprinted: options.isFingerprinted ?? (() => true),
|
|
405
|
+
isProving: options.isProving ?? true,
|
|
406
|
+
lastByFingerprint: new Map(),
|
|
407
|
+
decide:
|
|
408
|
+
pool?.decide ?? (async (prover, text, decideOptions) => decide(prover, text, decideOptions)),
|
|
409
|
+
};
|
|
410
|
+
// A few obligations per worker prove at once, and each reports once every earlier one has.
|
|
411
|
+
const limit = pool ? count * 4 : 1;
|
|
412
|
+
const pending: Promise<ProofReport>[] = [];
|
|
413
|
+
const isSettled: boolean[] = [];
|
|
414
|
+
const running = new Set<Promise<void>>();
|
|
415
|
+
const reports: ProofReport[] = [];
|
|
416
|
+
const reportSettled = async () => {
|
|
417
|
+
while (isSettled[reports.length]) {
|
|
418
|
+
options.signal?.throwIfAborted();
|
|
419
|
+
const report = await pending[reports.length];
|
|
420
|
+
reports.push(report);
|
|
421
|
+
options.onReport?.(report, obligations[reports.length - 1]);
|
|
422
|
+
// HACK: backends on this thread run synchronously, so yield to let an abort land.
|
|
423
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
try {
|
|
427
|
+
for (const [index, obligation] of obligations.entries()) {
|
|
428
|
+
options.signal?.throwIfAborted();
|
|
429
|
+
const done = Promise.withResolvers<void>();
|
|
430
|
+
run.tasks.push({ done: done.promise, session: undefined });
|
|
431
|
+
const report = getResult(obligation, () =>
|
|
432
|
+
proveWithBackends(obligation, index, run, options.signal),
|
|
433
|
+
);
|
|
434
|
+
pending.push(report);
|
|
435
|
+
running.add(done.promise);
|
|
436
|
+
const settle = () => {
|
|
437
|
+
isSettled[index] = true;
|
|
438
|
+
running.delete(done.promise);
|
|
439
|
+
done.resolve();
|
|
440
|
+
};
|
|
441
|
+
void report.then(settle, settle);
|
|
442
|
+
if (running.size >= limit) await Promise.race(running);
|
|
443
|
+
await reportSettled();
|
|
444
|
+
}
|
|
445
|
+
await Promise.all(running);
|
|
446
|
+
await reportSettled();
|
|
447
|
+
} finally {
|
|
448
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
449
|
+
pool?.terminate(new TlaProverError("prove stopped"));
|
|
450
|
+
}
|
|
451
|
+
return reports;
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
const getFromTlapm = (obligation: PrintedObligation, result: TlapmResult | undefined) =>
|
|
455
|
+
result
|
|
456
|
+
? { ...getBase(obligation), ...result }
|
|
457
|
+
: getUnproved(obligation, "unsupported", "tlapm reported no result");
|
|
458
|
+
|
|
459
|
+
export const prove = async (options: ProveOptions): Promise<ProveResult> => {
|
|
460
|
+
const name = getModuleName(options.source);
|
|
461
|
+
const modules = new Map<string, string>();
|
|
462
|
+
const results = getObligations(
|
|
463
|
+
[{ file: `${name}.tla`, source: options.source }],
|
|
464
|
+
(moduleName) => {
|
|
465
|
+
const source = options.loadModule?.(moduleName);
|
|
466
|
+
if (source !== undefined) modules.set(moduleName, source);
|
|
467
|
+
const loaded = source ?? (moduleName === "TLAPS" ? TLAPS_MODULE : undefined);
|
|
468
|
+
return loaded === undefined ? undefined : { file: `${moduleName}.tla`, source: loaded };
|
|
469
|
+
},
|
|
470
|
+
);
|
|
471
|
+
const obligations = results.flatMap((result) => result.obligations);
|
|
472
|
+
const counts = {
|
|
473
|
+
missingProofCount: results.reduce((total, result) => total + result.summary.absent.length, 0),
|
|
474
|
+
omittedProofCount: results.reduce((total, result) => total + result.summary.omitted.length, 0),
|
|
475
|
+
};
|
|
476
|
+
if (options.backend === "tlapm") {
|
|
477
|
+
if (typeof process === "undefined" || process.versions?.node === undefined)
|
|
478
|
+
throw new TlaUnsupportedError("The tlapm backend runs only in Node and Bun.");
|
|
479
|
+
const tlapm = await import("./tlapm/tlapm");
|
|
480
|
+
const byId = new Map(obligations.map((obligation) => [obligation.id, obligation]));
|
|
481
|
+
const reported = await tlapm.proveWithTlapm(
|
|
482
|
+
name,
|
|
483
|
+
new Map([[name, options.source], ...modules]),
|
|
484
|
+
{
|
|
485
|
+
signal: options.signal,
|
|
486
|
+
onResult: (id, result) => {
|
|
487
|
+
const obligation = byId.get(id);
|
|
488
|
+
if (obligation) options.onObligation?.(getFromTlapm(obligation, result));
|
|
489
|
+
},
|
|
490
|
+
},
|
|
491
|
+
);
|
|
492
|
+
return {
|
|
493
|
+
obligations: obligations.map((obligation) =>
|
|
494
|
+
getFromTlapm(obligation, reported.get(obligation.id)),
|
|
495
|
+
),
|
|
496
|
+
...counts,
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
const reports = await proveObligations(obligations, {
|
|
500
|
+
workers: options.workers,
|
|
501
|
+
signal: options.signal,
|
|
502
|
+
onReport: (report) => options.onObligation?.(report.obligation),
|
|
503
|
+
});
|
|
504
|
+
return { obligations: reports.map((report) => report.obligation), ...counts };
|
|
505
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
import { TlaSyntaxError } from "../../errors";
|
|
5
|
+
import type { DecideOptions, Verdict } from "../verdict";
|
|
6
|
+
import { getSatisfiability, type PtlFormula } from "./tableau";
|
|
7
|
+
|
|
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
|
+
const parseLs4 = (text: string): PtlFormula => {
|
|
11
|
+
const tokens = text.match(/<->|->|[()~&|]|[\w']+|\S/g) ?? [];
|
|
12
|
+
const state = { position: 0 };
|
|
13
|
+
const take = (expected?: string) => {
|
|
14
|
+
const token = tokens[state.position++];
|
|
15
|
+
if (token === undefined || (expected !== undefined && token !== expected))
|
|
16
|
+
throw new TlaSyntaxError(
|
|
17
|
+
`Expected ${expected ?? "a formula"} in LS4 input, found ${token ?? "the end"}`,
|
|
18
|
+
);
|
|
19
|
+
return token;
|
|
20
|
+
};
|
|
21
|
+
const parseUnary = (): PtlFormula => {
|
|
22
|
+
const token = take();
|
|
23
|
+
if (token === "(") {
|
|
24
|
+
const inner = parseEquiv();
|
|
25
|
+
take(")");
|
|
26
|
+
return inner;
|
|
27
|
+
}
|
|
28
|
+
if (token === "~" || token === "not") return { kind: "Not", body: parseUnary() };
|
|
29
|
+
if (token === "always") return { kind: "Always", body: parseUnary() };
|
|
30
|
+
if (token === "sometime") return { kind: "Eventually", body: parseUnary() };
|
|
31
|
+
if (token === "next") return { kind: "Next", body: parseUnary() };
|
|
32
|
+
if (!/^[\w']+$/.test(token))
|
|
33
|
+
throw new TlaSyntaxError(`Expected a formula in LS4 input, found ${token}`);
|
|
34
|
+
return { kind: "Atom", name: token };
|
|
35
|
+
};
|
|
36
|
+
const parseJunction = (operator: string, kind: "And" | "Or", parseOperand: () => PtlFormula) => {
|
|
37
|
+
const operands = [parseOperand()];
|
|
38
|
+
while (tokens[state.position] === operator) {
|
|
39
|
+
take();
|
|
40
|
+
operands.push(parseOperand());
|
|
41
|
+
}
|
|
42
|
+
return operands.reduce((left, right) => ({ kind, left, right }));
|
|
43
|
+
};
|
|
44
|
+
const parseImplies = (): PtlFormula => {
|
|
45
|
+
const left = parseJunction("|", "Or", () => parseJunction("&", "And", parseUnary));
|
|
46
|
+
if (tokens[state.position] !== "->") return left;
|
|
47
|
+
take();
|
|
48
|
+
return { kind: "Implies", left, right: parseImplies() };
|
|
49
|
+
};
|
|
50
|
+
const parseEquiv = (): PtlFormula => {
|
|
51
|
+
const left = parseImplies();
|
|
52
|
+
if (tokens[state.position] !== "<->") return left;
|
|
53
|
+
take();
|
|
54
|
+
return { kind: "Equiv", left, right: parseEquiv() };
|
|
55
|
+
};
|
|
56
|
+
const formula = parseEquiv();
|
|
57
|
+
if (state.position < tokens.length)
|
|
58
|
+
throw new TlaSyntaxError(`Expected the end of LS4 input, found ${tokens[state.position]}`);
|
|
59
|
+
return formula;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const decidePtl = (text: string, options: DecideOptions): Verdict => {
|
|
63
|
+
const deadline = performance.now() + options.timeLimitMs;
|
|
64
|
+
return getSatisfiability(
|
|
65
|
+
parseLs4(text),
|
|
66
|
+
() => options.signal?.aborted === true || performance.now() > deadline,
|
|
67
|
+
);
|
|
68
|
+
};
|