tla-ts 0.0.4-dev.b254db0 → 0.0.4-dev.ca40dfe

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 (207) hide show
  1. package/README.md +31 -10
  2. package/dist/cli.cjs +1 -1
  3. package/dist/cli.js +1 -1
  4. package/dist/deciders.cjs +27 -27
  5. package/dist/deciders.js +34 -34
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +12 -14
  8. package/dist/index.d.ts +12 -14
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +37 -27
  15. package/dist/prove.js +39 -29
  16. package/dist/run.cjs +45 -0
  17. package/dist/run.js +45 -0
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +2 -2
  20. package/dist/transfer.cjs +76 -86
  21. package/dist/transfer.js +73 -83
  22. package/dist/worker.cjs +6 -6
  23. package/dist/worker.js +6 -6
  24. package/package.json +1 -1
  25. package/src/ast.ts +2 -2
  26. package/src/bags.ts +22 -23
  27. package/src/builtins.ts +16 -8
  28. package/src/check.ts +131 -1154
  29. package/src/{cli-options.ts → cli/options.ts} +54 -9
  30. package/src/cli/run.ts +63 -0
  31. package/src/cli/shared.ts +106 -0
  32. package/src/cli/tlapm.ts +374 -0
  33. package/src/cli/tlc.ts +941 -0
  34. package/src/cli/xml-exporter.ts +221 -0
  35. package/src/cli.ts +1 -1
  36. package/src/codegen.ts +17 -15
  37. package/src/config.ts +5 -5
  38. package/src/dependencies.ts +4 -6
  39. package/src/environment.ts +55 -60
  40. package/src/errors.ts +12 -36
  41. package/src/evaluate.ts +81 -101
  42. package/src/exit-codes.ts +1 -1
  43. package/src/fingerprints.ts +3 -3
  44. package/src/instances.ts +56 -46
  45. package/src/java-overrides.ts +79 -41
  46. package/src/json.ts +31 -36
  47. package/src/levels.ts +10 -13
  48. package/src/{live-check.ts → liveness-checker.ts} +169 -142
  49. package/src/liveness.ts +38 -34
  50. package/src/obligations/action.ts +9 -45
  51. package/src/obligations/{anon.ts → anonymize.ts} +13 -25
  52. package/src/obligations/equality.ts +260 -0
  53. package/src/obligations/expression.ts +42 -517
  54. package/src/obligations/generate.ts +88 -778
  55. package/src/obligations/index.ts +20 -22
  56. package/src/obligations/levels.ts +36 -41
  57. package/src/obligations/module.ts +88 -708
  58. package/src/obligations/normalize.ts +554 -0
  59. package/src/obligations/operators.ts +176 -0
  60. package/src/obligations/pragma.ts +21 -15
  61. package/src/obligations/printer.ts +81 -188
  62. package/src/obligations/proof.ts +0 -1
  63. package/src/obligations/regroup.ts +100 -0
  64. package/src/obligations/simplify.ts +668 -0
  65. package/src/obligations/source.ts +25 -131
  66. package/src/obligations/{deref.ts → subexpression.ts} +48 -56
  67. package/src/obligations/substitution.ts +261 -0
  68. package/src/obligations/temporal.ts +28 -26
  69. package/src/obligations/tuples.ts +37 -53
  70. package/src/parallel-worker.ts +37 -33
  71. package/src/parallel.ts +30 -24
  72. package/src/parser.ts +67 -74
  73. package/src/{pcal-ast.ts → pcal/ast.ts} +2 -17
  74. package/src/{pcal-parse.ts → pcal/parse.ts} +28 -64
  75. package/src/{pcal-tokenize.ts → pcal/tokenize.ts} +10 -39
  76. package/src/{pcal-translate.ts → pcal/translate.ts} +30 -109
  77. package/src/{pcal-validate.ts → pcal/validate.ts} +10 -20
  78. package/src/prove/decide-pool.ts +7 -12
  79. package/src/{obligations/pickle.ts → prove/first-order.ts} +79 -2
  80. package/src/prove/isabelle/decide.ts +3 -6
  81. package/src/prove/isabelle/encode.ts +35 -93
  82. package/src/prove/isabelle/isar/inner-syntax.ts +1 -1
  83. package/src/prove/isabelle/isar/method.ts +3 -3
  84. package/src/prove/isabelle/isar/type-check.ts +1 -1
  85. package/src/prove/isabelle/provers/blast/blast.ts +1 -1
  86. package/src/prove/isabelle/provers/blast/branch.ts +1 -1
  87. package/src/prove/isabelle/provers/blast/term.ts +3 -4
  88. package/src/prove/isabelle/provers/clasimp.ts +1 -1
  89. package/src/prove/isabelle/provers/classical.ts +3 -3
  90. package/src/prove/isabelle/provers/hypsubst.ts +1 -9
  91. package/src/prove/isabelle/pure/conv.ts +1 -1
  92. package/src/prove/isabelle/pure/drule.ts +2 -2
  93. package/src/prove/isabelle/pure/envir.ts +3 -35
  94. package/src/prove/isabelle/pure/logic.ts +4 -76
  95. package/src/prove/isabelle/pure/name.ts +1 -13
  96. package/src/prove/isabelle/pure/net.ts +2 -49
  97. package/src/prove/isabelle/pure/pattern.ts +3 -22
  98. package/src/prove/isabelle/pure/raw-simplifier.ts +3 -18
  99. package/src/prove/isabelle/pure/seq.ts +0 -23
  100. package/src/prove/isabelle/pure/simplifier.ts +2 -8
  101. package/src/prove/isabelle/pure/table.ts +1 -8
  102. package/src/prove/isabelle/pure/tactic.ts +5 -113
  103. package/src/prove/isabelle/pure/tactical.ts +1 -84
  104. package/src/prove/isabelle/pure/term-ord.ts +1 -55
  105. package/src/prove/isabelle/pure/term.ts +8 -128
  106. package/src/prove/isabelle/pure/thm.ts +4 -27
  107. package/src/prove/isabelle/pure/type.ts +0 -12
  108. package/src/prove/isabelle/pure/unify.ts +1 -1
  109. package/src/prove/isabelle/tla/classical-setup.ts +1 -1
  110. package/src/prove/ocaml.ts +1 -1
  111. package/src/prove/prep/action.ts +23 -36
  112. package/src/prove/prep/enabled-axioms.ts +2 -2
  113. package/src/prove/prep/fingerprint.ts +3 -3
  114. package/src/prove/prep/level-comparison.ts +9 -37
  115. package/src/prove/prep/md5.ts +2 -9
  116. package/src/prove/prep/normalize.ts +309 -0
  117. package/src/prove/prove-worker.ts +2 -5
  118. package/src/prove/prove.ts +98 -111
  119. package/src/prove/ptl/encode.ts +19 -31
  120. package/src/prove/smt/axioms.ts +45 -58
  121. package/src/prove/smt/encode.ts +124 -15
  122. package/src/prove/smt/instances.ts +2 -3
  123. package/src/prove/smt/rewrite.ts +24 -31
  124. package/src/prove/smt/solver/ast-util.ts +0 -56
  125. package/src/prove/smt/solver/case-split-queue.ts +1 -1
  126. package/src/prove/smt/solver/enode.ts +1 -1
  127. package/src/prove/smt/solver/lp/dep-intervals.ts +0 -14
  128. package/src/prove/smt/solver/model-macro-solver.ts +1 -1
  129. package/src/prove/smt/solver/nlsat/algebraic.ts +3 -3
  130. package/src/prove/smt/solver/nlsat/atoms.ts +1 -1
  131. package/src/prove/smt/solver/nlsat/explain.ts +1 -1
  132. package/src/prove/smt/solver/nlsat/interval-set.ts +1 -1
  133. package/src/prove/smt/solver/nlsat/levelwise.ts +4 -7
  134. package/src/prove/smt/solver/nlsat/polynomial.ts +4 -4
  135. package/src/prove/smt/solver/nlsat/upolynomial.ts +2 -2
  136. package/src/prove/smt/solver/pattern-inference.ts +1 -1
  137. package/src/prove/smt/solver/relevancy.ts +2 -2
  138. package/src/prove/smt/solver/rewriter.ts +1 -1
  139. package/src/prove/smt/solver/solver.ts +2 -2
  140. package/src/{tlapm-cache.ts → prove/tlapm/cache.ts} +11 -11
  141. package/src/{ocaml-marshal.ts → prove/tlapm/ocaml-marshal.ts} +1 -1
  142. package/src/prove/verdict.ts +0 -5
  143. package/src/prove/zenon/decide.ts +5 -11
  144. package/src/prove/zenon/encode.ts +21 -80
  145. package/src/prove/zenon/eqrel.ts +1 -1
  146. package/src/prove/zenon/equality-rules.ts +1 -1
  147. package/src/prove/zenon/expr.ts +2 -2
  148. package/src/prove/zenon/index-table.ts +1 -1
  149. package/src/prove/zenon/isar.ts +1 -1
  150. package/src/prove/zenon/llproof.ts +1 -1
  151. package/src/prove/zenon/mltoll.ts +1 -1
  152. package/src/prove/zenon/node.ts +1 -1
  153. package/src/prove/zenon/search.ts +1 -1
  154. package/src/prove/zenon/tla/terms.ts +1 -20
  155. package/src/prove/zenon/tla/tla.ts +1 -1
  156. package/src/randomization.ts +19 -24
  157. package/src/resolve.ts +15 -22
  158. package/src/runtime.ts +8 -8
  159. package/src/{sany-builtins.ts → sany/builtins.ts} +1 -1
  160. package/src/{sany-generator.ts → sany/generator.ts} +38 -55
  161. package/src/{sany-levels.ts → sany/levels.ts} +45 -48
  162. package/src/{sany-lexer.ts → sany/lexer.ts} +2 -3
  163. package/src/{sany-linter.ts → sany/linter.ts} +1 -1
  164. package/src/{sany-modules.ts → sany/modules.ts} +2 -2
  165. package/src/{sany-nodes.ts → sany/nodes.ts} +2 -2
  166. package/src/{sany-parse-error.ts → sany/parse-error.ts} +2 -2
  167. package/src/{sany-report.ts → sany/report.ts} +16 -17
  168. package/src/{sany-selectors.ts → sany/selectors.ts} +3 -5
  169. package/src/{sany-source.ts → sany/source.ts} +6 -7
  170. package/src/{sany-xml.ts → sany/xml.ts} +5 -6
  171. package/src/search.ts +969 -0
  172. package/src/spec-description.ts +26 -20
  173. package/src/{standard-levels.ts → standard-definitions.ts} +118 -2
  174. package/src/standard-modules.ts +16 -20
  175. package/src/state-graph.ts +9 -8
  176. package/src/substitution-levels.ts +2 -2
  177. package/src/successors.ts +16 -19
  178. package/src/symmetry.ts +1 -1
  179. package/src/tableau.ts +6 -7
  180. package/src/tlc/fingerprint.ts +214 -0
  181. package/src/{tlc-messages.ts → tlc/messages.ts} +119 -7
  182. package/src/{tlc-order.ts → tlc/order.ts} +7 -7
  183. package/src/{tlc-random.ts → tlc/random.ts} +3 -213
  184. package/src/{tlc-replay.ts → tlc/replay.ts} +40 -36
  185. package/src/{tlc-module.ts → tlc/tlc-operators.ts} +9 -9
  186. package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +30 -25
  187. package/src/transfer.ts +32 -32
  188. package/src/values.ts +72 -67
  189. package/src/worker.ts +1 -4
  190. package/dist/run-cli.cjs +0 -45
  191. package/dist/run-cli.js +0 -45
  192. package/src/canonical.ts +0 -40
  193. package/src/obligations/ctx.ts +0 -64
  194. package/src/prove/prep/defs.ts +0 -33
  195. package/src/prove/prep/elab.ts +0 -156
  196. package/src/prove/prep/enabled.ts +0 -43
  197. package/src/prove/prep/flatten.ts +0 -70
  198. package/src/prove/prep/trivial.ts +0 -22
  199. package/src/prove/smt/axiomatize.ts +0 -69
  200. package/src/prove/smt/simplify.ts +0 -57
  201. package/src/run-cli.ts +0 -1806
  202. package/src/standard-ranges.ts +0 -116
  203. package/src/value-sources.ts +0 -29
  204. /package/src/prove/prep/{pragma.ts → methods.ts} +0 -0
  205. /package/src/{tlc-modules.ts → tlc/jar-data.ts} +0 -0
  206. /package/src/{tlc-summary.ts → tlc/summary.ts} +0 -0
  207. /package/src/{tlc-version.ts → tlc/version.ts} +0 -0
@@ -1,10 +1,10 @@
1
1
  // Ported from Isabelle2025's Pure/tactic.ML, the basic resolution tactics. Copyright (c) 1986-2025
2
2
  // University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
3
3
 
4
- import { cutRl, makeElim, thinRl } from "./drule";
4
+ import { makeElim } from "./drule";
5
5
  import { checkInterrupt, type Limits } from "./interrupt";
6
6
  import { stripAssumsConcl, stripAssumsHyp } from "./logic";
7
- import { insertTermNet, unifyTermNet, deleteTermSafe, emptyNet, type Net } from "./net";
7
+ import { insertTermNet, unifyTermNet, type Net } from "./net";
8
8
  import {
9
9
  assumption,
10
10
  bicompose,
@@ -14,25 +14,11 @@ import {
14
14
  flexflexRule,
15
15
  majorPremOf,
16
16
  nprems,
17
- permutePrems,
18
17
  rotateRule,
19
18
  type BiresRule,
20
19
  type Thm,
21
20
  } from "./thm";
22
- import {
23
- allTac,
24
- every,
25
- noTac,
26
- orElseGoal,
27
- primitive,
28
- primSeq,
29
- subgoal,
30
- thenGoal,
31
- thenTac,
32
- type GoalTactic,
33
- type Tactic,
34
- } from "./tactical";
35
- import { eqThmProp } from "./tactical";
21
+ import { allTac, primitive, primSeq, subgoal, type GoalTactic, type Tactic } from "./tactical";
36
22
 
37
23
  export const assumeTac =
38
24
  (limits: Limits): GoalTactic =>
@@ -57,7 +43,7 @@ export const composeTac =
57
43
  ),
58
44
  );
59
45
 
60
- export const biresolveTac =
46
+ const biresolveTac =
61
47
  (limits: Limits, rules: readonly BiresRule[]): GoalTactic =>
62
48
  (index) =>
63
49
  primSeq((state) => {
@@ -80,13 +66,7 @@ export const eresolveTac = (limits: Limits, rules: readonly Thm[]) =>
80
66
  export const dresolveTac = (limits: Limits, rules: readonly Thm[]) =>
81
67
  eresolveTac(limits, rules.map(makeElim));
82
68
 
83
- export const forwardTac = (limits: Limits, rules: readonly Thm[]) =>
84
- thenGoal(resolveTac(limits, rules.map(makeElim)), assumeTac(limits));
85
-
86
- export const aresTac = (limits: Limits, rules: readonly Thm[]) =>
87
- orElseGoal(assumeTac(limits), resolveTac(limits, rules));
88
-
89
- export const bimatchTac =
69
+ const bimatchTac =
90
70
  (limits: Limits, rules: readonly BiresRule[]): GoalTactic =>
91
71
  (index) =>
92
72
  primSeq((state) => {
@@ -109,23 +89,6 @@ export const ematchTac = (limits: Limits, rules: readonly Thm[]) =>
109
89
  export const flexflexTac = (limits: Limits): Tactic =>
110
90
  primSeq((state) => flexflexRule(limits, state));
111
91
 
112
- export const cutTac = (rule: Thm, index: number) =>
113
- thenTac(
114
- primSeq((state) =>
115
- biresolution(undefined, false, [{ isElim: false, rule: cutRl }], index, state),
116
- ),
117
- primSeq((state) => biresolution(undefined, false, [{ isElim: false, rule }], index + 1, state)),
118
- );
119
-
120
- export const cutRulesTac = (rules: readonly Thm[], index: number) =>
121
- every(rules.map((rule) => cutTac(rule, index)));
122
-
123
- export const cutFactsTac = (rules: readonly Thm[], index: number) =>
124
- cutRulesTac(
125
- rules.filter((rule) => nprems(rule) === 0),
126
- index,
127
- );
128
-
129
92
  export interface TaggedRule {
130
93
  readonly tag: number;
131
94
  readonly isElim: boolean;
@@ -137,8 +100,6 @@ export interface NetPair<Tagged> {
137
100
  readonly elim: Net<Tagged>;
138
101
  }
139
102
 
140
- export const emptyNetPair: NetPair<never> = { intro: emptyNet, elim: emptyNet };
141
-
142
103
  // Tactic.insert_tagged_brl
143
104
  export const insertTaggedBrl = <Tagged extends { isElim: boolean; rule: Thm }>(
144
105
  tagged: Tagged,
@@ -148,26 +109,6 @@ export const insertTaggedBrl = <Tagged extends { isElim: boolean; rule: Thm }>(
148
109
  ? { intro: netpair.intro, elim: insertTermNet(majorPremOf(tagged.rule), tagged, netpair.elim) }
149
110
  : { intro: insertTermNet(conclOf(tagged.rule), tagged, netpair.intro), elim: netpair.elim };
150
111
 
151
- const eqKbrl = (left: { rule: Thm }, right: { rule: Thm }) => eqThmProp(left.rule, right.rule);
152
-
153
- // Tactic.delete_tagged_brl
154
- export const deleteTaggedBrl = <Tagged extends { isElim: boolean; rule: Thm }>(
155
- brule: { isElim: boolean; rule: Thm },
156
- netpair: NetPair<Tagged>,
157
- ): NetPair<Tagged> => {
158
- if (brule.isElim) {
159
- if (nprems(brule.rule) === 0) return netpair;
160
- return {
161
- intro: netpair.intro,
162
- elim: deleteTermSafe(eqKbrl, majorPremOf(brule.rule), brule as Tagged, netpair.elim),
163
- };
164
- }
165
- return {
166
- intro: deleteTermSafe(eqKbrl, conclOf(brule.rule), brule as Tagged, netpair.intro),
167
- elim: netpair.elim,
168
- };
169
- };
170
-
171
112
  // Library.order_list: by tag, dropping all but the last item with each tag. The lists are short,
172
113
  // so this sorts them by insertion, which keeps items with equal tags in order as Isabelle's sort.
173
114
  export const orderList = <Item>(items: readonly { tag: number; item: Item }[]): Item[] => {
@@ -217,33 +158,6 @@ export const biresolveFromNetsTac = (limits: Limits, netpair: NetPair<TaggedRule
217
158
  export const bimatchFromNetsTac = (limits: Limits, netpair: NetPair<TaggedRule>) =>
218
159
  biresolutionFromNetsTac(limits, orderTagged, true, netpair);
219
160
 
220
- // Tactic.build_net
221
- export const buildNet = (rules: readonly Thm[]): Net<{ tag: number; rule: Thm }> =>
222
- rules.reduceRight<Net<{ tag: number; rule: Thm }>>(
223
- (net, rule, index) => insertTermNet(conclOf(rule), { tag: index + 1, rule }, net),
224
- emptyNet,
225
- );
226
-
227
- export const resolveFromNetTac = (
228
- limits: Limits,
229
- net: Net<{ tag: number; rule: Thm }>,
230
- ): GoalTactic =>
231
- subgoal((goal, index) => {
232
- const rules = unifyTermNet(net, stripAssumsConcl(goal));
233
- return primSeq((state) => {
234
- checkInterrupt(limits);
235
- return biresolution(
236
- limits,
237
- false,
238
- orderList(
239
- rules.map((rule) => ({ tag: rule.tag, item: { isElim: false, rule: rule.rule } })),
240
- ),
241
- index,
242
- state,
243
- );
244
- });
245
- });
246
-
247
161
  // The number of new subgoals of a rule.
248
162
  export const subgoalsOfBrl = (brule: { isElim: boolean; rule: Thm }) =>
249
163
  brule.isElim ? nprems(brule.rule) - 1 : nprems(brule.rule);
@@ -252,25 +166,3 @@ export const rotateTac =
252
166
  (count: number): GoalTactic =>
253
167
  (index) =>
254
168
  count === 0 ? allTac : primitive((state) => rotateRule(count, index, state));
255
-
256
- export const deferTac: GoalTactic = (index) =>
257
- primitive((state) => permutePrems(index - 1, 1, state));
258
-
259
- // Tactic.filter_prems_tac: removes the premises that fail the predicate.
260
- export const filterPremsTac = (
261
- limits: Limits,
262
- predicate: (hyp: ReturnType<typeof stripAssumsConcl>) => boolean,
263
- ): GoalTactic =>
264
- subgoal((goal, index) => {
265
- let tactic: GoalTactic | undefined;
266
- let count = 0;
267
- for (const hyp of stripAssumsHyp(goal)) {
268
- if (predicate(hyp)) count += 1;
269
- else {
270
- const step = thenGoal(rotateTac(count), eresolveTac(limits, [thinRl]));
271
- tactic = tactic === undefined ? step : thenGoal(tactic, step);
272
- count = 0;
273
- }
274
- }
275
- return tactic === undefined ? noTac : tactic(index);
276
- });
@@ -2,7 +2,6 @@
2
2
  // University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
3
3
 
4
4
  import { TlaIsabelleError } from "../../../errors";
5
- import { aeconv } from "./envir";
6
5
  import {
7
6
  appendSeq,
8
7
  emptySeq,
@@ -129,11 +128,6 @@ export const every = (tactics: readonly Tactic[]): Tactic => {
129
128
  return (state) => evy([], tactics, state);
130
129
  };
131
130
 
132
- export const everyGoal =
133
- (tactics: readonly GoalTactic[]): GoalTactic =>
134
- (index) =>
135
- every(tactics.map((tactic) => tactic(index)));
136
-
137
131
  export const first = (tactics: readonly Tactic[]): Tactic =>
138
132
  tactics.reduceRight((rest, tactic) => orElse(tactic, rest), noTac);
139
133
 
@@ -159,41 +153,7 @@ export const repeatDetermN =
159
153
 
160
154
  export const repeatDeterm = (tactic: Tactic) => repeatDetermN(-1, tactic);
161
155
 
162
- export const repeat =
163
- (tactic: Tactic): Tactic =>
164
- (start) => {
165
- const rep = (stack: readonly Seq<Thm>[], state: Thm): Cell<Thm> => {
166
- let current = state;
167
- let queue = stack;
168
- for (;;) {
169
- const cell = tactic(current).pull();
170
- if (cell === undefined) {
171
- const saved = queue;
172
- return [current, makeSeq(() => repq(saved))];
173
- }
174
- queue = [cell[1], ...queue];
175
- current = cell[0];
176
- }
177
- };
178
- const repq = (stack: readonly Seq<Thm>[]): Cell<Thm> => {
179
- let queue = stack;
180
- while (queue.length > 0) {
181
- const cell = queue[0].pull();
182
- if (cell !== undefined) return rep([cell[1], ...queue.slice(1)], cell[0]);
183
- queue = queue.slice(1);
184
- }
185
- return undefined;
186
- };
187
- return makeSeq(() => rep([], start));
188
- };
189
-
190
156
  export const repeatDeterm1 = (tactic: Tactic) => thenTac(determ(tactic), repeatDeterm(tactic));
191
- export const repeat1 = (tactic: Tactic) => thenTac(tactic, repeat(tactic));
192
-
193
- export const filterTac =
194
- (predicate: (state: Thm) => boolean, tactic: Tactic): Tactic =>
195
- (state) =>
196
- filterSeq(predicate, tactic(state));
197
157
 
198
158
  export const changed =
199
159
  (tactic: Tactic): Tactic =>
@@ -213,14 +173,6 @@ export const allGoals =
213
173
  return doall(nprems(state))(state);
214
174
  };
215
175
 
216
- export const someGoal =
217
- (tactic: GoalTactic): Tactic =>
218
- (state) => {
219
- const find = (index: number): Tactic =>
220
- index === 0 ? noTac : orElse(tactic(index), find(index - 1));
221
- return find(nprems(state))(state);
222
- };
223
-
224
176
  export const firstGoalTac =
225
177
  (tactic: GoalTactic): Tactic =>
226
178
  (state) => {
@@ -230,14 +182,6 @@ export const firstGoalTac =
230
182
  return find(1)(state);
231
183
  };
232
184
 
233
- export const repeatSome = (tactic: GoalTactic) =>
234
- repeat1(someGoal((index) => repeat1(tactic(index))));
235
- export const repeatFirst = (tactic: GoalTactic) =>
236
- repeat1(firstGoalTac((index) => repeat1(tactic(index))));
237
- export const repeatDetermFirst = (tactic: GoalTactic) =>
238
- repeatDeterm1(firstGoalTac((index) => repeatDeterm1(tactic(index))));
239
- export const tryAll = (tactic: GoalTactic) => allGoals((index) => tryTac(tactic(index)));
240
-
241
185
  const isThmError = (error: unknown) =>
242
186
  error instanceof TlaIsabelleError && error.exception === "THM";
243
187
 
@@ -250,25 +194,6 @@ export const subgoal =
250
194
  return build(premOf(state, index), index)(state);
251
195
  };
252
196
 
253
- export const changedGoal =
254
- (tactic: GoalTactic): GoalTactic =>
255
- (index) =>
256
- (state) => {
257
- if (index < 1 || index > nprems(state)) return emptySeq;
258
- const goal = premOf(state, index);
259
- const distance = nprems(state) - index;
260
- return filterSeq((result) => {
261
- const count = nprems(result);
262
- return count - distance <= 0 || !aeconv(goal, premOf(result, count - distance));
263
- }, tactic(index)(state));
264
- };
265
-
266
- export const solvedGoal =
267
- (tactic: GoalTactic): GoalTactic =>
268
- (index) =>
269
- (state) =>
270
- filterSeq((result) => nprems(result) < nprems(state), tactic(index)(state));
271
-
272
197
  // Seq.INTERVAL: applies tactic to goals last down to first.
273
198
  const interval = (tactic: GoalTactic, firstIndex: number, lastIndex: number): Tactic =>
274
199
  lastIndex < firstIndex
@@ -308,7 +233,7 @@ export const condTac =
308
233
  // Search.DEPTH_FIRST: depth-first search for a state satisfying the test. The stack of
309
234
  // alternatives and the states already returned are lists, as in Isabelle, since the stack can grow
310
235
  // as deep as the search goes.
311
- export const depthFirst = (test: (state: Thm) => boolean, tactic: Tactic): Tactic => {
236
+ const depthFirst = (test: (state: Thm) => boolean, tactic: Tactic): Tactic => {
312
237
  const isUsed = (used: List<Thm> | undefined, state: Thm) => {
313
238
  for (let current = used; current !== undefined; current = current.tail)
314
239
  if (eqThm(current.head, state)) return true;
@@ -335,13 +260,5 @@ export const depthFirst = (test: (state: Thm) => boolean, tactic: Tactic): Tacti
335
260
 
336
261
  export const hasFewerPrems = (count: number) => (state: Thm) => nprems(state) < count;
337
262
 
338
- // Search.DEPTH_SOLVE_1: depth-first search until one goal fewer remains.
339
- export const depthSolve1 =
340
- (tactic: Tactic): Tactic =>
341
- (state) => {
342
- const count = nprems(state);
343
- return count === 0 ? emptySeq : depthFirst(hasFewerPrems(count), tactic)(state);
344
- };
345
-
346
263
  // Search.DEPTH_SOLVE: depth-first search until no goals remain.
347
264
  export const depthSolve = (tactic: Tactic) => depthFirst(hasFewerPrems(1), tactic);
@@ -24,7 +24,7 @@ const sortOrd = (left: readonly string[], right: readonly string[]) =>
24
24
 
25
25
  const typConsNr = (type: Typ) => (type.kind === "TVar" ? 0 : type.kind === "TFree" ? 1 : 2);
26
26
 
27
- export const typOrd = (left: Typ, right: Typ): number => {
27
+ const typOrd = (left: Typ, right: Typ): number => {
28
28
  if (left === right) return 0;
29
29
  if (left.kind === "Type" && right.kind === "Type") {
30
30
  const order = fastStringOrd(left.name, right.name);
@@ -41,60 +41,6 @@ export const typOrd = (left: Typ, right: Typ): number => {
41
41
  return intOrd(typConsNr(left), typConsNr(right));
42
42
  };
43
43
 
44
- const termConsNr = (term: Term) =>
45
- ({ Const: 0, Free: 1, Var: 2, Bound: 3, Abs: 4, App: 5 })[term.kind];
46
-
47
- const structOrd = (left: Term, right: Term): number => {
48
- if (left === right) return 0;
49
- if (left.kind === "Abs" && right.kind === "Abs") return structOrd(left.body, right.body);
50
- if (left.kind === "App" && right.kind === "App") {
51
- const order = structOrd(left.fun, right.fun);
52
- return order !== 0 ? order : structOrd(left.arg, right.arg);
53
- }
54
- return intOrd(termConsNr(left), termConsNr(right));
55
- };
56
-
57
- const atomsOrd = (left: Term, right: Term): number => {
58
- if (left === right) return 0;
59
- if (left.kind === "Abs" && right.kind === "Abs") return atomsOrd(left.body, right.body);
60
- if (left.kind === "App" && right.kind === "App") {
61
- const order = atomsOrd(left.fun, right.fun);
62
- return order !== 0 ? order : atomsOrd(left.arg, right.arg);
63
- }
64
- if (left.kind === "Const" && right.kind === "Const") return fastStringOrd(left.name, right.name);
65
- if (left.kind === "Free" && right.kind === "Free") return fastStringOrd(left.name, right.name);
66
- if (left.kind === "Var" && right.kind === "Var") return fastIndexnameOrd(left, right);
67
- if (left.kind === "Bound" && right.kind === "Bound") return intOrd(left.index, right.index);
68
- return 0;
69
- };
70
-
71
- const typesOrd = (left: Term, right: Term): number => {
72
- if (left === right) return 0;
73
- if (left.kind === "Abs" && right.kind === "Abs") {
74
- const order = typOrd(left.type, right.type);
75
- return order !== 0 ? order : typesOrd(left.body, right.body);
76
- }
77
- if (left.kind === "App" && right.kind === "App") {
78
- const order = typesOrd(left.fun, right.fun);
79
- return order !== 0 ? order : typesOrd(left.arg, right.arg);
80
- }
81
- if (
82
- (left.kind === "Const" && right.kind === "Const") ||
83
- (left.kind === "Free" && right.kind === "Free") ||
84
- (left.kind === "Var" && right.kind === "Var")
85
- )
86
- return typOrd(left.type, right.type);
87
- return 0;
88
- };
89
-
90
- // Term_Ord.fast_term_ord
91
- export const fastTermOrd = (left: Term, right: Term) => {
92
- const struct = structOrd(left, right);
93
- if (struct !== 0) return struct;
94
- const atoms = atomsOrd(left, right);
95
- return atoms !== 0 ? atoms : typesOrd(left, right);
96
- };
97
-
98
44
  const hdDepth = (term: Term): [Term, number] => {
99
45
  let current = term;
100
46
  let depth = 0;
@@ -55,14 +55,8 @@ export type Term =
55
55
  | TermOf<"App", "fun" | "arg" | "loose" | "maxidx" | "flags">;
56
56
 
57
57
  export type Var = Extract<Term, { kind: "Var" }>;
58
- export type Abs = Extract<Term, { kind: "Abs" }>;
58
+ type Abs = Extract<Term, { kind: "Abs" }>;
59
59
  export type App = Extract<Term, { kind: "App" }>;
60
- export type TVar = Extract<Typ, { kind: "TVar" }>;
61
-
62
- export interface Indexname {
63
- readonly name: string;
64
- readonly index: number;
65
- }
66
60
 
67
61
  export const HAS_VAR = 1;
68
62
  export const HAS_REDEX = 2;
@@ -86,7 +80,7 @@ export const maxidxOfTerm = (term: Term, maxidx = -1): number => {
86
80
  };
87
81
 
88
82
  // The bound on loose bound variables: every one is below it.
89
- export const looseOf = (term: Term) =>
83
+ const looseOf = (term: Term) =>
90
84
  term.kind === "Bound"
91
85
  ? term.index + 1
92
86
  : term.kind === "App" || term.kind === "Abs"
@@ -208,19 +202,6 @@ export const funT = (domain: Typ, range: Typ) => mkType("fun", [domain, range]);
208
202
  export const funTs = (domains: readonly Typ[], range: Typ) =>
209
203
  domains.reduceRight((result, domain) => funT(domain, result), range);
210
204
 
211
- export const isFunType = (type: Typ) => type.kind === "Type" && type.name === "fun";
212
-
213
- export const domainType = (type: Typ) => {
214
- if (type.kind !== "Type" || type.name !== "fun")
215
- throw new TlaIsabelleError("TYPE", "domain_type");
216
- return type.args[0];
217
- };
218
-
219
- export const rangeType = (type: Typ) => {
220
- if (type.kind !== "Type" || type.name !== "fun") throw new TlaIsabelleError("TYPE", "range_type");
221
- return type.args[1];
222
- };
223
-
224
205
  export const binderTypes = (type: Typ): Typ[] => {
225
206
  const types: Typ[] = [];
226
207
  let current = type;
@@ -302,18 +283,6 @@ export const headOf = (term: Term): Term => {
302
283
  return current;
303
284
  };
304
285
 
305
- export const argsOf = (term: Term) => stripComb(term)[1];
306
-
307
- export const stripAbs = (term: Term): [{ name: string; type: Typ }[], Term] => {
308
- const vars: { name: string; type: Typ }[] = [];
309
- let current = term;
310
- while (current.kind === "Abs") {
311
- vars.push({ name: current.name, type: current.type });
312
- current = current.body;
313
- }
314
- return [vars, current];
315
- };
316
-
317
286
  export const stripAbsBody = (term: Term): Term =>
318
287
  term.kind === "Abs" ? stripAbsBody(term.body) : term;
319
288
 
@@ -328,7 +297,7 @@ export const sizeOfTerm = (term: Term): number => {
328
297
  }
329
298
  };
330
299
 
331
- export const isAllConst = (term: Term) => term.kind === "Const" && term.name === "Pure.all";
300
+ const isAllConst = (term: Term) => term.kind === "Const" && term.name === "Pure.all";
332
301
 
333
302
  export const stripAllBody = (term: Term): Term =>
334
303
  term.kind === "App" && isAllConst(term.fun) && term.arg.kind === "Abs"
@@ -366,13 +335,13 @@ const incrBvAt = (increment: number, level: number, term: Term): Term => {
366
335
  }
367
336
  };
368
337
 
369
- export const incrBv = (increment: number, level: number, term: Term) =>
338
+ const incrBv = (increment: number, level: number, term: Term) =>
370
339
  increment === 0 ? term : incrBvAt(increment, level, term);
371
340
 
372
341
  export const incrBoundvars = (increment: number, term: Term) => incrBv(increment, 0, term);
373
342
 
374
343
  // loose_bvar: whether term has a loose bound variable at level or beyond.
375
- export const looseBvar = (term: Term, level: number) => looseOf(term) > level;
344
+ const looseBvar = (term: Term, level: number) => looseOf(term) > level;
376
345
 
377
346
  export const looseBvar1 = (term: Term, level: number): boolean => {
378
347
  if (looseOf(term) <= level) return false;
@@ -542,14 +511,6 @@ export const termName = (term: Term) =>
542
511
  ? term.name
543
512
  : "uu";
544
513
 
545
- export const lambdaName = (name: string, variable: Term, body: Term) =>
546
- mkAbs(name === "" ? termName(variable) : name, fastypeOf(variable), abstractOver(variable, body));
547
-
548
- export const lambda = (variable: Term, body: Term) => lambdaName("", variable, body);
549
-
550
- export const absfree = (name: string, type: Typ, body: Term) =>
551
- mkAbs(name, type, abstractOver(mkFree(name, type), body));
552
-
553
514
  export const mapTypes = (mapType: (type: Typ) => Typ, term: Term): Term => {
554
515
  const visit = (current: Term): Term => {
555
516
  switch (current.kind) {
@@ -579,18 +540,7 @@ export const mapAtyps = (mapAtyp: (type: Typ) => Typ, type: Typ): Typ => {
579
540
  return args.every((arg, index) => arg === type.args[index]) ? type : mkType(type.name, args);
580
541
  };
581
542
 
582
- export const mapAterms = (mapAterm: (term: Term) => Term, term: Term): Term => {
583
- switch (term.kind) {
584
- case "Abs":
585
- return updateAbs(term, mapAterms(mapAterm, term.body));
586
- case "App":
587
- return updateApp(term, mapAterms(mapAterm, term.fun), mapAterms(mapAterm, term.arg));
588
- default:
589
- return mapAterm(term);
590
- }
591
- };
592
-
593
- export const foldAterms = <State>(
543
+ const foldAterms = <State>(
594
544
  visit: (term: Term, state: State) => State,
595
545
  term: Term,
596
546
  state: State,
@@ -660,10 +610,6 @@ export const existsSubterm = (predicate: (term: Term) => boolean, term: Term): b
660
610
  return false;
661
611
  };
662
612
 
663
- export const existsSubtype = (predicate: (type: Typ) => boolean, type: Typ): boolean =>
664
- predicate(type) ||
665
- (type.kind === "Type" && type.args.some((arg) => existsSubtype(predicate, arg)));
666
-
667
613
  export const existsType = (predicate: (type: Typ) => boolean, term: Term): boolean => {
668
614
  switch (term.kind) {
669
615
  case "Const":
@@ -679,9 +625,6 @@ export const existsType = (predicate: (type: Typ) => boolean, term: Term): boole
679
625
  }
680
626
  };
681
627
 
682
- export const eqIndexname = (left: Indexname, right: Indexname) =>
683
- left.index === right.index && left.name === right.name;
684
-
685
628
  const sameVar = (left: Var, right: Var) =>
686
629
  left.name === right.name && left.index === right.index && eqTyp(left.type, right.type);
687
630
 
@@ -694,25 +637,6 @@ export const addVars = (term: Term, vars: Var[]): Var[] =>
694
637
  vars,
695
638
  );
696
639
 
697
- export const addTVarsT = (type: Typ, tvars: TVar[]): TVar[] =>
698
- foldAtyps(
699
- (current, result: TVar[]) =>
700
- current.kind === "TVar" &&
701
- !result.some(
702
- (other) =>
703
- other.name === current.name &&
704
- other.index === current.index &&
705
- eqSort(other.sort, current.sort),
706
- )
707
- ? [current, ...result]
708
- : result,
709
- type,
710
- tvars,
711
- );
712
-
713
- export const addTVars = (term: Term, tvars: TVar[]) =>
714
- foldTypes((type, result: TVar[]) => addTVarsT(type, result), term, tvars);
715
-
716
640
  export const addFreeNames = (term: Term, names: string[]): string[] =>
717
641
  foldAterms(
718
642
  (current, result: string[]) =>
@@ -723,39 +647,8 @@ export const addFreeNames = (term: Term, names: string[]): string[] =>
723
647
  names,
724
648
  );
725
649
 
726
- export const addFrees = (term: Term, frees: Term[]): Term[] =>
727
- foldAterms(
728
- (current, result: Term[]) =>
729
- current.kind === "Free" && !result.some((other) => aconv(other, current))
730
- ? [current, ...result]
731
- : result,
732
- term,
733
- frees,
734
- );
735
-
736
- export const addTFreeNames = (term: Term, names: string[]): string[] =>
737
- foldTypes(
738
- (type, result: string[]) =>
739
- foldAtyps(
740
- (current, inner: string[]) =>
741
- current.kind === "TFree" && !inner.includes(current.name)
742
- ? [current.name, ...inner]
743
- : inner,
744
- type,
745
- result,
746
- ),
747
- term,
748
- names,
749
- );
750
-
751
- export const isSchematic = (term: Term) => maxidxOfTerm(term) >= 0;
752
-
753
650
  // match_bvs: the pairs of corresponding abstraction names while two terms look alike.
754
- export const matchBvs = (
755
- left: Term,
756
- right: Term,
757
- pairs: [string, string][],
758
- ): [string, string][] => {
651
+ const matchBvs = (left: Term, right: Term, pairs: [string, string][]): [string, string][] => {
759
652
  if (left.kind === "Abs" && right.kind === "Abs") {
760
653
  const added: [string, string][] =
761
654
  left.name !== "" && right.name !== "" ? [[left.name, right.name], ...pairs] : pairs;
@@ -769,7 +662,7 @@ export const matchBvs = (
769
662
  export const matchBvars = (left: Term, right: Term, pairs: [string, string][]) =>
770
663
  matchBvs(stripAbsBody(left), stripAbsBody(right), pairs);
771
664
 
772
- export const mapAbsVars = (rename: (name: string) => string, term: Term): Term => {
665
+ const mapAbsVars = (rename: (name: string) => string, term: Term): Term => {
773
666
  switch (term.kind) {
774
667
  case "Abs": {
775
668
  const name = rename(term.name);
@@ -793,16 +686,3 @@ export const renameAbs = (pattern: Term, object: Term, term: Term): Term | undef
793
686
  const renamed = mapAbsVars((name) => renaming.get(name) ?? name, term);
794
687
  return renamed === term ? undefined : renamed;
795
688
  };
796
-
797
- // subst_free: replaces subterms by the first pair whose left side they equal.
798
- export const substFree = (pairs: readonly [Term, Term][], term: Term): Term => {
799
- if (pairs.length === 0) return term;
800
- const visit = (current: Term): Term => {
801
- const pair = pairs.find(([from]) => aconv(from, current));
802
- if (pair) return pair[1];
803
- if (current.kind === "Abs") return updateAbs(current, visit(current.body));
804
- if (current.kind === "App") return updateApp(current, visit(current.fun), visit(current.arg));
805
- return current;
806
- };
807
- return visit(term);
808
- };
@@ -293,29 +293,6 @@ export const combination = (first: Thm, second: Thm): Thm => {
293
293
  );
294
294
  };
295
295
 
296
- const destImp = (prop: Term): [Term, Term] | undefined =>
297
- prop.kind === "App" &&
298
- prop.fun.kind === "App" &&
299
- prop.fun.fun.kind === "Const" &&
300
- prop.fun.fun.name === "Pure.imp"
301
- ? [prop.fun.arg, prop.arg]
302
- : undefined;
303
-
304
- export const equalIntr = (first: Thm, second: Thm): Thm => {
305
- const left = destImp(first.prop);
306
- const right = destImp(second.prop);
307
- if (left === undefined || right === undefined)
308
- throw new TlaIsabelleError("THM", "equal_intr: premises");
309
- if (!aconv(left[0], right[1]) || !aconv(left[1], right[0]))
310
- throw new TlaIsabelleError("THM", "equal_intr: not equal");
311
- return makeThm(
312
- Math.max(first.maxidx, second.maxidx),
313
- unionHyps(first.hyps, second.hyps),
314
- unionTpairs(first.tpairs, second.tpairs),
315
- mkEquals(left[0], left[1]),
316
- );
317
- };
318
-
319
296
  export const equalElim = (first: Thm, second: Thm): Thm => {
320
297
  const parts = destEq(first);
321
298
  if (parts === undefined) throw new TlaIsabelleError("THM", "equal_elim: major premise");
@@ -465,7 +442,7 @@ interface State {
465
442
  readonly conclusion: Term;
466
443
  }
467
444
 
468
- export const destState = (state: Thm, index: number): State => {
445
+ const destState = (state: Thm, index: number): State => {
469
446
  const premises = stripImpPrems(state.prop);
470
447
  if (index < 1 || index > premises.length)
471
448
  throw new TlaIsabelleError("THM", `dest_state ${index}`);
@@ -603,13 +580,13 @@ export const permutePrems = (fixed: number, count: number, rule: Thm): Thm => {
603
580
  );
604
581
  };
605
582
 
606
- export interface ComposeFlags {
583
+ interface ComposeFlags {
607
584
  readonly flatten: boolean;
608
585
  readonly match: boolean;
609
586
  readonly incremented: boolean;
610
587
  }
611
588
 
612
- export interface ComposeRule {
589
+ interface ComposeRule {
613
590
  readonly isElim: boolean;
614
591
  readonly rule: Thm;
615
592
  readonly subgoals: number;
@@ -750,7 +727,7 @@ export const bicompose = (
750
727
  state: Thm,
751
728
  ) => bicomposeAux(limits, flags, state, destState(state, index), false, compose);
752
729
 
753
- export const couldBires = (hyps: readonly Term[], goal: Term, isElim: boolean, rule: Thm) => {
730
+ const couldBires = (hyps: readonly Term[], goal: Term, isElim: boolean, rule: Thm) => {
754
731
  if (!couldUnify(conclOf(rule), goal)) return false;
755
732
  if (!isElim) return true;
756
733
  const first = premsOf(rule)[0];