tla-ts 0.0.4-dev.81d0769 → 0.0.4-dev.8fefa42
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 +62 -70
- 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 +515 -0
- package/dist/prove.js +515 -0
- package/dist/run-cli.cjs +30 -47
- package/dist/run-cli.js +30 -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/errors.ts +86 -0
- package/src/evaluate.ts +29 -8
- package/src/index.ts +10 -0
- package/src/{obligation-action.ts → obligations/action.ts} +258 -37
- package/src/{obligation-anon.ts → obligations/anon.ts} +13 -7
- package/src/obligations/ctx.ts +64 -0
- package/src/{obligation-deref.ts → obligations/deref.ts} +2 -2
- package/src/{obligation-expression.ts → obligations/expression.ts} +54 -8
- package/src/{obligation-generate.ts → obligations/generate.ts} +134 -61
- package/src/{obligations.ts → obligations/index.ts} +26 -12
- package/src/{obligation-levels.ts → obligations/levels.ts} +12 -2
- package/src/{obligation-module.ts → obligations/module.ts} +46 -20
- package/src/obligations/pickle.ts +100 -0
- package/src/obligations/pragma.ts +189 -0
- package/src/{obligation-printer.ts → obligations/printer.ts} +5 -59
- package/src/{obligation-proof.ts → obligations/proof.ts} +7 -1
- package/src/{obligation-source.ts → obligations/source.ts} +91 -35
- package/src/obligations/temporal.ts +319 -0
- package/src/{obligation-tuples.ts → obligations/tuples.ts} +1 -1
- 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 +27 -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 +477 -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 +520 -0
- package/src/prove/prep/defs.ts +27 -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 +552 -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 +29 -0
- package/src/prove/prove.ts +417 -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 +210 -0
- package/src/prove/smt/context.ts +108 -0
- package/src/prove/smt/data.ts +665 -0
- package/src/prove/smt/encode.ts +169 -0
- package/src/prove/smt/extensionality.ts +63 -0
- package/src/prove/smt/flatten.ts +127 -0
- package/src/prove/smt/format.ts +143 -0
- package/src/prove/smt/instances.ts +182 -0
- package/src/prove/smt/rewrite.ts +784 -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 +13 -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 +444 -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 +73 -20
- package/src/successors.ts +24 -5
- package/src/tlc-version.ts +8 -7
- package/src/values.ts +8 -3
- package/src/worker.ts +65 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
- /package/src/{obligation-format.ts → obligations/format.ts} +0 -0
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
// Ported from Isabelle2025's Provers/hypsubst.ML. Copyright (c) 1986-2025 University of
|
|
2
|
+
// Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
|
|
3
|
+
//
|
|
4
|
+
// Substitution using an equality assumption x = t: eliminates x from the subgoal.
|
|
5
|
+
|
|
6
|
+
import { TlaIsabelleError } from "../../../errors";
|
|
7
|
+
import { asmRl, compIncr, revcutRl, thinRl, zeroVarIndexes } from "../pure/drule";
|
|
8
|
+
import { aeconv, etaContract } from "../pure/envir";
|
|
9
|
+
import { occs, stripAssumsConcl, stripAssumsHyp, stripParams } from "../pure/logic";
|
|
10
|
+
import { isBoundName } from "../pure/name";
|
|
11
|
+
import { emptySimpset, type SimpContext } from "../pure/raw-simplifier";
|
|
12
|
+
import { listOfSeq } from "../pure/seq";
|
|
13
|
+
import { asmLrSimpTac } from "../pure/simplifier";
|
|
14
|
+
import {
|
|
15
|
+
determ,
|
|
16
|
+
every,
|
|
17
|
+
firstGoal,
|
|
18
|
+
noTac,
|
|
19
|
+
orElseGoal,
|
|
20
|
+
repeatDetermN,
|
|
21
|
+
repeatDeterm1,
|
|
22
|
+
subgoal,
|
|
23
|
+
thenTac,
|
|
24
|
+
allTac,
|
|
25
|
+
type GoalTactic,
|
|
26
|
+
type Tactic,
|
|
27
|
+
} from "../pure/tactical";
|
|
28
|
+
import type { Limits } from "../pure/interrupt";
|
|
29
|
+
import { composeTac, ematchTac, eresolveTac, resolveTac, rotateTac } from "../pure/tactic";
|
|
30
|
+
import {
|
|
31
|
+
abstractOver,
|
|
32
|
+
binderTypes,
|
|
33
|
+
bodyType,
|
|
34
|
+
flagsOf,
|
|
35
|
+
HAS_VAR,
|
|
36
|
+
existsType,
|
|
37
|
+
fastypeOf1,
|
|
38
|
+
funTs,
|
|
39
|
+
headOf,
|
|
40
|
+
incrBoundvars,
|
|
41
|
+
looseBvar1,
|
|
42
|
+
maxidxOfTyp,
|
|
43
|
+
mkAbs,
|
|
44
|
+
mkBound,
|
|
45
|
+
mkVar,
|
|
46
|
+
substBounds,
|
|
47
|
+
type Term,
|
|
48
|
+
} from "../pure/term";
|
|
49
|
+
import { emptyTyEnv, matchTypes, substType } from "../pure/type";
|
|
50
|
+
import {
|
|
51
|
+
assumption,
|
|
52
|
+
instantiate,
|
|
53
|
+
instantiateTypes,
|
|
54
|
+
liftRule,
|
|
55
|
+
premOf,
|
|
56
|
+
premsOf,
|
|
57
|
+
rs,
|
|
58
|
+
rsn,
|
|
59
|
+
symmetric,
|
|
60
|
+
type Thm,
|
|
61
|
+
} from "../pure/thm";
|
|
62
|
+
|
|
63
|
+
export interface HypsubstData {
|
|
64
|
+
readonly destTrueprop: (term: Term) => Term;
|
|
65
|
+
readonly destEq: (term: Term) => [Term, Term];
|
|
66
|
+
readonly destImp: (term: Term) => [Term, Term];
|
|
67
|
+
readonly eqReflection: Thm;
|
|
68
|
+
readonly revEqReflection: Thm;
|
|
69
|
+
readonly impIntr: Thm;
|
|
70
|
+
readonly revMp: Thm;
|
|
71
|
+
readonly subst: Thm;
|
|
72
|
+
readonly sym: Thm;
|
|
73
|
+
readonly thinRefl: Thm;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface HypsubstContext {
|
|
77
|
+
readonly limits: Limits;
|
|
78
|
+
readonly data: HypsubstData;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// The equality offers no variable to eliminate.
|
|
82
|
+
class NoMatch {}
|
|
83
|
+
// The subgoal has no suitable equality.
|
|
84
|
+
class EqVar {}
|
|
85
|
+
|
|
86
|
+
const isTermError = (error: unknown) =>
|
|
87
|
+
error instanceof TlaIsabelleError && error.exception === "TERM";
|
|
88
|
+
const isThmError = (error: unknown) =>
|
|
89
|
+
error instanceof TlaIsabelleError && error.exception === "THM";
|
|
90
|
+
|
|
91
|
+
// The simplifier turns bound variables into special free variables; any bound variable will do.
|
|
92
|
+
const inspectContract = (term: Term) => {
|
|
93
|
+
const contracted = etaContract(term);
|
|
94
|
+
return contracted.kind === "Free" && isBoundName(contracted.name) ? mkBound(0) : contracted;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const hasVars = (term: Term) => (flagsOf(term) & HAS_VAR) !== 0;
|
|
98
|
+
const hasTVars = (term: Term) => existsType((type) => maxidxOfTyp(type) >= 0, term);
|
|
99
|
+
|
|
100
|
+
// inspect_pair: true to use the equality as it is, false to reorient it first, with the variable
|
|
101
|
+
// to substitute.
|
|
102
|
+
const inspectPair = (
|
|
103
|
+
isBound: boolean,
|
|
104
|
+
isNoVars: boolean,
|
|
105
|
+
left: Term,
|
|
106
|
+
right: Term,
|
|
107
|
+
): [boolean, Term] => {
|
|
108
|
+
if (isNoVars && (hasTVars(left) || hasTVars(right))) throw new NoMatch();
|
|
109
|
+
const leftContracted = inspectContract(left);
|
|
110
|
+
const rightContracted = inspectContract(right);
|
|
111
|
+
if (leftContracted.kind === "Bound") {
|
|
112
|
+
if (looseBvar1(right, leftContracted.index) || (isNoVars && hasVars(right)))
|
|
113
|
+
throw new NoMatch();
|
|
114
|
+
return [true, leftContracted];
|
|
115
|
+
}
|
|
116
|
+
if (rightContracted.kind === "Bound") {
|
|
117
|
+
if (looseBvar1(left, rightContracted.index) || (isNoVars && hasVars(left))) throw new NoMatch();
|
|
118
|
+
return [false, rightContracted];
|
|
119
|
+
}
|
|
120
|
+
if (leftContracted.kind === "Free") {
|
|
121
|
+
if (isBound || occs(leftContracted, right) || (isNoVars && hasVars(right))) throw new NoMatch();
|
|
122
|
+
return [true, leftContracted];
|
|
123
|
+
}
|
|
124
|
+
if (rightContracted.kind === "Free") {
|
|
125
|
+
if (isBound || occs(rightContracted, left) || (isNoVars && hasVars(left))) throw new NoMatch();
|
|
126
|
+
return [false, rightContracted];
|
|
127
|
+
}
|
|
128
|
+
throw new NoMatch();
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// eq_var: the number of assumptions before a substitutable equality, its orientation, and whether
|
|
132
|
+
// it eliminates a free variable.
|
|
133
|
+
const eqVar = (
|
|
134
|
+
data: HypsubstData,
|
|
135
|
+
isBound: boolean,
|
|
136
|
+
isNoVars: boolean,
|
|
137
|
+
isCheckingFrees: boolean,
|
|
138
|
+
goal: Term,
|
|
139
|
+
) => {
|
|
140
|
+
const checkFree = (
|
|
141
|
+
terms: readonly Term[],
|
|
142
|
+
orientation: boolean,
|
|
143
|
+
variable: Term,
|
|
144
|
+
): [boolean, boolean] => {
|
|
145
|
+
if (variable.kind !== "Free") return [orientation, false];
|
|
146
|
+
if (!isCheckingFrees || !orientation || terms.some((term) => occs(variable, term)))
|
|
147
|
+
return [orientation, true];
|
|
148
|
+
throw new NoMatch();
|
|
149
|
+
};
|
|
150
|
+
const visit = (
|
|
151
|
+
count: number,
|
|
152
|
+
term: Term,
|
|
153
|
+
hyps: readonly Term[],
|
|
154
|
+
): [number, [boolean, boolean]] => {
|
|
155
|
+
if (
|
|
156
|
+
term.kind === "App" &&
|
|
157
|
+
term.fun.kind === "Const" &&
|
|
158
|
+
term.fun.name === "Pure.all" &&
|
|
159
|
+
term.arg.kind === "Abs"
|
|
160
|
+
)
|
|
161
|
+
return visit(count, term.arg.body, hyps);
|
|
162
|
+
if (
|
|
163
|
+
term.kind === "App" &&
|
|
164
|
+
term.fun.kind === "App" &&
|
|
165
|
+
term.fun.fun.kind === "Const" &&
|
|
166
|
+
term.fun.fun.name === "Pure.imp"
|
|
167
|
+
) {
|
|
168
|
+
const premise = term.fun.arg;
|
|
169
|
+
const conclusion = term.arg;
|
|
170
|
+
try {
|
|
171
|
+
const [left, right] = data.destEq(data.destTrueprop(premise));
|
|
172
|
+
const [orientation, variable] = inspectPair(isBound, isNoVars, left, right);
|
|
173
|
+
return [count, checkFree([conclusion, ...hyps], orientation, variable)];
|
|
174
|
+
} catch (error) {
|
|
175
|
+
if (!isTermError(error) && !(error instanceof NoMatch)) throw error;
|
|
176
|
+
return visit(count + 1, conclusion, [premise, ...hyps]);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
throw new EqVar();
|
|
180
|
+
};
|
|
181
|
+
return visit(0, goal, []);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const withEqVar = (build: (goal: Term, index: number) => Tactic): GoalTactic =>
|
|
185
|
+
subgoal((goal, index) => {
|
|
186
|
+
try {
|
|
187
|
+
return build(goal, index);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (error instanceof EqVar || isThmError(error)) return noTac;
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// mk_eqs: the equality as a rewrite rule that eliminates its variable.
|
|
195
|
+
const mkEqs = (data: HypsubstData, isBound: boolean, thm: Thm): Thm[] => {
|
|
196
|
+
try {
|
|
197
|
+
const [left, right] = data.destEq(data.destTrueprop(thm.prop));
|
|
198
|
+
return inspectPair(isBound, false, left, right)[0]
|
|
199
|
+
? [rs(thm, data.eqReflection)]
|
|
200
|
+
: [symmetric(rs(thm, data.eqReflection))];
|
|
201
|
+
} catch (error) {
|
|
202
|
+
if (isTermError(error) || error instanceof NoMatch) return [];
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const genHypSubstTac = (context: HypsubstContext, isBound: boolean): GoalTactic =>
|
|
208
|
+
withEqVar((goal, index) => {
|
|
209
|
+
const [count, [orientation, isFree]] = eqVar(context.data, isBound, true, true, goal);
|
|
210
|
+
const simpContext: SimpContext = {
|
|
211
|
+
limits: context.limits,
|
|
212
|
+
simpset: {
|
|
213
|
+
...emptySimpset,
|
|
214
|
+
mkRews: { mk: (thm) => mkEqs(context.data, isBound, thm), mkEqTrue: () => undefined },
|
|
215
|
+
},
|
|
216
|
+
bounds: 0,
|
|
217
|
+
};
|
|
218
|
+
return every([
|
|
219
|
+
rotateTac(count)(index),
|
|
220
|
+
asmLrSimpTac(simpContext)(index),
|
|
221
|
+
!isFree
|
|
222
|
+
? eresolveTac(context.limits, [thinRl])(index)
|
|
223
|
+
: orientation
|
|
224
|
+
? eresolveTac(context.limits, [context.data.revMp])(index)
|
|
225
|
+
: eresolveTac(context.limits, [rs(context.data.sym, context.data.revMp)])(index),
|
|
226
|
+
rotateTac(-count)(index),
|
|
227
|
+
isFree ? resolveTac(context.limits, [context.data.impIntr])(index) : allTac,
|
|
228
|
+
]);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const getSsubst = (data: HypsubstData) => zeroVarIndexes(rs(data.sym, data.subst));
|
|
232
|
+
|
|
233
|
+
const instSubstTac = (context: HypsubstContext, isLeft: boolean, rule: Thm): GoalTactic =>
|
|
234
|
+
subgoal((goal, index) => (state) => {
|
|
235
|
+
const data = context.data;
|
|
236
|
+
const sides = (() => {
|
|
237
|
+
try {
|
|
238
|
+
const hyp = stripAssumsHyp(goal)[0];
|
|
239
|
+
if (hyp === undefined) return undefined;
|
|
240
|
+
const [left, right] = data.destEq(data.destTrueprop(hyp));
|
|
241
|
+
return [etaContract(left), etaContract(right)] as const;
|
|
242
|
+
} catch (error) {
|
|
243
|
+
if (isTermError(error)) return undefined;
|
|
244
|
+
throw error;
|
|
245
|
+
}
|
|
246
|
+
})();
|
|
247
|
+
if (sides === undefined) return noTac(state);
|
|
248
|
+
const [left, right] = sides;
|
|
249
|
+
const params = stripParams(goal);
|
|
250
|
+
const paramType = fastypeOf1(
|
|
251
|
+
[...params].reverse().map((param) => param.type),
|
|
252
|
+
left,
|
|
253
|
+
);
|
|
254
|
+
const conclusion = data.destTrueprop(stripAssumsConcl(goal));
|
|
255
|
+
const lifted = liftRule(goal, state.maxidx, rule);
|
|
256
|
+
const head = headOf(data.destTrueprop(stripAssumsConcl(lifted.prop)));
|
|
257
|
+
const [v1, v2] = data.destEq(data.destTrueprop(stripAssumsConcl(premsOf(lifted)[0])));
|
|
258
|
+
if (head.kind !== "Var") throw new TlaIsabelleError("TERM", "dest_Var");
|
|
259
|
+
const binders = binderTypes(head.type);
|
|
260
|
+
const paramTypes = binders.slice(0, -1);
|
|
261
|
+
const lastType = binders[binders.length - 1];
|
|
262
|
+
const absParams = (body: Term) =>
|
|
263
|
+
params.reduceRight((result, param) => mkAbs(param.name, param.type, result), body);
|
|
264
|
+
const chosen = isLeft ? left : right;
|
|
265
|
+
const body =
|
|
266
|
+
chosen.kind === "Bound"
|
|
267
|
+
? substBounds(
|
|
268
|
+
[
|
|
269
|
+
...Array.from({ length: chosen.index }, (_, position) => mkBound(position + 1)),
|
|
270
|
+
mkBound(0),
|
|
271
|
+
...Array.from({ length: params.length - chosen.index - 1 }, (_, position) =>
|
|
272
|
+
mkBound(chosen.index + 2 + position),
|
|
273
|
+
),
|
|
274
|
+
],
|
|
275
|
+
conclusion,
|
|
276
|
+
)
|
|
277
|
+
: abstractOver(chosen, incrBoundvars(1, conclusion));
|
|
278
|
+
const motive = absParams(mkAbs("x", paramType, body));
|
|
279
|
+
const tyenv = matchTypes(lastType, paramType, emptyTyEnv);
|
|
280
|
+
if (tyenv === undefined) throw new TlaIsabelleError("TYPE", "Thm.match");
|
|
281
|
+
const headV1 = headOf(v1);
|
|
282
|
+
const headV2 = headOf(v2);
|
|
283
|
+
if (headV1.kind !== "Var" || headV2.kind !== "Var")
|
|
284
|
+
throw new TlaIsabelleError("TERM", "dest_Var");
|
|
285
|
+
const instantiated = instantiate(
|
|
286
|
+
[
|
|
287
|
+
{
|
|
288
|
+
variable: mkVar(
|
|
289
|
+
head.name,
|
|
290
|
+
head.index,
|
|
291
|
+
funTs(
|
|
292
|
+
[...paramTypes.map((type) => substType(tyenv, type)), paramType],
|
|
293
|
+
substType(tyenv, bodyType(head.type)),
|
|
294
|
+
),
|
|
295
|
+
),
|
|
296
|
+
term: motive,
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
variable: mkVar(
|
|
300
|
+
headV1.name,
|
|
301
|
+
headV1.index,
|
|
302
|
+
funTs(
|
|
303
|
+
paramTypes.map((type) => substType(tyenv, type)),
|
|
304
|
+
paramType,
|
|
305
|
+
),
|
|
306
|
+
),
|
|
307
|
+
term: absParams(left),
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
variable: mkVar(
|
|
311
|
+
headV2.name,
|
|
312
|
+
headV2.index,
|
|
313
|
+
funTs(
|
|
314
|
+
paramTypes.map((type) => substType(tyenv, type)),
|
|
315
|
+
paramType,
|
|
316
|
+
),
|
|
317
|
+
),
|
|
318
|
+
term: absParams(right),
|
|
319
|
+
},
|
|
320
|
+
],
|
|
321
|
+
instantiateTypes(tyenv, lifted),
|
|
322
|
+
);
|
|
323
|
+
return composeTac(
|
|
324
|
+
context.limits,
|
|
325
|
+
true,
|
|
326
|
+
compIncr(instantiated, asmRl),
|
|
327
|
+
premsOf(rule).length,
|
|
328
|
+
)(index)(state);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
const varsGenHypSubstTac = (context: HypsubstContext, isBound: boolean): GoalTactic =>
|
|
332
|
+
withEqVar((goal, index) => {
|
|
333
|
+
const count = stripAssumsHyp(goal).length - 1;
|
|
334
|
+
const [position, [orientation, isFree]] = eqVar(context.data, isBound, false, true, goal);
|
|
335
|
+
const ssubst = getSsubst(context.data);
|
|
336
|
+
const base = isFree ? revDupElim(ssubst) : ssubst;
|
|
337
|
+
const rule = orientation ? base : rs(context.data.sym, base);
|
|
338
|
+
return determ(
|
|
339
|
+
every([
|
|
340
|
+
repeatDetermN(position, eresolveTac(context.limits, [context.data.revMp])(index)),
|
|
341
|
+
rotateTac(1)(index),
|
|
342
|
+
repeatDetermN(count - position, eresolveTac(context.limits, [context.data.revMp])(index)),
|
|
343
|
+
instSubstTac(context, orientation, rule)(index),
|
|
344
|
+
repeatDetermN(
|
|
345
|
+
count,
|
|
346
|
+
thenTac(resolveTac(context.limits, [context.data.impIntr])(index), rotateTac(-1)(index)),
|
|
347
|
+
),
|
|
348
|
+
]),
|
|
349
|
+
);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
const revDupElim = (thm: Thm) => {
|
|
353
|
+
const result = listOfSeq(assumption(undefined, 2, rsn(thm, 2, revcutRl)))[0];
|
|
354
|
+
if (result === undefined) throw new TlaIsabelleError("THM", "rev_dup_elim");
|
|
355
|
+
return result;
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
// hyp_subst_tac with hypsubst_thin off, its default: substitutes for free or bound variables and
|
|
359
|
+
// drops equalities on bound variables.
|
|
360
|
+
export const hypSubstTac =
|
|
361
|
+
(context: HypsubstContext): GoalTactic =>
|
|
362
|
+
(index) =>
|
|
363
|
+
repeatDeterm1(
|
|
364
|
+
firstGoal([
|
|
365
|
+
ematchTac(context.limits, [context.data.thinRefl]),
|
|
366
|
+
genHypSubstTac(context, false),
|
|
367
|
+
varsGenHypSubstTac(context, false),
|
|
368
|
+
])(index),
|
|
369
|
+
);
|
|
370
|
+
|
|
371
|
+
export const boundHypSubstTac =
|
|
372
|
+
(context: HypsubstContext): GoalTactic =>
|
|
373
|
+
(index) =>
|
|
374
|
+
repeatDeterm1(
|
|
375
|
+
orElseGoal(genHypSubstTac(context, true), varsGenHypSubstTac(context, true))(index),
|
|
376
|
+
);
|
|
377
|
+
|
|
378
|
+
const reverseNTac = (context: HypsubstContext, count: number, index: number): Tactic =>
|
|
379
|
+
count === 0
|
|
380
|
+
? allTac
|
|
381
|
+
: count === 1
|
|
382
|
+
? rotateTac(-1)(index)
|
|
383
|
+
: thenTac(
|
|
384
|
+
repeatDetermN(
|
|
385
|
+
count,
|
|
386
|
+
thenTac(rotateTac(-1)(index), eresolveTac(context.limits, [context.data.revMp])(index)),
|
|
387
|
+
),
|
|
388
|
+
repeatDetermN(
|
|
389
|
+
count,
|
|
390
|
+
thenTac(
|
|
391
|
+
resolveTac(context.limits, [context.data.impIntr])(index),
|
|
392
|
+
rotateTac(-1)(index),
|
|
393
|
+
),
|
|
394
|
+
),
|
|
395
|
+
);
|
|
396
|
+
|
|
397
|
+
// all_imp_intr_tac: reintroduces the hypotheses, leaving the changed ones at the end.
|
|
398
|
+
const allImpIntrTac = (context: HypsubstContext, hyps: readonly Term[], index: number): Tactic => {
|
|
399
|
+
const imptac =
|
|
400
|
+
(count: number, remaining: readonly Term[]): Tactic =>
|
|
401
|
+
(state) => {
|
|
402
|
+
if (remaining.length === 0) return reverseNTac(context, count, index)(state);
|
|
403
|
+
const [hyp] = context.data.destImp(
|
|
404
|
+
context.data.destTrueprop(stripAssumsConcl(premOf(state, index))),
|
|
405
|
+
);
|
|
406
|
+
const isSame = aeconv(remaining[0], hyp);
|
|
407
|
+
const tactic = isSame
|
|
408
|
+
? thenTac(resolveTac(context.limits, [context.data.impIntr])(index), rotateTac(-1)(index))
|
|
409
|
+
: resolveTac(context.limits, [context.data.impIntr])(index);
|
|
410
|
+
const cell = tactic(state).pull();
|
|
411
|
+
return cell === undefined
|
|
412
|
+
? allTac(state)
|
|
413
|
+
: imptac(isSame ? count : count + 1, remaining.slice(1))(cell[0]);
|
|
414
|
+
};
|
|
415
|
+
return imptac(0, [...hyps].reverse());
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
// blast_hyp_subst_tac: the version for blast, which moves the hypotheses the substitution changes
|
|
419
|
+
// to the front.
|
|
420
|
+
export const blastHypSubstTac = (context: HypsubstContext): GoalTactic =>
|
|
421
|
+
withEqVar((goal, index) => {
|
|
422
|
+
const [count, [orientation]] = eqVar(context.data, false, false, false, goal);
|
|
423
|
+
const allHyps = stripAssumsHyp(goal).map(context.data.destTrueprop);
|
|
424
|
+
const hyps = [...allHyps.slice(0, count), ...allHyps.slice(count + 1)];
|
|
425
|
+
return determ(
|
|
426
|
+
every([
|
|
427
|
+
repeatDetermN(count, eresolveTac(context.limits, [context.data.revMp])(index)),
|
|
428
|
+
rotateTac(1)(index),
|
|
429
|
+
repeatDetermN(
|
|
430
|
+
hyps.length - count,
|
|
431
|
+
eresolveTac(context.limits, [context.data.revMp])(index),
|
|
432
|
+
),
|
|
433
|
+
instSubstTac(
|
|
434
|
+
context,
|
|
435
|
+
orientation,
|
|
436
|
+
orientation ? getSsubst(context.data) : context.data.subst,
|
|
437
|
+
)(index),
|
|
438
|
+
allImpIntrTac(context, hyps, index),
|
|
439
|
+
]),
|
|
440
|
+
);
|
|
441
|
+
});
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// Ported from Isabelle2025's Pure/thm.ML. Copyright (c) 1986-2025 University of Cambridge,
|
|
2
|
+
// Technische Universitaet Muenchen, and contributors, see LICENSE.
|
|
3
|
+
//
|
|
4
|
+
// The term operations behind Thm.bicompose, which builds the theorem itself in thm.ts.
|
|
5
|
+
|
|
6
|
+
import { TlaIsabelleError } from "../../../errors";
|
|
7
|
+
import { normTerm, type Envir } from "./envir";
|
|
8
|
+
import { allConst, mkImplies } from "./logic";
|
|
9
|
+
import { unifyTypesEnvir } from "./pattern";
|
|
10
|
+
import type { Thm } from "./thm";
|
|
11
|
+
import { normType } from "./type";
|
|
12
|
+
import { eqTyp, foldVars, matchBvars, mkAbs, mkApp, mkVar, type Term, type Typ } from "./term";
|
|
13
|
+
import type { Tpair } from "./unify";
|
|
14
|
+
|
|
15
|
+
const isImpApp = (
|
|
16
|
+
term: Term,
|
|
17
|
+
): term is Extract<Term, { kind: "App" }> & { fun: Extract<Term, { kind: "App" }> } =>
|
|
18
|
+
term.kind === "App" &&
|
|
19
|
+
term.fun.kind === "App" &&
|
|
20
|
+
term.fun.fun.kind === "Const" &&
|
|
21
|
+
term.fun.fun.name === "Pure.imp";
|
|
22
|
+
|
|
23
|
+
const isAllApp = (
|
|
24
|
+
term: Term,
|
|
25
|
+
): term is Extract<Term, { kind: "App" }> & { arg: Extract<Term, { kind: "Abs" }> } =>
|
|
26
|
+
term.kind === "App" &&
|
|
27
|
+
term.fun.kind === "Const" &&
|
|
28
|
+
term.fun.name === "Pure.all" &&
|
|
29
|
+
term.arg.kind === "Abs";
|
|
30
|
+
|
|
31
|
+
export const stripApply = (apply: (term: Term) => Term, lifted: Term, term: Term): Term => {
|
|
32
|
+
if (isImpApp(lifted) && isImpApp(term))
|
|
33
|
+
return mkApp(mkApp(lifted.fun.fun, term.fun.arg), stripApply(apply, lifted.arg, term.arg));
|
|
34
|
+
if (isAllApp(lifted) && isAllApp(term))
|
|
35
|
+
return mkApp(
|
|
36
|
+
lifted.fun,
|
|
37
|
+
mkAbs(term.arg.name, term.arg.type, stripApply(apply, lifted.arg.body, term.arg.body)),
|
|
38
|
+
);
|
|
39
|
+
return apply(term);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const stripLifted = (lifted: Term, term: Term): Term => {
|
|
43
|
+
if (isImpApp(lifted) && isImpApp(term)) return stripLifted(lifted.arg, term.arg);
|
|
44
|
+
if (isAllApp(lifted) && isAllApp(term)) return stripLifted(lifted.arg.body, term.arg.body);
|
|
45
|
+
return term;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const addVarNames = (term: Term, names: Set<string>) =>
|
|
49
|
+
foldVars((atom, result: Set<string>) => result.add(atom.name), term, names);
|
|
50
|
+
|
|
51
|
+
const makeDistinct = (pairs: readonly [string, string][]) => {
|
|
52
|
+
const table = new Map<string, string>();
|
|
53
|
+
for (const pair of pairs) if (!table.has(pair[0])) table.set(pair[0], pair[1]);
|
|
54
|
+
return table;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Thm.rename_bvars: renames bound variables and some unknowns of the new premises after the
|
|
58
|
+
// names in the disagreement pairs.
|
|
59
|
+
export const renameBvars = (
|
|
60
|
+
dpairs: readonly Tpair[],
|
|
61
|
+
tpairs: readonly Tpair[],
|
|
62
|
+
lifted: Term,
|
|
63
|
+
premises: readonly Term[],
|
|
64
|
+
): ((term: Term) => Term) | undefined => {
|
|
65
|
+
const pairs = dpairs.reduceRight<[string, string][]>(
|
|
66
|
+
(result, pair) => matchBvars(pair[0], pair[1], result),
|
|
67
|
+
[],
|
|
68
|
+
);
|
|
69
|
+
if (pairs.length === 0) return undefined;
|
|
70
|
+
const unknowns = new Set<string>();
|
|
71
|
+
for (const pair of dpairs) addVarNames(pair[0], unknowns);
|
|
72
|
+
for (const pair of tpairs) {
|
|
73
|
+
addVarNames(pair[0], unknowns);
|
|
74
|
+
addVarNames(pair[1], unknowns);
|
|
75
|
+
}
|
|
76
|
+
const premiseUnknowns = new Set<string>();
|
|
77
|
+
for (const premise of premises) addVarNames(stripLifted(lifted, premise), premiseUnknowns);
|
|
78
|
+
const filtered = pairs.filter(
|
|
79
|
+
(pair) => premiseUnknowns.has(pair[0]) && !unknowns.has(pair[0]) && !unknowns.has(pair[1]),
|
|
80
|
+
);
|
|
81
|
+
const distinct = filtered.filter(
|
|
82
|
+
(pair, position) => filtered.findIndex((other) => other[0] === pair[0]) === position,
|
|
83
|
+
);
|
|
84
|
+
const unchanged = new Set(
|
|
85
|
+
[...premiseUnknowns].filter((name) => !distinct.some((pair) => pair[0] === name)),
|
|
86
|
+
);
|
|
87
|
+
const delClashing = (
|
|
88
|
+
isClash: boolean,
|
|
89
|
+
xs: Set<string>,
|
|
90
|
+
ys: Set<string>,
|
|
91
|
+
rest: readonly [string, string][],
|
|
92
|
+
kept: [string, string][],
|
|
93
|
+
): [string, string][] => {
|
|
94
|
+
if (rest.length === 0) return isClash ? delClashing(false, xs, new Set(xs), kept, []) : kept;
|
|
95
|
+
const [pair, ...others] = rest;
|
|
96
|
+
if (ys.has(pair[1]))
|
|
97
|
+
return delClashing(true, new Set(xs).add(pair[0]), new Set(ys).add(pair[0]), others, kept);
|
|
98
|
+
return delClashing(isClash, xs, new Set(ys).add(pair[1]), others, [pair, ...kept]);
|
|
99
|
+
};
|
|
100
|
+
const vars = makeDistinct(delClashing(false, unchanged, new Set(unchanged), distinct, []));
|
|
101
|
+
const bounds = makeDistinct(pairs);
|
|
102
|
+
if (
|
|
103
|
+
[...vars].every((pair) => pair[0] === pair[1]) &&
|
|
104
|
+
[...bounds].every((pair) => pair[0] === pair[1])
|
|
105
|
+
)
|
|
106
|
+
return undefined;
|
|
107
|
+
const rename = (term: Term): Term => {
|
|
108
|
+
switch (term.kind) {
|
|
109
|
+
case "Var": {
|
|
110
|
+
const name = vars.get(term.name) ?? term.name;
|
|
111
|
+
return name === term.name ? term : mkVar(name, term.index, term.type);
|
|
112
|
+
}
|
|
113
|
+
case "Abs":
|
|
114
|
+
return mkAbs(bounds.get(term.name) ?? term.name, term.type, rename(term.body));
|
|
115
|
+
case "App":
|
|
116
|
+
return mkApp(rename(term.fun), rename(term.arg));
|
|
117
|
+
default:
|
|
118
|
+
return term;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
return rename;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export const stripAssums2 = (lifted: Term, goal: Term): Tpair => {
|
|
125
|
+
if (isImpApp(lifted) && isImpApp(goal)) return stripAssums2(lifted.arg, goal.arg);
|
|
126
|
+
if (isAllApp(lifted) && isAllApp(goal)) {
|
|
127
|
+
const [left, right] = stripAssums2(lifted.arg.body, goal.arg.body);
|
|
128
|
+
return [
|
|
129
|
+
mkAbs(lifted.arg.name, lifted.arg.type, left),
|
|
130
|
+
mkAbs(lifted.arg.name, lifted.arg.type, right),
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
return [lifted, goal];
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const normTermSkip = (envir: Envir, count: number, term: Term): Term => {
|
|
137
|
+
if (count === 0) return normTerm(envir, term);
|
|
138
|
+
if (isAllApp(term)) {
|
|
139
|
+
const type = normType(envir.tyenv, term.arg.type);
|
|
140
|
+
return mkApp(
|
|
141
|
+
allConst(type),
|
|
142
|
+
mkAbs(term.arg.name, type, normTermSkip(envir, count, term.arg.body)),
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
if (isImpApp(term)) return mkImplies(term.fun.arg, normTermSkip(envir, count - 1, term.arg));
|
|
146
|
+
throw new TlaIsabelleError("ERROR", "norm_term_skip: too few assumptions??");
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export const unifyVarTypes = (first: Thm, second: Thm, envir: Envir): Envir | undefined => {
|
|
150
|
+
const vars = new Map<string, Typ[]>();
|
|
151
|
+
const add = (term: Term) =>
|
|
152
|
+
foldVars(
|
|
153
|
+
(atom, result: Map<string, Typ[]>) => {
|
|
154
|
+
const key = `${atom.index}:${atom.name}`;
|
|
155
|
+
const types = result.get(key) ?? [];
|
|
156
|
+
if (!types.some((type) => eqTyp(type, atom.type))) result.set(key, [atom.type, ...types]);
|
|
157
|
+
return result;
|
|
158
|
+
},
|
|
159
|
+
term,
|
|
160
|
+
vars,
|
|
161
|
+
);
|
|
162
|
+
for (const thm of [first, second]) {
|
|
163
|
+
for (const pair of thm.tpairs) {
|
|
164
|
+
add(pair[0]);
|
|
165
|
+
add(pair[1]);
|
|
166
|
+
}
|
|
167
|
+
add(thm.prop);
|
|
168
|
+
}
|
|
169
|
+
let current: Envir | undefined = envir;
|
|
170
|
+
for (const types of vars.values())
|
|
171
|
+
for (const type of types.slice(1))
|
|
172
|
+
current = current && unifyTypesEnvir(types[0], type, current);
|
|
173
|
+
return current;
|
|
174
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Ported from Isabelle2025's Pure/consts.ML. Copyright (c) 1986-2025 University of Cambridge,
|
|
2
|
+
// Technische Universitaet Muenchen, and contributors, see LICENSE.
|
|
3
|
+
//
|
|
4
|
+
// A constant's type arguments: the instances of the type variables of its declared type, which
|
|
5
|
+
// Consts.declare locates once so that Consts.typargs only has to look them up.
|
|
6
|
+
|
|
7
|
+
import { TlaIsabelleError } from "../../../errors";
|
|
8
|
+
import type { Typ } from "./term";
|
|
9
|
+
|
|
10
|
+
export type TypargPosition = readonly number[];
|
|
11
|
+
|
|
12
|
+
// Consts.typargs_of: the path to the first occurrence of each type variable.
|
|
13
|
+
export const typargsOf = (type: Typ): TypargPosition[] => {
|
|
14
|
+
const found = new Map<string, TypargPosition>();
|
|
15
|
+
const visit = (current: Typ, path: readonly number[]) => {
|
|
16
|
+
if (current.kind === "Type") current.args.forEach((arg, index) => visit(arg, [...path, index]));
|
|
17
|
+
else if (current.kind === "TVar" && !found.has(`${current.name}.${current.index}`))
|
|
18
|
+
found.set(`${current.name}.${current.index}`, path);
|
|
19
|
+
};
|
|
20
|
+
visit(type, []);
|
|
21
|
+
return [...found.values()];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Consts.typargs: the type arguments of a constant at an instance of its declared type.
|
|
25
|
+
export const typargs = (positions: readonly TypargPosition[], type: Typ): Typ[] =>
|
|
26
|
+
positions.map((path) =>
|
|
27
|
+
path.reduce((current, index) => {
|
|
28
|
+
if (current.kind !== "Type" || index >= current.args.length)
|
|
29
|
+
throw new TlaIsabelleError("TYPE", "Consts.typargs: subscript");
|
|
30
|
+
return current.args[index];
|
|
31
|
+
}, type),
|
|
32
|
+
);
|