tla-ts 0.0.9 → 0.0.10-dev.28c823e4b

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 +106 -10
  8. package/dist/index.d.ts +106 -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 +129 -104
  21. package/dist/transfer.js +129 -104
  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 +4 -23
  26. package/src/bags.ts +99 -102
  27. package/src/builtins.ts +40 -78
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check.ts +599 -388
  30. package/src/cli/options.ts +11 -6
  31. package/src/cli/run.ts +0 -2
  32. package/src/cli/runtime-invariants.ts +136 -0
  33. package/src/cli/shared.ts +18 -11
  34. package/src/cli/tlapm.ts +0 -12
  35. package/src/cli/tlc-arguments.ts +640 -0
  36. package/src/cli/tlc-usage.ts +361 -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 +596 -339
  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 +4 -19
  54. package/src/json-reader.ts +455 -0
  55. package/src/json.ts +255 -139
  56. package/src/levels.ts +8 -17
  57. package/src/lexer.ts +80 -100
  58. package/src/liveness-checker.ts +82 -119
  59. package/src/liveness.ts +112 -64
  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 +53 -44
  83. package/src/parser.ts +565 -282
  84. package/src/pcal/ast.ts +53 -86
  85. package/src/pcal/parse.ts +144 -219
  86. package/src/pcal/tokenize.ts +91 -131
  87. package/src/pcal/translate.ts +83 -130
  88. package/src/pcal/validate.ts +48 -68
  89. package/src/pretty-print.ts +7 -8
  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 +81 -35
  336. package/src/resolve.ts +12 -112
  337. package/src/runtime.ts +22 -22
  338. package/src/sany/builtins.ts +2 -5
  339. package/src/sany/generator.ts +149 -252
  340. package/src/sany/levels.ts +6 -34
  341. package/src/sany/lexer.ts +41 -61
  342. package/src/sany/linter.ts +1 -9
  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 +495 -155
  351. package/src/simulate.ts +685 -0
  352. package/src/spec-description.ts +176 -69
  353. package/src/standard-definitions.ts +0 -4
  354. package/src/standard-modules.ts +254 -69
  355. package/src/state-graph.ts +50 -24
  356. package/src/subexpressions.ts +69 -52
  357. package/src/substitution-levels.ts +2 -3
  358. package/src/successors.ts +263 -94
  359. package/src/symmetry.ts +33 -25
  360. package/src/tableau.ts +27 -24
  361. package/src/tlc/fingerprint.ts +183 -67
  362. package/src/tlc/jar-data.ts +112 -6
  363. package/src/tlc/messages.ts +110 -44
  364. package/src/tlc/order.ts +37 -60
  365. package/src/tlc/random.ts +33 -45
  366. package/src/tlc/replay.ts +549 -217
  367. package/src/tlc/summary.ts +36 -47
  368. package/src/tlc/tlc-operators.ts +76 -41
  369. package/src/tlc/tlcext-operators.ts +139 -122
  370. package/src/tlc/trace-spec.ts +269 -0
  371. package/src/tlc/value-stream.ts +139 -0
  372. package/src/tlc/version.ts +1 -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 +780 -337
  390. package/src/worker.ts +7 -8
@@ -1,6 +1,3 @@
1
- // The check of unfolding a definition: a real definition from the input, or a pseudo-definition
2
- // that Zenon reads off a hypothesis.
3
-
4
1
  import type { Definition } from "../parse";
5
2
  import {
6
3
  app,
@@ -14,8 +11,6 @@ import {
14
11
  type Term,
15
12
  } from "./terms";
16
13
 
17
- // Checks that `unfolded` is `folded` with occurrences of the defined symbol replaced by its body,
18
- // going through applications and negations as Zenon does.
19
14
  const isUnfolding = (
20
15
  checker: Checker,
21
16
  definition: Definition,
@@ -67,7 +62,6 @@ const getBound = (origin: Term) => {
67
62
  return { bound, matrix };
68
63
  };
69
64
 
70
- // A pseudo-definition stands for its hypothesis, \A params : f(params) = body or <=> body.
71
65
  const isDefinedBy = (checker: Checker, definition: Definition, origin: Term) => {
72
66
  const quantified = getBound(origin);
73
67
  const bound = quantified.bound;
@@ -85,14 +79,13 @@ const isDefinedBy = (checker: Checker, definition: Definition, origin: Term) =>
85
79
  ];
86
80
  if (params.length === 0) heads.push(variable(definition.symbol));
87
81
  const sides = matrix.args;
88
- // The parameters are free in the head and the body, so compare them under the same names.
89
82
  const env: Env = new Map(bound.map((name, index) => [name, index]));
90
- const keyOf = (formula: Term) => checker.getKey(formula, env, bound.length);
91
- const headKeys = heads.map(keyOf);
92
- const bodyKey = keyOf(definition.body);
83
+ const getBoundKey = (formula: Term) => checker.getKey(formula, env, bound.length);
84
+ const headKeys = heads.map(getBoundKey);
85
+ const bodyKey = getBoundKey(definition.body);
93
86
  return (
94
- (headKeys.includes(keyOf(sides[0])) && keyOf(sides[1]) === bodyKey) ||
95
- (headKeys.includes(keyOf(sides[1])) && keyOf(sides[0]) === bodyKey)
87
+ (headKeys.includes(getBoundKey(sides[0])) && getBoundKey(sides[1]) === bodyKey) ||
88
+ (headKeys.includes(getBoundKey(sides[1])) && getBoundKey(sides[0]) === bodyKey)
96
89
  );
97
90
  };
98
91
 
@@ -102,7 +95,6 @@ const getFreeSymbols = (formula: Term, symbols: Set<string>) => {
102
95
  return symbols;
103
96
  };
104
97
 
105
- // Real definitions are sound when each symbol has one and they don't refer to themselves.
106
98
  const isWellFounded = (definition: Definition, definitions: Definition[]) => {
107
99
  const reals = definitions.filter((candidate) => candidate.kind === "real");
108
100
  const bySymbol = new Map(reals.map((candidate) => [candidate.symbol, candidate]));
@@ -130,8 +122,6 @@ export const getDefinitionSpec = (
130
122
  ): RuleSpec => {
131
123
  const definitions = checker.context.definitions;
132
124
  ensure(definitions.includes(definition));
133
- // An equivalence only says the two sides have the same truth value, so it unfolds where a
134
- // formula is expected, not inside a term.
135
125
  const isEquivalence =
136
126
  definition.kind === "pseudo" && getBound(definition.origin).matrix.kind === "equiv";
137
127
  ensure(isUnfolding(checker, definition, args[0], args[1], isEquivalence));
@@ -1,6 +1,3 @@
1
- // The checks of Zenon's rules for equality, strings and the relations that the hypotheses make
2
- // reflexive, symmetric or transitive.
3
-
4
1
  import type { PlainRuleName, Rule, RelationRuleName } from "../proof";
5
2
  import {
6
3
  app,
@@ -20,8 +17,6 @@ import {
20
17
 
21
18
  const relate = (symbol: string, left: Term, right: Term) => app(symbol, [left, right]);
22
19
 
23
- // The two branches that the relation fails to link and the ends differ. The ends come from
24
- // r(a, b) and ~r(c, d) in the order that Zenon's Trans or Trans_sym takes them.
25
20
  const getTransitivitySpec = (
26
21
  checker: Checker,
27
22
  args: [Term, Term],
@@ -48,7 +43,6 @@ const getTransitivitySpec = (
48
43
  };
49
44
  };
50
45
 
51
- // a = b against ~r(c, d), in the order of Zenon's TransEq, TransEq_sym or TransEq2.
52
46
  const getTransitiveEqualitySpec = (
53
47
  checker: Checker,
54
48
  args: [Term, Term, Term],
@@ -83,7 +77,6 @@ const getTransitiveEqualitySpec = (
83
77
  };
84
78
  };
85
79
 
86
- // Of t1 = s1 and t2 = s2 with distinct strings s1 and s2, in the order of the rule's sides.
87
80
  const getStringDifferenceSpec = (args: Term[], sides: "ll" | "lr" | "rl" | "rr"): RuleSpec => {
88
81
  const term1 = args[0];
89
82
  const string1 = args[1];
@@ -99,7 +92,6 @@ const getStringDifferenceSpec = (args: Term[], sides: "ll" | "lr" | "rl" | "rr")
99
92
  };
100
93
  };
101
94
 
102
- // Of f(a1, ..., an) and ~g(b1, ..., bn) with f and g the same: some argument differs.
103
95
  const getArgumentsDifferSpec = (premises: Term[], left: Term, right: Term): RuleSpec => {
104
96
  const leftArgs = expectKind(left, "app");
105
97
  const rightArgs = expectKind(right, "app");
@@ -1,6 +1,3 @@
1
- // The checks of the TLA+ extension's rules for functions, after the lemmas in Zenon.thy that justify
2
- // them.
3
-
4
1
  import type { PlainRuleName } from "../proof";
5
2
  import {
6
3
  and,
@@ -18,7 +15,6 @@ import {
18
15
  type Term,
19
16
  } from "./terms";
20
17
 
21
- // ~isAFcn(f) where f is built by a function constructor closes the branch.
22
18
  const getNotFunctionSpec = (formula: Term, constructor: string, arity: number) => {
23
19
  expectApp(expectApp(expectNot(formula), "TLA.isAFcn", 1)[0], constructor, arity);
24
20
  return { premises: [formula], branches: [] };
@@ -1,6 +1,3 @@
1
- // Comparing formulas by their own alpha-equivalence: each formula prints to a key in which a bound
2
- // variable is the number of binders between it and its own.
3
-
4
1
  import { term, UncheckedError, variable, type Env, type Operators, type Term } from "./terms";
5
2
 
6
3
  export const createKeys = () => {
@@ -8,8 +5,6 @@ export const createKeys = () => {
8
5
  const topKeys = new WeakMap<Term, string>();
9
6
  let freshCount = 0;
10
7
 
11
- // The variables and applied symbols that a formula doesn't bind, which are the names an
12
- // environment can change.
13
8
  const getFreeNames = (formula: Term): Set<string> => {
14
9
  const cached = freeNames.get(formula);
15
10
  if (cached !== undefined) return cached;
@@ -33,7 +28,6 @@ export const createKeys = () => {
33
28
  return names;
34
29
  };
35
30
 
36
- // `operators` replaces applied symbols, for definitions whose parameters are operators.
37
31
  const getKey = (formula: Term, env: Env, depth: number, operators?: Operators): string => {
38
32
  for (const name of getFreeNames(formula))
39
33
  if (env.has(name) || operators?.has(name) === true)
@@ -107,7 +101,6 @@ export const createKeys = () => {
107
101
  const getTopKey = (formula: Term) => {
108
102
  const cached = topKeys.get(formula);
109
103
  if (cached !== undefined) return cached;
110
- // Keys count binders from the variable, so a formula's key doesn't depend on where it sits.
111
104
  const key = getEnvKey(formula, new Map(), 0);
112
105
  topKeys.set(formula, key);
113
106
  return key;
@@ -1,5 +1,3 @@
1
- // The checks of Zenon's rules for connectives, quantifiers and the cut.
2
-
3
1
  import type { PlainRuleName } from "../proof";
4
2
  import {
5
3
  and,
@@ -39,7 +37,6 @@ const getDisjuncts = (formula: Term): Term[] => {
39
37
  return [formula];
40
38
  };
41
39
 
42
- // The witness of an existential: Hilbert's epsilon of its body.
43
40
  const getWitness = (exists: Term) => instantiate(exists, term("tau", exists.symbol, exists.args));
44
41
 
45
42
  export const PROPOSITIONAL_RULES = {
@@ -1,6 +1,3 @@
1
- // The checks of the TLA+ extension's rules for tuples and records, after the lemmas in Zenon.thy
2
- // that justify them.
3
-
4
1
  import type { PlainRuleName } from "../proof";
5
2
  import {
6
3
  app,
@@ -21,7 +18,6 @@ import {
21
18
  type Term,
22
19
  } from "./terms";
23
20
 
24
- // The fields of a record or a set of records, whose labels must be distinct string literals.
25
21
  export const getFields = (record: Term, constructor: "TLA.record" | "TLA.recordset") => {
26
22
  const fields = getPairs(expectApp(record, constructor));
27
23
  const labels = fields.map((field) => getStringText(field[0]));
@@ -49,7 +45,6 @@ const getRecordInequalitySpec = (formula: Term, isRecordRight: boolean): RuleSpe
49
45
  };
50
46
  };
51
47
 
52
- // Checks that the formulas list exactly the expected ones, and returns them as branches.
53
48
  const expectSameSet = (checker: Checker, given: Term[], expected: Term[]) => {
54
49
  const keys = new Set(expected.map(checker.getTopKey));
55
50
  ensure(
@@ -1,25 +1,13 @@
1
- // Whether the hypotheses make a relation reflexive, symmetric or transitive, which Zenon's rules for
2
- // relations other than = rely on. The property holds when no way for the relation to hold among
3
- // three elements satisfies the ground instances of the hypotheses and breaks the property.
4
-
5
1
  import type { CheckContext, RelationProperty, Term } from "./terms";
6
2
 
7
3
  type Polarity = "positive" | "negative" | "both";
8
4
 
9
- // A hypothesis as a test on how a relation holds among three elements: `values` gives the bound
10
- // variables their elements and bit 3 * i + j of `holds` says whether the relation holds from
11
- // element i to element j.
12
5
  type GroundTest = (values: number[], holds: number) => boolean;
13
6
 
14
7
  const ELEMENTS = [0, 1, 2];
15
8
 
16
- // The type Zenon gives a variable that its binder leaves untyped, which ranges over everything.
17
9
  const UNTYPED = "zenon_U";
18
10
 
19
- // The ground instances of a hypothesis over three elements. A universal quantifier where the
20
- // hypothesis asserts it, or an existential where it denies it, becomes a test over the three
21
- // elements, which the hypothesis implies. Undefined when the hypothesis says anything but how the
22
- // relation holds between bound variables, so that it's left out.
23
11
  const getGroundTest = (
24
12
  formula: Term,
25
13
  symbol: string,
@@ -92,7 +80,6 @@ const getGroundTest = (
92
80
  }
93
81
  };
94
82
 
95
- // = has every property. Another relation has the ones the hypotheses give it.
96
83
  export const createRelationProperties = (context: CheckContext) => {
97
84
  const cache = new Map<string, boolean>();
98
85
  const hasProperty = (symbol: string, property: RelationProperty) => {
@@ -1,7 +1,3 @@
1
- // The checks of the TLA+ extension's rules that rewrite a subterm in place: evaluating a function
2
- // application, DOMAIN, IF, CASE, Len, or a formula used as a term. Each rule names the context of
3
- // the subterm as a lambda, (\x. context).
4
-
5
1
  import type { PlainRuleName } from "../proof";
6
2
  import { getFields } from "./records";
7
3
  import {
@@ -28,7 +24,6 @@ import {
28
24
  type Term,
29
25
  } from "./terms";
30
26
 
31
- // The term that fills the hole of a context to give a formula.
32
27
  const getFilled = (lambda: Term, formula: Term) => {
33
28
  ensure(lambda.kind === "lam");
34
29
  const hole = lambda.args[0].symbol;
@@ -68,7 +63,6 @@ const getCaseBranches = (lambda: Term, args: Term[], condition: Term): Term[][]
68
63
  ];
69
64
  };
70
65
 
71
- // A formula used as a term splits into the cases where it equals TRUE and FALSE.
72
66
  const getBoolCaseSpec = (
73
67
  checker: Checker,
74
68
  args: Term[],
@@ -1,6 +1,3 @@
1
- // The checks of the TLA+ extension's rules for set membership, set equality and subsets, after the
2
- // lemmas in Zenon.thy that justify them.
3
-
4
1
  import type { PlainRuleName } from "../proof";
5
2
  import {
6
3
  and,
@@ -1,14 +1,9 @@
1
- // What the rule checks share: the formulas they build and take apart, and how a check rejects a
2
- // proof.
3
-
4
1
  import type { ExprKind } from "../expr";
5
2
  import type { Definition } from "../parse";
6
3
  import type { PlainRuleName, RuleArgs } from "../proof";
7
4
 
8
5
  type TermKind = ExprKind | "subst";
9
6
 
10
- // A formula as the checker sees it. The prover's expressions fit this shape. "subst" stands for
11
- // its first argument with the variable named `symbol` replaced by its second argument.
12
7
  export interface Term {
13
8
  kind: TermKind;
14
9
  symbol: string;
@@ -20,7 +15,6 @@ export interface CheckContext {
20
15
  definitions: Definition[];
21
16
  }
22
17
 
23
- // What a rule needs on its branch: its premises, and the formulas each of its branches adds.
24
18
  export interface RuleSpec {
25
19
  premises: Term[];
26
20
  branches: Term[][];
@@ -28,34 +22,25 @@ export interface RuleSpec {
28
22
 
29
23
  export type RelationProperty = "reflexive" | "symmetric" | "transitive";
30
24
 
31
- // What a variable stands for while printing a key: the depth of its binder, or a term substituted
32
- // for it with the environment where the substitution was made. A substituted term prints where it
33
- // lands, so its own binders get depths below the binders around it.
34
25
  export type Binding = number | { formula: Term; env: Env; operators?: Operators };
35
26
 
36
27
  export type Env = Map<string, Binding>;
37
28
 
38
29
  export type Operators = Map<string, Term>;
39
30
 
40
- // One check of a proof, with the caches that last as long as it does.
41
31
  export interface Checker {
42
32
  context: CheckContext;
43
- // A canonical text for a formula up to the names of bound variables.
44
33
  getKey: (formula: Term, env: Env, depth: number, operators?: Operators) => string;
45
34
  getTopKey: (formula: Term) => string;
46
35
  isSame: (left: Term, right: Term) => boolean;
47
- // A binder whose variable can't clash with any name in the input.
48
36
  bind: (kind: "all" | "ex", type: string, build: (bound: Term) => Term) => Term;
49
- // Rejects the proof unless the hypotheses give the relation these properties.
50
37
  ensureRelation: (symbol: string, properties: RelationProperty[]) => void;
51
38
  }
52
39
 
53
- // The check of each rule, given the rule's arguments and the formulas the proof says it uses.
54
40
  export type SpecTable<Name extends PlainRuleName> = {
55
41
  [Key in Name]: (args: RuleArgs<Key, Term>, checker: Checker, uses: Term[]) => RuleSpec;
56
42
  };
57
43
 
58
- // Raised inside a rule check to reject the proof.
59
44
  export class UncheckedError extends Error {}
60
45
 
61
46
  export const ensure: (condition: boolean) => asserts condition = (condition) => {
@@ -81,7 +66,6 @@ export const domain = (fcn: Term) => app("TLA.DOMAIN", [fcn]);
81
66
  export const TRUE = term("true", "", []);
82
67
  export const FALSE = term("false", "", []);
83
68
 
84
- // Instantiates the body of a binder with a term.
85
69
  export const instantiate = (binder: Term, value: Term) =>
86
70
  term("subst", binder.args[0].symbol, [binder.args[1], value]);
87
71
 
@@ -105,7 +89,6 @@ export const expectNot = (formula: Term) => expectKind(formula, "not")[0];
105
89
  export const isVariable = (formula: Term, name: string) =>
106
90
  formula.kind === "var" && formula.symbol === name;
107
91
 
108
- // The text of a string literal. Escapes could spell one string two ways, so they don't count.
109
92
  export const getStringText = (formula: Term) => {
110
93
  ensure(isApp(formula, "$string", 1) && formula.args[0].kind === "var");
111
94
  const text = formula.args[0].symbol;
@@ -1,6 +1,3 @@
1
- // The checks of the TLA+ extension's rules for booleans, CHOOSE, natural numbers, bounded
2
- // quantifiers and equal propositions, after the lemmas in Zenon.thy that justify them.
3
-
4
1
  import type { PlainRuleName } from "../proof";
5
2
  import {
6
3
  ensure,
@@ -18,8 +15,6 @@ import {
18
15
  type Term,
19
16
  } from "./terms";
20
17
 
21
- // From P and a = b, or ~P and a = b, where P is one side: P differs from that side, or the other
22
- // side holds.
23
18
  const getPropositionEqualitySpec = (
24
19
  args: Term[],
25
20
  isNegated: boolean,
@@ -77,7 +72,6 @@ export const TLA_RULES = {
77
72
  );
78
73
  return { premises: [args[0]], branches: [[differ]] };
79
74
  },
80
- // Zenon writes ~(P <=> Q) as $notequiv(P, Q).
81
75
  notequivdef: (_args, _checker, uses) => {
82
76
  ensure(uses.length === 1);
83
77
  const sides = expectApp(uses[0], "$notequiv", 2);
@@ -1,8 +1,4 @@
1
1
  // Ported from Zenon's main.ml, as shipped in tlapm. Copyright 1997 INRIA, see LICENSE.
2
- //
3
- // Runs Zenon on a .znn file as tlapm does, with -oisar. A proof counts only once the independent
4
- // checker accepts it. tlapm passes -max-time 1d and kills Zenon at its own timeout instead, whether
5
- // Zenon is still reading, searching or printing the proof.
6
2
 
7
3
  import { TlaZenonError } from "../../errors";
8
4
  import type { DecideOptions } from "../verdict";
@@ -20,11 +16,7 @@ import { getBuiltInDefinitions, PREDEFINED_SYMBOLS } from "./tla/tla";
20
16
 
21
17
  interface ZenonRun {
22
18
  proof: Proof | undefined;
23
- // Why Zenon gave up: in the search, or at the limits while it checked or printed the proof.
24
- // "zenon error" stands for the exceptions that stop Zenon mid-search.
25
19
  failure: SearchFailure | "zenon error" | undefined;
26
- // Zenon's -oisar output, once the checker accepts the proof and the printer ends within the
27
- // limits.
28
20
  isar: string | undefined;
29
21
  nodesSearched: number;
30
22
  maxBranchFormulas: number;
@@ -32,8 +24,6 @@ interface ZenonRun {
32
24
  formulasCreated: number;
33
25
  }
34
26
 
35
- // The search and its statistics, which match the -stats output of the OCaml Zenon. Throws
36
- // TlaZenonError when the text isn't a valid .znn file.
37
27
  export const runZenon = (text: string, options: DecideOptions): ZenonRun => {
38
28
  const limits = { deadline: Date.now() + options.timeLimitMs, signal: options.signal };
39
29
  const exprs = createExpressions();
@@ -99,8 +89,6 @@ export const runZenon = (text: string, options: DecideOptions): ZenonRun => {
99
89
 
100
90
  type ZenonDecision = { verdict: "unsat"; proof: string } | { verdict: "unknown" };
101
91
 
102
- // Zenon's verdict on a .znn file: "unsat" with the Isar proof that tlapm writes, when Zenon refutes
103
- // the hypotheses with a proof that the checker accepts and prints it within the time limit.
104
92
  export const decideZenon = (text: string, options: DecideOptions): ZenonDecision => {
105
93
  const isar = runZenon(text, options).isar;
106
94
  return isar === undefined ? { verdict: "unknown" } : { verdict: "unsat", proof: isar };
@@ -1,5 +1,4 @@
1
- // A port of tlapm's Backend.Zenon: an obligation as the input of Zenon's TLA+ front end, a $hyp for
2
- // each visible fact and a $goal, naming identifiers as Isabelle does.
1
+ // A port of tlapm's Backend.Zenon.
3
2
 
4
3
  import { TlapmBugError, TlaProverError, TlaUnsupportedError } from "../../errors";
5
4
  import { createContext, getBoundName, popNames, pushName } from "../../obligations/printer";
@@ -74,9 +73,6 @@ const getSuccessors = (integer: string) => {
74
73
  return `${"(TLA.fapply TLA.Succ ".repeat(count)}0${")".repeat(count)}`;
75
74
  };
76
75
 
77
- // pp_print_obligation: the text tlapm writes to the .znn file it hands Zenon, for an obligation
78
- // that Backend.Prep has shipped. Unsupported in the goal fails the obligation and in a fact omits
79
- // it.
80
76
  export const encodeZenon = (id: number, sequent: Sequent) => {
81
77
  const context = createContext();
82
78
  const adjoin = (name: string) => pushName(context, pickle(name));
@@ -85,7 +81,6 @@ export const encodeZenon = (id: number, sequent: Sequent) => {
85
81
  const delimited = (args: Expr[]) => formatDelimited(args, printExpr, SPACE);
86
82
  const nonatomic = (name: string, args: Expr[]) => format("(%s %a)", name, delimited(args));
87
83
 
88
- // A binder's name binds in the body, and what comes before prints outside it.
89
84
  const printBinder = (name: string, before: Doc, body: Expr) => {
90
85
  const bound = adjoin(name);
91
86
  const doc = format("%a((%s) %a))", before, bound, printExpr(body));
@@ -163,7 +158,6 @@ export const encodeZenon = (id: number, sequent: Sequent) => {
163
158
  );
164
159
  };
165
160
 
166
- // SetOf and Fcn take one bound, whose domain prints outside it.
167
161
  const printOneBound = (name: string, bounds: Bound[], body: Expr, what: string) => {
168
162
  if (bounds.length !== 1) throw new TlaUnsupportedError(`${what} (multiple declared constants)`);
169
163
  const bound = bounds[0];
@@ -175,7 +169,6 @@ export const encodeZenon = (id: number, sequent: Sequent) => {
175
169
  );
176
170
  };
177
171
 
178
- // A sequent inside an expression, as an implication under quantifiers.
179
172
  const printNestedSequent = (sequent: Sequent): Doc => {
180
173
  if (sequent.context.length === 0) return printExpr(sequent.active);
181
174
  const hyp = sequent.context[0];
@@ -1,15 +1,9 @@
1
1
  // Ported from Zenon's eqrel.ml, as shipped in tlapm. Copyright 2004 INRIA, see LICENSE.
2
- //
3
- // Finds the hypotheses that make a relation reflexive, symmetric or transitive. The prover then
4
- // reasons with those properties directly, and drops the hypotheses that only state them. The
5
- // translation to Isar proves the properties again from the hypotheses that stated them.
6
2
 
7
3
  import { TRUE, type Expr, type Expressions } from "./expr";
8
4
 
9
5
  export type Direction = "left" | "right";
10
6
 
11
- // Where a hypothesis states a property: the conjunct at `directions`, with the relation's
12
- // arguments bound by the quantifiers at `variables`, counted from the outermost.
13
7
  export interface Origin {
14
8
  formula: Expr;
15
9
  directions: Direction[];
@@ -21,7 +15,6 @@ interface RelationInfo {
21
15
  symmetric: Origin | undefined;
22
16
  transitive: Origin | undefined;
23
17
  transitiveSymmetric: Origin | undefined;
24
- // The type of the relation's arguments.
25
18
  type: string;
26
19
  }
27
20
 
@@ -30,8 +23,6 @@ interface Bound {
30
23
  type: string;
31
24
  }
32
25
 
33
- // A conjunct of a hypothesis: the variables quantified around it and the literals of its
34
- // disjunction, when they all relate two of those variables by the same symbol.
35
26
  interface Leaves {
36
27
  directions: Direction[];
37
28
  env: Bound[];
@@ -125,7 +116,6 @@ const getPair = (leaf: Expr) => {
125
116
  return [args[0].symbol, args[1].symbol];
126
117
  };
127
118
 
128
- // The leaves as Zenon's partition returns them: positive and negative, each reversed.
129
119
  const partition = (leaves: Expr[]) => ({
130
120
  positive: leaves
131
121
  .filter((leaf) => leaf.kind !== "not")
@@ -137,8 +127,6 @@ const partition = (leaves: Expr[]) => ({
137
127
  .map(getPair),
138
128
  });
139
129
 
140
- // Each check returns the variables that the translation instantiates to prove the property, or
141
- // undefined when the conjunct doesn't state it.
142
130
  const getReflexive = (leaves: Expr[]) => {
143
131
  if (leaves.length !== 1 || leaves[0].kind === "not") return undefined;
144
132
  const pair = getPair(leaves[0]);
@@ -292,7 +280,6 @@ export const createRelations = (exprs: Expressions) => {
292
280
  record.transitive !== undefined)
293
281
  );
294
282
  },
295
- // Where the hypotheses state a relation's properties, for the translation to Isar.
296
283
  get,
297
284
  };
298
285
  };
@@ -1,7 +1,4 @@
1
1
  // Ported from Zenon's prove.ml, as shipped in tlapm. Copyright 2002 INRIA, see LICENSE.
2
- //
3
- // The rules for equality and other relations: instances that unify a metavariable, matching a
4
- // literal against its negation, congruence, reflexivity, symmetry and transitivity.
5
2
 
6
3
  import { TlaZenonError } from "../../errors";
7
4
  import {
@@ -50,7 +47,6 @@ const makeInstance = (
50
47
  ]),
51
48
  );
52
49
  }
53
- // Zenon hands applications to the extension named by the symbol's prefix, and tla has none.
54
50
  if (quantified.kind === "app") return queue;
55
51
  throw new TlaZenonError("Zenon: make_inst on a formula that isn't quantified");
56
52
  };
@@ -1,13 +1,8 @@
1
1
  // Ported from Zenon's expr.ml, as shipped in tlapm. Copyright 2002 INRIA, see LICENSE.
2
- //
3
- // Formulas and terms, hash-consed so that equal expressions are the same object. Like Zenon,
4
- // equality treats bound variables up to renaming, and a hash ignores the names of bound variables.
5
- // Each run builds its expressions in its own store, so that fresh names and hashes start over.
6
2
 
7
3
  import { TlaZenonError } from "../../errors";
8
4
  import { combine, createHasher, toInt63, type Int63 } from "./ocaml";
9
5
 
10
- // What every expression caches about itself.
11
6
  interface ExprData {
12
7
  id: number;
13
8
  hash: number;
@@ -24,7 +19,6 @@ export interface VarExpr extends ExprData {
24
19
  args: [];
25
20
  }
26
21
 
27
- // A metavariable stands for a term that instantiates its quantifier.
28
22
  export interface MetaExpr extends ExprData {
29
23
  kind: "meta";
30
24
  symbol: "";
@@ -55,7 +49,6 @@ export interface ConstantExpr extends ExprData {
55
49
  args: [];
56
50
  }
57
51
 
58
- // `symbol` is the type of the bound variable.
59
52
  export interface BinderExpr extends ExprData {
60
53
  kind: "all" | "ex" | "tau" | "lam";
61
54
  symbol: string;
@@ -66,7 +59,6 @@ export type Expr = VarExpr | MetaExpr | AppExpr | NotExpr | BinaryExpr | Constan
66
59
 
67
60
  export type ExprKind = Expr["kind"];
68
61
 
69
- // An application to two arguments, such as an equality or another relation between two terms.
70
62
  export type RelationExpr = AppExpr & { args: [Expr, Expr] };
71
63
 
72
64
  export type NegatedRelationExpr = NotExpr & { args: [RelationExpr] };
@@ -121,8 +113,6 @@ const isBinder = (expression: Expr): expression is BinderExpr =>
121
113
  expression.kind === "tau" ||
122
114
  expression.kind === "lam";
123
115
 
124
- // Zenon's str_union: the names of the first list missing from the second, in reverse, then the
125
- // second. Hashes depend on this order.
126
116
  const unionNames = (left: string[], right: string[]) => {
127
117
  if (left.length === 0) return right;
128
118
  if (right.length === 0) return left;
@@ -139,7 +129,6 @@ const removeName = (name: string, names: string[]) => {
139
129
  export const difference = (left: Expr[], right: Expr[]) =>
140
130
  left.filter((inner) => !right.includes(inner));
141
131
 
142
- // Zenon's union on small sets: the first list's new elements in reverse, then the second list.
143
132
  export const union = (left: Expr[], right: Expr[]) => {
144
133
  const added = difference(left, right);
145
134
  return added.length === 0 ? right : [...added.reverse(), ...right];
@@ -212,7 +201,6 @@ const isEqualBody = (leftVar: Expr, rightVar: Expr, left: Expr, right: Expr) =>
212
201
  );
213
202
  };
214
203
 
215
- // Zenon's HashedExpr.equal on two binders whose children are already hash-consed.
216
204
  const isSameBinder = (left: BinderExpr, right: BinderExpr) =>
217
205
  left.kind === right.kind &&
218
206
  left.symbol === right.symbol &&
@@ -220,8 +208,6 @@ const isSameBinder = (left: BinderExpr, right: BinderExpr) =>
220
208
  ? left.args[1] === right.args[1]
221
209
  : isEqualBody(left.args[0], right.args[0], left.args[1], right.args[1]));
222
210
 
223
- // The symbol is part of the narrowed type, so a failed test for one symbol keeps the expression an
224
- // application for the next test.
225
211
  export const isApp = <Symbol extends string>(
226
212
  expression: Expr,
227
213
  symbol: Symbol,
@@ -239,7 +225,6 @@ export const isRelation = (expression: Expr): expression is RelationExpr =>
239
225
  export const isNegatedRelation = (expression: Expr): expression is NegatedRelationExpr =>
240
226
  expression.kind === "not" && isRelation(expression.args[0]);
241
227
 
242
- // Zenon orders by hash, and only breaks ties structurally.
243
228
  export const compareExprs = (left: Expr, right: Expr): number => {
244
229
  if (left.hash !== right.hash) return left.hash < right.hash ? -1 : 1;
245
230
  if (left === right) return 0;
@@ -263,20 +248,14 @@ const isIrrelevant = (names: string[], map: Substitution) =>
263
248
  const hasConflict = (variable: Expr, map: Substitution) =>
264
249
  map.some((pair) => pair[1].freeVars.includes(variable.symbol));
265
250
 
266
- // The store of one run's expressions, and the operations that build expressions in it.
267
251
  export const createExpressions = () => {
268
252
  const hasher = createHasher();
269
- // Binders are hash-consed by hash, since they're equal up to the names of their variables. Other
270
- // expressions are equal exactly when their kind, symbol and children are, so they're found by
271
- // those before their hash is computed.
272
253
  const binders = new Map<number, BinderExpr[]>();
273
254
  const interned = new Map<number, Expr[]>();
274
- // Numbers for the symbols, so an expression hashes by its symbol and children without strings.
275
255
  const symbolIds = new Map<string, number>();
276
256
  let nextId = FALSE.id + 1;
277
257
  let createdCount = 0;
278
- // Zenon's Ext_focal takes the first five fresh names when the program starts, for its built-in
279
- // definitions, so the first name Zenon gives out is zenon_Vf.
258
+ // Zenon's Ext_focal takes the first five fresh names at startup, so the first name Zenon gives out is zenon_Vf.
280
259
  let nameCounter = "e";
281
260
 
282
261
  const create = <Shape extends Pick<Expr, "kind" | "symbol" | "args">>(
@@ -437,8 +416,6 @@ export const createExpressions = () => {
437
416
  return evar(VAR_PREFIX + nameCounter);
438
417
  };
439
418
 
440
- // A binder's variable for a substitution, renamed when the substituted values capture it, and
441
- // the substitution to apply to its body.
442
419
  const enterBinder = (expression: BinderExpr, map: Substitution): [VarExpr, Substitution] => {
443
420
  const variable = expression.args[0];
444
421
  const rest = map.filter((pair) => pair[0] !== variable);
@@ -486,8 +463,6 @@ export const createExpressions = () => {
486
463
  return results;
487
464
  };
488
465
 
489
- // Zenon's substitute_2nd: also replaces applied symbols bound in the map, for definitions with
490
- // operator parameters. Undefined stands for Zenon's Higher_order exception.
491
466
  const substituteSecondOrder = (map: Substitution, expression: Expr): Expr | undefined => {
492
467
  switch (expression.kind) {
493
468
  case "var":