tla-ts 0.0.10-dev.8aec06f77 → 0.0.10-dev.94c3dd828
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/dist/deciders.cjs +37 -36
- package/dist/deciders.js +55 -54
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +146 -58
- package/dist/prove.js +142 -54
- package/dist/run.cjs +45 -43
- package/dist/run.js +47 -45
- package/dist/transfer.cjs +39 -36
- package/dist/transfer.js +23 -20
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/src/ast.ts +3 -3
- package/src/check.ts +203 -33
- package/src/cli/tlapm.ts +261 -68
- package/src/dependencies.ts +23 -2
- package/src/errors.ts +1 -1
- package/src/exit-codes.ts +1 -0
- package/src/liveness-checker.ts +530 -201
- package/src/liveness.ts +47 -32
- package/src/obligations/anonymize.ts +2 -4
- package/src/obligations/index.ts +5 -3
- package/src/obligations/pragma.ts +2 -2
- package/src/parallel.ts +2 -2
- package/src/parser.ts +151 -42
- package/src/prover/deciders.ts +1 -8
- package/src/prover/isabelle/isar/attrib.ts +86 -45
- package/src/prover/isabelle/isar/context.ts +25 -22
- package/src/prover/isabelle/isar/induct.ts +2 -5
- package/src/prover/isabelle/isar/method.ts +5 -7
- package/src/prover/isabelle/isar/proof.ts +33 -16
- package/src/prover/isabelle/isar/rule-cases.ts +6 -14
- package/src/prover/isabelle/isar/theory.ts +16 -17
- package/src/prover/isabelle/isar/toplevel.ts +46 -52
- package/src/prover/isabelle/provers/classical.ts +1 -1
- package/src/prover/ocaml.ts +4 -1
- package/src/prover/prep/action.ts +1 -0
- package/src/prover/prep/methods.ts +50 -3
- package/src/prover/prep/normalize.ts +4 -1
- package/src/prover/prove.ts +58 -32
- package/src/prover/ptl/decide.ts +43 -63
- package/src/prover/smt/data.ts +51 -45
- package/src/prover/smt/encode.ts +1 -2
- package/src/prover/smt/rewrite.ts +1 -0
- package/src/prover/smt/solver/aig-tactic.ts +25 -15
- package/src/prover/smt/solver/arith-rewriter.ts +3 -5
- package/src/prover/smt/solver/asserted-formulas.ts +1 -1
- package/src/prover/smt/solver/ast-util.ts +3 -1
- package/src/prover/smt/solver/ast.ts +110 -152
- package/src/prover/smt/solver/bound-manager.ts +39 -28
- package/src/prover/smt/solver/bv-bound-chk.ts +2 -8
- package/src/prover/smt/solver/bv-rewriter.ts +14 -16
- package/src/prover/smt/solver/bv1-blast.ts +1 -9
- package/src/prover/smt/solver/cg-table.ts +19 -14
- package/src/prover/smt/solver/check-logic.ts +6 -1
- package/src/prover/smt/solver/context.ts +20 -10
- package/src/prover/smt/solver/demodulator.ts +2 -2
- package/src/prover/smt/solver/dependent-expr-state.ts +16 -0
- package/src/prover/smt/solver/distribute-forall.ts +1 -10
- package/src/prover/smt/solver/dom-simplify.ts +1 -1
- package/src/prover/smt/solver/dt2bv-tactic.ts +2 -7
- package/src/prover/smt/solver/e-matching.ts +6 -6
- package/src/prover/smt/solver/elim-uncnstr.ts +3 -14
- package/src/prover/smt/solver/enode.ts +15 -1
- package/src/prover/smt/solver/euf/array-internalize.ts +19 -8
- package/src/prover/smt/solver/euf/dt-solver.ts +19 -19
- package/src/prover/smt/solver/euf/egraph.ts +65 -32
- package/src/prover/smt/solver/euf/euf-solver.ts +35 -18
- package/src/prover/smt/solver/euf/fpa-solver.ts +37 -51
- package/src/prover/smt/solver/euf/mam.ts +6 -48
- package/src/prover/smt/solver/euf/q-ematch.ts +21 -94
- package/src/prover/smt/solver/euf/q-mbi.ts +4 -2
- package/src/prover/smt/solver/euf/q-model-fixer.ts +1 -1
- package/src/prover/smt/solver/euf/q-solver.ts +2 -0
- package/src/prover/smt/solver/euf/th-solver.ts +1 -1
- package/src/prover/smt/solver/factor.ts +1 -11
- package/src/prover/smt/solver/fd-solver.ts +1 -2
- package/src/prover/smt/solver/fm-tactic.ts +19 -13
- package/src/prover/smt/solver/fpa-rewriter.ts +3 -1
- package/src/prover/smt/solver/fpa2bv-converter.ts +10 -6
- package/src/prover/smt/solver/internalizer.ts +41 -2
- package/src/prover/smt/solver/lia2pb.ts +18 -4
- package/src/prover/smt/solver/lp/lar-solver.ts +1 -1
- package/src/prover/smt/solver/lp/nla-powers.ts +144 -107
- package/src/prover/smt/solver/lp/nla-transcendentals.ts +50 -17
- package/src/prover/smt/solver/macro-finder.ts +1 -1
- package/src/prover/smt/solver/mam-compiler.ts +13 -13
- package/src/prover/smt/solver/max-bv-sharing-tactic.ts +1 -11
- package/src/prover/smt/solver/maxcore.ts +4 -12
- package/src/prover/smt/solver/maxlex.ts +0 -7
- package/src/prover/smt/solver/maxsmt-base.ts +7 -0
- package/src/prover/smt/solver/mbp/mbp-arith.ts +2 -11
- package/src/prover/smt/solver/mbp/mbp-plugin.ts +9 -0
- package/src/prover/smt/solver/mbp/mbp-solve-plugin.ts +1 -9
- package/src/prover/smt/solver/model-evaluator.ts +9 -5
- package/src/prover/smt/solver/model-macro-solver.ts +3 -3
- package/src/prover/smt/solver/muz/dl-context.ts +57 -3
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +68 -20
- package/src/prover/smt/solver/muz/dl-mk-elim-term-ite.ts +7 -1
- package/src/prover/smt/solver/muz/dl-mk-rule-inliner.ts +39 -10
- package/src/prover/smt/solver/muz/dl-mk-slice.ts +76 -13
- package/src/prover/smt/solver/muz/dl-mk-subsumption-checker.ts +9 -2
- package/src/prover/smt/solver/muz/dl-rule-transformer.ts +0 -2
- package/src/prover/smt/solver/muz/dl-rule.ts +93 -29
- package/src/prover/smt/solver/muz/hnf.ts +6 -5
- package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +178 -0
- package/src/prover/smt/solver/muz/horn-tactic.ts +14 -3
- package/src/prover/smt/solver/muz/rule-properties.ts +194 -36
- package/src/prover/smt/solver/muz/spacer-context.ts +102 -84
- package/src/prover/smt/solver/muz/spacer-dl-interface.ts +15 -2
- package/src/prover/smt/solver/muz/spacer-pdr.ts +3 -3
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +2 -7
- package/src/prover/smt/solver/muz/spacer-util.ts +2 -2
- package/src/prover/smt/solver/muz/substitution.ts +88 -37
- package/src/prover/smt/solver/nlqsat.ts +2 -2
- package/src/prover/smt/solver/nlsat/algebraic.ts +1 -2
- package/src/prover/smt/solver/nlsat/explain.ts +5 -0
- package/src/prover/smt/solver/nlsat/solver.ts +36 -25
- package/src/prover/smt/solver/opt-context.ts +9 -8
- package/src/prover/smt/solver/opt-nlsat.ts +68 -58
- package/src/prover/smt/solver/opt-solver.ts +16 -7
- package/src/prover/smt/solver/optsmt.ts +12 -9
- package/src/prover/smt/solver/pattern-inference.ts +2 -2
- package/src/prover/smt/solver/pb-rewriter.ts +13 -13
- package/src/prover/smt/solver/poly-rewriter.ts +2 -2
- package/src/prover/smt/solver/probes.ts +1 -1
- package/src/prover/smt/solver/propagate-values.ts +4 -0
- package/src/prover/smt/solver/proto-model.ts +5 -5
- package/src/prover/smt/solver/purify-arith.ts +50 -15
- package/src/prover/smt/solver/qe-arith-plugin.ts +2 -1
- package/src/prover/smt/solver/qe-mbp.ts +13 -23
- package/src/prover/smt/solver/qe.ts +45 -53
- package/src/prover/smt/solver/qsat.ts +70 -90
- package/src/prover/smt/solver/quantifier-analyzer.ts +9 -9
- package/src/prover/smt/solver/quasi-macros.ts +9 -18
- package/src/prover/smt/solver/rational.ts +17 -0
- package/src/prover/smt/solver/recfun-decl-plugin.ts +33 -19
- package/src/prover/smt/solver/recfun-rewriter.ts +1 -1
- package/src/prover/smt/solver/rewriter-tpl.ts +6 -2
- package/src/prover/smt/solver/rewriter.ts +1 -1
- package/src/prover/smt/solver/sat/asymm-branch.ts +59 -46
- package/src/prover/smt/solver/sat/clause-use-list.ts +0 -6
- package/src/prover/smt/solver/sat/clause.ts +1 -3
- package/src/prover/smt/solver/sat/config.ts +3 -3
- package/src/prover/smt/solver/sat/consequences.ts +1 -1
- package/src/prover/smt/solver/sat/goal2sat.ts +1 -1
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +4 -12
- package/src/prover/smt/solver/sat/model-converter.ts +1 -15
- package/src/prover/smt/solver/sat/pb-solver.ts +49 -23
- package/src/prover/smt/solver/sat/probing.ts +22 -19
- package/src/prover/smt/solver/sat/sat2goal.ts +9 -10
- package/src/prover/smt/solver/sat/simplifier.ts +15 -56
- package/src/prover/smt/solver/sat/solver.ts +20 -19
- package/src/prover/smt/solver/sat/watch-list.ts +7 -0
- package/src/prover/smt/solver/seq-decl-plugin.ts +7 -7
- package/src/prover/smt/solver/seq-derive.ts +6 -7
- package/src/prover/smt/solver/seq-eq-solver.ts +7 -7
- package/src/prover/smt/solver/seq-range-predicate.ts +14 -1
- package/src/prover/smt/solver/seq-re-rewriter.ts +1 -10
- package/src/prover/smt/solver/seq-re-util.ts +1 -2
- package/src/prover/smt/solver/seq-regex-bisim.ts +1 -1
- package/src/prover/smt/solver/seq-regex-live.ts +4 -4
- package/src/prover/smt/solver/seq-rewriter.ts +1 -4
- package/src/prover/smt/solver/smt-setup.ts +15 -9
- package/src/prover/smt/solver/smtlib-parser.ts +1174 -579
- package/src/prover/smt/solver/smtlib-script.ts +866 -728
- package/src/prover/smt/solver/tactic.ts +66 -14
- package/src/prover/smt/solver/theory-array.ts +25 -58
- package/src/prover/smt/solver/theory-bv.ts +13 -50
- package/src/prover/smt/solver/theory-fpa.ts +46 -78
- package/src/prover/smt/solver/theory-pb.ts +10 -6
- package/src/prover/smt/solver/theory-recfun.ts +2 -2
- package/src/prover/smt/solver/theory-seq-regex.ts +3 -6
- package/src/prover/smt/solver/theory-seq-solve.ts +5 -5
- package/src/prover/smt/solver/theory-seq-state.ts +6 -3
- package/src/prover/smt/solver/theory-seq.ts +32 -54
- package/src/prover/smt/solver/theory.ts +16 -1
- package/src/prover/smt/solver/tseitin-cnf.ts +3 -3
- package/src/prover/smt/solver/var-subst.ts +2 -2
- package/src/prover/smt/table.ts +3 -2
- package/src/prover/zenon/decide.ts +9 -11
- package/src/prover/zenon/node.ts +12 -11
- package/src/prover/zenon/tla/sets.ts +1 -1
- package/src/search.ts +131 -16
- package/src/successors.ts +1 -1
- package/src/symmetry.ts +2 -2
- package/src/tableau.ts +2 -2
- package/src/tlc/fingerprint.ts +81 -9
- package/src/tlc/summary.ts +29 -14
- package/src/typed-tier.ts +6535 -0
- package/src/prover/smt/solver/seq-regex-witness.ts +0 -100
|
@@ -3,15 +3,23 @@
|
|
|
3
3
|
// Muenchen, and contributors, see LICENSE.
|
|
4
4
|
|
|
5
5
|
import { TlaIsabelleError } from "../../../errors";
|
|
6
|
+
import { addUnsafeDest, addUnsafeElim, addUnsafeIntro, withClaset } from "../provers/classical";
|
|
6
7
|
import { asmRl, compIncr, genAll, multiResolves, zeroVarIndexes } from "../pure/drule";
|
|
8
|
+
import { addSimps } from "../pure/raw-simplifier";
|
|
7
9
|
import { chopSeq } from "../pure/seq";
|
|
8
10
|
import { stripImpConcl } from "../pure/logic";
|
|
9
|
-
import { fastypeOf, type
|
|
11
|
+
import { fastypeOf, type Var } from "../pure/term";
|
|
10
12
|
import { instantiate, instantiateTypes, type Thm } from "../pure/thm";
|
|
11
13
|
import { emptyTyEnv, matchTypes, substType, type TyEnv } from "../pure/type";
|
|
12
|
-
import { getFact, readTerms, type IsarContext } from "./context";
|
|
13
|
-
import { rewriteRule } from "./method";
|
|
14
|
-
import {
|
|
14
|
+
import { getFact, readTerms, varsOf, type IsarContext } from "./context";
|
|
15
|
+
import { rewriteRule, type ProofContext } from "./method";
|
|
16
|
+
import {
|
|
17
|
+
innerText,
|
|
18
|
+
syntaxError,
|
|
19
|
+
type AttributeSource,
|
|
20
|
+
type FactReference,
|
|
21
|
+
type OuterToken,
|
|
22
|
+
} from "./theory";
|
|
15
23
|
|
|
16
24
|
const isInnerToken = (token: OuterToken | undefined) =>
|
|
17
25
|
token !== undefined &&
|
|
@@ -20,11 +28,6 @@ const isInnerToken = (token: OuterToken | undefined) =>
|
|
|
20
28
|
token.kind === "word" ||
|
|
21
29
|
token.kind === "var");
|
|
22
30
|
|
|
23
|
-
const innerText = (token: OuterToken) =>
|
|
24
|
-
token.kind === "cartouche"
|
|
25
|
-
? token.text.slice("\\<open>".length, -"\\<close>".length)
|
|
26
|
-
: token.text;
|
|
27
|
-
|
|
28
31
|
export const parseFactReferences = (tokens: readonly OuterToken[]): FactReference[] => {
|
|
29
32
|
const references: FactReference[] = [];
|
|
30
33
|
let position = 0;
|
|
@@ -66,25 +69,6 @@ export const parseFactReferences = (tokens: readonly OuterToken[]): FactReferenc
|
|
|
66
69
|
return references;
|
|
67
70
|
};
|
|
68
71
|
|
|
69
|
-
// Vars.add_vars: the variables in the order they occur.
|
|
70
|
-
const varsOf = (terms: readonly Term[]): Var[] => {
|
|
71
|
-
const found: Var[] = [];
|
|
72
|
-
const visit = (term: Term) => {
|
|
73
|
-
if (
|
|
74
|
-
term.kind === "Var" &&
|
|
75
|
-
!found.some((other) => other.name === term.name && other.index === term.index)
|
|
76
|
-
)
|
|
77
|
-
found.push(term);
|
|
78
|
-
if (term.kind === "Abs") visit(term.body);
|
|
79
|
-
if (term.kind === "App") {
|
|
80
|
-
visit(term.fun);
|
|
81
|
-
visit(term.arg);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
for (const term of terms) visit(term);
|
|
85
|
-
return found;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
72
|
const varsOfThm = (thm: Thm) => varsOf([...thm.tpairs.flat(), thm.prop]);
|
|
89
73
|
|
|
90
74
|
// Rule_Insts.where_rule: the terms are read against the variables' types, whose type variables
|
|
@@ -98,7 +82,10 @@ const whereRule = (
|
|
|
98
82
|
const targets = insts.map((inst) => {
|
|
99
83
|
const variable = vars.find((other) => other.name === inst.name && other.index === inst.index);
|
|
100
84
|
if (variable === undefined)
|
|
101
|
-
throw new TlaIsabelleError(
|
|
85
|
+
throw new TlaIsabelleError(
|
|
86
|
+
"ERROR",
|
|
87
|
+
`No such variable in theorem: "?${inst.name}${inst.index === 0 ? "" : inst.index}"`,
|
|
88
|
+
);
|
|
102
89
|
return variable;
|
|
103
90
|
});
|
|
104
91
|
const terms = readTerms(
|
|
@@ -154,14 +141,17 @@ const parseWhere = (args: readonly OuterToken[]) => {
|
|
|
154
141
|
const insts: { name: string; index: number; text: string }[] = [];
|
|
155
142
|
let position = 0;
|
|
156
143
|
while (position < args.length) {
|
|
157
|
-
if (args[position].kind === "symbol" && args[position].text === "?") position += 1;
|
|
158
144
|
const variable = args[position];
|
|
159
|
-
if (variable
|
|
145
|
+
if ((variable.kind !== "word" && variable.kind !== "var") || variable.text.startsWith("'"))
|
|
146
|
+
throw syntaxError(variable);
|
|
160
147
|
const digits = /\d*$/.exec(variable.text)?.[0] ?? "";
|
|
161
148
|
if (args[position + 1]?.text !== "=" || !isInnerToken(args[position + 2]))
|
|
162
149
|
throw syntaxError(args[position + 1]);
|
|
163
150
|
insts.push({
|
|
164
|
-
name: variable.text.slice(
|
|
151
|
+
name: variable.text.slice(
|
|
152
|
+
variable.kind === "var" ? 1 : 0,
|
|
153
|
+
variable.text.length - digits.length,
|
|
154
|
+
),
|
|
165
155
|
index: Number(digits || 0),
|
|
166
156
|
text: innerText(args[position + 2]),
|
|
167
157
|
});
|
|
@@ -186,28 +176,79 @@ const ofFacts = (context: IsarContext, rule: Thm, facts: readonly Thm[]): Thm =>
|
|
|
186
176
|
const rulify = (context: IsarContext, thm: Thm): Thm =>
|
|
187
177
|
zeroVarIndexes(genAll(rewriteRule(context.tactics.limits, context.tactics.rulifyRules, thm)));
|
|
188
178
|
|
|
189
|
-
|
|
179
|
+
// Simplifier.simp_add and Classical's unsafe_intro, unsafe_elim and unsafe_dest: the declarations
|
|
180
|
+
// that add the theorem to a set the methods read.
|
|
181
|
+
const declareRule = (tactics: ProofContext, name: string, thm: Thm): ProofContext => {
|
|
182
|
+
if (name === "simp")
|
|
183
|
+
return {
|
|
184
|
+
...tactics,
|
|
185
|
+
simpset: addSimps({ limits: tactics.limits, simpset: tactics.simpset, bounds: 0 }, [thm]),
|
|
186
|
+
};
|
|
187
|
+
const classical = tactics.classical;
|
|
188
|
+
const add = name === "intro" ? addUnsafeIntro : name === "elim" ? addUnsafeElim : addUnsafeDest;
|
|
189
|
+
return {
|
|
190
|
+
...tactics,
|
|
191
|
+
classical: withClaset(classical, add(classical, thm, tactics.atomizeRules)),
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// Thm.apply_attribute: a rule attribute changes the theorem, a declaration the context.
|
|
196
|
+
const applyAttribute = (
|
|
197
|
+
context: IsarContext,
|
|
198
|
+
attribute: AttributeSource,
|
|
199
|
+
thm: Thm,
|
|
200
|
+
): [IsarContext, Thm] => {
|
|
190
201
|
switch (attribute.name) {
|
|
191
202
|
case "of":
|
|
192
|
-
return ofRule(context, attribute.args, thm);
|
|
203
|
+
return [context, ofRule(context, attribute.args, thm)];
|
|
193
204
|
case "where":
|
|
194
|
-
return whereRule(context, parseWhere(attribute.args), thm);
|
|
205
|
+
return [context, whereRule(context, parseWhere(attribute.args), thm)];
|
|
195
206
|
case "rule_format":
|
|
196
207
|
if (attribute.args.length > 0) throw syntaxError(attribute.args[0]);
|
|
197
|
-
return rulify(context, thm);
|
|
208
|
+
return [context, rulify(context, thm)];
|
|
198
209
|
case "OF":
|
|
199
|
-
return
|
|
210
|
+
return [
|
|
211
|
+
context,
|
|
212
|
+
ofFacts(context, thm, getThms(context, parseFactReferences(attribute.args))),
|
|
213
|
+
];
|
|
214
|
+
case "simp":
|
|
215
|
+
case "intro":
|
|
216
|
+
case "elim":
|
|
217
|
+
case "dest":
|
|
218
|
+
if (attribute.args.length > 0)
|
|
219
|
+
throw new TlaIsabelleError("ERROR", `Unsupported ${attribute.name} attribute arguments`);
|
|
220
|
+
return [{ ...context, tactics: declareRule(context.tactics, attribute.name, thm) }, thm];
|
|
200
221
|
default:
|
|
201
222
|
throw new TlaIsabelleError("ERROR", `Unsupported attribute: ${attribute.name}`);
|
|
202
223
|
}
|
|
203
224
|
};
|
|
204
225
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
)
|
|
226
|
+
// Thm.proof_attributes over a fact's theorems: each attribute sees what those before it declared.
|
|
227
|
+
export const applyAttributes = (
|
|
228
|
+
context: IsarContext,
|
|
229
|
+
attributes: readonly AttributeSource[],
|
|
230
|
+
thms: readonly Thm[],
|
|
231
|
+
): [IsarContext, Thm[]] =>
|
|
232
|
+
thms.reduce<[IsarContext, Thm[]]>(
|
|
233
|
+
([current, results], thm) => {
|
|
234
|
+
const [declared, result] = attributes.reduce<[IsarContext, Thm]>(
|
|
235
|
+
([inner, changed], attribute) => applyAttribute(inner, attribute, changed),
|
|
236
|
+
[current, thm],
|
|
237
|
+
);
|
|
238
|
+
return [declared, [...results, result]];
|
|
239
|
+
},
|
|
240
|
+
[context, []],
|
|
213
241
|
);
|
|
242
|
+
|
|
243
|
+
// The facts a command or a method cites, where the port keeps no declaration.
|
|
244
|
+
export const getThms = (context: IsarContext, references: readonly FactReference[]): Thm[] =>
|
|
245
|
+
references.flatMap((reference) => {
|
|
246
|
+
const [declared, thms] = applyAttributes(
|
|
247
|
+
context,
|
|
248
|
+
reference.attributes,
|
|
249
|
+
getFact(context, reference.name),
|
|
250
|
+
);
|
|
251
|
+
if (declared !== context)
|
|
252
|
+
throw new TlaIsabelleError("ERROR", "Unsupported declaration in a fact reference");
|
|
253
|
+
return thms;
|
|
254
|
+
});
|
|
@@ -201,7 +201,7 @@ export const readTerms = (
|
|
|
201
201
|
);
|
|
202
202
|
if (mode === "pattern") return checked;
|
|
203
203
|
const expanded = checked.map((term) => expandBinds(context, term));
|
|
204
|
-
if (mode === "default" &&
|
|
204
|
+
if (mode === "default" && varsOf(expanded).length > 0)
|
|
205
205
|
throw new TlaIsabelleError("ERROR", "Unbound schematic variable");
|
|
206
206
|
return expanded;
|
|
207
207
|
};
|
|
@@ -233,17 +233,22 @@ const decrIndexes = (term: Term, maxidx: number, offset: number): Term => {
|
|
|
233
233
|
return decrVars(mapTypes(decrType, term));
|
|
234
234
|
};
|
|
235
235
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
236
|
+
// Vars.add_vars: the variables in the order they occur.
|
|
237
|
+
export const varsOf = (terms: readonly Term[]): Var[] => {
|
|
238
|
+
const found: Var[] = [];
|
|
239
|
+
const visit = (term: Term) => {
|
|
240
|
+
if (
|
|
241
|
+
term.kind === "Var" &&
|
|
242
|
+
!found.some((other) => other.name === term.name && other.index === term.index)
|
|
243
|
+
)
|
|
244
|
+
found.push(term);
|
|
245
|
+
if (term.kind === "Abs") visit(term.body);
|
|
246
|
+
if (term.kind === "App") {
|
|
247
|
+
visit(term.fun);
|
|
248
|
+
visit(term.arg);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
for (const term of terms) visit(term);
|
|
247
252
|
return found;
|
|
248
253
|
};
|
|
249
254
|
|
|
@@ -268,16 +273,14 @@ export const simultMatches = (
|
|
|
268
273
|
),
|
|
269
274
|
);
|
|
270
275
|
if (envir === undefined) throw new TlaIsabelleError("ERROR", "Pattern match failed!");
|
|
271
|
-
return pairs
|
|
272
|
-
|
|
273
|
-
.
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
: [[variable.name, variable.index - offset, decrIndexes(normalized, maxidx, offset)]];
|
|
280
|
-
});
|
|
276
|
+
return varsOf(pairs.map((pair) => pair[0])).flatMap((variable): [string, number, Term][] => {
|
|
277
|
+
const normalized = normTerm(envir, variable);
|
|
278
|
+
return normalized.kind === "Var" &&
|
|
279
|
+
normalized.name === variable.name &&
|
|
280
|
+
normalized.index === variable.index
|
|
281
|
+
? []
|
|
282
|
+
: [[variable.name, variable.index - offset, decrIndexes(normalized, maxidx, offset)]];
|
|
283
|
+
});
|
|
281
284
|
};
|
|
282
285
|
|
|
283
286
|
// Assumption.add_assms: each proposition becomes a hypothesis.
|
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
type CaseInfo,
|
|
50
50
|
type CasesRule,
|
|
51
51
|
} from "./rule-cases";
|
|
52
|
-
import { syntaxError, type OuterToken } from "./theory";
|
|
52
|
+
import { innerText, syntaxError, type OuterToken } from "./theory";
|
|
53
53
|
|
|
54
54
|
export interface NamedCasesRule {
|
|
55
55
|
readonly name: string;
|
|
@@ -203,10 +203,7 @@ const parseCasesArgs = (isar: IsarContext, tokens: readonly OuterToken[]): Cases
|
|
|
203
203
|
isar,
|
|
204
204
|
[
|
|
205
205
|
{
|
|
206
|
-
text:
|
|
207
|
-
token.kind === "cartouche"
|
|
208
|
-
? token.text.slice("\\<open>".length, -"\\<close>".length)
|
|
209
|
-
: token.text,
|
|
206
|
+
text: innerText(token),
|
|
210
207
|
type: mkTVar("'a", 0),
|
|
211
208
|
},
|
|
212
209
|
],
|
|
@@ -482,11 +482,11 @@ const allAssmTac =
|
|
|
482
482
|
allAssmTac(limits)(index + 1),
|
|
483
483
|
)(state);
|
|
484
484
|
|
|
485
|
-
// Method.finish
|
|
486
|
-
export const finishTac =
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
485
|
+
// Method.finish of an immediate proof, as qed and by are: assumptions finish the closing step.
|
|
486
|
+
export const finishTac =
|
|
487
|
+
(limits: Limits): Tactic =>
|
|
488
|
+
(state) =>
|
|
489
|
+
mapsSeq(flexflexTac(limits), allAssmTac(limits)(1)(state));
|
|
490
490
|
|
|
491
491
|
// Seq.REPEAT, depth first.
|
|
492
492
|
const repeat =
|
|
@@ -649,7 +649,5 @@ export const evaluate = (isar: IsarContext, text: MethodText): Method => {
|
|
|
649
649
|
const method = evaluate(isar, text.texts[0]);
|
|
650
650
|
return (facts) => (state) => mapsSeq(repeat(method(facts)), method(facts)(state));
|
|
651
651
|
}
|
|
652
|
-
default:
|
|
653
|
-
throw new TlaIsabelleError("ERROR", `Unsupported method combinator: ${text.kind}`);
|
|
654
652
|
}
|
|
655
653
|
};
|
|
@@ -36,10 +36,11 @@ import {
|
|
|
36
36
|
type IsarContext,
|
|
37
37
|
type ReadMode,
|
|
38
38
|
} from "./context";
|
|
39
|
+
import { applyAttributes } from "./attrib";
|
|
39
40
|
import { evaluate, finishTac, normHhfTac, unfoldGoals, unfoldRule, type GoalState } from "./method";
|
|
40
41
|
import { applyCase, dropJudgment } from "./rule-cases";
|
|
41
42
|
import { parseType } from "./inner-syntax";
|
|
42
|
-
import type { FixedVariable, MethodText, StatementPart } from "./theory";
|
|
43
|
+
import type { AttributeSource, FixedVariable, MethodText, StatementPart } from "./theory";
|
|
43
44
|
|
|
44
45
|
const initGoal = (prop: Term) =>
|
|
45
46
|
instantiate([{ variable: mkVar("A", 0, propT), term: prop }], protectI);
|
|
@@ -162,7 +163,7 @@ const theResult = <Item>(seq: Seq<Item>, message: string): Item => {
|
|
|
162
163
|
};
|
|
163
164
|
|
|
164
165
|
// Proof.end_proof: the closing method, then the goal must have no subgoals.
|
|
165
|
-
const endProof = (state: State, text: MethodText | undefined
|
|
166
|
+
const endProof = (state: State, text: MethodText | undefined): Seq<State> => {
|
|
166
167
|
assertMode(state, ["forward"]);
|
|
167
168
|
const closed = usingFacts(closeBlock(state), []);
|
|
168
169
|
if (top(closed).goal === undefined) throw error("No goal in this block");
|
|
@@ -173,7 +174,7 @@ const endProof = (state: State, text: MethodText | undefined, isImmediate: boole
|
|
|
173
174
|
(result: State) =>
|
|
174
175
|
mapSeq(
|
|
175
176
|
(thm: Thm) => provideGoal(result, thm),
|
|
176
|
-
finishTac(contextOf(result).tactics.limits
|
|
177
|
+
finishTac(contextOf(result).tactics.limits)(findGoal(result)[2].goal),
|
|
177
178
|
),
|
|
178
179
|
finish,
|
|
179
180
|
),
|
|
@@ -199,7 +200,7 @@ const genericQed = (state: State): State => {
|
|
|
199
200
|
};
|
|
200
201
|
|
|
201
202
|
export const qed = (state: State, text: MethodText | undefined): State =>
|
|
202
|
-
genericQed(theResult(endProof(state, text
|
|
203
|
+
genericQed(theResult(endProof(state, text), "Failed to finish proof"));
|
|
203
204
|
|
|
204
205
|
// Proof.terminal_proof, as by: the first initial result that the terminal method finishes.
|
|
205
206
|
export const terminalProof = (
|
|
@@ -209,7 +210,7 @@ export const terminalProof = (
|
|
|
209
210
|
): State =>
|
|
210
211
|
genericQed(
|
|
211
212
|
theResult(
|
|
212
|
-
mapsSeq((result: State) => endProof(result, terminal
|
|
213
|
+
mapsSeq((result: State) => endProof(result, terminal), proof(state, initial)),
|
|
213
214
|
"Failed to finish proof",
|
|
214
215
|
),
|
|
215
216
|
);
|
|
@@ -294,14 +295,15 @@ const localResults = (
|
|
|
294
295
|
parts: readonly StatementPart[],
|
|
295
296
|
results: readonly (readonly Thm[])[],
|
|
296
297
|
): State => {
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
298
|
+
const noted: Thm[] = [];
|
|
299
|
+
const named = parts.reduce((context, part, index) => {
|
|
300
|
+
const [declared, thms] = applyAttributes(context, part.attributes, results[index]);
|
|
301
|
+
noted.push(...thms);
|
|
302
|
+
return part.name === undefined ? declared : putFacts(declared, part.name, thms);
|
|
303
|
+
}, contextOf(state));
|
|
302
304
|
return putFactsOf(
|
|
303
305
|
mapContext(state, () => named),
|
|
304
|
-
|
|
306
|
+
noted,
|
|
305
307
|
);
|
|
306
308
|
};
|
|
307
309
|
|
|
@@ -421,23 +423,33 @@ export const collect = (state: State, isFinal: boolean): State => {
|
|
|
421
423
|
// Proof.assume: each group of propositions becomes hypotheses, which a named group names.
|
|
422
424
|
const assumeProps = (
|
|
423
425
|
state: State,
|
|
424
|
-
groups: readonly {
|
|
426
|
+
groups: readonly {
|
|
427
|
+
readonly name: string | undefined;
|
|
428
|
+
readonly attributes: readonly AttributeSource[];
|
|
429
|
+
readonly props: readonly Term[];
|
|
430
|
+
}[],
|
|
425
431
|
): State => {
|
|
426
432
|
assertMode(state, ["forward"]);
|
|
427
433
|
const props = groups.flatMap((group) => group.props);
|
|
428
434
|
const [thms, context] = addAssumptions(contextOf(state), false, props);
|
|
429
435
|
let offset = 0;
|
|
436
|
+
const noted: Thm[] = [];
|
|
430
437
|
const named = groups.reduce(
|
|
431
438
|
(current, group) => {
|
|
432
|
-
const slice =
|
|
439
|
+
const [declared, slice] = applyAttributes(
|
|
440
|
+
current,
|
|
441
|
+
group.attributes,
|
|
442
|
+
thms.slice(offset, offset + group.props.length),
|
|
443
|
+
);
|
|
433
444
|
offset += group.props.length;
|
|
434
|
-
|
|
445
|
+
noted.push(...slice);
|
|
446
|
+
return group.name === undefined ? declared : putFacts(declared, group.name, slice);
|
|
435
447
|
},
|
|
436
448
|
props.reduce(declareTerm, context),
|
|
437
449
|
);
|
|
438
450
|
return putFactsOf(
|
|
439
451
|
mapContext(state, () => named),
|
|
440
|
-
|
|
452
|
+
noted,
|
|
441
453
|
);
|
|
442
454
|
};
|
|
443
455
|
|
|
@@ -446,7 +458,11 @@ export const assume = (state: State, parts: readonly StatementPart[]): State =>
|
|
|
446
458
|
const statement = readStatement(contextOf(state), parts, "default");
|
|
447
459
|
return assumeProps(
|
|
448
460
|
mapContext(state, (context) => bindAll(context, statement.binds)),
|
|
449
|
-
parts.map((part, index) => ({
|
|
461
|
+
parts.map((part, index) => ({
|
|
462
|
+
name: part.name,
|
|
463
|
+
attributes: part.attributes,
|
|
464
|
+
props: statement.props[index],
|
|
465
|
+
})),
|
|
450
466
|
);
|
|
451
467
|
};
|
|
452
468
|
|
|
@@ -491,6 +507,7 @@ export const invokeCase = (
|
|
|
491
507
|
mapContext(state, () => updateCases(bound, applied.cases)),
|
|
492
508
|
applied.assumes.map((assumption) => ({
|
|
493
509
|
name: assumption.name === "" ? undefined : `${caseName}.${assumption.name}`,
|
|
510
|
+
attributes: [],
|
|
494
511
|
props: assumption.props,
|
|
495
512
|
})),
|
|
496
513
|
);
|
|
@@ -43,7 +43,6 @@ export type Cases = readonly { readonly name: string; readonly case: RuleCase |
|
|
|
43
43
|
|
|
44
44
|
export type CaseInfo = readonly {
|
|
45
45
|
readonly name: string;
|
|
46
|
-
readonly hyps: readonly string[];
|
|
47
46
|
readonly concls: readonly string[];
|
|
48
47
|
}[];
|
|
49
48
|
|
|
@@ -84,20 +83,13 @@ export const getCases = (rule: CasesRule): [CaseInfo, number] => {
|
|
|
84
83
|
}))
|
|
85
84
|
: explodeArgs(names).map((name) => ({ name, concls: getCaseConcls(rule.tags, name) }));
|
|
86
85
|
const hypNames = lookupTag(rule.tags, "cases_hyp_names");
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
throw new TlaIsabelleError("ERROR", "Malformed cases_hyp_names tag of theorem");
|
|
93
|
-
return names === "," ? [] : names.slice(0, -1).split(",");
|
|
94
|
-
});
|
|
95
|
-
if (hyps.length !== cases.length)
|
|
86
|
+
const hypGroups = hypNames === undefined ? undefined : explodeArgs(hypNames);
|
|
87
|
+
if (
|
|
88
|
+
hypGroups !== undefined &&
|
|
89
|
+
(hypGroups.length !== cases.length || hypGroups.some((group) => !group.endsWith(",")))
|
|
90
|
+
)
|
|
96
91
|
throw new TlaIsabelleError("ERROR", "Malformed cases_hyp_names tag of theorem");
|
|
97
|
-
return [
|
|
98
|
-
cases.map((entry, index) => ({ name: entry.name, hyps: hyps[index], concls: entry.concls })),
|
|
99
|
-
consumes,
|
|
100
|
-
];
|
|
92
|
+
return [cases, consumes];
|
|
101
93
|
};
|
|
102
94
|
|
|
103
95
|
const destConjunctions = (term: Term): Term[] =>
|
|
@@ -41,10 +41,9 @@ export type StatementElement =
|
|
|
41
41
|
export type MethodText =
|
|
42
42
|
| { readonly kind: "source"; readonly name: string; readonly args: readonly OuterToken[] }
|
|
43
43
|
| {
|
|
44
|
-
readonly kind: "then" | "
|
|
44
|
+
readonly kind: "then" | "orelse" | "try" | "repeat1";
|
|
45
45
|
readonly texts: readonly MethodText[];
|
|
46
|
-
}
|
|
47
|
-
| { readonly kind: "select"; readonly count: number; readonly text: MethodText };
|
|
46
|
+
};
|
|
48
47
|
|
|
49
48
|
export type Command =
|
|
50
49
|
| {
|
|
@@ -100,6 +99,11 @@ export const syntaxError = (token: OuterToken | undefined) =>
|
|
|
100
99
|
`Outer syntax error at: ${token === undefined ? "end of input" : token.text}`,
|
|
101
100
|
);
|
|
102
101
|
|
|
102
|
+
export const innerText = (token: OuterToken) =>
|
|
103
|
+
token.kind === "cartouche"
|
|
104
|
+
? token.text.slice("\\<open>".length, -"\\<close>".length)
|
|
105
|
+
: token.text;
|
|
106
|
+
|
|
103
107
|
const isWordChar = (char: string) => /[A-Za-z0-9_'.]/.test(char);
|
|
104
108
|
|
|
105
109
|
const readString = (text: string, start: number): [string, number] => {
|
|
@@ -294,13 +298,9 @@ export const parseTheory = (text: string): TheoryText => {
|
|
|
294
298
|
peek()?.kind === "string" || peek()?.kind === "cartouche" || peek()?.kind === "var" || isName();
|
|
295
299
|
const inner = () => {
|
|
296
300
|
const token = peek();
|
|
297
|
-
if (token?.kind === "cartouche") {
|
|
301
|
+
if (token?.kind === "cartouche" || token?.kind === "var") {
|
|
298
302
|
position += 1;
|
|
299
|
-
return token
|
|
300
|
-
}
|
|
301
|
-
if (token?.kind === "var") {
|
|
302
|
-
position += 1;
|
|
303
|
-
return token.text;
|
|
303
|
+
return innerText(token);
|
|
304
304
|
}
|
|
305
305
|
return token?.kind === "string" ? expectString() : expectName();
|
|
306
306
|
};
|
|
@@ -432,12 +432,7 @@ export const parseTheory = (text: string): TheoryText => {
|
|
|
432
432
|
position += 1;
|
|
433
433
|
return { kind: "repeat1", texts: [text] };
|
|
434
434
|
}
|
|
435
|
-
if (isSymbol("["))
|
|
436
|
-
position += 1;
|
|
437
|
-
const count = isSymbol("]") ? 1 : Number(expectName());
|
|
438
|
-
expectSymbol("]");
|
|
439
|
-
return { kind: "select", count, text };
|
|
440
|
-
}
|
|
435
|
+
if (isSymbol("[")) throw new TlaIsabelleError("ERROR", "Unsupported method combinator: [");
|
|
441
436
|
return text;
|
|
442
437
|
};
|
|
443
438
|
const method3 = (): MethodText => {
|
|
@@ -453,7 +448,7 @@ export const parseTheory = (text: string): TheoryText => {
|
|
|
453
448
|
};
|
|
454
449
|
const enumeration = (
|
|
455
450
|
separator: string,
|
|
456
|
-
kind: "then" | "
|
|
451
|
+
kind: "then" | "orelse",
|
|
457
452
|
read: () => MethodText,
|
|
458
453
|
): MethodText => {
|
|
459
454
|
const texts = [read()];
|
|
@@ -464,7 +459,11 @@ export const parseTheory = (text: string): TheoryText => {
|
|
|
464
459
|
return texts.length === 1 ? texts[0] : { kind, texts };
|
|
465
460
|
};
|
|
466
461
|
const method2 = () => enumeration(",", "then", method3);
|
|
467
|
-
const method1 = () =>
|
|
462
|
+
const method1 = () => {
|
|
463
|
+
const text = method2();
|
|
464
|
+
if (isSymbol(";")) throw new TlaIsabelleError("ERROR", "Unsupported method combinator: ;");
|
|
465
|
+
return text;
|
|
466
|
+
};
|
|
468
467
|
const method0 = (): MethodText => enumeration("|", "orelse", method1);
|
|
469
468
|
const isMethodStart = () =>
|
|
470
469
|
isSymbol("(") ||
|