tla-ts 0.0.9 → 0.0.10-dev.63a6693bd

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (400) 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 +29 -29
  5. package/dist/deciders.js +42 -42
  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 +117 -37
  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 +48 -62
  26. package/src/bags.ts +99 -102
  27. package/src/builtins.ts +28 -75
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check-failure.ts +116 -0
  30. package/src/check-trace.ts +282 -0
  31. package/src/check.ts +599 -754
  32. package/src/cli/options.ts +12 -32
  33. package/src/cli/run.ts +0 -2
  34. package/src/cli/runtime-invariants.ts +136 -0
  35. package/src/cli/shared.ts +19 -12
  36. package/src/cli/tlapm.ts +14 -25
  37. package/src/cli/tlc-arguments.ts +652 -0
  38. package/src/cli/tlc-output.ts +687 -0
  39. package/src/cli/tlc-usage.ts +361 -0
  40. package/src/cli/tlc.ts +309 -658
  41. package/src/cli/typescript.ts +23 -0
  42. package/src/cli/xml-exporter.ts +27 -49
  43. package/src/cli.ts +0 -1
  44. package/src/codegen.ts +196 -74
  45. package/src/config.ts +140 -109
  46. package/src/coverage.ts +830 -0
  47. package/src/dependencies.ts +14 -53
  48. package/src/dfid.ts +618 -0
  49. package/src/environment-config.ts +315 -0
  50. package/src/environment.ts +169 -335
  51. package/src/errors.ts +71 -55
  52. package/src/evaluate.ts +598 -340
  53. package/src/exit-codes.ts +37 -3
  54. package/src/fingerprints.ts +75 -11
  55. package/src/index.ts +3 -0
  56. package/src/instances.ts +126 -21
  57. package/src/java-hash.ts +7 -0
  58. package/src/java-overrides.ts +4 -19
  59. package/src/json-reader.ts +455 -0
  60. package/src/json.ts +252 -139
  61. package/src/levels.ts +46 -58
  62. package/src/lexer.ts +80 -100
  63. package/src/liveness-checker.ts +103 -153
  64. package/src/liveness.ts +150 -109
  65. package/src/obligations/action.ts +8 -39
  66. package/src/obligations/anonymize.ts +88 -82
  67. package/src/obligations/equality.ts +1 -1
  68. package/src/obligations/expression.ts +20 -21
  69. package/src/obligations/format.ts +1 -9
  70. package/src/obligations/generate.ts +46 -49
  71. package/src/obligations/index.ts +2 -13
  72. package/src/obligations/levels.ts +4 -8
  73. package/src/obligations/module.ts +28 -53
  74. package/src/obligations/normalize.ts +7 -25
  75. package/src/obligations/operators.ts +1 -2
  76. package/src/obligations/pragma.ts +1 -10
  77. package/src/obligations/printer.ts +47 -46
  78. package/src/obligations/proof.ts +1 -5
  79. package/src/obligations/regroup.ts +1 -4
  80. package/src/obligations/simplify.ts +42 -58
  81. package/src/obligations/source.ts +48 -78
  82. package/src/obligations/subexpression.ts +5 -11
  83. package/src/obligations/substitution.ts +1 -3
  84. package/src/obligations/temporal.ts +13 -19
  85. package/src/obligations/tuples.ts +3 -9
  86. package/src/parallel-worker.ts +30 -60
  87. package/src/parallel.ts +57 -71
  88. package/src/parser.ts +584 -316
  89. package/src/pcal/ast.ts +53 -86
  90. package/src/pcal/parse.ts +144 -219
  91. package/src/pcal/tokenize.ts +91 -131
  92. package/src/pcal/translate.ts +83 -130
  93. package/src/pcal/validate.ts +48 -68
  94. package/src/pretty-print.ts +7 -8
  95. package/src/prover/decide-pool.ts +8 -13
  96. package/src/prover/deciders.ts +3 -7
  97. package/src/prover/first-order.ts +0 -11
  98. package/src/prover/isabelle/decide.ts +0 -6
  99. package/src/prover/isabelle/encode.ts +11 -23
  100. package/src/prover/isabelle/isar/inner-syntax.ts +114 -115
  101. package/src/prover/isabelle/isar/method.ts +29 -53
  102. package/src/prover/isabelle/isar/proof.ts +1 -10
  103. package/src/prover/isabelle/isar/statement.ts +1 -6
  104. package/src/prover/isabelle/isar/theory.ts +26 -36
  105. package/src/prover/isabelle/isar/type-check.ts +17 -31
  106. package/src/prover/isabelle/provers/blast/blast.ts +17 -104
  107. package/src/prover/isabelle/provers/blast/branch.ts +1 -32
  108. package/src/prover/isabelle/provers/blast/prove.ts +1 -35
  109. package/src/prover/isabelle/provers/blast/rules.ts +6 -44
  110. package/src/prover/isabelle/provers/blast/state.ts +2 -28
  111. package/src/prover/isabelle/provers/blast/term.ts +9 -36
  112. package/src/prover/isabelle/provers/clasimp.ts +1 -13
  113. package/src/prover/isabelle/provers/classical.ts +14 -42
  114. package/src/prover/isabelle/provers/hypsubst.ts +28 -51
  115. package/src/prover/isabelle/pure/bicompose.ts +25 -38
  116. package/src/prover/isabelle/pure/consts.ts +1 -7
  117. package/src/prover/isabelle/pure/conv.ts +3 -17
  118. package/src/prover/isabelle/pure/drule.ts +33 -42
  119. package/src/prover/isabelle/pure/envir.ts +3 -52
  120. package/src/prover/isabelle/pure/goal.ts +1 -7
  121. package/src/prover/isabelle/pure/interrupt.ts +0 -5
  122. package/src/prover/isabelle/pure/list.ts +0 -3
  123. package/src/prover/isabelle/pure/logic.ts +2 -15
  124. package/src/prover/isabelle/pure/name.ts +2 -9
  125. package/src/prover/isabelle/pure/net.ts +3 -59
  126. package/src/prover/isabelle/pure/object-logic.ts +3 -10
  127. package/src/prover/isabelle/pure/pattern.ts +2 -19
  128. package/src/prover/isabelle/pure/raw-simplifier.ts +17 -62
  129. package/src/prover/isabelle/pure/rewriter.ts +31 -67
  130. package/src/prover/isabelle/pure/search.ts +3 -10
  131. package/src/prover/isabelle/pure/seq.ts +1 -10
  132. package/src/prover/isabelle/pure/simplifier.ts +4 -12
  133. package/src/prover/isabelle/pure/table.ts +3 -32
  134. package/src/prover/isabelle/pure/tactic.ts +12 -22
  135. package/src/prover/isabelle/pure/tactical.ts +48 -47
  136. package/src/prover/isabelle/pure/term-ord.ts +2 -6
  137. package/src/prover/isabelle/pure/term.ts +2 -43
  138. package/src/prover/isabelle/pure/thm.ts +27 -47
  139. package/src/prover/isabelle/pure/type.ts +2 -15
  140. package/src/prover/isabelle/pure/unify.ts +20 -30
  141. package/src/prover/isabelle/pure/variable.ts +3 -7
  142. package/src/prover/isabelle/tla/classical-setup.ts +17 -24
  143. package/src/prover/isabelle/tla/context.ts +15 -18
  144. package/src/prover/isabelle/tla/logic.ts +14 -32
  145. package/src/prover/isabelle/tla/simpdata.ts +46 -43
  146. package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
  147. package/src/prover/ocaml.ts +0 -6
  148. package/src/prover/prep/action.ts +14 -54
  149. package/src/prover/prep/enabled-axioms.ts +12 -19
  150. package/src/prover/prep/fingerprint.ts +2 -21
  151. package/src/prover/prep/level-comparison.ts +8 -12
  152. package/src/prover/prep/md5.ts +0 -2
  153. package/src/prover/prep/methods.ts +33 -39
  154. package/src/prover/prep/normalize.ts +4 -28
  155. package/src/prover/prove-worker.ts +0 -2
  156. package/src/prover/prove.ts +87 -100
  157. package/src/prover/ptl/decide.ts +7 -12
  158. package/src/prover/ptl/encode.ts +14 -36
  159. package/src/prover/ptl/sat.ts +24 -32
  160. package/src/prover/ptl/tableau.ts +12 -26
  161. package/src/prover/smt/axioms.ts +0 -7
  162. package/src/prover/smt/context.ts +20 -28
  163. package/src/prover/smt/data.ts +433 -424
  164. package/src/prover/smt/encode.ts +43 -52
  165. package/src/prover/smt/extensionality.ts +0 -10
  166. package/src/prover/smt/flatten.ts +3 -22
  167. package/src/prover/smt/format.ts +5 -10
  168. package/src/prover/smt/instances.ts +0 -10
  169. package/src/prover/smt/rewrite.ts +663 -667
  170. package/src/prover/smt/solver/act-cache.ts +0 -15
  171. package/src/prover/smt/solver/arith-rewriter.ts +3 -48
  172. package/src/prover/smt/solver/array.ts +1 -3
  173. package/src/prover/smt/solver/asserted-formulas.ts +1 -43
  174. package/src/prover/smt/solver/ast-lt.ts +1 -11
  175. package/src/prover/smt/solver/ast-util.ts +1 -6
  176. package/src/prover/smt/solver/ast.ts +1 -165
  177. package/src/prover/smt/solver/auf-solver.ts +8 -44
  178. package/src/prover/smt/solver/case-split-queue.ts +1 -9
  179. package/src/prover/smt/solver/cg-table.ts +1 -18
  180. package/src/prover/smt/solver/clause.ts +1 -27
  181. package/src/prover/smt/solver/conflict-resolution.ts +0 -9
  182. package/src/prover/smt/solver/context.ts +7 -64
  183. package/src/prover/smt/solver/ctx-simplify.ts +14 -41
  184. package/src/prover/smt/solver/der.ts +2 -21
  185. package/src/prover/smt/solver/dyn-ack.ts +1 -11
  186. package/src/prover/smt/solver/e-matching.ts +4 -35
  187. package/src/prover/smt/solver/enode.ts +1 -21
  188. package/src/prover/smt/solver/expr-ref.ts +1 -5
  189. package/src/prover/smt/solver/expr-safe-replace.ts +1 -6
  190. package/src/prover/smt/solver/fingerprints.ts +1 -12
  191. package/src/prover/smt/solver/flat-literals.ts +1 -9
  192. package/src/prover/smt/solver/goal.ts +2 -14
  193. package/src/prover/smt/solver/hash.ts +0 -8
  194. package/src/prover/smt/solver/hashtable.ts +1 -12
  195. package/src/prover/smt/solver/internalizer.ts +7 -100
  196. package/src/prover/smt/solver/lbool.ts +1 -2
  197. package/src/prover/smt/solver/literal.ts +0 -3
  198. package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
  199. package/src/prover/smt/solver/lp/constraints.ts +2 -8
  200. package/src/prover/smt/solver/lp/containers.ts +12 -30
  201. package/src/prover/smt/solver/lp/core-solver.ts +10 -31
  202. package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
  203. package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
  204. package/src/prover/smt/solver/lp/dependency.ts +1 -4
  205. package/src/prover/smt/solver/lp/dioph-eq.ts +9 -102
  206. package/src/prover/smt/solver/lp/explanation.ts +1 -6
  207. package/src/prover/smt/solver/lp/gomory.ts +9 -22
  208. package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
  209. package/src/prover/smt/solver/lp/hnf.ts +11 -26
  210. package/src/prover/smt/solver/lp/int-cube.ts +15 -36
  211. package/src/prover/smt/solver/lp/int-solver.ts +4 -34
  212. package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
  213. package/src/prover/smt/solver/lp/lar-term.ts +1 -5
  214. package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
  215. package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
  216. package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
  217. package/src/prover/smt/solver/lp/nex.ts +1 -6
  218. package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
  219. package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
  220. package/src/prover/smt/solver/lp/nla-core.ts +36 -135
  221. package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
  222. package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
  223. package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
  224. package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
  225. package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
  226. package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
  227. package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
  228. package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
  229. package/src/prover/smt/solver/lp/nla-order.ts +2 -13
  230. package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
  231. package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
  232. package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
  233. package/src/prover/smt/solver/lp/nla-types.ts +1 -11
  234. package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
  235. package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
  236. package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
  237. package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
  238. package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
  239. package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
  240. package/src/prover/smt/solver/lp/pdd.ts +7 -70
  241. package/src/prover/smt/solver/lp/random-updater.ts +1 -8
  242. package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
  243. package/src/prover/smt/solver/lp/union-find.ts +1 -6
  244. package/src/prover/smt/solver/mam-compiler.ts +18 -58
  245. package/src/prover/smt/solver/mam-interpreter.ts +1 -21
  246. package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
  247. package/src/prover/smt/solver/model-checker.ts +3 -37
  248. package/src/prover/smt/solver/model-evaluator.ts +3 -29
  249. package/src/prover/smt/solver/model-finder.ts +15 -32
  250. package/src/prover/smt/solver/model-generator.ts +1 -12
  251. package/src/prover/smt/solver/model-macro-solver.ts +23 -88
  252. package/src/prover/smt/solver/nlsat/algebraic.ts +63 -159
  253. package/src/prover/smt/solver/nlsat/atoms.ts +25 -23
  254. package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
  255. package/src/prover/smt/solver/nlsat/explain.ts +10 -69
  256. package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
  257. package/src/prover/smt/solver/nlsat/levelwise.ts +49 -135
  258. package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
  259. package/src/prover/smt/solver/nlsat/polynomial.ts +29 -159
  260. package/src/prover/smt/solver/nlsat/solver.ts +18 -90
  261. package/src/prover/smt/solver/nlsat/types.ts +1 -8
  262. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +2 -45
  263. package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
  264. package/src/prover/smt/solver/nnf.ts +3 -38
  265. package/src/prover/smt/solver/pattern-inference.ts +2 -15
  266. package/src/prover/smt/solver/poly-rewriter.ts +3 -23
  267. package/src/prover/smt/solver/propagate-values.ts +1 -10
  268. package/src/prover/smt/solver/proto-model.ts +3 -52
  269. package/src/prover/smt/solver/pull-quant.ts +1 -12
  270. package/src/prover/smt/solver/qe-lite-der.ts +1 -29
  271. package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
  272. package/src/prover/smt/solver/qe-lite.ts +3 -33
  273. package/src/prover/smt/solver/qi-queue.ts +1 -16
  274. package/src/prover/smt/solver/quant-tactics.ts +5 -22
  275. package/src/prover/smt/solver/quantifier-analyzer.ts +27 -47
  276. package/src/prover/smt/solver/quantifier-manager.ts +2 -13
  277. package/src/prover/smt/solver/random-gen.ts +1 -2
  278. package/src/prover/smt/solver/rational.ts +1 -8
  279. package/src/prover/smt/solver/ref-vector.ts +1 -6
  280. package/src/prover/smt/solver/relevancy.ts +2 -15
  281. package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
  282. package/src/prover/smt/solver/rewriter.ts +3 -85
  283. package/src/prover/smt/solver/rlimit.ts +2 -20
  284. package/src/prover/smt/solver/smtlib-parser.ts +80 -131
  285. package/src/prover/smt/solver/solver.ts +23 -34
  286. package/src/prover/smt/solver/sort.ts +1 -5
  287. package/src/prover/smt/solver/sticky-generations.ts +0 -5
  288. package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
  289. package/src/prover/smt/solver/theory-lra-bounds.ts +1 -7
  290. package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
  291. package/src/prover/smt/solver/theory-lra-internalize.ts +6 -43
  292. package/src/prover/smt/solver/theory-lra-model.ts +4 -19
  293. package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
  294. package/src/prover/smt/solver/theory-lra-state.ts +3 -8
  295. package/src/prover/smt/solver/theory-lra.ts +1 -8
  296. package/src/prover/smt/solver/var-subst.ts +2 -26
  297. package/src/prover/smt/table.ts +0 -8
  298. package/src/prover/tlapm/cache.ts +45 -40
  299. package/src/prover/tlapm/ocaml-marshal.ts +19 -21
  300. package/src/prover/tlapm/tlapm.ts +21 -20
  301. package/src/prover/verdict.ts +7 -2
  302. package/src/prover/zenon/check/check.ts +1 -11
  303. package/src/prover/zenon/check/definitions.ts +5 -15
  304. package/src/prover/zenon/check/equality.ts +0 -8
  305. package/src/prover/zenon/check/functions.ts +0 -4
  306. package/src/prover/zenon/check/keys.ts +0 -7
  307. package/src/prover/zenon/check/propositional.ts +0 -3
  308. package/src/prover/zenon/check/records.ts +1 -6
  309. package/src/prover/zenon/check/relations.ts +2 -14
  310. package/src/prover/zenon/check/rewrites.ts +2 -21
  311. package/src/prover/zenon/check/sets.ts +40 -61
  312. package/src/prover/zenon/check/terms.ts +1 -19
  313. package/src/prover/zenon/check/tla.ts +0 -6
  314. package/src/prover/zenon/decide.ts +0 -12
  315. package/src/prover/zenon/encode.ts +1 -8
  316. package/src/prover/zenon/eqrel.ts +2 -13
  317. package/src/prover/zenon/equality-rules.ts +0 -4
  318. package/src/prover/zenon/expr.ts +8 -26
  319. package/src/prover/zenon/index-table.ts +26 -57
  320. package/src/prover/zenon/isar-case.ts +9 -19
  321. package/src/prover/zenon/isar.ts +36 -64
  322. package/src/prover/zenon/limits.ts +0 -4
  323. package/src/prover/zenon/llproof.ts +2 -20
  324. package/src/prover/zenon/mltoll.ts +66 -104
  325. package/src/prover/zenon/node.ts +1 -11
  326. package/src/prover/zenon/ocaml.ts +1 -17
  327. package/src/prover/zenon/parse.ts +4 -12
  328. package/src/prover/zenon/phrase.ts +1 -11
  329. package/src/prover/zenon/proof.ts +0 -9
  330. package/src/prover/zenon/propositional-rules.ts +0 -5
  331. package/src/prover/zenon/rules.ts +2 -6
  332. package/src/prover/zenon/search.ts +5 -31
  333. package/src/prover/zenon/tla/functions.ts +59 -31
  334. package/src/prover/zenon/tla/llproof.ts +67 -76
  335. package/src/prover/zenon/tla/records.ts +57 -33
  336. package/src/prover/zenon/tla/rewrites.ts +12 -19
  337. package/src/prover/zenon/tla/sets.ts +83 -53
  338. package/src/prover/zenon/tla/terms.ts +0 -6
  339. package/src/prover/zenon/tla/tla.ts +66 -64
  340. package/src/randomization.ts +81 -35
  341. package/src/resolve.ts +67 -184
  342. package/src/runtime.ts +22 -22
  343. package/src/sany/builtins.ts +2 -5
  344. package/src/sany/generation.ts +394 -0
  345. package/src/sany/generator-def-entries.ts +210 -0
  346. package/src/sany/generator-definitions.ts +686 -0
  347. package/src/sany/generator-expressions.ts +1100 -0
  348. package/src/sany/generator-proofs.ts +662 -0
  349. package/src/sany/generator.ts +191 -2764
  350. package/src/sany/levels.ts +6 -34
  351. package/src/sany/lexer.ts +58 -77
  352. package/src/sany/linter.ts +1 -9
  353. package/src/sany/modules.ts +1 -5
  354. package/src/sany/nodes.ts +5 -43
  355. package/src/sany/parse-error.ts +39 -117
  356. package/src/sany/report.ts +32 -69
  357. package/src/sany/selectors.ts +49 -76
  358. package/src/sany/source.ts +1 -17
  359. package/src/sany/xml.ts +35 -117
  360. package/src/search.ts +541 -163
  361. package/src/simulate.ts +709 -0
  362. package/src/spec-description.ts +192 -100
  363. package/src/standard-definitions.ts +0 -4
  364. package/src/standard-modules.ts +264 -95
  365. package/src/state-graph.ts +52 -31
  366. package/src/subexpressions.ts +69 -52
  367. package/src/substitution-levels.ts +7 -7
  368. package/src/successors.ts +266 -99
  369. package/src/symmetry.ts +33 -25
  370. package/src/tableau.ts +27 -24
  371. package/src/tlc/fingerprint.ts +183 -67
  372. package/src/tlc/jar-data.ts +112 -6
  373. package/src/tlc/messages.ts +125 -54
  374. package/src/tlc/order.ts +39 -69
  375. package/src/tlc/random.ts +37 -49
  376. package/src/tlc/replay.ts +553 -228
  377. package/src/tlc/summary.ts +36 -47
  378. package/src/tlc/tlc-operators.ts +78 -44
  379. package/src/tlc/tlcext-operators.ts +139 -122
  380. package/src/tlc/trace-spec.ts +249 -0
  381. package/src/tlc/value-stream.ts +139 -0
  382. package/src/tlc/version.ts +1 -4
  383. package/src/transfer.ts +22 -25
  384. package/src/typescript/actions.ts +479 -0
  385. package/src/typescript/collections.ts +614 -0
  386. package/src/typescript/compile.ts +63 -0
  387. package/src/typescript/context.ts +94 -0
  388. package/src/typescript/emit.ts +121 -0
  389. package/src/typescript/expressions.ts +496 -0
  390. package/src/typescript/formula.ts +154 -0
  391. package/src/typescript/functions.ts +284 -0
  392. package/src/typescript/model.ts +162 -0
  393. package/src/typescript/names.ts +114 -0
  394. package/src/typescript/program.ts +48 -0
  395. package/src/typescript/properties.ts +139 -0
  396. package/src/typescript/scope.ts +112 -0
  397. package/src/typescript/steps.ts +167 -0
  398. package/src/typescript/types.ts +171 -0
  399. package/src/values.ts +832 -484
  400. package/src/worker.ts +7 -8
@@ -1,9 +1,5 @@
1
- // encode/n_table.ml: the axioms tlapm's SMT encoding can assert, in the order it prints them.
2
-
3
1
  import { compareValues } from "../ocaml";
4
2
 
5
- // The order of tlapm's Table.tla_axm constructors. OCaml compares constant constructors before
6
- // those with arguments, so the axioms of an obligation print in this order.
7
3
  const CONSTANT_AXIOMS = [
8
4
  "ChooseDef",
9
5
  "ChooseExt",
@@ -124,7 +120,6 @@ const BLOCK_AXIOMS = [
124
120
  "AssertIsSetOf",
125
121
  ];
126
122
 
127
- // Table.tla_smb's typed constant constructors, which Typing takes, in order.
128
123
  export const TYPED_SYMBOLS = [
129
124
  "TIntPlus",
130
125
  "TIntUminus",
@@ -137,8 +132,6 @@ export const TYPED_SYMBOLS = [
137
132
 
138
133
  export type AxiomArgument = number | string | string[];
139
134
 
140
- // An axiom without a formula belongs to a second-order symbol. Flattening instantiates it for
141
- // each use of the symbol, and otherwise it isn't printed.
142
135
  export interface Axiom {
143
136
  name: string;
144
137
  args: AxiomArgument[];
@@ -165,6 +158,5 @@ const getAxiomRank = (entry: Axiom) => {
165
158
  return constant === -1 ? CONSTANT_AXIOMS.length + BLOCK_AXIOMS.indexOf(entry.name) : constant;
166
159
  };
167
160
 
168
- // N_axiomatize.TlaAxmSet orders axioms as OCaml's compare does.
169
161
  export const compareAxioms = (left: Axiom, right: Axiom) =>
170
162
  getAxiomRank(left) - getAxiomRank(right) || compareValues(left.args, right.args);
@@ -1,5 +1,3 @@
1
- // tlapm's fingerprints file, ported from src/backend/fpfile.ml.
2
-
3
1
  import {
4
2
  cpSync,
5
3
  existsSync,
@@ -14,18 +12,24 @@ import {
14
12
  import { basename, join } from "node:path";
15
13
  import { version } from "../../../package.json";
16
14
  import { TlaProofError } from "../../errors";
17
- import { block, isBlock, readMarshaled, writeMarshaled, type OcamlValue } from "./ocaml-marshal";
18
- import type { ProofAttempt } from "../prove";
15
+ import {
16
+ createBlock,
17
+ isBlock,
18
+ readMarshaled,
19
+ writeMarshaled,
20
+ type OcamlValue,
21
+ } from "./ocaml-marshal";
22
+ import { getBudget } from "../prep/methods";
23
+ import { getFailureReason, isProvedAttempt, type ProofAttempt } from "../prove";
24
+ import { BACKENDS, type Backend } from "../verdict";
19
25
 
20
- // One optional result per prover, in V13.str's order.
21
26
  export type FingerprintTable = Map<string, OcamlValue[]>;
22
27
 
23
28
  const MAGIC_NUMBER = 20210223;
24
29
 
25
30
  const RECORD_SIZE = 23;
26
31
 
27
- // Each prover's field in V13.str and constructor in V13.meth.
28
- const PROVERS: Record<string, { field: number; tag: number }> = {
32
+ const PROVERS: Record<Backend, { field: number; tag: number }> = {
29
33
  zenon: { field: 1, tag: 1 },
30
34
  isabelle: { field: 2, tag: 0 },
31
35
  smt: { field: 10, tag: 8 },
@@ -37,7 +41,6 @@ const FAIL_METHOD = 5;
37
41
 
38
42
  const REASONS = ["false", "timeout"];
39
43
 
40
- // Stored as the tlapm, Zenon and Isabelle versions, which --safefp compares.
41
44
  const VERSION = `tla-ts ${version}`;
42
45
 
43
46
  const CHECKED_VERSIONS = new Map([
@@ -53,13 +56,12 @@ const getField = (value: OcamlValue | undefined, index: number) =>
53
56
  const getFloat = (value: OcamlValue | undefined) =>
54
57
  value !== undefined && typeof value === "object" && "float" in value ? value.float : Infinity;
55
58
 
56
- // Hashtbl.hash on a string.
57
59
  const hashKey = (key: string) => {
58
60
  const bytes = new TextEncoder().encode(key);
59
61
  const rotate = (value: number, shift: number) => (value << shift) | (value >>> (32 - shift));
60
62
  const mixed = Array.from(
61
63
  { length: Math.ceil(bytes.length / 4) },
62
- (_, index) =>
64
+ (_value, index) =>
63
65
  bytes[index * 4] |
64
66
  (bytes[index * 4 + 1] << 8) |
65
67
  (bytes[index * 4 + 2] << 16) |
@@ -78,7 +80,6 @@ const readBucket = (entry: OcamlValue | undefined): [OcamlValue, OcamlValue][] =
78
80
  ? [[entry.fields[0], entry.fields[1]], ...readBucket(entry.fields[2])]
79
81
  : [];
80
82
 
81
- // Fpfile.load_fingerprints. Each bucket lists the latest fingerprint first.
82
83
  export const loadFingerprints = (table: FingerprintTable, path: string, isSafe: boolean) => {
83
84
  const bytes = readFileSync(path);
84
85
  const magic = readMarshaled(bytes, 0);
@@ -103,7 +104,10 @@ export const loadFingerprints = (table: FingerprintTable, path: string, isSafe:
103
104
  });
104
105
  };
105
106
 
106
- const decodeResult = (prover: string, result: OcamlValue | undefined): ProofAttempt | undefined => {
107
+ const decodeResult = (
108
+ prover: Backend,
109
+ result: OcamlValue | undefined,
110
+ ): ProofAttempt | undefined => {
107
111
  const status = getField(result, 0);
108
112
  const outcome = getField(status, 0);
109
113
  const argument = getField(getField(status, 1), 0);
@@ -112,13 +116,13 @@ const decodeResult = (prover: string, result: OcamlValue | undefined): ProofAtte
112
116
  const tactic = prover === "isabelle" ? getField(argument, 1) : undefined;
113
117
  const reason = getField(getField(outcome, 0), 0);
114
118
  return {
119
+ kind: "stored",
115
120
  method: {
116
121
  prover,
117
122
  timeLimitMs: seconds * 1000,
118
123
  ...(typeof tactic === "string" && { tactic }),
119
124
  },
120
125
  isProved: outcome === 0,
121
- isReused: false,
122
126
  ...(reason !== undefined && {
123
127
  reason: typeof reason === "number" ? REASONS[reason] : String(getField(reason, 0)),
124
128
  }),
@@ -126,31 +130,32 @@ const decodeResult = (prover: string, result: OcamlValue | undefined): ProofAtte
126
130
  };
127
131
 
128
132
  // Fpfile.fp_writes, whose date counts months from 0.
129
- const encodeResult = (attempt: ProofAttempt) => {
133
+ const encodeResult = (prover: Backend, attempt: ProofAttempt) => {
130
134
  const now = new Date();
131
135
  const method = attempt.method;
132
- const timeout = { float: method.rlimit ?? method.timeLimitMs / 1000 };
136
+ const timeout = { float: getBudget(method) };
133
137
  const argument =
134
- method.prover === "zenon"
135
- ? block(0, timeout, FAIL_METHOD)
136
- : method.prover === "isabelle"
137
- ? block(0, block(0, timeout), method.tactic ?? "auto")
138
- : block(0, timeout);
139
- const reasonIndex = REASONS.indexOf(attempt.reason ?? "");
138
+ prover === "zenon"
139
+ ? createBlock(0, timeout, FAIL_METHOD)
140
+ : prover === "isabelle"
141
+ ? createBlock(0, createBlock(0, timeout), method.tactic ?? "auto")
142
+ : createBlock(0, timeout);
143
+ const failure = getFailureReason(attempt);
144
+ const reasonIndex = REASONS.indexOf(failure ?? "");
140
145
  const reason =
141
- attempt.reason === undefined
146
+ failure === undefined
142
147
  ? 0
143
- : block(0, reasonIndex === -1 ? block(0, attempt.reason) : reasonIndex);
144
- return block(
148
+ : createBlock(0, reasonIndex === -1 ? createBlock(0, failure) : reasonIndex);
149
+ return createBlock(
145
150
  0,
146
- block(
151
+ createBlock(
147
152
  0,
148
- block(
153
+ createBlock(
149
154
  0,
150
- attempt.isProved ? 0 : block(0, reason),
151
- block(PROVERS[method.prover].tag, argument),
155
+ isProvedAttempt(attempt) ? 0 : createBlock(0, reason),
156
+ createBlock(PROVERS[prover].tag, argument),
152
157
  ),
153
- block(
158
+ createBlock(
154
159
  0,
155
160
  now.getFullYear(),
156
161
  now.getMonth(),
@@ -171,14 +176,13 @@ const encodeTable = (table: FingerprintTable) => {
171
176
  const buckets: OcamlValue[] = Array.from({ length }, () => 0);
172
177
  table.forEach((record, fingerprint) => {
173
178
  const index = hashKey(fingerprint) & (length - 1);
174
- buckets[index] = block(0, fingerprint, block(0, ...record), buckets[index]);
179
+ buckets[index] = createBlock(0, fingerprint, createBlock(0, ...record), buckets[index]);
175
180
  });
176
- return block(0, block(0, table.size, block(0, ...buckets), 0, 512));
181
+ return createBlock(0, createBlock(0, table.size, createBlock(0, ...buckets), 0, 512));
177
182
  };
178
183
 
179
184
  const pad = (value: number) => String(value).padStart(2, "0");
180
185
 
181
- // Fpfile.fp_init.
182
186
  export const saveHistory = (path: string, sources: string[]) => {
183
187
  const now = new Date();
184
188
  const history = `${path}.history`;
@@ -197,19 +201,17 @@ export const saveHistory = (path: string, sources: string[]) => {
197
201
  .forEach((old) => rmSync(old, { recursive: true, force: true }));
198
202
  };
199
203
 
200
- // Fpfile.query: what each prover concluded for each fingerprint. Saving them, as fp_writes,
201
- // add_to_table and fp_close_and_consolidate do, keeps each record and result loaded unchanged, with
202
- // its date, versions and other provers' results.
203
204
  export const getKnownResults = (table: FingerprintTable) => {
204
205
  const storedResults = new Map<ProofAttempt, OcamlValue>();
205
206
  const storedRecords = new Map<Map<string, ProofAttempt>, OcamlValue[]>();
206
207
  const results = new Map(
207
208
  [...table].map(([fingerprint, record]) => {
208
209
  const attempts = new Map(
209
- Object.entries(PROVERS).flatMap(([prover, known]) => {
210
- const result = decodeResult(prover, getField(record[known.field], 0));
210
+ BACKENDS.flatMap((prover) => {
211
+ const stored = record[PROVERS[prover].field];
212
+ const result = decodeResult(prover, getField(stored, 0));
211
213
  if (!result) return [];
212
- storedResults.set(result, record[known.field]);
214
+ storedResults.set(result, stored);
213
215
  return [[prover, result]];
214
216
  }),
215
217
  );
@@ -221,8 +223,11 @@ export const getKnownResults = (table: FingerprintTable) => {
221
223
  table.clear();
222
224
  results.forEach((attempts, fingerprint) => {
223
225
  const record = [...(storedRecords.get(attempts) ?? Array<OcamlValue>(RECORD_SIZE).fill(0))];
224
- attempts.forEach((attempt, prover) => {
225
- record[PROVERS[prover].field] = storedResults.get(attempt) ?? encodeResult(attempt);
226
+ BACKENDS.forEach((prover) => {
227
+ const attempt = attempts.get(prover);
228
+ if (attempt)
229
+ record[PROVERS[prover].field] =
230
+ storedResults.get(attempt) ?? encodeResult(prover, attempt);
226
231
  });
227
232
  table.set(fingerprint, record);
228
233
  });
@@ -1,6 +1,3 @@
1
- // OCaml's Marshal format, ported from runtime/intern.c and runtime/extern.c, for the values in
2
- // tlapm's fingerprints file. It writes no sharing, which OCaml reads the same.
3
-
4
1
  import { TlaProofError } from "../../errors";
5
2
 
6
3
  interface OcamlBlock {
@@ -33,23 +30,22 @@ const PREFIX = { smallInt: 0x40, smallString: 0x20, smallBlock: 0x80 };
33
30
 
34
31
  const HEADER_SIZE = 20;
35
32
 
36
- export const block = (tag: number, ...fields: OcamlValue[]): OcamlBlock => ({ tag, fields });
33
+ export const createBlock = (tag: number, ...fields: OcamlValue[]): OcamlBlock => ({ tag, fields });
37
34
 
38
35
  export const isBlock = (value: OcamlValue): value is OcamlBlock =>
39
36
  typeof value === "object" && "tag" in value;
40
37
 
41
- // Returns the value marshaled at offset, and where the next one starts.
42
38
  export const readMarshaled = (bytes: Uint8Array, offset: number) => {
43
39
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
44
40
  if (bytes.length < offset + HEADER_SIZE || view.getUint32(offset) !== MAGIC_NUMBER_SMALL)
45
41
  throw new TlaProofError("corrupted fingerprint file");
46
42
  const end = offset + HEADER_SIZE + view.getUint32(offset + 4);
47
43
  const objects: OcamlValue[] = [];
48
- const state = { position: offset + HEADER_SIZE };
44
+ let position = offset + HEADER_SIZE;
49
45
  const take = (length: number) => {
50
- const start = state.position;
51
- state.position += length;
52
- if (state.position > end) throw new TlaProofError("corrupted fingerprint file");
46
+ const start = position;
47
+ position += length;
48
+ if (position > end) throw new TlaProofError("corrupted fingerprint file");
53
49
  return start;
54
50
  };
55
51
  const decoder = new TextDecoder();
@@ -60,7 +56,7 @@ export const readMarshaled = (bytes: Uint8Array, offset: number) => {
60
56
  return value;
61
57
  };
62
58
  const readBlock = (tag: number, size: number): OcamlBlock => {
63
- const value = block(tag);
59
+ const value = createBlock(tag);
64
60
  if (size > 0) objects.push(value);
65
61
  for (let index = 0; index < size; index++) value.fields.push(read());
66
62
  return value;
@@ -105,7 +101,9 @@ export const readMarshaled = (bytes: Uint8Array, offset: number) => {
105
101
 
106
102
  export const writeMarshaled = (value: OcamlValue) => {
107
103
  const bytes: number[] = [];
108
- const sizes = { objects: 0, words32: 0, words64: 0 };
104
+ let objectCount = 0;
105
+ let words32 = 0;
106
+ let words64 = 0;
109
107
  const pushInteger = (integer: number, length: number) => {
110
108
  for (let shift = (length - 1) * 8; shift >= 0; shift -= 8)
111
109
  bytes.push((integer >>> shift) & 0xff);
@@ -122,7 +120,7 @@ export const writeMarshaled = (value: OcamlValue) => {
122
120
  bytes.push(CODE.int32);
123
121
  return pushInteger(inner, 4);
124
122
  }
125
- sizes.objects++;
123
+ objectCount++;
126
124
  if (typeof inner === "string") {
127
125
  const encoded = encoder.encode(inner);
128
126
  if (encoded.length < 0x20) bytes.push(PREFIX.smallString + encoded.length);
@@ -132,23 +130,23 @@ export const writeMarshaled = (value: OcamlValue) => {
132
130
  pushInteger(encoded.length, 4);
133
131
  }
134
132
  bytes.push(...encoded);
135
- sizes.words32 += 1 + Math.floor((encoded.length + 4) / 4);
136
- sizes.words64 += 1 + Math.floor((encoded.length + 8) / 8);
133
+ words32 += 1 + Math.floor((encoded.length + 4) / 4);
134
+ words64 += 1 + Math.floor((encoded.length + 8) / 8);
137
135
  return;
138
136
  }
139
137
  if (!isBlock(inner)) {
140
138
  const float = new DataView(new ArrayBuffer(8));
141
139
  float.setFloat64(0, inner.float, true);
142
140
  bytes.push(CODE.doubleLittle, ...new Uint8Array(float.buffer));
143
- sizes.words32 += 3;
144
- sizes.words64 += 2;
141
+ words32 += 3;
142
+ words64 += 2;
145
143
  return;
146
144
  }
147
145
  const size = inner.fields.length;
148
- if (size === 0) sizes.objects--;
146
+ if (size === 0) objectCount--;
149
147
  else {
150
- sizes.words32 += 1 + size;
151
- sizes.words64 += 1 + size;
148
+ words32 += 1 + size;
149
+ words64 += 1 + size;
152
150
  }
153
151
  if (inner.tag < 16 && size < 8) bytes.push(PREFIX.smallBlock + inner.tag + (size << 4));
154
152
  else {
@@ -159,8 +157,8 @@ export const writeMarshaled = (value: OcamlValue) => {
159
157
  };
160
158
  write(value);
161
159
  const header = new DataView(new ArrayBuffer(HEADER_SIZE));
162
- [MAGIC_NUMBER_SMALL, bytes.length, sizes.objects, sizes.words32, sizes.words64].forEach(
163
- (field, index) => header.setUint32(index * 4, field),
160
+ [MAGIC_NUMBER_SMALL, bytes.length, objectCount, words32, words64].forEach((field, index) =>
161
+ header.setUint32(index * 4, field),
164
162
  );
165
163
  return new Uint8Array([...new Uint8Array(header.buffer), ...bytes]);
166
164
  };
@@ -1,12 +1,9 @@
1
- // The tlapm backend: runs tlapm on a module and reads each obligation's result from its Toolbox
2
- // messages.
3
-
4
- import { TlaUnsupportedError } from "../../errors";
1
+ import { TlaProverError, TlaUnsupportedError } from "../../errors";
5
2
 
6
3
  // Loaded at runtime so browser bundles leave them out. prove loads this module only in Node and Bun.
7
4
  const childProcess = process.getBuiltinModule("node:child_process");
8
- const fs = process.getBuiltinModule("node:fs");
9
- const os = process.getBuiltinModule("node:os");
5
+ const fileSystem = process.getBuiltinModule("node:fs");
6
+ const operatingSystem = process.getBuiltinModule("node:os");
10
7
  const path = process.getBuiltinModule("node:path");
11
8
 
12
9
  export type TlapmResult =
@@ -23,15 +20,16 @@ export const getTlapmPaths = () =>
23
20
  (process.env.PATH ?? "")
24
21
  .split(path.delimiter)
25
22
  .map((directory) => path.join(directory, "tlapm"))
26
- .filter((tlapm) => fs.existsSync(tlapm));
23
+ .filter((tlapm) => fileSystem.existsSync(tlapm));
24
+
25
+ const MESSAGE_END = "@!!END";
27
26
 
28
- // tlapm's Toolbox protocol: each message is @!!BEGIN, then @!!name:value lines, then @!!END.
29
27
  const parseToolboxMessages = (text: string) =>
30
28
  text
31
29
  .split("@!!BEGIN\n")
32
30
  .slice(1)
33
31
  .flatMap((block) => {
34
- const end = block.indexOf("@!!END");
32
+ const end = block.indexOf(MESSAGE_END);
35
33
  if (end === -1) return [];
36
34
  const fields = new Map<string, string>();
37
35
  block
@@ -53,8 +51,6 @@ const getResult = (fields: Map<string, string>): TlapmResult | undefined => {
53
51
  return undefined;
54
52
  };
55
53
 
56
- // Runs tlapm with --toolbox 0 0 on the module name, which modules holds with each module it
57
- // extends or instances, and returns the last result tlapm reported for each obligation.
58
54
  export const proveWithTlapm = async (
59
55
  name: string,
60
56
  modules: Map<string, string>,
@@ -63,9 +59,9 @@ export const proveWithTlapm = async (
63
59
  const tlapm = getTlapmPaths()[0];
64
60
  if (tlapm === undefined)
65
61
  throw new TlaUnsupportedError("The tlapm backend needs tlapm on your PATH.");
66
- const directory = fs.mkdtempSync(path.join(os.tmpdir(), "tla-ts-"));
62
+ const directory = fileSystem.mkdtempSync(path.join(operatingSystem.tmpdir(), "tla-ts-"));
67
63
  modules.forEach((source, moduleName) =>
68
- fs.writeFileSync(path.join(directory, `${moduleName}.tla`), source),
64
+ fileSystem.writeFileSync(path.join(directory, `${moduleName}.tla`), source),
69
65
  );
70
66
  const results = new Map<number, TlapmResult>();
71
67
  const child = childProcess.spawn(
@@ -75,22 +71,27 @@ export const proveWithTlapm = async (
75
71
  );
76
72
  const kill = () => child.kill();
77
73
  options.signal?.addEventListener("abort", kill);
78
- const output = { text: "", parsed: 0 };
74
+ let unparsed = "";
79
75
  child.stderr.on("data", (chunk: Buffer) => {
80
- output.text += chunk.toString("utf8");
81
- const messages = parseToolboxMessages(output.text);
82
- messages.slice(output.parsed).forEach((fields) => {
76
+ const text = unparsed + chunk.toString("utf8");
77
+ const end = text.lastIndexOf(MESSAGE_END);
78
+ const parsedLength = end === -1 ? 0 : end + MESSAGE_END.length;
79
+ unparsed = text.slice(parsedLength);
80
+ parseToolboxMessages(text.slice(0, parsedLength)).forEach((fields) => {
83
81
  const result = getResult(fields);
84
82
  const id = Number(fields.get("id"));
85
83
  if (fields.get("type") !== "obligation" || !result) return;
86
84
  results.set(id, result);
87
85
  options.onResult?.(id, result);
88
86
  });
89
- output.parsed = messages.length;
90
87
  });
91
- await new Promise((resolve) => child.on("close", resolve));
88
+ const failure = await new Promise<Error | undefined>((resolve) => {
89
+ child.on("error", resolve);
90
+ child.on("close", () => resolve(undefined));
91
+ });
92
92
  options.signal?.removeEventListener("abort", kill);
93
- fs.rmSync(directory, { recursive: true, force: true });
93
+ fileSystem.rmSync(directory, { recursive: true, force: true });
94
94
  options.signal?.throwIfAborted();
95
+ if (failure) throw new TlaProverError(failure.message, failure);
95
96
  return results;
96
97
  };
@@ -1,7 +1,12 @@
1
- // A backend's answer to an obligation. tlapm frames an obligation as unsatisfiable when the backend
2
- // proves it.
3
1
  export type Verdict = "unsat" | "sat" | "unknown";
4
2
 
3
+ export const BACKENDS = ["zenon", "isabelle", "smt", "z3", "ls4"] as const;
4
+
5
+ export type Backend = (typeof BACKENDS)[number];
6
+
7
+ export const isBackend = (prover: string): prover is Backend =>
8
+ BACKENDS.some((backend) => backend === prover);
9
+
5
10
  export interface Decision {
6
11
  verdict: Verdict;
7
12
  timeUsedMs: number;
@@ -1,9 +1,3 @@
1
- // An independent check of the proofs that the Zenon port finds. It shares no code with the search:
2
- // formulas compare by their own alpha-equivalence, substitution and unfolding are rebuilt here, and
3
- // each rule's branches come from the lemma that justifies the rule in tlapm's Zenon.thy rather than
4
- // from the prover. The check walks the proof bottom up and computes the formulas each subproof
5
- // needs. A proof is valid when every rule is one of the lemmas and the root needs only hypotheses.
6
-
7
1
  import { getLimitFailure, type Limits } from "../limits";
8
2
  import type { PlainRuleName, Proof, RuleArgs } from "../proof";
9
3
  import { getDefinitionSpec } from "./definitions";
@@ -57,8 +51,6 @@ const getRuleSpec = (proof: Proof<Term>, checker: Checker): RuleSpec => {
57
51
  }
58
52
  };
59
53
 
60
- // True when the proof refutes the hypotheses.
61
- // Whether the proof is valid, or false once the limits pass.
62
54
  export const checkProof = (root: Proof<Term>, context: CheckContext, limits: Limits) => {
63
55
  const keys = createKeys();
64
56
  const hasRelation = createRelationProperties(context);
@@ -79,7 +71,6 @@ export const checkProof = (root: Proof<Term>, context: CheckContext, limits: Lim
79
71
  return result;
80
72
  };
81
73
  try {
82
- // Subproofs before their parents, without recursion: proofs can be deep.
83
74
  const stack: [Proof<Term>, boolean][] = [[root, false]];
84
75
  while (stack.length > 0) {
85
76
  if (getLimitFailure(limits) !== undefined) return false;
@@ -96,8 +87,7 @@ export const checkProof = (root: Proof<Term>, context: CheckContext, limits: Lim
96
87
  if (!needed.has(subproof)) stack.push([subproof, false]);
97
88
  }
98
89
  const hypotheses = new Set(context.hypotheses.map(keys.getTopKey));
99
- const missing = [...(needed.get(root) ?? [])].filter((key) => !hypotheses.has(key));
100
- return missing.length === 0;
90
+ return [...(needed.get(root) ?? [])].every((key) => hypotheses.has(key));
101
91
  } catch (error) {
102
92
  if (error instanceof UncheckedError) return false;
103
93
  throw error;
@@ -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 = {