tla-ts 0.0.8-dev.d9bffda → 0.0.9-dev.0493be549

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 +30 -0
  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 +80 -10
  8. package/dist/index.d.ts +80 -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 +605 -311
  30. package/src/cli/options.ts +12 -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 +545 -218
  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 +632 -298
  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 +31 -38
  82. package/src/parallel.ts +41 -17
  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 +128 -176
  340. package/src/sany/levels.ts +6 -30
  341. package/src/sany/lexer.ts +7 -23
  342. package/src/sany/linter.ts +31 -29
  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 +533 -174
  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 +832 -255
  390. package/src/worker.ts +7 -8
@@ -1,16 +1,8 @@
1
- // Parses Isabelle's inner syntax, the terms inside quotes, as far as tlapm's theory printer
2
- // (isabelle.ml) uses it. The notation and its priorities come from Isabelle2025's Pure and from
3
- // the Isabelle/TLA+ theories that declare it: PredicateLogic, SetTheory, Functions, Tuples,
4
- // Strings and CaseExpressions. The translations those theories declare apply while parsing, so a
5
- // term comes out as constants, names, applications and abstractions only.
6
-
7
1
  import { TlaIsabelleError } from "../../../errors";
8
2
  import { funT, mkType, propT, type Typ } from "../pure/term";
9
3
 
10
4
  const TLA_TYPE = mkType("PredicateLogic.c");
11
5
 
12
- // A parsed term before names resolve and types are inferred. A name is a bound or free variable
13
- // or a constant; a constant comes from notation.
14
6
  export type Ast =
15
7
  | { readonly kind: "name"; readonly name: string }
16
8
  | { readonly kind: "const"; readonly name: string }
@@ -109,31 +101,30 @@ const tokenize = (text: string): Token[] => {
109
101
  return tokens;
110
102
  };
111
103
 
112
- const constant = (name: string): Ast => ({ kind: "const", name });
104
+ const toConstant = (name: string): Ast => ({ kind: "const", name });
113
105
  const apply = (fun: Ast, ...args: Ast[]) =>
114
106
  args.reduce<Ast>((result, arg) => ({ kind: "app", fun: result, arg }), fun);
115
107
 
116
- // Strings.thy: a string is the tuple of its characters, each a pair of nibbles.
117
- const nibble = (value: number): Ast =>
108
+ const toNibble = (value: number): Ast =>
118
109
  value === 0
119
- ? constant("Integers.zero")
120
- : apply(constant("Functions.fapply"), constant("Integers.succ"), nibble(value - 1));
110
+ ? toConstant("Integers.zero")
111
+ : apply(toConstant("Functions.fapply"), toConstant("Integers.succ"), toNibble(value - 1));
121
112
 
122
- const stringTerm = (text: string) =>
113
+ const toStringTerm = (text: string) =>
123
114
  [...text].reduce((tuple, char) => {
124
115
  const code = char.charCodeAt(0);
125
116
  if (code >= 128) throw new TlaIsabelleError("ERROR", `Non-ASCII symbol: ${char}`);
126
117
  return apply(
127
- constant("Tuples.Append"),
118
+ toConstant("Tuples.Append"),
128
119
  tuple,
129
- apply(constant("Strings.char"), nibble(code >> 4), nibble(code & 15)),
120
+ apply(toConstant("Strings.char"), toNibble(code >> 4), toNibble(code & 15)),
130
121
  );
131
- }, constant("Tuples.emptySeq"));
122
+ }, toConstant("Tuples.emptySeq"));
132
123
 
133
- const tuple = (elements: readonly Ast[]) =>
124
+ const toTuple = (elements: readonly Ast[]) =>
134
125
  elements.reduce(
135
- (result, element) => apply(constant("Tuples.Append"), result, element),
136
- constant("Tuples.emptySeq"),
126
+ (result, element) => apply(toConstant("Tuples.Append"), result, element),
127
+ toConstant("Tuples.emptySeq"),
137
128
  );
138
129
 
139
130
  interface Infix {
@@ -188,14 +179,17 @@ const PREFIXES = new Map<
188
179
  ["DOMAIN", { constant: "Functions.DOMAIN", argument: 100, priority: 90 }],
189
180
  ]);
190
181
 
191
- // A parse result: the term, its priority, and whether it is a proposition rather than an object
192
- // of the logic, which Isabelle tells apart by syntactic category.
193
182
  interface Parsed {
194
183
  readonly ast: Ast;
195
184
  readonly priority: number;
196
185
  readonly isProp: boolean;
197
186
  }
198
187
 
188
+ interface TypedName {
189
+ readonly name: string;
190
+ readonly type: Typ | undefined;
191
+ }
192
+
199
193
  const MAX_PRIORITY = 1000;
200
194
 
201
195
  class Parser {
@@ -231,23 +225,22 @@ class Parser {
231
225
  );
232
226
  }
233
227
 
234
- private identifier(): string {
228
+ private parseIdentifier(): string {
235
229
  const token = this.next();
236
230
  if (token.kind !== "id") throw this.syntaxError();
237
231
  return token.text;
238
232
  }
239
233
 
240
- atEnd() {
234
+ isAtEnd() {
241
235
  return this.peek().kind === "end";
242
236
  }
243
237
 
244
- // A type: c, prop, a function type, or [c, c] => c.
245
- type(): Typ {
246
- const domains = this.isDelimiter("[") ? this.typeList() : undefined;
247
- const atom = domains === undefined ? this.typeAtom() : undefined;
238
+ parseType(): Typ {
239
+ const domains = this.isDelimiter("[") ? this.parseTypeList() : undefined;
240
+ const atom = domains === undefined ? this.parseTypeAtom() : undefined;
248
241
  if (this.isDelimiter("=>") || this.isDelimiter("\\<Rightarrow>")) {
249
242
  this.position += 1;
250
- const range = this.type();
243
+ const range = this.parseType();
251
244
  return (domains ?? [atom ?? TLA_TYPE]).reduceRight(
252
245
  (result, domain) => funT(domain, result),
253
246
  range,
@@ -257,75 +250,71 @@ class Parser {
257
250
  return atom;
258
251
  }
259
252
 
260
- private typeList(): Typ[] {
253
+ private parseTypeList(): Typ[] {
261
254
  this.expect("[");
262
- const types = [this.type()];
255
+ const types = [this.parseType()];
263
256
  while (this.isDelimiter(",")) {
264
257
  this.position += 1;
265
- types.push(this.type());
258
+ types.push(this.parseType());
266
259
  }
267
260
  this.expect("]");
268
261
  return types;
269
262
  }
270
263
 
271
- private typeAtom(): Typ {
264
+ private parseTypeAtom(): Typ {
272
265
  if (this.isDelimiter("(")) {
273
266
  this.position += 1;
274
- const type = this.type();
267
+ const type = this.parseType();
275
268
  this.expect(")");
276
269
  return type;
277
270
  }
278
- const name = this.identifier();
271
+ const name = this.parseIdentifier();
279
272
  if (name === "c") return TLA_TYPE;
280
273
  if (name === "prop") return propT;
281
274
  throw new TlaIsabelleError("ERROR", `Undefined type name: ${name}`);
282
275
  }
283
276
 
284
- // Binder variables, each optionally constrained: x, x :: c.
285
- private binders(isConstrainable: boolean): { name: string; type: Typ | undefined }[] {
286
- const binders: { name: string; type: Typ | undefined }[] = [];
277
+ private parseBinders(isConstrainable: boolean): TypedName[] {
278
+ const binders: TypedName[] = [];
287
279
  while (this.peek().kind === "id") {
288
- const name = this.identifier();
280
+ const name = this.parseIdentifier();
289
281
  if (isConstrainable && this.isDelimiter("::")) {
290
282
  this.position += 1;
291
- binders.push({ name, type: this.type() });
283
+ binders.push({ name, type: this.parseType() });
292
284
  } else binders.push({ name, type: undefined });
293
285
  }
294
286
  if (binders.length === 0) throw this.syntaxError();
295
287
  return binders;
296
288
  }
297
289
 
298
- private commaList(close: string): Ast[] {
290
+ private parseCommaList(close: string): Ast[] {
299
291
  if (this.isDelimiter(close)) {
300
292
  this.position += 1;
301
293
  return [];
302
294
  }
303
- const items = [this.logic(0)];
295
+ const items = [this.parseLogic(0)];
304
296
  while (this.isDelimiter(",")) {
305
297
  this.position += 1;
306
- items.push(this.logic(0));
298
+ items.push(this.parseLogic(0));
307
299
  }
308
300
  this.expect(close);
309
301
  return items;
310
302
  }
311
303
 
312
- // An object-logic term of at least the given priority.
313
- logic(minimum: number): Ast {
314
- const parsed = this.expression(minimum);
304
+ parseLogic(minimum: number): Ast {
305
+ const parsed = this.parseExpression(minimum);
315
306
  if (parsed.isProp)
316
307
  throw new TlaIsabelleError("ERROR", "Inner syntax error: proposition in term position");
317
308
  return parsed.ast;
318
309
  }
319
310
 
320
- // A proposition: an object-logic term becomes one through Trueprop, as PredicateLogic's
321
- // "(_)" 5 mixfix declares.
322
- prop(minimum: number): Ast {
323
- const parsed = this.expression(minimum);
324
- return parsed.isProp ? parsed.ast : apply(constant("PredicateLogic.Trueprop"), parsed.ast);
311
+ parseProp(minimum: number): Ast {
312
+ const parsed = this.parseExpression(minimum);
313
+ return parsed.isProp ? parsed.ast : apply(toConstant("PredicateLogic.Trueprop"), parsed.ast);
325
314
  }
326
315
 
327
- private expression(minimum: number): Parsed {
328
- let left = this.prefix(minimum);
316
+ private parseExpression(minimum: number): Parsed {
317
+ let left = this.parsePrefix(minimum);
329
318
  for (;;) {
330
319
  const token = this.peek();
331
320
  if (token.kind !== "delimiter") return left;
@@ -334,9 +323,9 @@ class Parser {
334
323
  this.position += 1;
335
324
  const premise = left.isProp
336
325
  ? left.ast
337
- : apply(constant("PredicateLogic.Trueprop"), left.ast);
326
+ : apply(toConstant("PredicateLogic.Trueprop"), left.ast);
338
327
  left = {
339
- ast: apply(constant("Pure.imp"), premise, this.prop(1)),
328
+ ast: apply(toConstant("Pure.imp"), premise, this.parseProp(1)),
340
329
  priority: 1,
341
330
  isProp: true,
342
331
  };
@@ -347,7 +336,7 @@ class Parser {
347
336
  if (minimum > 3 || left.priority < 4) return left;
348
337
  this.position += 1;
349
338
  left = {
350
- ast: { kind: "constrain", term: left.ast, type: this.type() },
339
+ ast: { kind: "constrain", term: left.ast, type: this.parseType() },
351
340
  priority: 3,
352
341
  isProp: false,
353
342
  };
@@ -356,7 +345,7 @@ class Parser {
356
345
  if (token.text === "(") {
357
346
  if (left.priority < MAX_PRIORITY) return left;
358
347
  this.position += 1;
359
- const args = this.commaList(")");
348
+ const args = this.parseCommaList(")");
360
349
  if (args.length === 0) throw this.syntaxError();
361
350
  left = { ast: apply(left.ast, ...args), priority: MAX_PRIORITY, isProp: false };
362
351
  continue;
@@ -364,10 +353,10 @@ class Parser {
364
353
  if (token.text === "[") {
365
354
  if (minimum > 90 || left.priority < 89) return left;
366
355
  this.position += 1;
367
- const index = this.logic(0);
356
+ const index = this.parseLogic(0);
368
357
  this.expect("]");
369
358
  left = {
370
- ast: apply(constant("Functions.fapply"), left.ast, index),
359
+ ast: apply(toConstant("Functions.fapply"), left.ast, index),
371
360
  priority: 90,
372
361
  isProp: false,
373
362
  };
@@ -378,61 +367,61 @@ class Parser {
378
367
  return left;
379
368
  this.position += 1;
380
369
  left = {
381
- ast: apply(constant(infix.constant), left.ast, this.logic(infix.right)),
370
+ ast: apply(toConstant(infix.constant), left.ast, this.parseLogic(infix.right)),
382
371
  priority: infix.priority,
383
372
  isProp: false,
384
373
  };
385
374
  }
386
375
  }
387
376
 
388
- private prefix(minimum: number): Parsed {
377
+ private parsePrefix(minimum: number): Parsed {
389
378
  const token = this.next();
390
- const term = (ast: Ast, priority = MAX_PRIORITY): Parsed => ({ ast, priority, isProp: false });
379
+ const toTerm = (ast: Ast, priority = MAX_PRIORITY): Parsed => ({
380
+ ast,
381
+ priority,
382
+ isProp: false,
383
+ });
391
384
  if (token.kind === "end") {
392
385
  this.position -= 1;
393
386
  throw this.syntaxError();
394
387
  }
395
- if (token.kind === "id") return term({ kind: "name", name: token.text });
396
- if (token.kind === "string") return term(stringTerm(token.text));
388
+ if (token.kind === "id") return toTerm({ kind: "name", name: token.text });
389
+ if (token.kind === "string") return toTerm(toStringTerm(token.text));
397
390
  switch (token.text) {
398
391
  case "(": {
399
- const inner = this.expression(0);
392
+ const inner = this.parseExpression(0);
400
393
  this.expect(")");
401
394
  return { ...inner, priority: MAX_PRIORITY };
402
395
  }
403
396
  case "0":
404
- return term(constant("Integers.zero"));
397
+ return toTerm(toConstant("Integers.zero"));
405
398
  case "{":
406
399
  if (this.isDelimiter("}")) {
407
400
  this.position += 1;
408
- return term(constant("SetTheory.emptyset"), 100);
401
+ return toTerm(toConstant("SetTheory.emptyset"), 100);
409
402
  }
410
- return term(
411
- this.commaList("}").reduceRight(
412
- (set, element) => apply(constant("SetTheory.addElt"), element, set),
413
- constant("SetTheory.emptyset"),
403
+ return toTerm(
404
+ this.parseCommaList("}").reduceRight(
405
+ (set, element) => apply(toConstant("SetTheory.addElt"), element, set),
406
+ toConstant("SetTheory.emptyset"),
414
407
  ),
415
408
  );
416
409
  case "<<":
417
- return term(
418
- this.isDelimiter(">>")
419
- ? (this.next(), constant("Tuples.emptySeq"))
420
- : tuple(this.commaList(">>")),
421
- );
410
+ return toTerm(toTuple(this.parseCommaList(">>")));
422
411
  case "\\<langle>":
423
- return term(tuple(this.commaList("\\<rangle>")));
412
+ return toTerm(toTuple(this.parseCommaList("\\<rangle>")));
424
413
  case "[":
425
- return this.bracket();
414
+ return this.parseBracket();
426
415
  case "\\<forall>":
427
416
  case "\\<exists>":
428
- return term(this.quantifier(token.text === "\\<forall>"), 10);
417
+ return toTerm(this.parseQuantifier(token.text === "\\<forall>"), 10);
429
418
  case "%":
430
419
  case "\\<lambda>": {
431
420
  if (minimum > 3) throw this.syntaxError();
432
- const binders = this.binders(true);
421
+ const binders = this.parseBinders(true);
433
422
  this.expect(".");
434
- const body = this.logic(3);
435
- return term(
423
+ const body = this.parseLogic(3);
424
+ return toTerm(
436
425
  binders.reduceRight<Ast>(
437
426
  (result, binder) => ({
438
427
  kind: "abs",
@@ -447,13 +436,13 @@ class Parser {
447
436
  }
448
437
  case "\\<And>": {
449
438
  if (minimum > 0) throw this.syntaxError();
450
- const binders = this.binders(true);
439
+ const binders = this.parseBinders(true);
451
440
  this.expect(".");
452
- const body = this.prop(0);
441
+ const body = this.parseProp(0);
453
442
  return {
454
443
  ast: binders.reduceRight<Ast>(
455
444
  (result, binder) =>
456
- apply(constant("Pure.all"), {
445
+ apply(toConstant("Pure.all"), {
457
446
  kind: "abs",
458
447
  name: binder.name,
459
448
  type: binder.type,
@@ -471,30 +460,32 @@ class Parser {
471
460
  this.position -= 1;
472
461
  throw this.syntaxError();
473
462
  }
474
- return term(apply(constant(prefix.constant), this.logic(prefix.argument)), prefix.priority);
463
+ return toTerm(
464
+ apply(toConstant(prefix.constant), this.parseLogic(prefix.argument)),
465
+ prefix.priority,
466
+ );
475
467
  }
476
468
 
477
- // \<forall>x, y : P and \<forall>x, y \<in> S : P, with \<exists> alike.
478
- private quantifier(isForall: boolean): Ast {
479
- const names = [this.identifier()];
469
+ private parseQuantifier(isForall: boolean): Ast {
470
+ const names = [this.parseIdentifier()];
480
471
  while (this.isDelimiter(",")) {
481
472
  this.position += 1;
482
- names.push(this.identifier());
473
+ names.push(this.parseIdentifier());
483
474
  }
484
475
  if (this.isDelimiter(":")) {
485
476
  this.position += 1;
486
- const body = this.logic(10);
487
- const quantifier = constant(isForall ? "PredicateLogic.All" : "PredicateLogic.Ex");
477
+ const body = this.parseLogic(10);
478
+ const quantifier = toConstant(isForall ? "PredicateLogic.All" : "PredicateLogic.Ex");
488
479
  return names.reduceRight(
489
480
  (result, name) => apply(quantifier, { kind: "abs", name, type: undefined, body: result }),
490
481
  body,
491
482
  );
492
483
  }
493
484
  this.expect("\\<in>");
494
- const domain = this.logic(0);
485
+ const domain = this.parseLogic(0);
495
486
  this.expect(":");
496
- const body = this.logic(0);
497
- const quantifier = constant(isForall ? "SetTheory.bAll" : "SetTheory.bEx");
487
+ const body = this.parseLogic(0);
488
+ const quantifier = toConstant(isForall ? "SetTheory.bAll" : "SetTheory.bEx");
498
489
  return names.reduceRight(
499
490
  (result, name) =>
500
491
  apply(quantifier, domain, { kind: "abs", name, type: undefined, body: result }),
@@ -502,29 +493,32 @@ class Parser {
502
493
  );
503
494
  }
504
495
 
505
- // The bracketed forms: [x \<in> S \<mapsto> e], [S \<rightarrow> T], [f EXCEPT ![x] = e, ...]
506
- // and [d : r, ...].
507
- private bracket(): Parsed {
496
+ private parseBracket(): Parsed {
508
497
  if (this.peek().kind === "id" && this.isDelimiter("\\<in>", 1)) {
509
- const name = this.identifier();
498
+ const name = this.parseIdentifier();
510
499
  this.position += 1;
511
- const domain = this.logic(0);
500
+ const domain = this.parseLogic(0);
512
501
  this.expect("\\<mapsto>");
513
- const body = this.logic(0);
502
+ const body = this.parseLogic(0);
514
503
  this.expect("]");
515
504
  return {
516
- ast: apply(constant("Functions.Fcn"), domain, { kind: "abs", name, type: undefined, body }),
505
+ ast: apply(toConstant("Functions.Fcn"), domain, {
506
+ kind: "abs",
507
+ name,
508
+ type: undefined,
509
+ body,
510
+ }),
517
511
  priority: 900,
518
512
  isProp: false,
519
513
  };
520
514
  }
521
- const first = this.logic(0);
515
+ const first = this.parseLogic(0);
522
516
  if (this.isDelimiter("\\<rightarrow>")) {
523
517
  this.position += 1;
524
- const range = this.logic(0);
518
+ const range = this.parseLogic(0);
525
519
  this.expect("]");
526
520
  return {
527
- ast: apply(constant("Functions.FuncSet"), first, range),
521
+ ast: apply(toConstant("Functions.FuncSet"), first, range),
528
522
  priority: 900,
529
523
  isProp: false,
530
524
  };
@@ -535,10 +529,10 @@ class Parser {
535
529
  for (;;) {
536
530
  this.expect("!");
537
531
  this.expect("[");
538
- const index = this.logic(0);
532
+ const index = this.parseLogic(0);
539
533
  this.expect("]");
540
534
  this.expect("=");
541
- result = apply(constant("Functions.except"), result, index, this.logic(0));
535
+ result = apply(toConstant("Functions.except"), result, index, this.parseLogic(0));
542
536
  if (!this.isDelimiter(",")) break;
543
537
  this.position += 1;
544
538
  }
@@ -547,16 +541,16 @@ class Parser {
547
541
  }
548
542
  this.expect(":");
549
543
  const domains = [first];
550
- const ranges = [this.logic(0)];
544
+ const ranges = [this.parseLogic(0)];
551
545
  while (this.isDelimiter(",")) {
552
546
  this.position += 1;
553
- domains.push(this.logic(0));
547
+ domains.push(this.parseLogic(0));
554
548
  this.expect(":");
555
- ranges.push(this.logic(0));
549
+ ranges.push(this.parseLogic(0));
556
550
  }
557
551
  this.expect("]");
558
552
  return {
559
- ast: apply(constant("Tuples.EnumFuncSet"), tuple(domains), tuple(ranges)),
553
+ ast: apply(toConstant("Tuples.EnumFuncSet"), toTuple(domains), toTuple(ranges)),
560
554
  priority: MAX_PRIORITY,
561
555
  isProp: false,
562
556
  };
@@ -566,7 +560,7 @@ class Parser {
566
560
  const parseWith = <Result>(text: string, parse: (parser: Parser) => Result): Result => {
567
561
  const parser = new Parser(tokenize(text));
568
562
  const result = parse(parser);
569
- if (!parser.atEnd())
563
+ if (!parser.isAtEnd())
570
564
  throw new TlaIsabelleError(
571
565
  "ERROR",
572
566
  `Inner syntax error: trailing input in ${text.slice(0, 40)}`,
@@ -574,6 +568,6 @@ const parseWith = <Result>(text: string, parse: (parser: Parser) => Result): Res
574
568
  return result;
575
569
  };
576
570
 
577
- export const parseProp = (text: string) => parseWith(text, (parser) => parser.prop(0));
571
+ export const parseProp = (text: string) => parseWith(text, (parser) => parser.parseProp(0));
578
572
 
579
- export const parseType = (text: string) => parseWith(text, (parser) => parser.type());
573
+ export const parseType = (text: string) => parseWith(text, (parser) => parser.parseType());
@@ -1,13 +1,9 @@
1
- // Ported from Isabelle2025's Pure/Isar/method.ML (method syntax, combinators, SIMPLE_METHOD,
2
- // finish), the assume_rule_tac and norm_hhf_tac of Pure/goal.ML, and the methods the theories
3
- // tlapm writes use: auto, force and clarsimp (Provers/clasimp.ML), blast (Provers/blast.ML),
4
- // iprover (Tools/intuitionistic.ML) and intro. Copyright (c) 1986-2025 University of Cambridge,
5
- // Technische Universitaet Muenchen, and contributors, see LICENSE.
1
+ // Ported from Isabelle2025's Pure/Isar/method.ML and Pure/goal.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 { asmRl, isNormHhf, normHhfEq, reflexiveThm, termI } from "../pure/drule";
9
5
  import { isEquals, stripImpPrems, stripAssumsConcl } from "../pure/logic";
10
- import { addSimps, emptySimpset, type Simpset } from "../pure/raw-simplifier";
6
+ import { makeSimpContext, type Simpset } from "../pure/raw-simplifier";
11
7
  import { genericRewriteGoalTac } from "../pure/rewriter";
12
8
  import { filterSeq, mapsSeq, singleSeq, type Seq } from "../pure/seq";
13
9
  import { atomizePremsTac } from "../pure/object-logic";
@@ -65,13 +61,11 @@ type MethodText =
65
61
  | { readonly kind: "then"; readonly methods: readonly MethodText[] }
66
62
  | { readonly kind: "try"; readonly method: MethodText };
67
63
 
68
- // The methods of by: the initial one, and the terminal one that qed runs.
69
64
  interface ProofText {
70
65
  readonly initial: MethodText;
71
66
  readonly terminal: MethodText | undefined;
72
67
  }
73
68
 
74
- // What a proof method reads from the Isabelle proof context.
75
69
  export interface ProofContext {
76
70
  readonly limits: Limits;
77
71
  readonly simpset: Simpset;
@@ -89,7 +83,6 @@ const syntaxError = (token: OuterToken | undefined) =>
89
83
  `Outer syntax error at: ${token === undefined ? "end of input" : token.text}`,
90
84
  );
91
85
 
92
- // Method.parse for the proof methods of by.
93
86
  export const parseProofText = (tokens: readonly OuterToken[]): ProofText => {
94
87
  let position = 0;
95
88
  const peek = () => tokens[position];
@@ -100,62 +93,67 @@ export const parseProofText = (tokens: readonly OuterToken[]): ProofText => {
100
93
  position += 1;
101
94
  };
102
95
  const isWord = () => peek()?.kind === "word";
103
- const word = () => {
96
+ const readWord = () => {
104
97
  const token = peek();
105
98
  if (token?.kind !== "word") throw syntaxError(token);
106
99
  position += 1;
107
100
  return token.text;
108
101
  };
109
102
  const isSectionStart = () => isWord() && isSymbol(":", 1);
110
- const facts = () => {
103
+ const readFacts = () => {
111
104
  const names: string[] = [];
112
- while (isWord() && !isSectionStart()) names.push(word());
105
+ while (isWord() && !isSectionStart()) names.push(readWord());
113
106
  return names;
114
107
  };
115
- const modifiers = (): Modifier[] => {
108
+ const readModifiers = (): Modifier[] => {
116
109
  const result: Modifier[] = [];
117
110
  while (isSectionStart()) {
118
- const kind = word();
111
+ const kind = readWord();
119
112
  position += 1;
120
113
  if (kind !== "intro" && kind !== "dest")
121
114
  throw new TlaIsabelleError("ERROR", `Unsupported method modifier: ${kind}`);
122
- result.push({ kind, facts: facts() });
115
+ result.push({ kind, facts: readFacts() });
123
116
  }
124
117
  return result;
125
118
  };
126
- const method = (name: string, hasArgs: boolean): MethodText => {
119
+ const readMethod = (name: string, hasArgs: boolean): MethodText => {
127
120
  switch (name) {
128
121
  case "auto":
129
122
  case "blast":
130
123
  case "force":
131
124
  case "clarsimp":
132
- return { kind: name, modifiers: hasArgs ? modifiers() : [] };
125
+ return { kind: name, modifiers: hasArgs ? readModifiers() : [] };
133
126
  case "iprover":
134
127
  return { kind: "iprover" };
135
128
  case "intro":
136
- return { kind: "intro", facts: hasArgs ? facts() : [] };
129
+ return { kind: "intro", facts: hasArgs ? readFacts() : [] };
137
130
  default:
138
131
  throw new TlaIsabelleError("ERROR", `Undefined method: ${name}`);
139
132
  }
140
133
  };
141
- const suffixed = (text: MethodText): MethodText => {
134
+ const readSuffixed = (text: MethodText): MethodText => {
142
135
  if (!isSymbol("?")) return text;
143
136
  position += 1;
144
- return suffixed({ kind: "try", method: text });
137
+ return readSuffixed({ kind: "try", method: text });
145
138
  };
146
- const parenthesized = (): MethodText => {
139
+ const readParenthesized = (): MethodText => {
147
140
  expectSymbol("(");
148
- const elements = [suffixed(isSymbol("(") ? parenthesized() : method(word(), true))];
141
+ const elements = [
142
+ readSuffixed(isSymbol("(") ? readParenthesized() : readMethod(readWord(), true)),
143
+ ];
149
144
  while (isSymbol(",")) {
150
145
  position += 1;
151
- elements.push(suffixed(isSymbol("(") ? parenthesized() : method(word(), true)));
146
+ elements.push(
147
+ readSuffixed(isSymbol("(") ? readParenthesized() : readMethod(readWord(), true)),
148
+ );
152
149
  }
153
150
  expectSymbol(")");
154
151
  return elements.length === 1 ? elements[0] : { kind: "then", methods: elements };
155
152
  };
156
- const atom = () => suffixed(isSymbol("(") ? parenthesized() : method(word(), false));
157
- const initial = atom();
158
- const terminal = position < tokens.length ? atom() : undefined;
153
+ const readAtom = () =>
154
+ readSuffixed(isSymbol("(") ? readParenthesized() : readMethod(readWord(), false));
155
+ const initial = readAtom();
156
+ const terminal = position < tokens.length ? readAtom() : undefined;
159
157
  if (position !== tokens.length) throw syntaxError(peek());
160
158
  return { initial, terminal };
161
159
  };
@@ -163,7 +161,6 @@ export const parseProofText = (tokens: readonly OuterToken[]): ProofText => {
163
161
  const getFacts = (context: ProofContext, names: readonly string[]) =>
164
162
  names.flatMap((name) => context.getFact(name));
165
163
 
166
- // Method.sections: the claset the modifiers declare.
167
164
  const withModifiers = (context: ProofContext, modifiers: readonly Modifier[]): ClassicalContext =>
168
165
  modifiers.reduce(
169
166
  (classical, modifier) =>
@@ -189,7 +186,6 @@ const getClasimp = (context: ProofContext, classical: ClassicalContext): Clasimp
189
186
  const insertAllTac = (context: ProofContext, facts: readonly Thm[]) =>
190
187
  allGoals((index) => insertTac(context.limits, facts, index));
191
188
 
192
- // SIMPLE_METHOD'
193
189
  const simpleMethodHead = (context: ProofContext, facts: readonly Thm[], tactic: GoalTactic) =>
194
190
  thenGoal((index) => insertTac(context.limits, facts, index), tactic)(1);
195
191
 
@@ -255,10 +251,8 @@ const evaluate = (context: ProofContext, text: MethodText): Method => {
255
251
  }
256
252
  };
257
253
 
258
- // Goal.norm_hhf_tac
259
254
  const normHhfTac = (limits: Limits): GoalTactic => {
260
- const empty = { limits, simpset: emptySimpset, bounds: 0 };
261
- const context = { ...empty, simpset: addSimps(empty, [normHhfEq]) };
255
+ const context = makeSimpContext(limits, [normHhfEq]);
262
256
  return thenGoal(
263
257
  resolveTac(limits, [asmRl]),
264
258
  subgoal((goal, index) =>
@@ -274,12 +268,10 @@ const normHhfTac = (limits: Limits): GoalTactic => {
274
268
  );
275
269
  };
276
270
 
277
- // Goal.assume_rule_tac: solves a goal with one of its non-atomic premises.
278
271
  const assumeRuleTac = (limits: Limits): GoalTactic =>
279
272
  thenGoal(
280
273
  normHhfTac(limits),
281
274
  subgoal((goal, index) => {
282
- // Variable.focus_cterm and Variable.export: the parameters become schematic variables.
283
275
  const params = stripAllVars(goal);
284
276
  const names = variantList(
285
277
  addFreeNames(goal, []),
@@ -309,7 +301,6 @@ const assumeRuleTac = (limits: Limits): GoalTactic =>
309
301
  }),
310
302
  );
311
303
 
312
- // Method.assm_tac
313
304
  const assmTac = (limits: Limits): GoalTactic => {
314
305
  const condRtac = (isRule: (concl: Term) => boolean, rule: Thm) =>
315
306
  subgoal((goal, index) =>
@@ -331,7 +322,6 @@ const assmTac = (limits: Limits): GoalTactic => {
331
322
  );
332
323
  };
333
324
 
334
- // Method.all_assm_tac
335
325
  const allAssmTac =
336
326
  (limits: Limits) =>
337
327
  (index: number): Tactic =>
@@ -343,9 +333,6 @@ const allAssmTac =
343
333
  allAssmTac(limits)(index + 1),
344
334
  )(state);
345
335
 
346
- // Proof.local_terminal_proof: by initial terminal runs the initial method with the facts, then
347
- // the terminal one without them and Method.finish, and succeeds on the first result that leaves
348
- // no goal.
349
336
  export const terminalProof = (
350
337
  context: ProofContext,
351
338
  text: ProofText,