tla-ts 0.0.9 → 0.0.10-dev.b4a856304

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 (390) hide show
  1. package/README.md +29 -1
  2. package/dist/compile.cjs +23 -0
  3. package/dist/compile.js +23 -0
  4. package/dist/deciders.cjs +28 -28
  5. package/dist/deciders.js +43 -43
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +72 -10
  8. package/dist/index.d.ts +72 -10
  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 +116 -36
  15. package/dist/prove.js +116 -36
  16. package/dist/run.cjs +143 -31
  17. package/dist/run.js +143 -31
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +2 -2
  20. package/dist/transfer.cjs +128 -103
  21. package/dist/transfer.js +128 -103
  22. package/dist/worker.cjs +7 -7
  23. package/dist/worker.js +7 -7
  24. package/package.json +3 -1
  25. package/src/ast.ts +7 -21
  26. package/src/bags.ts +99 -99
  27. package/src/builtins.ts +44 -75
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check.ts +576 -300
  30. package/src/cli/options.ts +11 -6
  31. package/src/cli/run.ts +2 -2
  32. package/src/cli/runtime-invariants.ts +135 -0
  33. package/src/cli/shared.ts +20 -9
  34. package/src/cli/tlapm.ts +0 -12
  35. package/src/cli/tlc-arguments.ts +646 -0
  36. package/src/cli/tlc-usage.ts +362 -0
  37. package/src/cli/tlc.ts +538 -220
  38. package/src/cli/typescript.ts +23 -0
  39. package/src/cli/xml-exporter.ts +4 -16
  40. package/src/cli.ts +0 -1
  41. package/src/codegen.ts +191 -64
  42. package/src/config.ts +140 -109
  43. package/src/coverage.ts +837 -0
  44. package/src/dependencies.ts +6 -40
  45. package/src/dfid.ts +618 -0
  46. package/src/environment.ts +240 -118
  47. package/src/errors.ts +70 -55
  48. package/src/evaluate.ts +630 -297
  49. package/src/exit-codes.ts +37 -3
  50. package/src/fingerprints.ts +10 -10
  51. package/src/index.ts +3 -0
  52. package/src/instances.ts +79 -11
  53. package/src/java-overrides.ts +2 -12
  54. package/src/json-reader.ts +456 -0
  55. package/src/json.ts +262 -139
  56. package/src/levels.ts +2 -3
  57. package/src/lexer.ts +17 -26
  58. package/src/liveness-checker.ts +10 -18
  59. package/src/liveness.ts +121 -49
  60. package/src/obligations/action.ts +4 -28
  61. package/src/obligations/anonymize.ts +84 -80
  62. package/src/obligations/equality.ts +1 -1
  63. package/src/obligations/expression.ts +2 -19
  64. package/src/obligations/format.ts +1 -9
  65. package/src/obligations/generate.ts +1 -11
  66. package/src/obligations/index.ts +0 -11
  67. package/src/obligations/levels.ts +4 -8
  68. package/src/obligations/module.ts +1 -15
  69. package/src/obligations/normalize.ts +5 -24
  70. package/src/obligations/operators.ts +1 -2
  71. package/src/obligations/pragma.ts +1 -10
  72. package/src/obligations/printer.ts +47 -46
  73. package/src/obligations/proof.ts +1 -5
  74. package/src/obligations/regroup.ts +1 -4
  75. package/src/obligations/simplify.ts +3 -14
  76. package/src/obligations/source.ts +1 -21
  77. package/src/obligations/subexpression.ts +5 -11
  78. package/src/obligations/substitution.ts +1 -3
  79. package/src/obligations/temporal.ts +8 -14
  80. package/src/obligations/tuples.ts +3 -9
  81. package/src/parallel-worker.ts +29 -39
  82. package/src/parallel.ts +29 -13
  83. package/src/parser.ts +436 -90
  84. package/src/pcal/ast.ts +7 -28
  85. package/src/pcal/parse.ts +11 -39
  86. package/src/pcal/tokenize.ts +4 -20
  87. package/src/pcal/translate.ts +10 -42
  88. package/src/pcal/validate.ts +3 -21
  89. package/src/pretty-print.ts +1 -2
  90. package/src/prover/decide-pool.ts +5 -10
  91. package/src/prover/deciders.ts +0 -4
  92. package/src/prover/first-order.ts +0 -11
  93. package/src/prover/isabelle/decide.ts +0 -6
  94. package/src/prover/isabelle/encode.ts +11 -23
  95. package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
  96. package/src/prover/isabelle/isar/method.ts +25 -38
  97. package/src/prover/isabelle/isar/proof.ts +1 -10
  98. package/src/prover/isabelle/isar/statement.ts +1 -6
  99. package/src/prover/isabelle/isar/theory.ts +15 -26
  100. package/src/prover/isabelle/isar/type-check.ts +11 -25
  101. package/src/prover/isabelle/provers/blast/blast.ts +10 -41
  102. package/src/prover/isabelle/provers/blast/branch.ts +1 -32
  103. package/src/prover/isabelle/provers/blast/prove.ts +1 -35
  104. package/src/prover/isabelle/provers/blast/rules.ts +6 -44
  105. package/src/prover/isabelle/provers/blast/state.ts +2 -28
  106. package/src/prover/isabelle/provers/blast/term.ts +9 -36
  107. package/src/prover/isabelle/provers/clasimp.ts +1 -13
  108. package/src/prover/isabelle/provers/classical.ts +14 -42
  109. package/src/prover/isabelle/provers/hypsubst.ts +11 -25
  110. package/src/prover/isabelle/pure/bicompose.ts +16 -13
  111. package/src/prover/isabelle/pure/consts.ts +1 -7
  112. package/src/prover/isabelle/pure/conv.ts +1 -9
  113. package/src/prover/isabelle/pure/drule.ts +24 -40
  114. package/src/prover/isabelle/pure/envir.ts +3 -52
  115. package/src/prover/isabelle/pure/goal.ts +1 -7
  116. package/src/prover/isabelle/pure/interrupt.ts +0 -5
  117. package/src/prover/isabelle/pure/list.ts +0 -3
  118. package/src/prover/isabelle/pure/logic.ts +1 -14
  119. package/src/prover/isabelle/pure/name.ts +2 -9
  120. package/src/prover/isabelle/pure/net.ts +3 -59
  121. package/src/prover/isabelle/pure/object-logic.ts +3 -10
  122. package/src/prover/isabelle/pure/pattern.ts +2 -19
  123. package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
  124. package/src/prover/isabelle/pure/rewriter.ts +26 -58
  125. package/src/prover/isabelle/pure/search.ts +3 -10
  126. package/src/prover/isabelle/pure/seq.ts +1 -10
  127. package/src/prover/isabelle/pure/simplifier.ts +4 -12
  128. package/src/prover/isabelle/pure/table.ts +1 -31
  129. package/src/prover/isabelle/pure/tactic.ts +12 -22
  130. package/src/prover/isabelle/pure/tactical.ts +6 -12
  131. package/src/prover/isabelle/pure/term-ord.ts +2 -6
  132. package/src/prover/isabelle/pure/term.ts +2 -43
  133. package/src/prover/isabelle/pure/thm.ts +13 -36
  134. package/src/prover/isabelle/pure/type.ts +2 -15
  135. package/src/prover/isabelle/pure/unify.ts +20 -30
  136. package/src/prover/isabelle/pure/variable.ts +3 -7
  137. package/src/prover/isabelle/tla/classical-setup.ts +9 -19
  138. package/src/prover/isabelle/tla/context.ts +8 -16
  139. package/src/prover/isabelle/tla/logic.ts +4 -11
  140. package/src/prover/isabelle/tla/simpdata.ts +46 -34
  141. package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
  142. package/src/prover/ocaml.ts +0 -6
  143. package/src/prover/prep/action.ts +4 -36
  144. package/src/prover/prep/enabled-axioms.ts +12 -19
  145. package/src/prover/prep/fingerprint.ts +0 -16
  146. package/src/prover/prep/level-comparison.ts +8 -12
  147. package/src/prover/prep/md5.ts +0 -2
  148. package/src/prover/prep/methods.ts +9 -36
  149. package/src/prover/prep/normalize.ts +4 -28
  150. package/src/prover/prove-worker.ts +0 -2
  151. package/src/prover/prove.ts +0 -36
  152. package/src/prover/ptl/decide.ts +7 -12
  153. package/src/prover/ptl/encode.ts +14 -36
  154. package/src/prover/ptl/sat.ts +24 -32
  155. package/src/prover/ptl/tableau.ts +12 -26
  156. package/src/prover/smt/axioms.ts +0 -7
  157. package/src/prover/smt/context.ts +19 -26
  158. package/src/prover/smt/data.ts +51 -54
  159. package/src/prover/smt/encode.ts +14 -35
  160. package/src/prover/smt/extensionality.ts +0 -10
  161. package/src/prover/smt/flatten.ts +3 -22
  162. package/src/prover/smt/format.ts +5 -10
  163. package/src/prover/smt/instances.ts +0 -10
  164. package/src/prover/smt/rewrite.ts +66 -101
  165. package/src/prover/smt/solver/act-cache.ts +0 -15
  166. package/src/prover/smt/solver/arith-rewriter.ts +3 -48
  167. package/src/prover/smt/solver/array.ts +1 -3
  168. package/src/prover/smt/solver/asserted-formulas.ts +1 -43
  169. package/src/prover/smt/solver/ast-lt.ts +1 -11
  170. package/src/prover/smt/solver/ast-util.ts +1 -6
  171. package/src/prover/smt/solver/ast.ts +1 -143
  172. package/src/prover/smt/solver/auf-solver.ts +6 -39
  173. package/src/prover/smt/solver/case-split-queue.ts +1 -9
  174. package/src/prover/smt/solver/cg-table.ts +1 -18
  175. package/src/prover/smt/solver/clause.ts +1 -27
  176. package/src/prover/smt/solver/conflict-resolution.ts +0 -9
  177. package/src/prover/smt/solver/context.ts +4 -61
  178. package/src/prover/smt/solver/ctx-simplify.ts +14 -41
  179. package/src/prover/smt/solver/der.ts +2 -21
  180. package/src/prover/smt/solver/dyn-ack.ts +1 -11
  181. package/src/prover/smt/solver/e-matching.ts +3 -34
  182. package/src/prover/smt/solver/enode.ts +1 -21
  183. package/src/prover/smt/solver/expr-ref.ts +1 -5
  184. package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
  185. package/src/prover/smt/solver/fingerprints.ts +1 -12
  186. package/src/prover/smt/solver/flat-literals.ts +1 -9
  187. package/src/prover/smt/solver/goal.ts +2 -14
  188. package/src/prover/smt/solver/hash.ts +0 -8
  189. package/src/prover/smt/solver/hashtable.ts +1 -12
  190. package/src/prover/smt/solver/internalizer.ts +6 -98
  191. package/src/prover/smt/solver/lbool.ts +1 -2
  192. package/src/prover/smt/solver/literal.ts +0 -3
  193. package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
  194. package/src/prover/smt/solver/lp/constraints.ts +2 -8
  195. package/src/prover/smt/solver/lp/containers.ts +12 -30
  196. package/src/prover/smt/solver/lp/core-solver.ts +10 -31
  197. package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
  198. package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
  199. package/src/prover/smt/solver/lp/dependency.ts +1 -4
  200. package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
  201. package/src/prover/smt/solver/lp/explanation.ts +1 -6
  202. package/src/prover/smt/solver/lp/gomory.ts +9 -22
  203. package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
  204. package/src/prover/smt/solver/lp/hnf.ts +11 -26
  205. package/src/prover/smt/solver/lp/int-cube.ts +15 -36
  206. package/src/prover/smt/solver/lp/int-solver.ts +4 -34
  207. package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
  208. package/src/prover/smt/solver/lp/lar-term.ts +1 -5
  209. package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
  210. package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
  211. package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
  212. package/src/prover/smt/solver/lp/nex.ts +1 -6
  213. package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
  214. package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
  215. package/src/prover/smt/solver/lp/nla-core.ts +35 -130
  216. package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
  217. package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
  218. package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
  219. package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
  220. package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
  221. package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
  222. package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
  223. package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
  224. package/src/prover/smt/solver/lp/nla-order.ts +2 -13
  225. package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
  226. package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
  227. package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
  228. package/src/prover/smt/solver/lp/nla-types.ts +1 -11
  229. package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
  230. package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
  231. package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
  232. package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
  233. package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
  234. package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
  235. package/src/prover/smt/solver/lp/pdd.ts +7 -70
  236. package/src/prover/smt/solver/lp/random-updater.ts +1 -8
  237. package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
  238. package/src/prover/smt/solver/lp/union-find.ts +1 -6
  239. package/src/prover/smt/solver/mam-compiler.ts +14 -56
  240. package/src/prover/smt/solver/mam-interpreter.ts +1 -21
  241. package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
  242. package/src/prover/smt/solver/model-checker.ts +2 -36
  243. package/src/prover/smt/solver/model-evaluator.ts +3 -29
  244. package/src/prover/smt/solver/model-finder.ts +3 -15
  245. package/src/prover/smt/solver/model-generator.ts +1 -12
  246. package/src/prover/smt/solver/model-macro-solver.ts +12 -69
  247. package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
  248. package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
  249. package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
  250. package/src/prover/smt/solver/nlsat/explain.ts +3 -47
  251. package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
  252. package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
  253. package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
  254. package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
  255. package/src/prover/smt/solver/nlsat/solver.ts +7 -67
  256. package/src/prover/smt/solver/nlsat/types.ts +1 -8
  257. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
  258. package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
  259. package/src/prover/smt/solver/nnf.ts +3 -38
  260. package/src/prover/smt/solver/pattern-inference.ts +2 -15
  261. package/src/prover/smt/solver/poly-rewriter.ts +3 -23
  262. package/src/prover/smt/solver/propagate-values.ts +1 -10
  263. package/src/prover/smt/solver/proto-model.ts +3 -48
  264. package/src/prover/smt/solver/pull-quant.ts +1 -12
  265. package/src/prover/smt/solver/qe-lite-der.ts +1 -29
  266. package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
  267. package/src/prover/smt/solver/qe-lite.ts +3 -33
  268. package/src/prover/smt/solver/qi-queue.ts +1 -16
  269. package/src/prover/smt/solver/quant-tactics.ts +5 -22
  270. package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
  271. package/src/prover/smt/solver/quantifier-manager.ts +1 -8
  272. package/src/prover/smt/solver/random-gen.ts +1 -2
  273. package/src/prover/smt/solver/rational.ts +1 -8
  274. package/src/prover/smt/solver/ref-vector.ts +1 -6
  275. package/src/prover/smt/solver/relevancy.ts +2 -15
  276. package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
  277. package/src/prover/smt/solver/rewriter.ts +3 -85
  278. package/src/prover/smt/solver/rlimit.ts +2 -20
  279. package/src/prover/smt/solver/smtlib-parser.ts +2 -37
  280. package/src/prover/smt/solver/solver.ts +23 -34
  281. package/src/prover/smt/solver/sort.ts +1 -5
  282. package/src/prover/smt/solver/sticky-generations.ts +0 -5
  283. package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
  284. package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
  285. package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
  286. package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
  287. package/src/prover/smt/solver/theory-lra-model.ts +4 -19
  288. package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
  289. package/src/prover/smt/solver/theory-lra-state.ts +3 -8
  290. package/src/prover/smt/solver/theory-lra.ts +1 -8
  291. package/src/prover/smt/solver/var-subst.ts +2 -26
  292. package/src/prover/smt/table.ts +0 -8
  293. package/src/prover/tlapm/cache.ts +20 -25
  294. package/src/prover/tlapm/ocaml-marshal.ts +19 -21
  295. package/src/prover/tlapm/tlapm.ts +12 -17
  296. package/src/prover/verdict.ts +0 -2
  297. package/src/prover/zenon/check/check.ts +0 -9
  298. package/src/prover/zenon/check/definitions.ts +5 -15
  299. package/src/prover/zenon/check/equality.ts +0 -8
  300. package/src/prover/zenon/check/functions.ts +0 -4
  301. package/src/prover/zenon/check/keys.ts +0 -7
  302. package/src/prover/zenon/check/propositional.ts +0 -3
  303. package/src/prover/zenon/check/records.ts +0 -5
  304. package/src/prover/zenon/check/relations.ts +0 -13
  305. package/src/prover/zenon/check/rewrites.ts +0 -6
  306. package/src/prover/zenon/check/sets.ts +0 -3
  307. package/src/prover/zenon/check/terms.ts +0 -17
  308. package/src/prover/zenon/check/tla.ts +0 -6
  309. package/src/prover/zenon/decide.ts +0 -12
  310. package/src/prover/zenon/encode.ts +1 -8
  311. package/src/prover/zenon/eqrel.ts +0 -13
  312. package/src/prover/zenon/equality-rules.ts +0 -4
  313. package/src/prover/zenon/expr.ts +1 -26
  314. package/src/prover/zenon/index-table.ts +17 -38
  315. package/src/prover/zenon/isar-case.ts +9 -19
  316. package/src/prover/zenon/isar.ts +1 -29
  317. package/src/prover/zenon/limits.ts +0 -4
  318. package/src/prover/zenon/llproof.ts +0 -9
  319. package/src/prover/zenon/mltoll.ts +54 -76
  320. package/src/prover/zenon/node.ts +1 -11
  321. package/src/prover/zenon/ocaml.ts +1 -17
  322. package/src/prover/zenon/parse.ts +2 -7
  323. package/src/prover/zenon/phrase.ts +1 -11
  324. package/src/prover/zenon/proof.ts +0 -9
  325. package/src/prover/zenon/propositional-rules.ts +0 -5
  326. package/src/prover/zenon/rules.ts +2 -6
  327. package/src/prover/zenon/search.ts +1 -17
  328. package/src/prover/zenon/tla/functions.ts +57 -29
  329. package/src/prover/zenon/tla/llproof.ts +63 -70
  330. package/src/prover/zenon/tla/records.ts +56 -27
  331. package/src/prover/zenon/tla/rewrites.ts +12 -19
  332. package/src/prover/zenon/tla/sets.ts +68 -39
  333. package/src/prover/zenon/tla/terms.ts +0 -6
  334. package/src/prover/zenon/tla/tla.ts +59 -58
  335. package/src/randomization.ts +84 -35
  336. package/src/resolve.ts +18 -60
  337. package/src/runtime.ts +11 -4
  338. package/src/sany/builtins.ts +3 -4
  339. package/src/sany/generator.ts +119 -169
  340. package/src/sany/levels.ts +6 -30
  341. package/src/sany/lexer.ts +7 -23
  342. package/src/sany/linter.ts +1 -8
  343. package/src/sany/modules.ts +1 -5
  344. package/src/sany/nodes.ts +0 -31
  345. package/src/sany/parse-error.ts +39 -117
  346. package/src/sany/report.ts +29 -63
  347. package/src/sany/selectors.ts +15 -39
  348. package/src/sany/source.ts +1 -17
  349. package/src/sany/xml.ts +13 -63
  350. package/src/search.ts +494 -154
  351. package/src/simulate.ts +694 -0
  352. package/src/spec-description.ts +166 -48
  353. package/src/standard-definitions.ts +2 -3
  354. package/src/standard-modules.ts +264 -68
  355. package/src/state-graph.ts +51 -18
  356. package/src/subexpressions.ts +31 -5
  357. package/src/substitution-levels.ts +2 -3
  358. package/src/successors.ts +267 -77
  359. package/src/symmetry.ts +31 -8
  360. package/src/tableau.ts +27 -24
  361. package/src/tlc/fingerprint.ts +183 -61
  362. package/src/tlc/jar-data.ts +113 -6
  363. package/src/tlc/messages.ts +122 -37
  364. package/src/tlc/order.ts +33 -38
  365. package/src/tlc/random.ts +16 -16
  366. package/src/tlc/replay.ts +563 -211
  367. package/src/tlc/summary.ts +2 -4
  368. package/src/tlc/tlc-operators.ts +81 -36
  369. package/src/tlc/tlcext-operators.ts +138 -117
  370. package/src/tlc/trace-spec.ts +273 -0
  371. package/src/tlc/value-stream.ts +143 -0
  372. package/src/tlc/version.ts +2 -4
  373. package/src/transfer.ts +22 -25
  374. package/src/typescript/actions.ts +481 -0
  375. package/src/typescript/collections.ts +600 -0
  376. package/src/typescript/compile.ts +65 -0
  377. package/src/typescript/context.ts +94 -0
  378. package/src/typescript/emit.ts +121 -0
  379. package/src/typescript/expressions.ts +496 -0
  380. package/src/typescript/formula.ts +152 -0
  381. package/src/typescript/functions.ts +284 -0
  382. package/src/typescript/model.ts +163 -0
  383. package/src/typescript/names.ts +114 -0
  384. package/src/typescript/program.ts +48 -0
  385. package/src/typescript/properties.ts +139 -0
  386. package/src/typescript/scope.ts +112 -0
  387. package/src/typescript/steps.ts +165 -0
  388. package/src/typescript/types.ts +171 -0
  389. package/src/values.ts +826 -276
  390. package/src/worker.ts +7 -8
@@ -1,8 +1,4 @@
1
- // Ported from Isabelle2025's Provers/clasimp.ML and the prune_params_tac of Pure/tactic.ML.
2
- // Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and
3
- // contributors, see LICENSE.
4
- //
5
- // The classical reasoner combined with the simplifier: auto, clarsimp and force.
1
+ // Ported from Isabelle2025's Provers/clasimp.ML and Pure/tactic.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
6
2
 
7
3
  import { trivForallEquality } from "../pure/drule";
8
4
  import { selectGoal } from "../pure/goal";
@@ -49,11 +45,9 @@ import {
49
45
  export interface ClasimpContext {
50
46
  readonly classical: ClassicalContext;
51
47
  readonly simp: SimpContext;
52
- // Blast.depth_tac, the Blast argument of the Clasimp functor.
53
48
  readonly blastDepthTac: (context: ClassicalContext, limit: number) => GoalTactic;
54
49
  }
55
50
 
56
- // addss: the simplifier as an unsafe wrapper.
57
51
  const addss = (context: ClasimpContext): ClassicalContext =>
58
52
  withClaset(
59
53
  context.classical,
@@ -62,7 +56,6 @@ const addss = (context: ClasimpContext): ClassicalContext =>
62
56
  ),
63
57
  );
64
58
 
65
- // addSss: the simplifier as a safe wrapper.
66
59
  const addSss = (context: ClasimpContext): ClassicalContext =>
67
60
  withClaset(
68
61
  context.classical,
@@ -74,7 +67,6 @@ const addSss = (context: ClasimpContext): ClassicalContext =>
74
67
  export const clarsimpTac = (context: ClasimpContext): GoalTactic =>
75
68
  thenAllNew(safeAsmFullSimpTac(context.simp), clarifyTac(addSss(context)));
76
69
 
77
- // A variant of Classical.depth_tac that keeps the simplifier from interfering with dup_step_tac.
78
70
  const nodupDepthTac =
79
71
  (context: ClassicalContext, limit: number): GoalTactic =>
80
72
  (index) =>
@@ -97,7 +89,6 @@ const nodupDepthTac =
97
89
  ),
98
90
  )(index)(state);
99
91
 
100
- // prune_params_tac: drops the parameters that no goal uses.
101
92
  const pruneParamsTac = (simp: SimpContext): Tactic => {
102
93
  const empty = { ...simp, simpset: emptySimpset };
103
94
  const context = { ...empty, simpset: addSimps(empty, [trivForallEquality]) };
@@ -125,8 +116,6 @@ const mkAutoTac = (context: ClasimpContext, depth: number, nodupDepth: number):
125
116
  changed(nodupDepthTac(addss(context), nodupDepth)(index)),
126
117
  );
127
118
  return every([
128
- // PARALLEL_ALLGOALS simplifies each goal on its own only when no goal has schematic variables,
129
- // which gives the same result as simplifying them in turn.
130
119
  determ(allGoals(asmFullSimpTac(context.simp))),
131
120
  tryTac(safeTac(context.classical)),
132
121
  repeatDeterm(firstGoalTac(mainTac)),
@@ -137,7 +126,6 @@ const mkAutoTac = (context: ClasimpContext, depth: number, nodupDepth: number):
137
126
 
138
127
  export const autoTac = (context: ClasimpContext) => mkAutoTac(context, 4, 2);
139
128
 
140
- // force_tac: aims to solve the goal outright, with clarify, the simplifier and best-first search.
141
129
  export const forceTac = (context: ClasimpContext, atomizeRules: readonly Thm[]): GoalTactic => {
142
130
  const classical = addss(context);
143
131
  return selectGoal(
@@ -1,14 +1,9 @@
1
- // Ported from Isabelle2025's Provers/classical.ML. Copyright (c) 1986-2025 University of
2
- // Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
3
- //
4
- // The classical reasoner: rule sets of safe and unsafe introduction and elimination rules, and
5
- // the tactics that search with them. The rules Isabelle/TLA+ declares come with the logic; a
6
- // method adds more with intro: and dest:.
1
+ // Ported from Isabelle2025's Provers/classical.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
7
2
 
8
3
  import { TlaIsabelleError } from "../../../errors";
9
4
  import { revcutRl, thinRl, zeroVarIndexes, makeElim } from "../pure/drule";
10
5
  import { selectGoal } from "../pure/goal";
11
- import { aconv, sizeOfTerm } from "../pure/term";
6
+ import { aconv, sizeOfTerm, type Term } from "../pure/term";
12
7
  import { stripAssumsConcl, stripAssumsHyp } from "../pure/logic";
13
8
  import { listOfSeq, seqHead } from "../pure/seq";
14
9
  import { trade } from "../pure/variable";
@@ -48,10 +43,17 @@ import {
48
43
  type NetPair,
49
44
  type TaggedRule,
50
45
  } from "../pure/tactic";
51
- import { assumption, biresolution, nprems, premsOf, rs, rsn, type Thm } from "../pure/thm";
46
+ import {
47
+ assumption,
48
+ biresolution,
49
+ nprems,
50
+ premsOf,
51
+ rs,
52
+ rsn,
53
+ type BiresRule,
54
+ type Thm,
55
+ } from "../pure/thm";
52
56
 
53
- // A rule as the user gave it, as the nets use it, and as the complete search duplicates it, each
54
- // with its swapped forms for negated assumptions.
55
57
  export interface ClassicalRule {
56
58
  readonly rule: Thm;
57
59
  readonly internal: Thm;
@@ -66,7 +68,6 @@ export interface Wrapper {
66
68
  }
67
69
 
68
70
  export interface Claset {
69
- // Newest first, as Item_Net.content lists them.
70
71
  readonly safeIs: readonly ClassicalRule[];
71
72
  readonly safeEs: readonly ClassicalRule[];
72
73
  readonly unsafeIs: readonly ClassicalRule[];
@@ -79,17 +80,11 @@ export interface Claset {
79
80
  readonly dup: NetPair<TaggedRule>;
80
81
  }
81
82
 
82
- // CLASSICAL_DATA: the object logic's rules for the classical reasoner.
83
83
  export interface ClassicalData {
84
- // P --> Q ==> (~ R ==> P) ==> (Q ==> R) ==> R
85
84
  readonly impElim: Thm;
86
- // ~P ==> P ==> R
87
85
  readonly notElim: Thm;
88
- // ~ P ==> (~ R ==> P) ==> R
89
86
  readonly swap: Thm;
90
- // (~ P ==> P) ==> P
91
87
  readonly classical: Thm;
92
- // The object logic's Trueprop, which Object_Logic.elim_concl looks through.
93
88
  readonly judgment: string;
94
89
  readonly hypSubstTacs: readonly ((limits: Limits) => GoalTactic)[];
95
90
  }
@@ -105,8 +100,6 @@ export const withClaset = (context: ClassicalContext, claset: Claset): Classical
105
100
  claset,
106
101
  });
107
102
 
108
- // classical_rule: strengthens an elimination rule whose conclusion is a variable, so that the
109
- // negated conclusion becomes available to every case.
110
103
  const classicalRule = (data: ClassicalData, rule: Thm, limits: Limits): Thm => {
111
104
  const concl = premsOf(rule).length === 0 ? rule.prop : stripAssumsConcl(rule.prop);
112
105
  const body =
@@ -118,7 +111,7 @@ const classicalRule = (data: ClassicalData, rule: Thm, limits: Limits): Thm => {
118
111
  if (!isElim) return rule;
119
112
  const strengthened = rs(rule, data.classical);
120
113
  const strengthenedConcl = stripAssumsConcl(strengthened.prop);
121
- const isRedundant = (goal: ReturnType<typeof premsOf>[number]) => {
114
+ const isRedundant = (goal: Term) => {
122
115
  if (aconv(strengthenedConcl, stripAssumsConcl(goal))) return true;
123
116
  const hyps = stripAssumsHyp(goal);
124
117
  return hyps.length > 0 && hyps.slice(1).some((hyp) => aconv(hyp, hyps[0]));
@@ -135,7 +128,6 @@ const classicalRule = (data: ClassicalData, rule: Thm, limits: Limits): Thm => {
135
128
  return aconv(result.prop, rule.prop) ? rule : result;
136
129
  };
137
130
 
138
- // swapify: the rules that eliminate ~A from the rules that introduce A.
139
131
  const swapify = (data: ClassicalData, rules: readonly Thm[]) =>
140
132
  rules.flatMap((rule) =>
141
133
  listOfSeq(biresolution(undefined, false, [{ isElim: false, rule }], 2, data.swap)),
@@ -143,8 +135,6 @@ const swapify = (data: ClassicalData, rules: readonly Thm[]) =>
143
135
 
144
136
  const dupIntr = (data: ClassicalData, rule: Thm) => zeroVarIndexes(rs(rule, data.classical));
145
137
 
146
- // Drule.rule_by_tactic: runs the tactic on the rule with its variables fixed.
147
- // Tactic.rule_by_tactic
148
138
  const ruleByTactic = (tactic: Tactic, rule: Thm): Thm =>
149
139
  zeroVarIndexes(
150
140
  trade((fixed) => {
@@ -163,8 +153,7 @@ const dupElim = (limits: Limits, rule: Thm) => {
163
153
  );
164
154
  };
165
155
 
166
- // tag_brls: rules with fewer subgoals first, then the rules added last.
167
- const tagRules = (start: number, rules: readonly { isElim: boolean; rule: Thm }[]): TaggedRule[] =>
156
+ const tagRules = (start: number, rules: readonly BiresRule[]): TaggedRule[] =>
168
157
  rules.map((brule, index) => ({ tag: 1000000 * subgoalsOfBrl(brule) + start + index, ...brule }));
169
158
 
170
159
  const insertRules = (
@@ -181,7 +170,6 @@ const insertRules = (
181
170
  const isMember = (rules: readonly ClassicalRule[], rule: ClassicalRule) =>
182
171
  rules.some((other) => aconv(other.rule.prop, rule.rule.prop));
183
172
 
184
- // addI: an unsafe introduction rule, which intro: declares.
185
173
  export const addUnsafeIntro = (context: ClassicalContext, rule: Thm): Claset => {
186
174
  const claset = context.claset;
187
175
  if (
@@ -211,7 +199,6 @@ export const addUnsafeIntro = (context: ClassicalContext, rule: Thm): Claset =>
211
199
  };
212
200
  };
213
201
 
214
- // addE: an unsafe elimination rule.
215
202
  const addUnsafeElim = (context: ClassicalContext, rule: Thm): Claset => {
216
203
  const claset = context.claset;
217
204
  if (nprems(rule) < 1) throw new TlaIsabelleError("ERROR", "Ill-formed elimination rule");
@@ -233,25 +220,21 @@ const addUnsafeElim = (context: ClassicalContext, rule: Thm): Claset => {
233
220
  };
234
221
  };
235
222
 
236
- // addD: an unsafe destruction rule, which dest: declares.
237
223
  export const addUnsafeDest = (context: ClassicalContext, rule: Thm): Claset => {
238
224
  if (nprems(rule) < 1) throw new TlaIsabelleError("ERROR", "Ill-formed destruction rule");
239
225
  return addUnsafeElim(context, makeElim(rule));
240
226
  };
241
227
 
242
- // AList.update: replaces a wrapper of the same name in place, or adds it in front.
243
228
  const updateWrappers = (wrappers: readonly Wrapper[], wrapper: Wrapper) =>
244
229
  wrappers.some((other) => other.name === wrapper.name)
245
230
  ? wrappers.map((other) => (other.name === wrapper.name ? wrapper : other))
246
231
  : [wrapper, ...wrappers];
247
232
 
248
- // addSafter: a safe tactic to try after safe_step_tac fails.
249
233
  export const addSafter = (claset: Claset, name: string, tactic: GoalTactic): Claset => ({
250
234
  ...claset,
251
235
  swrappers: updateWrappers(claset.swrappers, { name, wrap: (inner) => orElseGoal(inner, tactic) }),
252
236
  });
253
237
 
254
- // addbefore: a tactic to try before the unsafe step tactic, with backtracking.
255
238
  export const addbefore = (claset: Claset, name: string, tactic: GoalTactic): Claset => ({
256
239
  ...claset,
257
240
  uwrappers: updateWrappers(claset.uwrappers, { name, wrap: (inner) => appendGoal(tactic, inner) }),
@@ -263,14 +246,12 @@ const appSWrappers = (context: ClassicalContext, tactic: GoalTactic) =>
263
246
  export const appWrappers = (context: ClassicalContext, tactic: GoalTactic) =>
264
247
  context.claset.uwrappers.reduce((result, wrapper) => wrapper.wrap(result), tactic);
265
248
 
266
- // contr_tac: solves a goal that assumes both P and ~P.
267
249
  const contrTac = (context: ClassicalContext): GoalTactic =>
268
250
  thenGoal(
269
251
  eresolveTac(context.limits, [context.data.notElim]),
270
252
  orElseGoal(eqAssumeTac, assumeTac(context.limits)),
271
253
  );
272
254
 
273
- // eq_mp_tac: from P --> Q and P, keeps Q, without instantiating variables.
274
255
  const eqMpTac =
275
256
  (context: ClassicalContext): GoalTactic =>
276
257
  (index) =>
@@ -279,7 +260,6 @@ const eqMpTac =
279
260
  eqAssumeTac(index),
280
261
  );
281
262
 
282
- // safe_step_tac: one safe inference, by matching rather than unification.
283
263
  const safeStepTac = (context: ClassicalContext): GoalTactic =>
284
264
  appSWrappers(
285
265
  context,
@@ -292,7 +272,6 @@ const safeStepTac = (context: ClassicalContext): GoalTactic =>
292
272
  ]),
293
273
  );
294
274
 
295
- // safe_steps_tac: safe inferences on goal index for as long as they apply.
296
275
  export const safeStepsTac =
297
276
  (context: ClassicalContext): GoalTactic =>
298
277
  (index) =>
@@ -300,7 +279,6 @@ export const safeStepsTac =
300
279
  condTac(hasFewerPrems(index), noTac, (state) => safeStepTac(context)(index)(state)),
301
280
  );
302
281
 
303
- // safe_tac: safe inferences on all goals for as long as they apply.
304
282
  export const safeTac = (context: ClassicalContext): Tactic =>
305
283
  repeatDeterm1(firstGoalTac(safeStepsTac(context)));
306
284
 
@@ -324,7 +302,6 @@ const eqContrTac =
324
302
  const eqAssumeContrTac = (context: ClassicalContext) =>
325
303
  orElseGoal(eqAssumeTac, eqContrTac(context));
326
304
 
327
- // bimatch2_tac: two-way branching only where one branch closes at once.
328
305
  const bimatch2Tac =
329
306
  (context: ClassicalContext, netpair: NetPair<TaggedRule>): GoalTactic =>
330
307
  (index) =>
@@ -345,7 +322,6 @@ const clarifyStepTac = (context: ClassicalContext): GoalTactic =>
345
322
  ]),
346
323
  );
347
324
 
348
- // clarify_tac: safe steps that do not split the goal.
349
325
  export const clarifyTac = (context: ClassicalContext): GoalTactic =>
350
326
  selectGoal(repeatDeterm(clarifyStepTac(context)(1)));
351
327
 
@@ -364,7 +340,6 @@ const instStepTac = (context: ClassicalContext): GoalTactic =>
364
340
  export const unsafeStepTac = (context: ClassicalContext): GoalTactic =>
365
341
  biresolveFromNetsTac(context.limits, context.claset.unsafe);
366
342
 
367
- // step_tac: a safe step, or else an unsafe one.
368
343
  const stepTac =
369
344
  (context: ClassicalContext): GoalTactic =>
370
345
  (index) =>
@@ -373,15 +348,12 @@ const stepTac =
373
348
  appWrappers(context, orElseGoal(instStepTac(context), unsafeStepTac(context)))(index),
374
349
  );
375
350
 
376
- // Drule.size_of_thm, the sizef of Isabelle/TLA+'s Classical: the size of the proposition with its
377
- // flex-flex pairs.
378
351
  const sizeOfThm = (thm: Thm) =>
379
352
  thm.tpairs.reduce(
380
353
  (size, pair) => size + 2 + sizeOfTerm(pair[0]) + sizeOfTerm(pair[1]),
381
354
  sizeOfTerm(thm.prop),
382
355
  );
383
356
 
384
- // first_best_tac: best-first search with step_tac on the first goal.
385
357
  export const firstBestTac = (context: ClassicalContext, atomizeRules: readonly Thm[]): GoalTactic =>
386
358
  thenGoal(
387
359
  atomizePremsTac(context.limits, atomizeRules),
@@ -1,7 +1,4 @@
1
- // Ported from Isabelle2025's Provers/hypsubst.ML. Copyright (c) 1986-2025 University of
2
- // Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
3
- //
4
- // Substitution using an equality assumption x = t: eliminates x from the subgoal.
1
+ // Ported from Isabelle2025's Provers/hypsubst.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
5
2
 
6
3
  import { TlaIsabelleError } from "../../../errors";
7
4
  import { asmRl, compIncr, revcutRl, thinRl, zeroVarIndexes } from "../pure/drule";
@@ -77,9 +74,7 @@ interface HypsubstContext {
77
74
  readonly data: HypsubstData;
78
75
  }
79
76
 
80
- // The equality offers no variable to eliminate.
81
77
  class NoMatch {}
82
- // The subgoal has no suitable equality.
83
78
  class EqVar {}
84
79
 
85
80
  const isTermError = (error: unknown) =>
@@ -87,7 +82,6 @@ const isTermError = (error: unknown) =>
87
82
  const isThmError = (error: unknown) =>
88
83
  error instanceof TlaIsabelleError && error.exception === "THM";
89
84
 
90
- // The simplifier turns bound variables into special free variables; any bound variable will do.
91
85
  const inspectContract = (term: Term) => {
92
86
  const contracted = etaContract(term);
93
87
  return contracted.kind === "Free" && isBoundName(contracted.name) ? mkBound(0) : contracted;
@@ -96,8 +90,6 @@ const inspectContract = (term: Term) => {
96
90
  const hasVars = (term: Term) => (flagsOf(term) & HAS_VAR) !== 0;
97
91
  const hasTVars = (term: Term) => existsType((type) => maxidxOfTyp(type) >= 0, term);
98
92
 
99
- // inspect_pair: true to use the equality as it is, false to reorient it first, with the variable
100
- // to substitute.
101
93
  const inspectPair = (
102
94
  isBound: boolean,
103
95
  isNoVars: boolean,
@@ -127,8 +119,6 @@ const inspectPair = (
127
119
  throw new NoMatch();
128
120
  };
129
121
 
130
- // eq_var: the number of assumptions before a substitutable equality, its orientation, and whether
131
- // it eliminates a free variable.
132
122
  const eqVar = (
133
123
  data: HypsubstData,
134
124
  isBound: boolean,
@@ -190,7 +180,6 @@ const withEqVar = (build: (goal: Term, index: number) => Tactic): GoalTactic =>
190
180
  }
191
181
  });
192
182
 
193
- // mk_eqs: the equality as a rewrite rule that eliminates its variable.
194
183
  const mkEqs = (data: HypsubstData, isBound: boolean, thm: Thm): Thm[] => {
195
184
  try {
196
185
  const [left, right] = data.destEq(data.destTrueprop(thm.prop));
@@ -253,7 +242,9 @@ const instSubstTac = (context: HypsubstContext, isLeft: boolean, rule: Thm): Goa
253
242
  const conclusion = data.destTrueprop(stripAssumsConcl(goal));
254
243
  const lifted = liftRule(goal, state.maxidx, rule);
255
244
  const head = headOf(data.destTrueprop(stripAssumsConcl(lifted.prop)));
256
- const [v1, v2] = data.destEq(data.destTrueprop(stripAssumsConcl(premsOf(lifted)[0])));
245
+ const [leftVar, rightVar] = data.destEq(
246
+ data.destTrueprop(stripAssumsConcl(premsOf(lifted)[0])),
247
+ );
257
248
  if (head.kind !== "Var") throw new TlaIsabelleError("TERM", "dest_Var");
258
249
  const binders = binderTypes(head.type);
259
250
  const paramTypes = binders.slice(0, -1);
@@ -277,9 +268,9 @@ const instSubstTac = (context: HypsubstContext, isLeft: boolean, rule: Thm): Goa
277
268
  const motive = absParams(mkAbs("x", paramType, body));
278
269
  const tyenv = matchTypes(lastType, paramType, emptyTyEnv);
279
270
  if (tyenv === undefined) throw new TlaIsabelleError("TYPE", "Thm.match");
280
- const headV1 = headOf(v1);
281
- const headV2 = headOf(v2);
282
- if (headV1.kind !== "Var" || headV2.kind !== "Var")
271
+ const leftHead = headOf(leftVar);
272
+ const rightHead = headOf(rightVar);
273
+ if (leftHead.kind !== "Var" || rightHead.kind !== "Var")
283
274
  throw new TlaIsabelleError("TERM", "dest_Var");
284
275
  const instantiated = instantiate(
285
276
  [
@@ -296,8 +287,8 @@ const instSubstTac = (context: HypsubstContext, isLeft: boolean, rule: Thm): Goa
296
287
  },
297
288
  {
298
289
  variable: mkVar(
299
- headV1.name,
300
- headV1.index,
290
+ leftHead.name,
291
+ leftHead.index,
301
292
  funTs(
302
293
  paramTypes.map((type) => substType(tyenv, type)),
303
294
  paramType,
@@ -307,8 +298,8 @@ const instSubstTac = (context: HypsubstContext, isLeft: boolean, rule: Thm): Goa
307
298
  },
308
299
  {
309
300
  variable: mkVar(
310
- headV2.name,
311
- headV2.index,
301
+ rightHead.name,
302
+ rightHead.index,
312
303
  funTs(
313
304
  paramTypes.map((type) => substType(tyenv, type)),
314
305
  paramType,
@@ -354,8 +345,6 @@ const revDupElim = (thm: Thm) => {
354
345
  return result;
355
346
  };
356
347
 
357
- // hyp_subst_tac with hypsubst_thin off, its default: substitutes for free or bound variables and
358
- // drops equalities on bound variables.
359
348
  export const hypSubstTac =
360
349
  (context: HypsubstContext): GoalTactic =>
361
350
  (index) =>
@@ -386,7 +375,6 @@ const reverseNTac = (context: HypsubstContext, count: number, index: number): Ta
386
375
  ),
387
376
  );
388
377
 
389
- // all_imp_intr_tac: reintroduces the hypotheses, leaving the changed ones at the end.
390
378
  const allImpIntrTac = (context: HypsubstContext, hyps: readonly Term[], index: number): Tactic => {
391
379
  const imptac =
392
380
  (count: number, remaining: readonly Term[]): Tactic =>
@@ -407,8 +395,6 @@ const allImpIntrTac = (context: HypsubstContext, hyps: readonly Term[], index: n
407
395
  return imptac(0, [...hyps].reverse());
408
396
  };
409
397
 
410
- // blast_hyp_subst_tac: the version for blast, which moves the hypotheses the substitution changes
411
- // to the front.
412
398
  export const blastHypSubstTac = (context: HypsubstContext): GoalTactic =>
413
399
  withEqVar((goal, index) => {
414
400
  const [count, [orientation]] = eqVar(context.data, false, false, false, goal);
@@ -1,7 +1,4 @@
1
- // Ported from Isabelle2025's Pure/thm.ML. Copyright (c) 1986-2025 University of Cambridge,
2
- // Technische Universitaet Muenchen, and contributors, see LICENSE.
3
- //
4
- // The term operations behind Thm.bicompose, which builds the theorem itself in thm.ts.
1
+ // Ported from Isabelle2025's Pure/thm.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
5
2
 
6
3
  import { TlaIsabelleError } from "../../../errors";
7
4
  import { normTerm, type Envir } from "./envir";
@@ -54,8 +51,6 @@ const makeDistinct = (pairs: readonly [string, string][]) => {
54
51
  return table;
55
52
  };
56
53
 
57
- // Thm.rename_bvars: renames bound variables and some unknowns of the new premises after the
58
- // names in the disagreement pairs.
59
54
  export const renameBvars = (
60
55
  dpairs: readonly Tpair[],
61
56
  tpairs: readonly Tpair[],
@@ -86,16 +81,24 @@ export const renameBvars = (
86
81
  );
87
82
  const delClashing = (
88
83
  isClash: boolean,
89
- xs: Set<string>,
90
- ys: Set<string>,
84
+ clashed: Set<string>,
85
+ taken: Set<string>,
91
86
  rest: readonly [string, string][],
92
87
  kept: [string, string][],
93
88
  ): [string, string][] => {
94
- if (rest.length === 0) return isClash ? delClashing(false, xs, new Set(xs), kept, []) : kept;
95
- const [pair, ...others] = rest;
96
- if (ys.has(pair[1]))
97
- return delClashing(true, new Set(xs).add(pair[0]), new Set(ys).add(pair[0]), others, kept);
98
- return delClashing(isClash, xs, new Set(ys).add(pair[1]), others, [pair, ...kept]);
89
+ if (rest.length === 0)
90
+ return isClash ? delClashing(false, clashed, new Set(clashed), kept, []) : kept;
91
+ const pair = rest[0];
92
+ const others = rest.slice(1);
93
+ if (taken.has(pair[1]))
94
+ return delClashing(
95
+ true,
96
+ new Set(clashed).add(pair[0]),
97
+ new Set(taken).add(pair[0]),
98
+ others,
99
+ kept,
100
+ );
101
+ return delClashing(isClash, clashed, new Set(taken).add(pair[1]), others, [pair, ...kept]);
99
102
  };
100
103
  const vars = makeDistinct(delClashing(false, unchanged, new Set(unchanged), distinct, []));
101
104
  const bounds = makeDistinct(pairs);
@@ -1,15 +1,10 @@
1
- // Ported from Isabelle2025's Pure/consts.ML. Copyright (c) 1986-2025 University of Cambridge,
2
- // Technische Universitaet Muenchen, and contributors, see LICENSE.
3
- //
4
- // A constant's type arguments: the instances of the type variables of its declared type, which
5
- // Consts.declare locates once so that Consts.typargs only has to look them up.
1
+ // Ported from Isabelle2025's Pure/consts.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
6
2
 
7
3
  import { TlaIsabelleError } from "../../../errors";
8
4
  import type { Typ } from "./term";
9
5
 
10
6
  export type TypargPosition = readonly number[];
11
7
 
12
- // Consts.typargs_of: the path to the first occurrence of each type variable.
13
8
  export const typargsOf = (type: Typ): TypargPosition[] => {
14
9
  const found = new Map<string, TypargPosition>();
15
10
  const visit = (current: Typ, path: readonly number[]) => {
@@ -21,7 +16,6 @@ export const typargsOf = (type: Typ): TypargPosition[] => {
21
16
  return [...found.values()];
22
17
  };
23
18
 
24
- // Consts.typargs: the type arguments of a constant at an instance of its declared type.
25
19
  export const typargs = (positions: readonly TypargPosition[], type: Typ): Typ[] =>
26
20
  positions.map((path) =>
27
21
  path.reduce((current, index) => {
@@ -1,6 +1,4 @@
1
- // Ported from Isabelle2025's Pure/conv.ML, conversions: functions from a term to a theorem that
2
- // it equals another. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet
3
- // Muenchen, and contributors, see LICENSE.
1
+ // Ported from Isabelle2025's Pure/conv.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
4
2
 
5
3
  import { TlaIsabelleError } from "../../../errors";
6
4
  import { destEquals, destImplies, implies, isImplies } from "./logic";
@@ -24,11 +22,9 @@ const isReflexive = (eq: Thm) => {
24
22
  return aconv(lhs, rhs);
25
23
  };
26
24
 
27
- // Drule.imp_cong_rule
28
25
  export const impCongRule = (first: Thm, second: Thm) =>
29
26
  combination(combination(reflexive(implies), first), second);
30
27
 
31
- // Conv.prems_conv ~1: converts every premise.
32
28
  export const premsConv =
33
29
  (convert: Conversion): Conversion =>
34
30
  (term) =>
@@ -36,8 +32,6 @@ export const premsConv =
36
32
  ? impCongRule(convert(destImplies(term)[0]), premsConv(convert)(destImplies(term)[1]))
37
33
  : reflexive(term);
38
34
 
39
- // Conv.params_conv ~1: converts the body under every outer parameter, fixed as a fresh free
40
- // variable.
41
35
  export const paramsConv = (convert: Conversion): Conversion => {
42
36
  const under =
43
37
  (names: NameContext): Conversion =>
@@ -60,7 +54,6 @@ export const paramsConv = (convert: Conversion): Conversion => {
60
54
  return (term) => under(makeNameContext(addFreeNames(term, [])))(term);
61
55
  };
62
56
 
63
- // Conv.gconv_rule: converts goal index of a state.
64
57
  export const gconvRule = (convert: Conversion, index: number, state: Thm): Thm => {
65
58
  if (index < 1 || index > nprems(state)) throw new TlaIsabelleError("THM", `gconv_rule ${index}`);
66
59
  const eq = convert(premOf(state, index));
@@ -72,7 +65,6 @@ export const gconvRule = (convert: Conversion, index: number, state: Thm): Thm =
72
65
  return permutePrems(0, 1 - index, converted);
73
66
  };
74
67
 
75
- // Conv.fconv_rule: converts a theorem's proposition.
76
68
  export const fconvRule = (convert: Conversion, thm: Thm): Thm => {
77
69
  const eq = convert(thm.prop);
78
70
  return isReflexive(eq) ? thm : equalElim(eq, thm);
@@ -1,6 +1,4 @@
1
- // Ported from Isabelle2025's Pure/drule.ML, Pure/term_subst.ML and the basic rules of Pure.thy.
2
- // Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and
3
- // contributors, see LICENSE.
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.
4
2
 
5
3
  import { cleanName, emptyNameContext, variantList, variantName, type NameContext } from "./name";
6
4
  import {
@@ -14,7 +12,7 @@ import {
14
12
  import { TlaIsabelleError } from "../../../errors";
15
13
  import { allConst, isProtected, mkEquals, mkImplies, mkTerm, protect } from "./logic";
16
14
  import { listOfSeq } from "./seq";
17
- import { eqThm } from "./tactical";
15
+ import { distinctThms } from "./tactical";
18
16
  import {
19
17
  foldVars,
20
18
  foldAtyps,
@@ -47,13 +45,6 @@ import {
47
45
 
48
46
  const propVar = (name: string) => mkVar(name, 0, propT);
49
47
 
50
- // The basic rules of Pure.thy, with the variable names Isabelle gives them.
51
- export const cutRl = axiomThm(
52
- mkImplies(
53
- mkImplies(propVar("psi"), propVar("theta")),
54
- mkImplies(propVar("psi"), propVar("theta")),
55
- ),
56
- );
57
48
  export const revcutRl = axiomThm(
58
49
  mkImplies(propVar("V"), mkImplies(mkImplies(propVar("V"), propVar("W")), propVar("W"))),
59
50
  );
@@ -94,7 +85,6 @@ export const trivForallEquality = axiomThm(
94
85
  mkEquals(mkApp(allConst(typeA), mkAbs("x", typeA, propVar("V"))), propVar("V")),
95
86
  );
96
87
 
97
- // Drule.norm_hhf_eq: (PROP ?phi ==> (!!x. PROP ?psi x)) == (!!x. PROP ?phi ==> PROP ?psi x).
98
88
  export const normHhfEq = axiomThm(
99
89
  mkEquals(
100
90
  mkImplies(
@@ -115,7 +105,6 @@ export const normHhfEq = axiomThm(
115
105
  ),
116
106
  );
117
107
 
118
- // Drule.is_norm_hhf: no quantifier right of an implication and no beta redex.
119
108
  export const isNormHhf = (isProtecting: boolean, term: Term): boolean => {
120
109
  if (term.kind === "Const") return term.name !== "Pure.sort_constraint";
121
110
  if (term.kind === "Abs") return isNormHhf(isProtecting, term.body);
@@ -134,7 +123,6 @@ export const isNormHhf = (isProtecting: boolean, term: Term): boolean => {
134
123
  return isNormHhf(isProtecting, term.fun) && isNormHhf(isProtecting, term.arg);
135
124
  };
136
125
 
137
- // Drule.outer_params: the outermost parameters, named apart.
138
126
  const outerParams = (term: Term) => {
139
127
  const vars = stripAllVars(term);
140
128
  const names = variantList(
@@ -144,7 +132,6 @@ const outerParams = (term: Term) => {
144
132
  return vars.map((variable, index) => ({ name: names[index], type: variable.type }));
145
133
  };
146
134
 
147
- // Variable.gen_all: the outermost parameters become schematic variables.
148
135
  export const genAll = (thm: Thm) => {
149
136
  const index = Math.max(thm.maxidx, -1) + 1;
150
137
  return outerParams(thm.prop).reduce(
@@ -153,9 +140,8 @@ export const genAll = (thm: Thm) => {
153
140
  );
154
141
  };
155
142
 
156
- // Thm.forall_intr_vars: quantifies the schematic variables in order of appearance.
157
143
  export const forallIntrVars = (thm: Thm) => {
158
- const vars = fullProps(thm).reduce(
144
+ const vars = fullProps(thm).reduce<Var[]>(
159
145
  (result, term) =>
160
146
  foldVars(
161
147
  (atom, current: Var[]) =>
@@ -165,7 +151,7 @@ export const forallIntrVars = (thm: Thm) => {
165
151
  term,
166
152
  result,
167
153
  ),
168
- [] as Var[],
154
+ [],
169
155
  );
170
156
  return vars.reduceRight((result, variable) => forallIntr(variable, result), thm);
171
157
  };
@@ -175,7 +161,6 @@ const variantBound = (name: string, used: NameContext) =>
175
161
 
176
162
  const fullProps = (thm: Thm) => [...thm.tpairs.flatMap((pair) => [pair[0], pair[1]]), thm.prop];
177
163
 
178
- // Drule.zero_var_indexes: renames the schematic variables apart with index 0.
179
164
  export const zeroVarIndexes = (thm: Thm): Thm => {
180
165
  const terms = fullProps(thm);
181
166
  const tvars = terms.reduce(
@@ -224,41 +209,40 @@ export const zeroVarIndexes = (thm: Thm): Thm => {
224
209
  return instantiate(insts, instantiateTypes(tyenv, thm));
225
210
  };
226
211
 
227
- // Tactic.make_elim: turns a destruction rule into an elimination rule.
228
212
  export const makeElim = (rule: Thm) => zeroVarIndexes(rs(rule, revcutRl));
229
213
 
230
- // Drule.compose: resolves tha into premise index of thb without lifting, with a unique result.
231
214
  const compose = (tha: Thm, index: number, thb: Thm): Thm => {
232
- const results = listOfSeq(
233
- bicompose(
234
- undefined,
235
- { flatten: true, match: false, incremented: true },
236
- { isElim: false, rule: tha, subgoals: 0 },
237
- index,
238
- thb,
215
+ const results = distinctThms(
216
+ listOfSeq(
217
+ bicompose(
218
+ undefined,
219
+ { flatten: true, match: false, incremented: true },
220
+ { isElim: false, rule: tha, subgoals: 0 },
221
+ index,
222
+ thb,
223
+ ),
239
224
  ),
240
- ).filter((result, position, all) => all.findIndex((other) => eqThm(other, result)) === position);
225
+ );
241
226
  if (results.length !== 1)
242
227
  throw new TlaIsabelleError("THM", `compose: unique result expected ${index}`);
243
228
  return results[0];
244
229
  };
245
230
 
246
- // COMP_INCR
247
231
  export const compIncr = (tha: Thm, thb: Thm) =>
248
232
  compose(tha, 1, incrIndexesThm(tha.maxidx + 1, thb));
249
233
 
250
- // Drule.comp_no_flatten: composes th, keeping its first count premises, into premise index of
251
- // rule.
252
234
  export const compNoFlatten = (thm: Thm, count: number, index: number, rule: Thm): Thm => {
253
- const results = listOfSeq(
254
- bicompose(
255
- undefined,
256
- { flatten: false, match: false, incremented: true },
257
- { isElim: false, rule: thm, subgoals: count },
258
- index,
259
- incrIndexesThm(thm.maxidx + 1, rule),
235
+ const results = distinctThms(
236
+ listOfSeq(
237
+ bicompose(
238
+ undefined,
239
+ { flatten: false, match: false, incremented: true },
240
+ { isElim: false, rule: thm, subgoals: count },
241
+ index,
242
+ incrIndexesThm(thm.maxidx + 1, rule),
243
+ ),
260
244
  ),
261
- ).filter((result, position, all) => all.findIndex((other) => eqThm(other, result)) === position);
245
+ );
262
246
  if (results.length !== 1) throw new TlaIsabelleError("THM", `comp_no_flatten ${index}`);
263
247
  return results[0];
264
248
  };