tla-ts 0.0.10-dev.28c823e4b → 0.0.10-dev.63a6693bd

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/dist/compile.cjs +6 -6
  2. package/dist/compile.js +10 -10
  3. package/dist/deciders.cjs +29 -29
  4. package/dist/deciders.js +40 -40
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/parallel-worker.cjs +1 -1
  8. package/dist/parallel-worker.js +1 -1
  9. package/dist/prove-worker.cjs +1 -1
  10. package/dist/prove-worker.js +1 -1
  11. package/dist/prove.cjs +54 -54
  12. package/dist/prove.js +52 -52
  13. package/dist/run.cjs +42 -42
  14. package/dist/run.js +44 -44
  15. package/dist/tlapm.cjs +2 -2
  16. package/dist/tlapm.js +2 -2
  17. package/dist/transfer.cjs +39 -39
  18. package/dist/transfer.js +41 -41
  19. package/dist/worker.cjs +4 -4
  20. package/dist/worker.js +4 -4
  21. package/package.json +1 -1
  22. package/src/ast.ts +44 -39
  23. package/src/builtins.ts +4 -13
  24. package/src/check-failure.ts +116 -0
  25. package/src/check-trace.ts +282 -0
  26. package/src/check.ts +152 -518
  27. package/src/cli/options.ts +6 -31
  28. package/src/cli/shared.ts +1 -1
  29. package/src/cli/tlapm.ts +14 -13
  30. package/src/cli/tlc-arguments.ts +222 -210
  31. package/src/cli/tlc-output.ts +687 -0
  32. package/src/cli/tlc-usage.ts +1 -1
  33. package/src/cli/tlc.ts +34 -701
  34. package/src/cli/xml-exporter.ts +23 -33
  35. package/src/codegen.ts +5 -10
  36. package/src/coverage.ts +3 -10
  37. package/src/dependencies.ts +8 -13
  38. package/src/dfid.ts +16 -16
  39. package/src/environment-config.ts +315 -0
  40. package/src/environment.ts +45 -333
  41. package/src/errors.ts +3 -2
  42. package/src/evaluate.ts +5 -4
  43. package/src/fingerprints.ts +65 -1
  44. package/src/instances.ts +47 -10
  45. package/src/java-hash.ts +7 -0
  46. package/src/json.ts +4 -7
  47. package/src/levels.ts +39 -42
  48. package/src/liveness-checker.ts +24 -37
  49. package/src/liveness.ts +47 -54
  50. package/src/obligations/action.ts +4 -11
  51. package/src/obligations/anonymize.ts +4 -2
  52. package/src/obligations/expression.ts +18 -2
  53. package/src/obligations/generate.ts +45 -38
  54. package/src/obligations/index.ts +2 -2
  55. package/src/obligations/module.ts +27 -38
  56. package/src/obligations/normalize.ts +2 -1
  57. package/src/obligations/simplify.ts +39 -44
  58. package/src/obligations/source.ts +47 -57
  59. package/src/obligations/temporal.ts +5 -5
  60. package/src/parallel-worker.ts +10 -30
  61. package/src/parallel.ts +22 -45
  62. package/src/parser.ts +19 -34
  63. package/src/prover/decide-pool.ts +3 -3
  64. package/src/prover/deciders.ts +3 -3
  65. package/src/prover/isabelle/encode.ts +1 -1
  66. package/src/prover/isabelle/isar/inner-syntax.ts +9 -4
  67. package/src/prover/isabelle/isar/method.ts +14 -25
  68. package/src/prover/isabelle/isar/theory.ts +11 -10
  69. package/src/prover/isabelle/isar/type-check.ts +6 -6
  70. package/src/prover/isabelle/provers/blast/blast.ts +7 -63
  71. package/src/prover/isabelle/provers/hypsubst.ts +17 -26
  72. package/src/prover/isabelle/pure/bicompose.ts +9 -25
  73. package/src/prover/isabelle/pure/conv.ts +2 -8
  74. package/src/prover/isabelle/pure/drule.ts +9 -2
  75. package/src/prover/isabelle/pure/logic.ts +1 -1
  76. package/src/prover/isabelle/pure/raw-simplifier.ts +4 -13
  77. package/src/prover/isabelle/pure/rewriter.ts +5 -9
  78. package/src/prover/isabelle/pure/table.ts +2 -1
  79. package/src/prover/isabelle/pure/tactical.ts +42 -35
  80. package/src/prover/isabelle/pure/thm.ts +14 -11
  81. package/src/prover/isabelle/tla/classical-setup.ts +17 -14
  82. package/src/prover/isabelle/tla/context.ts +7 -2
  83. package/src/prover/isabelle/tla/logic.ts +10 -21
  84. package/src/prover/isabelle/tla/simpdata.ts +1 -10
  85. package/src/prover/prep/action.ts +11 -19
  86. package/src/prover/prep/fingerprint.ts +2 -5
  87. package/src/prover/prep/methods.ts +24 -3
  88. package/src/prover/prove.ts +87 -64
  89. package/src/prover/smt/context.ts +1 -2
  90. package/src/prover/smt/data.ts +418 -406
  91. package/src/prover/smt/encode.ts +30 -18
  92. package/src/prover/smt/rewrite.ts +657 -626
  93. package/src/prover/smt/solver/ast.ts +0 -22
  94. package/src/prover/smt/solver/auf-solver.ts +2 -5
  95. package/src/prover/smt/solver/context.ts +3 -3
  96. package/src/prover/smt/solver/e-matching.ts +1 -1
  97. package/src/prover/smt/solver/expr-safe-replace.ts +1 -1
  98. package/src/prover/smt/solver/internalizer.ts +1 -2
  99. package/src/prover/smt/solver/lp/dioph-eq.ts +1 -8
  100. package/src/prover/smt/solver/lp/hnf-cutter.ts +1 -1
  101. package/src/prover/smt/solver/lp/nla-core.ts +2 -6
  102. package/src/prover/smt/solver/mam-compiler.ts +4 -2
  103. package/src/prover/smt/solver/model-checker.ts +1 -1
  104. package/src/prover/smt/solver/model-finder.ts +12 -17
  105. package/src/prover/smt/solver/model-macro-solver.ts +11 -19
  106. package/src/prover/smt/solver/nlsat/algebraic.ts +9 -9
  107. package/src/prover/smt/solver/nlsat/atoms.ts +20 -4
  108. package/src/prover/smt/solver/nlsat/explain.ts +7 -22
  109. package/src/prover/smt/solver/nlsat/levelwise.ts +1 -6
  110. package/src/prover/smt/solver/nlsat/polynomial.ts +12 -3
  111. package/src/prover/smt/solver/nlsat/solver.ts +12 -24
  112. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -1
  113. package/src/prover/smt/solver/proto-model.ts +0 -4
  114. package/src/prover/smt/solver/quantifier-analyzer.ts +10 -10
  115. package/src/prover/smt/solver/quantifier-manager.ts +1 -5
  116. package/src/prover/smt/solver/smtlib-parser.ts +78 -94
  117. package/src/prover/smt/solver/theory-lra-bounds.ts +1 -2
  118. package/src/prover/smt/solver/theory-lra-internalize.ts +5 -16
  119. package/src/prover/tlapm/cache.ts +28 -18
  120. package/src/prover/tlapm/tlapm.ts +15 -9
  121. package/src/prover/verdict.ts +7 -0
  122. package/src/prover/zenon/check/check.ts +1 -2
  123. package/src/prover/zenon/check/records.ts +1 -1
  124. package/src/prover/zenon/check/relations.ts +2 -1
  125. package/src/prover/zenon/check/rewrites.ts +2 -15
  126. package/src/prover/zenon/check/sets.ts +40 -58
  127. package/src/prover/zenon/check/terms.ts +1 -2
  128. package/src/prover/zenon/eqrel.ts +2 -0
  129. package/src/prover/zenon/expr.ts +7 -0
  130. package/src/prover/zenon/index-table.ts +9 -19
  131. package/src/prover/zenon/isar.ts +35 -35
  132. package/src/prover/zenon/llproof.ts +2 -11
  133. package/src/prover/zenon/mltoll.ts +12 -28
  134. package/src/prover/zenon/parse.ts +3 -6
  135. package/src/prover/zenon/search.ts +4 -14
  136. package/src/prover/zenon/tla/functions.ts +2 -2
  137. package/src/prover/zenon/tla/llproof.ts +9 -11
  138. package/src/prover/zenon/tla/records.ts +1 -6
  139. package/src/prover/zenon/tla/sets.ts +15 -14
  140. package/src/prover/zenon/tla/tla.ts +7 -6
  141. package/src/resolve.ts +55 -72
  142. package/src/sany/generation.ts +394 -0
  143. package/src/sany/generator-def-entries.ts +210 -0
  144. package/src/sany/generator-definitions.ts +686 -0
  145. package/src/sany/generator-expressions.ts +1100 -0
  146. package/src/sany/generator-proofs.ts +662 -0
  147. package/src/sany/generator.ts +155 -2625
  148. package/src/sany/lexer.ts +17 -16
  149. package/src/sany/nodes.ts +6 -13
  150. package/src/sany/report.ts +3 -6
  151. package/src/sany/selectors.ts +35 -38
  152. package/src/sany/xml.ts +23 -55
  153. package/src/search.ts +65 -27
  154. package/src/simulate.ts +157 -133
  155. package/src/spec-description.ts +33 -48
  156. package/src/standard-modules.ts +16 -32
  157. package/src/state-graph.ts +2 -7
  158. package/src/substitution-levels.ts +5 -4
  159. package/src/successors.ts +5 -7
  160. package/src/tlc/messages.ts +20 -15
  161. package/src/tlc/order.ts +2 -9
  162. package/src/tlc/random.ts +4 -4
  163. package/src/tlc/replay.ts +8 -15
  164. package/src/tlc/tlc-operators.ts +2 -3
  165. package/src/tlc/trace-spec.ts +25 -45
  166. package/src/typescript/actions.ts +2 -4
  167. package/src/typescript/collections.ts +34 -20
  168. package/src/typescript/compile.ts +1 -3
  169. package/src/typescript/formula.ts +5 -3
  170. package/src/typescript/model.ts +4 -5
  171. package/src/typescript/steps.ts +20 -18
  172. package/src/values.ts +63 -158
@@ -18,6 +18,12 @@ export interface TheoryText {
18
18
  readonly method: readonly OuterToken[];
19
19
  }
20
20
 
21
+ export const syntaxError = (token: OuterToken | undefined) =>
22
+ new TlaIsabelleError(
23
+ "ERROR",
24
+ `Outer syntax error at: ${token === undefined ? "end of input" : token.text}`,
25
+ );
26
+
21
27
  const isWordChar = (char: string) => /[A-Za-z0-9_'.]/.test(char);
22
28
 
23
29
  const readString = (text: string, start: number): [string, number] => {
@@ -96,28 +102,23 @@ export const parseTheory = (text: string): TheoryText => {
96
102
  let position = 0;
97
103
  const peek = () => tokens[position];
98
104
  const isWord = (word: string) => peek()?.kind === "word" && peek().text === word;
99
- const syntaxError = () =>
100
- new TlaIsabelleError(
101
- "ERROR",
102
- `Outer syntax error at: ${peek() === undefined ? "end of input" : peek().text}`,
103
- );
104
105
  const expectWord = (word: string) => {
105
- if (!isWord(word)) throw syntaxError();
106
+ if (!isWord(word)) throw syntaxError(peek());
106
107
  position += 1;
107
108
  };
108
109
  const expectSymbol = (symbol: string) => {
109
- if (peek()?.kind !== "symbol" || peek().text !== symbol) throw syntaxError();
110
+ if (peek()?.kind !== "symbol" || peek().text !== symbol) throw syntaxError(peek());
110
111
  position += 1;
111
112
  };
112
113
  const expectName = () => {
113
114
  const token = peek();
114
- if (token?.kind !== "word" || KEYWORDS.has(token.text)) throw syntaxError();
115
+ if (token?.kind !== "word" || KEYWORDS.has(token.text)) throw syntaxError(token);
115
116
  position += 1;
116
117
  return token.text;
117
118
  };
118
119
  const expectString = () => {
119
120
  const token = peek();
120
- if (token?.kind !== "string") throw syntaxError();
121
+ if (token?.kind !== "string") throw syntaxError(token);
121
122
  position += 1;
122
123
  return token.text;
123
124
  };
@@ -176,6 +177,6 @@ export const parseTheory = (text: string): TheoryText => {
176
177
  const method = tokens.slice(methodStart, position);
177
178
  expectWord("qed");
178
179
  expectWord("end");
179
- if (position !== tokens.length) throw syntaxError();
180
+ if (position !== tokens.length) throw syntaxError(peek());
180
181
  return { name: theoryName, consts, elements, shows, isUsingAssms, method };
181
182
  };
@@ -109,11 +109,14 @@ const unify = (inference: Inference, left: Typ, right: Typ) => {
109
109
  throw new TlaIsabelleError("ERROR", "Type unification failed");
110
110
  };
111
111
 
112
+ const getSchemeKey = (atom: Exclude<Typ, { kind: "Type" }>) =>
113
+ atom.kind === "TFree" ? atom.name : `${atom.name}.${atom.index}`;
114
+
112
115
  const instantiateScheme = (inference: Inference, type: Typ) => {
113
116
  const params = new Map<string, Typ>();
114
117
  const instantiate = (current: Typ): Typ => {
115
118
  if (current.kind === "Type") return mkType(current.name, current.args.map(instantiate));
116
- const key = current.kind === "TFree" ? current.name : `${current.name}.${current.index}`;
119
+ const key = getSchemeKey(current);
117
120
  const known = params.get(key);
118
121
  if (known !== undefined) return known;
119
122
  const param = createParam(inference);
@@ -186,10 +189,7 @@ const matchScheme = (pattern: Typ, object: Typ, instantiation: Map<string, Typ>)
186
189
  pattern.args.forEach((arg, index) => matchScheme(arg, object.args[index], instantiation));
187
190
  return;
188
191
  }
189
- instantiation.set(
190
- pattern.kind === "TFree" ? pattern.name : `${pattern.name}.${pattern.index}`,
191
- object,
192
- );
192
+ instantiation.set(getSchemeKey(pattern), object);
193
193
  };
194
194
 
195
195
  const instantiateMatched = (type: Typ, instantiation: ReadonlyMap<string, Typ>): Typ =>
@@ -198,7 +198,7 @@ const instantiateMatched = (type: Typ, instantiation: ReadonlyMap<string, Typ>):
198
198
  type.name,
199
199
  type.args.map((arg) => instantiateMatched(arg, instantiation)),
200
200
  )
201
- : (instantiation.get(type.kind === "TFree" ? type.name : `${type.name}.${type.index}`) ?? type);
201
+ : (instantiation.get(getSchemeKey(type)) ?? type);
202
202
 
203
203
  const expandAbbreviations = (scope: NameScope, term: Term): Term => {
204
204
  const [head, args] = stripComb(term);
@@ -1,11 +1,11 @@
1
1
  // Ported from Isabelle2025's Provers/blast.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
2
2
 
3
- import { TlaIsabelleError } from "../../../../errors";
3
+ import { isIsabelleError, TlaIsabelleError } from "../../../../errors";
4
4
  import { selectGoal } from "../../pure/goal";
5
- import { destImplies, stripParams } from "../../pure/logic";
5
+ import { destImplies, isAllAbs, stripParams } from "../../pure/logic";
6
6
  import { makeNameContext } from "../../pure/name";
7
- import { emptySeq, makeSeq, ofCell, type Cell, type Seq } from "../../pure/seq";
8
- import { eqThm, orElse, thenTac, type GoalTactic, type Tactic } from "../../pure/tactical";
7
+ import { emptySeq, ofCell, type Seq } from "../../pure/seq";
8
+ import { every, orElse, thenTac, type GoalTactic, type Tactic } from "../../pure/tactical";
9
9
  import { addFreeNames, stripComb, type Term } from "../../pure/term";
10
10
  import { nprems, type Thm } from "../../pure/thm";
11
11
  import { atomizePremsTac } from "../../pure/object-logic";
@@ -36,15 +36,10 @@ import {
36
36
  type VarRef,
37
37
  } from "./term";
38
38
 
39
- export type { BlastContext } from "./state";
40
-
41
39
  const DEPTH_LIMIT = 20;
42
40
 
43
41
  class Trans extends Error {}
44
42
 
45
- const isTermError = (error: unknown) =>
46
- error instanceof TlaIsabelleError && error.exception === "TERM";
47
-
48
43
  const initialize = (context: BlastContext, state: Thm): BlastState => {
49
44
  for (const name of [GOAL_NAME, FALSE_NAME])
50
45
  if (context.consts.has(name))
@@ -53,12 +48,7 @@ const initialize = (context: BlastContext, state: Thm): BlastState => {
53
48
  };
54
49
 
55
50
  const discardForalls = (term: Term): Term =>
56
- term.kind === "App" &&
57
- term.fun.kind === "Const" &&
58
- term.fun.name === "Pure.all" &&
59
- term.arg.kind === "Abs"
60
- ? discardForalls(term.arg.body)
61
- : term;
51
+ isAllAbs(term) ? discardForalls(term.arg.body) : term;
62
52
 
63
53
  interface SubgoalVar {
64
54
  readonly key: string;
@@ -122,52 +112,6 @@ const fromSubgoal = (state: BlastState, term: Term): BlastTerm => {
122
112
  return result;
123
113
  };
124
114
 
125
- interface EveryTrail {
126
- readonly state: Thm;
127
- readonly rest: Seq<Thm>;
128
- readonly position: number;
129
- readonly next: EveryTrail | undefined;
130
- }
131
-
132
- const everyTac =
133
- (tactics: readonly Tactic[]): Tactic =>
134
- (start) => {
135
- const advance = (
136
- initialTrail: EveryTrail | undefined,
137
- initialPosition: number,
138
- initialState: Thm | undefined,
139
- ): Cell<Thm> => {
140
- let trail = initialTrail;
141
- let position = initialPosition;
142
- let state = initialState;
143
- for (;;) {
144
- if (state === undefined) {
145
- if (trail === undefined) return undefined;
146
- const cell = trail.rest.pull();
147
- if (cell === undefined) trail = trail.next;
148
- else if (eqThm(trail.state, cell[0])) trail = { ...trail, rest: cell[1] };
149
- else {
150
- trail = { state: cell[0], rest: cell[1], position: trail.position, next: trail.next };
151
- position = trail.position;
152
- state = cell[0];
153
- }
154
- } else if (position === tactics.length) {
155
- const saved = trail;
156
- return [state, makeSeq(() => advance(saved, 0, undefined))];
157
- } else {
158
- const cell = tactics[position](state).pull();
159
- if (cell === undefined) state = undefined;
160
- else {
161
- trail = { state: cell[0], rest: cell[1], position: position + 1, next: trail };
162
- position += 1;
163
- state = cell[0];
164
- }
165
- }
166
- }
167
- };
168
- return makeSeq(() => advance(undefined, 0, start));
169
- };
170
-
171
115
  const initBranch = (terms: readonly BlastTerm[], lim: number): Branch => ({
172
116
  pairs: [{ safe: terms.map((term) => ({ term, md: true })), unsafe: [] }],
173
117
  lits: [],
@@ -185,9 +129,9 @@ const rawBlast =
185
129
  const replay: Tactic[] = [];
186
130
  for (let current = tactics; current !== undefined; current = current.tail)
187
131
  replay.push(current.head(1));
188
- return everyTac(replay.reverse())(goalState).pull();
132
+ return every(replay.reverse())(goalState).pull();
189
133
  } catch (error) {
190
- if (isTermError(error)) return backtrack(choices);
134
+ if (isIsabelleError(error, "TERM")) return backtrack(choices);
191
135
  throw error;
192
136
  }
193
137
  })();
@@ -1,12 +1,19 @@
1
1
  // Ported from Isabelle2025's Provers/hypsubst.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
2
2
 
3
- import { TlaIsabelleError } from "../../../errors";
3
+ import { isIsabelleError, TlaIsabelleError } from "../../../errors";
4
4
  import { asmRl, compIncr, revcutRl, thinRl, zeroVarIndexes } from "../pure/drule";
5
5
  import { aeconv, etaContract } from "../pure/envir";
6
- import { occs, stripAssumsConcl, stripAssumsHyp, stripParams } from "../pure/logic";
6
+ import {
7
+ isAllAbs,
8
+ isImplies,
9
+ occs,
10
+ stripAssumsConcl,
11
+ stripAssumsHyp,
12
+ stripParams,
13
+ } from "../pure/logic";
7
14
  import { isBoundName } from "../pure/name";
8
15
  import { emptySimpset, type SimpContext } from "../pure/raw-simplifier";
9
- import { listOfSeq } from "../pure/seq";
16
+ import { seqHead } from "../pure/seq";
10
17
  import { asmLrSimpTac } from "../pure/simplifier";
11
18
  import {
12
19
  determ,
@@ -77,11 +84,6 @@ interface HypsubstContext {
77
84
  class NoMatch {}
78
85
  class EqVar {}
79
86
 
80
- const isTermError = (error: unknown) =>
81
- error instanceof TlaIsabelleError && error.exception === "TERM";
82
- const isThmError = (error: unknown) =>
83
- error instanceof TlaIsabelleError && error.exception === "THM";
84
-
85
87
  const inspectContract = (term: Term) => {
86
88
  const contracted = etaContract(term);
87
89
  return contracted.kind === "Free" && isBoundName(contracted.name) ? mkBound(0) : contracted;
@@ -141,19 +143,8 @@ const eqVar = (
141
143
  term: Term,
142
144
  hyps: readonly Term[],
143
145
  ): [number, [boolean, boolean]] => {
144
- if (
145
- term.kind === "App" &&
146
- term.fun.kind === "Const" &&
147
- term.fun.name === "Pure.all" &&
148
- term.arg.kind === "Abs"
149
- )
150
- return visit(count, term.arg.body, hyps);
151
- if (
152
- term.kind === "App" &&
153
- term.fun.kind === "App" &&
154
- term.fun.fun.kind === "Const" &&
155
- term.fun.fun.name === "Pure.imp"
156
- ) {
146
+ if (isAllAbs(term)) return visit(count, term.arg.body, hyps);
147
+ if (isImplies(term)) {
157
148
  const premise = term.fun.arg;
158
149
  const conclusion = term.arg;
159
150
  try {
@@ -161,7 +152,7 @@ const eqVar = (
161
152
  const [orientation, variable] = inspectPair(isBound, isNoVars, left, right);
162
153
  return [count, checkFree([conclusion, ...hyps], orientation, variable)];
163
154
  } catch (error) {
164
- if (!isTermError(error) && !(error instanceof NoMatch)) throw error;
155
+ if (!isIsabelleError(error, "TERM") && !(error instanceof NoMatch)) throw error;
165
156
  return visit(count + 1, conclusion, [premise, ...hyps]);
166
157
  }
167
158
  }
@@ -175,7 +166,7 @@ const withEqVar = (build: (goal: Term, index: number) => Tactic): GoalTactic =>
175
166
  try {
176
167
  return build(goal, index);
177
168
  } catch (error) {
178
- if (error instanceof EqVar || isThmError(error)) return noTac;
169
+ if (error instanceof EqVar || isIsabelleError(error, "THM")) return noTac;
179
170
  throw error;
180
171
  }
181
172
  });
@@ -187,7 +178,7 @@ const mkEqs = (data: HypsubstData, isBound: boolean, thm: Thm): Thm[] => {
187
178
  ? [rs(thm, data.eqReflection)]
188
179
  : [symmetric(rs(thm, data.eqReflection))];
189
180
  } catch (error) {
190
- if (isTermError(error) || error instanceof NoMatch) return [];
181
+ if (isIsabelleError(error, "TERM") || error instanceof NoMatch) return [];
191
182
  throw error;
192
183
  }
193
184
  };
@@ -228,7 +219,7 @@ const instSubstTac = (context: HypsubstContext, isLeft: boolean, rule: Thm): Goa
228
219
  const [left, right] = data.destEq(data.destTrueprop(hyp));
229
220
  return [etaContract(left), etaContract(right)] as const;
230
221
  } catch (error) {
231
- if (isTermError(error)) return undefined;
222
+ if (isIsabelleError(error, "TERM")) return undefined;
232
223
  throw error;
233
224
  }
234
225
  })();
@@ -340,7 +331,7 @@ const varsGenHypSubstTac = (context: HypsubstContext, isBound: boolean): GoalTac
340
331
  });
341
332
 
342
333
  const revDupElim = (thm: Thm) => {
343
- const result = listOfSeq(assumption(undefined, 2, rsn(thm, 2, revcutRl)))[0];
334
+ const result = seqHead(assumption(undefined, 2, rsn(thm, 2, revcutRl)));
344
335
  if (result === undefined) throw new TlaIsabelleError("THM", "rev_dup_elim");
345
336
  return result;
346
337
  };
@@ -2,33 +2,17 @@
2
2
 
3
3
  import { TlaIsabelleError } from "../../../errors";
4
4
  import { normTerm, type Envir } from "./envir";
5
- import { allConst, mkImplies } from "./logic";
5
+ import { allConst, isAllAbs, isImplies, mkImplies } from "./logic";
6
6
  import { unifyTypesEnvir } from "./pattern";
7
7
  import type { Thm } from "./thm";
8
8
  import { normType } from "./type";
9
9
  import { eqTyp, foldVars, matchBvars, mkAbs, mkApp, mkVar, type Term, type Typ } from "./term";
10
10
  import type { Tpair } from "./unify";
11
11
 
12
- const isImpApp = (
13
- term: Term,
14
- ): term is Extract<Term, { kind: "App" }> & { fun: Extract<Term, { kind: "App" }> } =>
15
- term.kind === "App" &&
16
- term.fun.kind === "App" &&
17
- term.fun.fun.kind === "Const" &&
18
- term.fun.fun.name === "Pure.imp";
19
-
20
- const isAllApp = (
21
- term: Term,
22
- ): term is Extract<Term, { kind: "App" }> & { arg: Extract<Term, { kind: "Abs" }> } =>
23
- term.kind === "App" &&
24
- term.fun.kind === "Const" &&
25
- term.fun.name === "Pure.all" &&
26
- term.arg.kind === "Abs";
27
-
28
12
  export const stripApply = (apply: (term: Term) => Term, lifted: Term, term: Term): Term => {
29
- if (isImpApp(lifted) && isImpApp(term))
13
+ if (isImplies(lifted) && isImplies(term))
30
14
  return mkApp(mkApp(lifted.fun.fun, term.fun.arg), stripApply(apply, lifted.arg, term.arg));
31
- if (isAllApp(lifted) && isAllApp(term))
15
+ if (isAllAbs(lifted) && isAllAbs(term))
32
16
  return mkApp(
33
17
  lifted.fun,
34
18
  mkAbs(term.arg.name, term.arg.type, stripApply(apply, lifted.arg.body, term.arg.body)),
@@ -37,8 +21,8 @@ export const stripApply = (apply: (term: Term) => Term, lifted: Term, term: Term
37
21
  };
38
22
 
39
23
  const stripLifted = (lifted: Term, term: Term): Term => {
40
- if (isImpApp(lifted) && isImpApp(term)) return stripLifted(lifted.arg, term.arg);
41
- if (isAllApp(lifted) && isAllApp(term)) return stripLifted(lifted.arg.body, term.arg.body);
24
+ if (isImplies(lifted) && isImplies(term)) return stripLifted(lifted.arg, term.arg);
25
+ if (isAllAbs(lifted) && isAllAbs(term)) return stripLifted(lifted.arg.body, term.arg.body);
42
26
  return term;
43
27
  };
44
28
 
@@ -125,8 +109,8 @@ export const renameBvars = (
125
109
  };
126
110
 
127
111
  export const stripAssums2 = (lifted: Term, goal: Term): Tpair => {
128
- if (isImpApp(lifted) && isImpApp(goal)) return stripAssums2(lifted.arg, goal.arg);
129
- if (isAllApp(lifted) && isAllApp(goal)) {
112
+ if (isImplies(lifted) && isImplies(goal)) return stripAssums2(lifted.arg, goal.arg);
113
+ if (isAllAbs(lifted) && isAllAbs(goal)) {
130
114
  const [left, right] = stripAssums2(lifted.arg.body, goal.arg.body);
131
115
  return [
132
116
  mkAbs(lifted.arg.name, lifted.arg.type, left),
@@ -138,14 +122,14 @@ export const stripAssums2 = (lifted: Term, goal: Term): Tpair => {
138
122
 
139
123
  export const normTermSkip = (envir: Envir, count: number, term: Term): Term => {
140
124
  if (count === 0) return normTerm(envir, term);
141
- if (isAllApp(term)) {
125
+ if (isAllAbs(term)) {
142
126
  const type = normType(envir.tyenv, term.arg.type);
143
127
  return mkApp(
144
128
  allConst(type),
145
129
  mkAbs(term.arg.name, type, normTermSkip(envir, count, term.arg.body)),
146
130
  );
147
131
  }
148
- if (isImpApp(term)) return mkImplies(term.fun.arg, normTermSkip(envir, count - 1, term.arg));
132
+ if (isImplies(term)) return mkImplies(term.fun.arg, normTermSkip(envir, count - 1, term.arg));
149
133
  throw new TlaIsabelleError("ERROR", "norm_term_skip: too few assumptions??");
150
134
  };
151
135
 
@@ -1,7 +1,7 @@
1
1
  // Ported from Isabelle2025's Pure/conv.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
2
2
 
3
3
  import { TlaIsabelleError } from "../../../errors";
4
- import { destEquals, destImplies, implies, isImplies } from "./logic";
4
+ import { destEquals, destImplies, implies, isAllAbs, isImplies } from "./logic";
5
5
  import { declareName, makeNameContext, variantName, type NameContext } from "./name";
6
6
  import { aconv, addFreeNames, mkFree, substBound, type Term } from "./term";
7
7
  import {
@@ -36,13 +36,7 @@ export const paramsConv = (convert: Conversion): Conversion => {
36
36
  const under =
37
37
  (names: NameContext): Conversion =>
38
38
  (term) => {
39
- if (
40
- term.kind !== "App" ||
41
- term.fun.kind !== "Const" ||
42
- term.fun.name !== "Pure.all" ||
43
- term.arg.kind !== "Abs"
44
- )
45
- return convert(term);
39
+ if (!isAllAbs(term)) return convert(term);
46
40
  const abs = term.arg;
47
41
  const [name, nextNames] = variantName(abs.name, names);
48
42
  const free = mkFree(name, abs.type);
@@ -1,6 +1,13 @@
1
1
  // Ported from Isabelle2025's Pure/drule.ML, Pure/term_subst.ML and Pure/Pure.thy. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
2
2
 
3
- import { cleanName, emptyNameContext, variantList, variantName, type NameContext } from "./name";
3
+ import {
4
+ cleanName,
5
+ emptyNameContext,
6
+ isBoundName,
7
+ variantList,
8
+ variantName,
9
+ type NameContext,
10
+ } from "./name";
4
11
  import {
5
12
  emptyTable,
6
13
  fastIndexnameOrd,
@@ -157,7 +164,7 @@ export const forallIntrVars = (thm: Thm) => {
157
164
  };
158
165
 
159
166
  const variantBound = (name: string, used: NameContext) =>
160
- variantName(name.startsWith(":") ? "u" : name, used);
167
+ variantName(isBoundName(name) ? "u" : name, used);
161
168
 
162
169
  const fullProps = (thm: Thm) => [...thm.tpairs.flatMap((pair) => [pair[0], pair[1]]), thm.prop];
163
170
 
@@ -183,7 +183,7 @@ const incrIndexesFixed = (
183
183
  export const incrIndexes = (types: readonly Typ[], increment: number, term: Term) =>
184
184
  incrIndexesFixed([], types, increment, 0, term);
185
185
 
186
- const isAllAbs = (
186
+ export const isAllAbs = (
187
187
  term: Term,
188
188
  ): term is Extract<Term, { kind: "App" }> & {
189
189
  arg: Extract<Term, { kind: "Abs" }>;
@@ -6,7 +6,7 @@ import { symmetricThm } from "./drule";
6
6
  import { destEquals, isEquals, occs, stripImpConcl, stripImpPrems } from "./logic";
7
7
  import { emptyNet, insertNet, keyOfTerm, type Net } from "./net";
8
8
  import { isFirstOrder, isPattern, matches } from "./pattern";
9
- import { emptyTable, type Table } from "./table";
9
+ import { emptyTable, stringOrd, type Table } from "./table";
10
10
  import { emptyTyEnv } from "./type";
11
11
  import {
12
12
  aconv,
@@ -20,7 +20,7 @@ import {
20
20
  type Typ,
21
21
  type Var,
22
22
  } from "./term";
23
- import { rs, type Thm } from "./thm";
23
+ import { catchThm, rs, type Thm } from "./thm";
24
24
  import { eqThmProp, noTac, type GoalTactic } from "./tactical";
25
25
  import type { Limits } from "./interrupt";
26
26
 
@@ -227,14 +227,7 @@ const orientRrule = (context: SimpContext, thm: Thm): RawRrule[] => {
227
227
  return rruleEqTrue(context, thm, decomposed.lhs, decomposed.elhs, decomposed.rhs, thm);
228
228
  if (defaultReorient(decomposed.prems, decomposed.rhs, decomposed.lhs))
229
229
  return mkEqTrue(context, thm);
230
- const symmetric = (() => {
231
- try {
232
- return rs(thm, symmetricThm);
233
- } catch (error) {
234
- if (error instanceof TlaIsabelleError && error.exception === "THM") return undefined;
235
- throw error;
236
- }
237
- })();
230
+ const symmetric = catchThm(() => rs(thm, symmetricThm));
238
231
  if (symmetric === undefined) return [];
239
232
  const flipped = decompSimp(symmetric);
240
233
  return rruleEqTrue(context, symmetric, flipped.lhs, flipped.elhs, flipped.rhs, thm);
@@ -275,9 +268,7 @@ export const rulesFromEntries = (thms: readonly Thm[]): Net<Rrule> =>
275
268
  return insertNet(() => false, keyOfTerm(rrule.elhs), rrule, net) ?? net;
276
269
  }, emptyNet);
277
270
 
278
- export const emptyCongs: Table<string, Thm> = emptyTable((left: string, right: string) =>
279
- left === right ? 0 : left < right ? -1 : 1,
280
- );
271
+ export const emptyCongs: Table<string, Thm> = emptyTable(stringOrd);
281
272
 
282
273
  export const emptySimpset: Simpset = {
283
274
  rules: emptyNet,
@@ -1,6 +1,6 @@
1
1
  // Ported from Isabelle2025's Pure/raw_simplifier.ML and Pure/conv.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
2
2
 
3
- import { TlaIsabelleError } from "../../../errors";
3
+ import { isIsabelleError, TlaIsabelleError } from "../../../errors";
4
4
  import { gconvRule, impCongRule } from "./conv";
5
5
  import { impCong, swapPremsEq } from "./drule";
6
6
  import { emptyTEnv } from "./envir";
@@ -80,9 +80,6 @@ export type Prover = (context: SimpContext, thm: Thm) => Thm | undefined;
80
80
  export const simpleProver: Prover = (context, thm) =>
81
81
  seqHead(allGoals(resolveTac(context.limits, context.simpset.prems))(thm));
82
82
 
83
- const isThmError = (error: unknown) =>
84
- error instanceof TlaIsabelleError && error.exception === "THM";
85
-
86
83
  const lhsOf = (thm: Thm) => destEquals(thm.prop)[0];
87
84
  const rhsOf = (thm: Thm) => destEquals(thm.prop)[1];
88
85
 
@@ -109,18 +106,18 @@ const checkConv = (thm: Thm, next: Thm): Thm | undefined => {
109
106
  try {
110
107
  return transitive(thm, next);
111
108
  } catch (error) {
112
- if (!isThmError(error)) throw error;
109
+ if (!isIsabelleError(error, "THM")) throw error;
113
110
  }
114
111
  try {
115
112
  const normalized = transitive(symmetric(betaEtaConversion(lhsOf(next))), next);
116
113
  try {
117
114
  return transitive(thm, normalized);
118
115
  } catch (error) {
119
- if (!isThmError(error)) throw error;
116
+ if (!isIsabelleError(error, "THM")) throw error;
120
117
  return transitive(transitive(thm, betaEtaConversion(rhsOf(thm))), normalized);
121
118
  }
122
119
  } catch (error) {
123
- if (isThmError(error)) return undefined;
120
+ if (isIsabelleError(error, "THM")) return undefined;
124
121
  throw error;
125
122
  }
126
123
  };
@@ -328,9 +325,8 @@ const bottomc = (mode: RewriteMode, prover: Prover, maxidx: number) => {
328
325
  return inner === undefined ? undefined : abstractRule(term.name, variable, inner);
329
326
  }
330
327
  if (term.kind !== "App") return undefined;
328
+ if (isImplies(term)) return impc(term, context);
331
329
  const head = term.fun;
332
- if (head.kind === "App" && head.fun.kind === "Const" && head.fun.name === "Pure.imp")
333
- return impc(term, context);
334
330
  if (head.kind === "Abs") {
335
331
  const beta = betaConversion(false, term);
336
332
  const rest = subc(SKEL0, context, rhsOf(beta));
@@ -157,7 +157,8 @@ export const fastStringOrd = (left: string, right: string) =>
157
157
  ? -1
158
158
  : 1;
159
159
 
160
- const stringOrd = (left: string, right: string) => (left === right ? 0 : left < right ? -1 : 1);
160
+ export const stringOrd = (left: string, right: string) =>
161
+ left === right ? 0 : left < right ? -1 : 1;
161
162
 
162
163
  export interface IndexKey {
163
164
  readonly name: string;
@@ -1,6 +1,6 @@
1
1
  // Ported from Isabelle2025's Pure/tactical.ML and Pure/search.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
2
2
 
3
- import { TlaIsabelleError } from "../../../errors";
3
+ import { isIsabelleError } from "../../../errors";
4
4
  import {
5
5
  appendSeq,
6
6
  emptySeq,
@@ -94,39 +94,49 @@ export const eqThmProp = (left: Thm, right: Thm) => aconv(left.prop, right.prop)
94
94
  interface Trail {
95
95
  readonly state: Thm;
96
96
  readonly rest: Seq<Thm>;
97
- readonly tactics: readonly Tactic[];
97
+ readonly position: number;
98
+ readonly next: Trail | undefined;
98
99
  }
99
100
 
100
- export const every = (tactics: readonly Tactic[]): Tactic => {
101
- const evy = (trail: readonly Trail[], remaining: readonly Tactic[], state: Thm): Seq<Thm> => {
102
- if (remaining.length === 0) return makeSeq(() => [state, makeSeq(() => evyBack(trail).pull())]);
103
- const cell = remaining[0](state).pull();
104
- if (cell === undefined) return evyBack(trail);
105
- return evy(
106
- [{ state: cell[0], rest: cell[1], tactics: remaining.slice(1) }, ...trail],
107
- remaining.slice(1),
108
- cell[0],
109
- );
110
- };
111
- const evyBack = (trail: readonly Trail[]): Seq<Thm> => {
112
- let current = trail;
113
- while (current.length > 0) {
114
- const top = current[0];
115
- const cell = top.rest.pull();
116
- if (cell === undefined) current = current.slice(1);
117
- else if (eqThm(top.state, cell[0]))
118
- current = [{ ...top, rest: cell[1] }, ...current.slice(1)];
119
- else
120
- return evy(
121
- [{ state: cell[0], rest: cell[1], tactics: top.tactics }, ...current.slice(1)],
122
- top.tactics,
123
- cell[0],
124
- );
125
- }
126
- return emptySeq;
101
+ // EVY and evyBack as one loop: blast replays thousands of tactics, too deep for mutual recursion.
102
+ export const every =
103
+ (tactics: readonly Tactic[]): Tactic =>
104
+ (start) => {
105
+ const evy = (
106
+ initialTrail: Trail | undefined,
107
+ initialPosition: number,
108
+ initialState: Thm | undefined,
109
+ ): Cell<Thm> => {
110
+ let trail = initialTrail;
111
+ let position = initialPosition;
112
+ let state = initialState;
113
+ for (;;) {
114
+ if (state === undefined) {
115
+ if (trail === undefined) return undefined;
116
+ const cell = trail.rest.pull();
117
+ if (cell === undefined) trail = trail.next;
118
+ else if (eqThm(trail.state, cell[0])) trail = { ...trail, rest: cell[1] };
119
+ else {
120
+ trail = { state: cell[0], rest: cell[1], position: trail.position, next: trail.next };
121
+ position = trail.position;
122
+ state = cell[0];
123
+ }
124
+ } else if (position === tactics.length) {
125
+ const saved = trail;
126
+ return [state, makeSeq(() => evy(saved, 0, undefined))];
127
+ } else {
128
+ const cell = tactics[position](state).pull();
129
+ if (cell === undefined) state = undefined;
130
+ else {
131
+ trail = { state: cell[0], rest: cell[1], position: position + 1, next: trail };
132
+ position += 1;
133
+ state = cell[0];
134
+ }
135
+ }
136
+ }
137
+ };
138
+ return ofCell(evy(undefined, 0, start));
127
139
  };
128
- return (state) => evy([], tactics, state);
129
- };
130
140
 
131
141
  export const first = (tactics: readonly Tactic[]): Tactic =>
132
142
  tactics.reduceRight((rest, tactic) => orElse(tactic, rest), noTac);
@@ -182,9 +192,6 @@ export const firstGoalTac =
182
192
  return find(1)(state);
183
193
  };
184
194
 
185
- const isThmError = (error: unknown) =>
186
- error instanceof TlaIsabelleError && error.exception === "THM";
187
-
188
195
  export const subgoal =
189
196
  (build: (goal: Term, index: number) => Tactic): GoalTactic =>
190
197
  (index) =>
@@ -215,7 +222,7 @@ export const primSeq =
215
222
  try {
216
223
  return apply(state);
217
224
  } catch (error) {
218
- if (isThmError(error)) return emptySeq;
225
+ if (isIsabelleError(error, "THM")) return emptySeq;
219
226
  throw error;
220
227
  }
221
228
  };