tla-ts 0.0.4-dev.2be6058 → 0.0.4-dev.2da24e1
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 +37 -126
- 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 +26 -7
- package/src/errors.ts +86 -0
- package/src/evaluate.ts +255 -56
- package/src/index.ts +10 -0
- package/src/{obligation-action.ts → obligations/action.ts} +247 -69
- package/src/{obligation-anon.ts → obligations/anon.ts} +49 -47
- package/src/obligations/ctx.ts +64 -0
- package/src/{obligation-deref.ts → obligations/deref.ts} +51 -92
- package/src/{obligation-expression.ts → obligations/expression.ts} +117 -57
- package/src/{obligation-format.ts → obligations/format.ts} +7 -8
- package/src/{obligation-generate.ts → obligations/generate.ts} +170 -192
- package/src/{obligations.ts → obligations/index.ts} +32 -16
- package/src/{obligation-levels.ts → obligations/levels.ts} +26 -28
- package/src/{obligation-module.ts → obligations/module.ts} +113 -121
- 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 -2
- package/src/{obligation-source.ts → obligations/source.ts} +154 -99
- package/src/obligations/temporal.ts +321 -0
- package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
- 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 +95 -0
- package/src/prove/deciders.ts +33 -0
- package/src/prove/first-order.ts +78 -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 +446 -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 +508 -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 +529 -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 +22 -0
- package/src/prove/prove.ts +498 -0
- package/src/prove/ptl/decide.ts +68 -0
- package/src/prove/ptl/encode.ts +255 -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 +209 -0
- package/src/prove/smt/context.ts +108 -0
- package/src/prove/smt/data.ts +636 -0
- package/src/prove/smt/encode.ts +164 -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 +181 -0
- package/src/prove/smt/rewrite.ts +772 -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 +379 -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 +283 -81
- package/src/standard-modules.ts +5 -2
- package/src/successors.ts +25 -6
- 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 +97 -47
- package/src/worker.ts +65 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// The Isabelle/TLA+ object logic that tlapm ships, decoded from logic-data.ts: its constants, the
|
|
2
|
+
// theorems its theories prove, and the order of the simpset and the classical rule nets.
|
|
3
|
+
|
|
4
|
+
import { axiomThm, type Thm } from "../pure/thm";
|
|
5
|
+
import type { ClassicalRule } from "../provers/classical";
|
|
6
|
+
import {
|
|
7
|
+
mkAbs,
|
|
8
|
+
mkApp,
|
|
9
|
+
mkBound,
|
|
10
|
+
mkConst,
|
|
11
|
+
mkFree,
|
|
12
|
+
mkTFree,
|
|
13
|
+
mkTVar,
|
|
14
|
+
mkType,
|
|
15
|
+
mkVar,
|
|
16
|
+
} from "../pure/term";
|
|
17
|
+
import { typargsOf, type TypargPosition } from "../pure/consts";
|
|
18
|
+
import type { Term, Typ } from "../pure/term";
|
|
19
|
+
import { LOGIC_DATA } from "./logic-data";
|
|
20
|
+
|
|
21
|
+
type TypeNode = [0, number, ...number[]] | [1, number] | [2, number, number];
|
|
22
|
+
type TermNode =
|
|
23
|
+
| [0, number, number]
|
|
24
|
+
| [1, number, number]
|
|
25
|
+
| [2, number, number, number]
|
|
26
|
+
| [3, number]
|
|
27
|
+
| [4, number, number, number]
|
|
28
|
+
| [5, number, number];
|
|
29
|
+
// A rule of a claset or of the context rules, by theorem id, with its insertion tag.
|
|
30
|
+
type NetItem = [number, 0 | 1, number];
|
|
31
|
+
type ExtraNetItem = [number, number, 0 | 1, number];
|
|
32
|
+
type RawRule = [number, number, number[], number, number[]];
|
|
33
|
+
|
|
34
|
+
interface LogicJson {
|
|
35
|
+
strings: string[];
|
|
36
|
+
types: TypeNode[];
|
|
37
|
+
terms: TermNode[];
|
|
38
|
+
thms: number[];
|
|
39
|
+
consts: ([string, number] | [string, number, number])[];
|
|
40
|
+
names: [string, string][];
|
|
41
|
+
facts: [string, number[]][];
|
|
42
|
+
factNames: [string, string][];
|
|
43
|
+
simps: number[];
|
|
44
|
+
congs: [boolean, string, number][];
|
|
45
|
+
weakCongs: [boolean, string][];
|
|
46
|
+
simprocs: [string, number[]][];
|
|
47
|
+
claset: {
|
|
48
|
+
safeIs: RawRule[];
|
|
49
|
+
safeEs: RawRule[];
|
|
50
|
+
unsafeIs: RawRule[];
|
|
51
|
+
unsafeEs: RawRule[];
|
|
52
|
+
safe0: [NetItem[], NetItem[]];
|
|
53
|
+
safep: [NetItem[], NetItem[]];
|
|
54
|
+
unsafe: [NetItem[], NetItem[]];
|
|
55
|
+
dup: [NetItem[], NetItem[]];
|
|
56
|
+
extra: [ExtraNetItem[], ExtraNetItem[]];
|
|
57
|
+
};
|
|
58
|
+
contextRules: { bang: [ExtraNetItem[], ExtraNetItem[]]; plain: [ExtraNetItem[], ExtraNetItem[]] };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface ConstInfo {
|
|
62
|
+
readonly type: Typ;
|
|
63
|
+
readonly typargs: readonly TypargPosition[];
|
|
64
|
+
// The right-hand side of an abbreviation, which parsing unfolds.
|
|
65
|
+
readonly abbreviation: Term | undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface LogicNetItem {
|
|
69
|
+
readonly tag: number;
|
|
70
|
+
readonly isElim: boolean;
|
|
71
|
+
readonly rule: Thm;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface LogicExtraNetItem extends LogicNetItem {
|
|
75
|
+
readonly weight: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface LogicNetPair<Item> {
|
|
79
|
+
readonly intro: readonly Item[];
|
|
80
|
+
readonly elim: readonly Item[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface TlaLogic {
|
|
84
|
+
readonly consts: ReadonlyMap<string, ConstInfo>;
|
|
85
|
+
// The constant each unqualified name stands for.
|
|
86
|
+
readonly constNames: ReadonlyMap<string, string>;
|
|
87
|
+
readonly facts: ReadonlyMap<string, readonly Thm[]>;
|
|
88
|
+
readonly factNames: ReadonlyMap<string, string>;
|
|
89
|
+
// The simpset's rewrite rules, in the order of Net.entries.
|
|
90
|
+
readonly simps: readonly Thm[];
|
|
91
|
+
readonly congs: readonly {
|
|
92
|
+
readonly isConst: boolean;
|
|
93
|
+
readonly name: string;
|
|
94
|
+
readonly rule: Thm;
|
|
95
|
+
}[];
|
|
96
|
+
readonly weakCongs: readonly { readonly isConst: boolean; readonly name: string }[];
|
|
97
|
+
readonly simprocs: readonly { readonly name: string; readonly lhss: readonly Term[] }[];
|
|
98
|
+
readonly claset: {
|
|
99
|
+
readonly safeIs: readonly ClassicalRule[];
|
|
100
|
+
readonly safeEs: readonly ClassicalRule[];
|
|
101
|
+
readonly unsafeIs: readonly ClassicalRule[];
|
|
102
|
+
readonly unsafeEs: readonly ClassicalRule[];
|
|
103
|
+
readonly safe0: LogicNetPair<LogicNetItem>;
|
|
104
|
+
readonly safep: LogicNetPair<LogicNetItem>;
|
|
105
|
+
readonly unsafe: LogicNetPair<LogicNetItem>;
|
|
106
|
+
readonly dup: LogicNetPair<LogicNetItem>;
|
|
107
|
+
};
|
|
108
|
+
readonly contextRules: {
|
|
109
|
+
readonly bang: LogicNetPair<LogicExtraNetItem>;
|
|
110
|
+
readonly plain: LogicNetPair<LogicExtraNetItem>;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const parseLogic = (): TlaLogic => {
|
|
115
|
+
const data: LogicJson = JSON.parse(LOGIC_DATA);
|
|
116
|
+
const types: Typ[] = [];
|
|
117
|
+
const getType = (id: number): Typ => {
|
|
118
|
+
const known = types[id];
|
|
119
|
+
if (known !== undefined) return known;
|
|
120
|
+
const node = data.types[id];
|
|
121
|
+
const type =
|
|
122
|
+
node[0] === 0
|
|
123
|
+
? mkType(data.strings[node[1]], node.slice(2).map(getType))
|
|
124
|
+
: node[0] === 1
|
|
125
|
+
? mkTFree(data.strings[node[1]])
|
|
126
|
+
: mkTVar(data.strings[node[1]], node[2]);
|
|
127
|
+
types[id] = type;
|
|
128
|
+
return type;
|
|
129
|
+
};
|
|
130
|
+
const terms: Term[] = [];
|
|
131
|
+
const getTerm = (id: number): Term => {
|
|
132
|
+
const known = terms[id];
|
|
133
|
+
if (known !== undefined) return known;
|
|
134
|
+
const node = data.terms[id];
|
|
135
|
+
const term =
|
|
136
|
+
node[0] === 0
|
|
137
|
+
? mkConst(data.strings[node[1]], getType(node[2]))
|
|
138
|
+
: node[0] === 1
|
|
139
|
+
? mkFree(data.strings[node[1]], getType(node[2]))
|
|
140
|
+
: node[0] === 2
|
|
141
|
+
? mkVar(data.strings[node[1]], node[2], getType(node[3]))
|
|
142
|
+
: node[0] === 3
|
|
143
|
+
? mkBound(node[1])
|
|
144
|
+
: node[0] === 4
|
|
145
|
+
? mkAbs(data.strings[node[1]], getType(node[2]), getTerm(node[3]))
|
|
146
|
+
: mkApp(getTerm(node[1]), getTerm(node[2]));
|
|
147
|
+
terms[id] = term;
|
|
148
|
+
return term;
|
|
149
|
+
};
|
|
150
|
+
const thms = data.thms.map((id) => axiomThm(getTerm(id)));
|
|
151
|
+
const toRule = (raw: RawRule): ClassicalRule => ({
|
|
152
|
+
rule: thms[raw[0]],
|
|
153
|
+
internal: thms[raw[1]],
|
|
154
|
+
swapped: raw[2].map((id) => thms[id]),
|
|
155
|
+
dup: thms[raw[3]],
|
|
156
|
+
dupSwapped: raw[4].map((id) => thms[id]),
|
|
157
|
+
});
|
|
158
|
+
const toItems = (pair: [NetItem[], NetItem[]]): LogicNetPair<LogicNetItem> => {
|
|
159
|
+
const [intro, elim] = pair.map((side) =>
|
|
160
|
+
side.map((item) => ({ tag: item[0], isElim: item[1] === 1, rule: thms[item[2]] })),
|
|
161
|
+
);
|
|
162
|
+
return { intro, elim };
|
|
163
|
+
};
|
|
164
|
+
const toExtraItems = (
|
|
165
|
+
pair: [ExtraNetItem[], ExtraNetItem[]],
|
|
166
|
+
): LogicNetPair<LogicExtraNetItem> => {
|
|
167
|
+
const [intro, elim] = pair.map((side) =>
|
|
168
|
+
side.map((item) => ({
|
|
169
|
+
weight: item[0],
|
|
170
|
+
tag: item[1],
|
|
171
|
+
isElim: item[2] === 1,
|
|
172
|
+
rule: thms[item[3]],
|
|
173
|
+
})),
|
|
174
|
+
);
|
|
175
|
+
return { intro, elim };
|
|
176
|
+
};
|
|
177
|
+
return {
|
|
178
|
+
consts: new Map(
|
|
179
|
+
data.consts.map((entry) => [
|
|
180
|
+
entry[0],
|
|
181
|
+
{
|
|
182
|
+
type: getType(entry[1]),
|
|
183
|
+
typargs: typargsOf(getType(entry[1])),
|
|
184
|
+
abbreviation: entry.length === 3 ? getTerm(entry[2]) : undefined,
|
|
185
|
+
},
|
|
186
|
+
]),
|
|
187
|
+
),
|
|
188
|
+
constNames: new Map(data.names),
|
|
189
|
+
facts: new Map(data.facts.map((entry) => [entry[0], entry[1].map((id) => thms[id])])),
|
|
190
|
+
factNames: new Map(data.factNames),
|
|
191
|
+
simps: data.simps.map((id) => thms[id]),
|
|
192
|
+
congs: data.congs.map((entry) => ({ isConst: entry[0], name: entry[1], rule: thms[entry[2]] })),
|
|
193
|
+
weakCongs: data.weakCongs.map((entry) => ({ isConst: entry[0], name: entry[1] })),
|
|
194
|
+
simprocs: data.simprocs.map((entry) => ({ name: entry[0], lhss: entry[1].map(getTerm) })),
|
|
195
|
+
claset: {
|
|
196
|
+
safeIs: data.claset.safeIs.map(toRule),
|
|
197
|
+
safeEs: data.claset.safeEs.map(toRule),
|
|
198
|
+
unsafeIs: data.claset.unsafeIs.map(toRule),
|
|
199
|
+
unsafeEs: data.claset.unsafeEs.map(toRule),
|
|
200
|
+
safe0: toItems(data.claset.safe0),
|
|
201
|
+
safep: toItems(data.claset.safep),
|
|
202
|
+
unsafe: toItems(data.claset.unsafe),
|
|
203
|
+
dup: toItems(data.claset.dup),
|
|
204
|
+
},
|
|
205
|
+
contextRules: {
|
|
206
|
+
bang: toExtraItems(data.contextRules.bang),
|
|
207
|
+
plain: toExtraItems(data.contextRules.plain),
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const loaded: { logic?: TlaLogic } = {};
|
|
213
|
+
|
|
214
|
+
// Nothing changes the logic, so it parses once.
|
|
215
|
+
export const loadLogic = (): TlaLogic => (loaded.logic ??= parseLogic());
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// The simplifier as Isabelle/TLA+ sets it up in simplifier_setup.ML and PredicateLogic.thy (BSD
|
|
2
|
+
// licensed, see LICENSE): how theorems become rewrite rules, the solvers, the neq simproc, and the
|
|
3
|
+
// simpset of the reference heap.
|
|
4
|
+
//
|
|
5
|
+
// The heap's only looper, "split PredicateLogic.cond", is left out: its rule splitCond has the
|
|
6
|
+
// premise isBool(Q(x)), so Splitter.split_tac never composes it with a goal and the looper always
|
|
7
|
+
// fails.
|
|
8
|
+
|
|
9
|
+
import { TlaIsabelleError } from "../../../errors";
|
|
10
|
+
import { genAll, reflexiveThm } from "../pure/drule";
|
|
11
|
+
import { emptyNet, insertTermNet, type Net } from "../pure/net";
|
|
12
|
+
import {
|
|
13
|
+
congKey,
|
|
14
|
+
emptyCongs,
|
|
15
|
+
rulesFromEntries,
|
|
16
|
+
type Procedure,
|
|
17
|
+
type SimpContext,
|
|
18
|
+
type Simpset,
|
|
19
|
+
type Solver,
|
|
20
|
+
} from "../pure/raw-simplifier";
|
|
21
|
+
import { asmSimpTac, simplify } from "../pure/simplifier";
|
|
22
|
+
import { updateTable } from "../pure/table";
|
|
23
|
+
import {
|
|
24
|
+
assumeTac,
|
|
25
|
+
eqAssumeTac,
|
|
26
|
+
ematchTac,
|
|
27
|
+
eresolveTac,
|
|
28
|
+
matchTac,
|
|
29
|
+
resolveTac,
|
|
30
|
+
} from "../pure/tactic";
|
|
31
|
+
import {
|
|
32
|
+
first,
|
|
33
|
+
firstGoal,
|
|
34
|
+
orElse,
|
|
35
|
+
repeatDeterm,
|
|
36
|
+
thenAllNew,
|
|
37
|
+
thenGoal,
|
|
38
|
+
type GoalTactic,
|
|
39
|
+
} from "../pure/tactical";
|
|
40
|
+
import { aconv, eqTerm, headOf, type Term } from "../pure/term";
|
|
41
|
+
import { conclOf, rs, type Thm } from "../pure/thm";
|
|
42
|
+
import { trade } from "../pure/variable";
|
|
43
|
+
import { getFact } from "./classical-setup";
|
|
44
|
+
import type { TlaLogic } from "./logic";
|
|
45
|
+
|
|
46
|
+
const isConstApp = (name: string, arity: number, term: Term): boolean =>
|
|
47
|
+
arity === 0
|
|
48
|
+
? term.kind === "Const" && term.name === name
|
|
49
|
+
: term.kind === "App" && isConstApp(name, arity - 1, term.fun);
|
|
50
|
+
|
|
51
|
+
const catchThm = <Result>(derive: () => Result): Result | undefined => {
|
|
52
|
+
try {
|
|
53
|
+
return derive();
|
|
54
|
+
} catch (error) {
|
|
55
|
+
if (error instanceof TlaIsabelleError && error.exception === "THM") return undefined;
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const getRewriting = (logic: TlaLogic) => {
|
|
61
|
+
const fact = (name: string) => getFact(logic, `PredicateLogic.${name}`);
|
|
62
|
+
const eqReflection = fact("eq_reflection");
|
|
63
|
+
const eqTrueI = fact("eqTrueI");
|
|
64
|
+
const neqToEqFalse = rs(fact("neq_conv_eq_False"), eqReflection);
|
|
65
|
+
// Simpdata.mk_eq
|
|
66
|
+
const mkEq = (thm: Thm): Thm => {
|
|
67
|
+
const conclusion = conclOf(thm);
|
|
68
|
+
const concl = conclusion.kind === "App" ? conclusion : undefined;
|
|
69
|
+
if (isConstApp("Pure.eq", 2, conclusion)) return thm;
|
|
70
|
+
if (concl !== undefined && isConstApp("PredicateLogic.eq", 2, concl.arg))
|
|
71
|
+
return rs(thm, eqReflection);
|
|
72
|
+
if (
|
|
73
|
+
concl !== undefined &&
|
|
74
|
+
concl.arg.kind === "App" &&
|
|
75
|
+
isConstApp("PredicateLogic.not", 0, concl.arg.fun) &&
|
|
76
|
+
isConstApp("PredicateLogic.eq", 2, concl.arg.arg)
|
|
77
|
+
)
|
|
78
|
+
return rs(thm, neqToEqFalse);
|
|
79
|
+
return rs(rs(thm, eqTrueI), eqReflection);
|
|
80
|
+
};
|
|
81
|
+
// The final Simpdata.mksimps_pairs: the rules that split a premise by its outermost operator,
|
|
82
|
+
// and whether to simplify what they give.
|
|
83
|
+
const pairs = new Map<string, { rules: Thm[]; isSimplified: boolean }>([
|
|
84
|
+
["PredicateLogic.not", { rules: [fact("boolifyFalseI")], isSimplified: true }],
|
|
85
|
+
["PredicateLogic.iff", { rules: [fact("iffThenBoolifyEqual")], isSimplified: true }],
|
|
86
|
+
["PredicateLogic.imp", { rules: [fact("mp")], isSimplified: false }],
|
|
87
|
+
["PredicateLogic.conj", { rules: [fact("conjD1"), fact("conjD2")], isSimplified: false }],
|
|
88
|
+
["PredicateLogic.All", { rules: [fact("spec")], isSimplified: false }],
|
|
89
|
+
["PredicateLogic.TRUE", { rules: [], isSimplified: false }],
|
|
90
|
+
["PredicateLogic.FALSE", { rules: [], isSimplified: false }],
|
|
91
|
+
[
|
|
92
|
+
"PredicateLogic.cond",
|
|
93
|
+
{ rules: [rs(fact("if_bool_equiv_conj"), fact("iffD1"))], isSimplified: false },
|
|
94
|
+
],
|
|
95
|
+
]);
|
|
96
|
+
// Simpdata.mk_atomize
|
|
97
|
+
const atoms = (context: SimpContext, thm: Thm): Thm[] => {
|
|
98
|
+
const concl = conclOf(thm);
|
|
99
|
+
if (!(concl.kind === "App" && isConstApp("PredicateLogic.Trueprop", 1, concl))) return [thm];
|
|
100
|
+
const head = headOf(concl.arg);
|
|
101
|
+
const pair = head.kind === "Const" ? pairs.get(head.name) : undefined;
|
|
102
|
+
if (pair === undefined) return [thm];
|
|
103
|
+
const derive = (fixed: Thm) => pair.rules.map((rule) => rs(fixed, rule));
|
|
104
|
+
const split = catchThm(() =>
|
|
105
|
+
(thm.maxidx === -1 ? derive(thm) : trade(derive, thm)).flatMap((result) =>
|
|
106
|
+
atoms(context, result),
|
|
107
|
+
),
|
|
108
|
+
);
|
|
109
|
+
if (split === undefined) return [thm];
|
|
110
|
+
return pair.isSimplified ? split.map((result) => simplify(context, result)) : split;
|
|
111
|
+
};
|
|
112
|
+
return {
|
|
113
|
+
mk: (thm: Thm, context: SimpContext) =>
|
|
114
|
+
atoms(context, genAll(thm)).flatMap((atom) => {
|
|
115
|
+
const eq = catchThm(() => mkEq(atom));
|
|
116
|
+
return eq === undefined ? [] : [eq];
|
|
117
|
+
}),
|
|
118
|
+
mkEqTrue: (thm: Thm) => catchThm(() => rs(rs(thm, eqTrueI), eqReflection)),
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const getSolvers = (logic: TlaLogic): { unsafe: Solver; safe: Solver } => {
|
|
123
|
+
const fact = (name: string) => getFact(logic, `PredicateLogic.${name}`);
|
|
124
|
+
const solutions = [
|
|
125
|
+
reflexiveThm,
|
|
126
|
+
fact("trueI"),
|
|
127
|
+
fact("refl"),
|
|
128
|
+
fact("iff_refl"),
|
|
129
|
+
fact("notFalseI"),
|
|
130
|
+
];
|
|
131
|
+
const contradictions = [fact("falseE"), fact("not_refl_False")];
|
|
132
|
+
const conjI = fact("conjI");
|
|
133
|
+
const simpImpliesI = fact("simp_impliesI");
|
|
134
|
+
const introSimpImplies =
|
|
135
|
+
(context: SimpContext): GoalTactic =>
|
|
136
|
+
(index) =>
|
|
137
|
+
repeatDeterm(matchTac(context.limits, [simpImpliesI])(index));
|
|
138
|
+
return {
|
|
139
|
+
unsafe: {
|
|
140
|
+
name: "PredicateLogic unsafe",
|
|
141
|
+
tactic: (context) => {
|
|
142
|
+
const limits = context.limits;
|
|
143
|
+
const solveTac: GoalTactic = (index) =>
|
|
144
|
+
orElse(
|
|
145
|
+
first([
|
|
146
|
+
resolveTac(limits, [...solutions, ...context.simpset.prems])(index),
|
|
147
|
+
assumeTac(limits)(index),
|
|
148
|
+
eresolveTac(limits, contradictions)(index),
|
|
149
|
+
]),
|
|
150
|
+
thenAllNew(matchTac(limits, [conjI]), solveTac)(index),
|
|
151
|
+
);
|
|
152
|
+
return thenGoal(introSimpImplies(context), solveTac);
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
safe: {
|
|
156
|
+
name: "PredicateLogic safe",
|
|
157
|
+
tactic: (context) =>
|
|
158
|
+
thenGoal(
|
|
159
|
+
introSimpImplies(context),
|
|
160
|
+
firstGoal([
|
|
161
|
+
matchTac(context.limits, [...solutions, ...context.simpset.prems]),
|
|
162
|
+
eqAssumeTac,
|
|
163
|
+
ematchTac(context.limits, contradictions),
|
|
164
|
+
]),
|
|
165
|
+
),
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// PredicateLogic.thy's neq simproc: rewrites x = y to FALSE given y ~= x or (y = x) = FALSE.
|
|
171
|
+
const getNeqProc = (logic: TlaLogic) => {
|
|
172
|
+
const fact = (name: string) => getFact(logic, `PredicateLogic.${name}`);
|
|
173
|
+
const eqReflection = fact("eq_reflection");
|
|
174
|
+
const neqToEqFalse = rs(rs(fact("not_sym"), fact("neq_conv_eq_False")), eqReflection);
|
|
175
|
+
const symEqLeft = rs(fact("symEqLeft"), eqReflection);
|
|
176
|
+
const isNeq = (eq: Term, lhs: Term, rhs: Term, thm: Thm) => {
|
|
177
|
+
const prop = thm.prop;
|
|
178
|
+
if (prop.kind !== "App" || prop.arg.kind !== "App") return false;
|
|
179
|
+
const body = prop.arg;
|
|
180
|
+
if (body.arg.kind === "App" && body.arg.fun.kind === "App") {
|
|
181
|
+
const negated = body.arg;
|
|
182
|
+
return (
|
|
183
|
+
isConstApp("PredicateLogic.not", 0, body.fun) &&
|
|
184
|
+
negated.fun.kind === "App" &&
|
|
185
|
+
eqTerm(negated.fun.fun, eq) &&
|
|
186
|
+
aconv(negated.arg, lhs) &&
|
|
187
|
+
aconv(negated.fun.arg, rhs)
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
if (body.fun.kind !== "App") return false;
|
|
191
|
+
const equation = body.fun.arg;
|
|
192
|
+
return (
|
|
193
|
+
isConstApp("PredicateLogic.eq", 0, body.fun.fun) &&
|
|
194
|
+
equation.kind === "App" &&
|
|
195
|
+
equation.fun.kind === "App" &&
|
|
196
|
+
isConstApp("PredicateLogic.eq", 0, equation.fun.fun) &&
|
|
197
|
+
isConstApp("PredicateLogic.FALSE", 0, body.arg) &&
|
|
198
|
+
aconv(equation.arg, lhs) &&
|
|
199
|
+
aconv(equation.fun.arg, rhs)
|
|
200
|
+
);
|
|
201
|
+
};
|
|
202
|
+
return (context: SimpContext, term: Term): Thm | undefined => {
|
|
203
|
+
if (term.kind !== "App" || term.fun.kind !== "App") return undefined;
|
|
204
|
+
const eq = term.fun.fun;
|
|
205
|
+
const lhs = term.fun.arg;
|
|
206
|
+
const rhs = term.arg;
|
|
207
|
+
const prem = context.simpset.prems.find((thm) => isNeq(eq, lhs, rhs, thm));
|
|
208
|
+
if (prem === undefined) return undefined;
|
|
209
|
+
return catchThm(() => rs(prem, symEqLeft)) ?? rs(prem, neqToEqFalse);
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export const getSimpset = (logic: TlaLogic): Simpset => {
|
|
214
|
+
const neq = getNeqProc(logic);
|
|
215
|
+
const solvers = getSolvers(logic);
|
|
216
|
+
const procs = new Map([["PredicateLogic.neq", neq]]);
|
|
217
|
+
return {
|
|
218
|
+
rules: rulesFromEntries(logic.simps),
|
|
219
|
+
prems: [],
|
|
220
|
+
depth: 0,
|
|
221
|
+
congs: logic.congs.reduce(
|
|
222
|
+
(table, cong) => updateTable(table, congKey(cong), cong.rule),
|
|
223
|
+
emptyCongs,
|
|
224
|
+
),
|
|
225
|
+
weakCongs: logic.weakCongs,
|
|
226
|
+
simprocs: logic.simprocs.reduce<Net<Procedure>>((net, simproc) => {
|
|
227
|
+
const proc = procs.get(simproc.name);
|
|
228
|
+
if (proc === undefined)
|
|
229
|
+
throw new TlaIsabelleError("ERROR", `Undefined simproc: ${simproc.name}`);
|
|
230
|
+
return simproc.lhss.reduce(
|
|
231
|
+
(result, lhs) => insertTermNet(lhs, { name: simproc.name, lhs, proc }, result),
|
|
232
|
+
net,
|
|
233
|
+
);
|
|
234
|
+
}, emptyNet),
|
|
235
|
+
mkRews: getRewriting(logic),
|
|
236
|
+
subgoalTac: asmSimpTac,
|
|
237
|
+
loopTacs: [],
|
|
238
|
+
unsafeSolvers: [solvers.unsafe],
|
|
239
|
+
safeSolvers: [solvers.safe],
|
|
240
|
+
};
|
|
241
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Ported from Isabelle2025's Tools/intuitionistic.ML and the rule order of
|
|
2
|
+
// Pure/Isar/context_rules.ML. Copyright (c) 1986-2025 University of Cambridge, Technische
|
|
3
|
+
// Universitaet Muenchen, and contributors, see LICENSE.
|
|
4
|
+
//
|
|
5
|
+
// iprover: intuitionistic proof search with the context rules, the rules declared intro, elim and
|
|
6
|
+
// dest. Isabelle/TLA+ declares no context rule wrappers, so Swrap and wrap leave tactics as they
|
|
7
|
+
// are.
|
|
8
|
+
|
|
9
|
+
import { remdupsRl } from "../pure/drule";
|
|
10
|
+
import { selectGoal } from "../pure/goal";
|
|
11
|
+
import { deepen } from "../pure/search";
|
|
12
|
+
import { stripAssumsConcl, stripAssumsHyp } from "../pure/logic";
|
|
13
|
+
import type { Limits } from "../pure/interrupt";
|
|
14
|
+
import {
|
|
15
|
+
assumeTac,
|
|
16
|
+
biresolutionFromNetsTac,
|
|
17
|
+
eqAssumeTac,
|
|
18
|
+
ematchTac,
|
|
19
|
+
type NetPair,
|
|
20
|
+
} from "../pure/tactic";
|
|
21
|
+
import {
|
|
22
|
+
appendGoal,
|
|
23
|
+
noTac,
|
|
24
|
+
orElse,
|
|
25
|
+
orElseGoal,
|
|
26
|
+
repeatDeterm1,
|
|
27
|
+
repeatDetermN,
|
|
28
|
+
subgoal,
|
|
29
|
+
thenAllNew,
|
|
30
|
+
thenTac,
|
|
31
|
+
type GoalTactic,
|
|
32
|
+
} from "../pure/tactical";
|
|
33
|
+
import { aconv, type Term } from "../pure/term";
|
|
34
|
+
import type { BiresRule, Thm } from "../pure/thm";
|
|
35
|
+
|
|
36
|
+
export interface ContextRule {
|
|
37
|
+
readonly weight: number;
|
|
38
|
+
readonly tag: number;
|
|
39
|
+
readonly isElim: boolean;
|
|
40
|
+
readonly rule: Thm;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface IntuitionisticContext {
|
|
44
|
+
readonly limits: Limits;
|
|
45
|
+
// Context_Rules.netpair_bang and Context_Rules.netpair.
|
|
46
|
+
readonly safeRules: NetPair<ContextRule>;
|
|
47
|
+
readonly rules: NetPair<ContextRule>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface Visited {
|
|
51
|
+
readonly hyps: readonly Term[];
|
|
52
|
+
readonly concl: Term;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Context_Rules.orderlist: by weight, then by tag, dropping all but the last of equal keys.
|
|
56
|
+
const orderRules = (rules: ContextRule[]): BiresRule[] => {
|
|
57
|
+
const sorted = [...rules].sort(
|
|
58
|
+
(left, right) => left.weight - right.weight || left.tag - right.tag,
|
|
59
|
+
);
|
|
60
|
+
return sorted
|
|
61
|
+
.filter(
|
|
62
|
+
(rule, index) =>
|
|
63
|
+
index + 1 >= sorted.length ||
|
|
64
|
+
sorted[index + 1].weight !== rule.weight ||
|
|
65
|
+
sorted[index + 1].tag !== rule.tag,
|
|
66
|
+
)
|
|
67
|
+
.map((rule) => ({ isElim: rule.isElim, rule: rule.rule }));
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const countDistinct = (terms: readonly Term[]) =>
|
|
71
|
+
terms.reduce<Term[]>(
|
|
72
|
+
(result, term) => (result.some((other) => aconv(other, term)) ? result : [...result, term]),
|
|
73
|
+
[],
|
|
74
|
+
).length;
|
|
75
|
+
|
|
76
|
+
const isSubset = (left: readonly Term[], right: readonly Term[]) =>
|
|
77
|
+
left.every((term) => right.some((other) => aconv(term, other)));
|
|
78
|
+
|
|
79
|
+
const remdupsTac = (limits: Limits): GoalTactic =>
|
|
80
|
+
subgoal((goal, index) => {
|
|
81
|
+
const prems = stripAssumsHyp(goal);
|
|
82
|
+
return repeatDetermN(
|
|
83
|
+
prems.length - countDistinct(prems),
|
|
84
|
+
thenTac(ematchTac(limits, [remdupsRl])(index), eqAssumeTac(index)),
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const stepTac = (context: IntuitionisticContext): GoalTactic => {
|
|
89
|
+
const limits = context.limits;
|
|
90
|
+
const biresTac = (match: boolean, netpair: NetPair<ContextRule>) =>
|
|
91
|
+
biresolutionFromNetsTac(limits, orderRules, match, netpair);
|
|
92
|
+
const safeStepTac = thenAllNew(
|
|
93
|
+
orElseGoal(eqAssumeTac, biresTac(true, context.safeRules)),
|
|
94
|
+
remdupsTac(limits),
|
|
95
|
+
);
|
|
96
|
+
const unsafeStepTac = thenAllNew(
|
|
97
|
+
appendGoal(
|
|
98
|
+
assumeTac(limits),
|
|
99
|
+
appendGoal(biresTac(false, context.safeRules), biresTac(false, context.rules)),
|
|
100
|
+
),
|
|
101
|
+
remdupsTac(limits),
|
|
102
|
+
);
|
|
103
|
+
return (index) => orElse(repeatDeterm1(safeStepTac(index)), unsafeStepTac(index));
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const intproverTac = (
|
|
107
|
+
context: IntuitionisticContext,
|
|
108
|
+
visited: readonly Visited[],
|
|
109
|
+
depth: number,
|
|
110
|
+
limit: number,
|
|
111
|
+
): GoalTactic =>
|
|
112
|
+
subgoal((goal, index) => {
|
|
113
|
+
if (depth > limit) return noTac;
|
|
114
|
+
const hyps = stripAssumsHyp(goal);
|
|
115
|
+
const concl = stripAssumsConcl(goal);
|
|
116
|
+
const isVisited = visited.some(
|
|
117
|
+
(other) =>
|
|
118
|
+
aconv(other.concl, concl) &&
|
|
119
|
+
other.hyps.length === hyps.length &&
|
|
120
|
+
isSubset(other.hyps, hyps) &&
|
|
121
|
+
isSubset(hyps, other.hyps),
|
|
122
|
+
);
|
|
123
|
+
if (isVisited) return noTac;
|
|
124
|
+
return thenAllNew(
|
|
125
|
+
stepTac(context),
|
|
126
|
+
intproverTac(context, [{ hyps, concl }, ...visited], depth + 1, limit),
|
|
127
|
+
)(index);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Intuitionistic.prover_tac with the default depth limit.
|
|
131
|
+
export const proverTac = (context: IntuitionisticContext): GoalTactic =>
|
|
132
|
+
selectGoal(deepen(2, 20, (limit) => intproverTac(context, [], 0, limit), 4)(1));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// The parts of OCaml's standard library whose exact order steers what tlapm prints.
|
|
2
|
+
|
|
3
|
+
type OcamlValue = number | string | OcamlValue[];
|
|
4
|
+
|
|
5
|
+
// String.compare: byte by byte, on the UTF-8 bytes. Code units order the same way for the ASCII
|
|
6
|
+
// names tlapm compares.
|
|
7
|
+
export const compareStrings = (left: string, right: string) =>
|
|
8
|
+
left < right ? -1 : left > right ? 1 : 0;
|
|
9
|
+
|
|
10
|
+
// Stdlib.compare on ints, strings, and lists, where a list is smaller than any longer list it
|
|
11
|
+
// starts.
|
|
12
|
+
export const compareValues = (left: OcamlValue, right: OcamlValue): number => {
|
|
13
|
+
if (typeof left === "number" && typeof right === "number") return left - right;
|
|
14
|
+
if (typeof left === "string" && typeof right === "string") return compareStrings(left, right);
|
|
15
|
+
if (!Array.isArray(left) || !Array.isArray(right)) return 0;
|
|
16
|
+
const index = left.findIndex(
|
|
17
|
+
(item, position) => position >= right.length || compareValues(item, right[position]) !== 0,
|
|
18
|
+
);
|
|
19
|
+
if (index === -1) return left.length - right.length;
|
|
20
|
+
if (index >= right.length) return 1;
|
|
21
|
+
return compareValues(left[index], right[index]);
|
|
22
|
+
};
|