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,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]));
@@ -29,7 +25,7 @@ export const getFields = (record: Term, constructor: "TLA.record" | "TLA.records
29
25
  return fields;
30
26
  };
31
27
 
32
- const getLabels = (fields: [Term, Term][]) =>
28
+ export const getLabels = (fields: [Term, Term][]) =>
33
29
  app(
34
30
  "TLA.set",
35
31
  fields.map((field) => 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,14 @@
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
- import type { CheckContext, RelationProperty, Term } from "./terms";
1
+ import type { RelationProperty } from "../eqrel";
2
+ import type { CheckContext, Term } from "./terms";
6
3
 
7
4
  type Polarity = "positive" | "negative" | "both";
8
5
 
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
6
  type GroundTest = (values: number[], holds: number) => boolean;
13
7
 
14
8
  const ELEMENTS = [0, 1, 2];
15
9
 
16
- // The type Zenon gives a variable that its binder leaves untyped, which ranges over everything.
17
10
  const UNTYPED = "zenon_U";
18
11
 
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
12
  const getGroundTest = (
24
13
  formula: Term,
25
14
  symbol: string,
@@ -92,7 +81,6 @@ const getGroundTest = (
92
81
  }
93
82
  };
94
83
 
95
- // = has every property. Another relation has the ones the hypotheses give it.
96
84
  export const createRelationProperties = (context: CheckContext) => {
97
85
  const cache = new Map<string, boolean>();
98
86
  const hasProperty = (symbol: string, property: RelationProperty) => {
@@ -1,19 +1,13 @@
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
- import { getFields } from "./records";
2
+ import { getFields, getLabels } from "./records";
7
3
  import {
8
4
  and,
9
- app,
10
5
  domain,
11
6
  ensure,
12
7
  equal,
13
8
  expectApp,
14
9
  FALSE,
15
10
  fapply,
16
- getPairs,
17
11
  getStringText,
18
12
  instantiate,
19
13
  isApp,
@@ -28,7 +22,6 @@ import {
28
22
  type Term,
29
23
  } from "./terms";
30
24
 
31
- // The term that fills the hole of a context to give a formula.
32
25
  const getFilled = (lambda: Term, formula: Term) => {
33
26
  ensure(lambda.kind === "lam");
34
27
  const hole = lambda.args[0].symbol;
@@ -68,7 +61,6 @@ const getCaseBranches = (lambda: Term, args: Term[], condition: Term): Term[][]
68
61
  ];
69
62
  };
70
63
 
71
- // A formula used as a term splits into the cases where it equals TRUE and FALSE.
72
64
  const getBoolCaseSpec = (
73
65
  checker: Checker,
74
66
  args: Term[],
@@ -163,18 +155,7 @@ export const REWRITE_RULES = {
163
155
  record_domain: (args, checker) =>
164
156
  getRewriteSpec(checker, args[0], args[2], (filled) => {
165
157
  const record = expectApp(filled, "TLA.DOMAIN", 1)[0];
166
- const fields = getPairs(expectApp(record, "TLA.record"));
167
- return [
168
- [
169
- instantiate(
170
- args[2],
171
- app(
172
- "TLA.set",
173
- fields.map((field) => field[0]),
174
- ),
175
- ),
176
- ],
177
- ];
158
+ return [[instantiate(args[2], getLabels(getFields(record, "TLA.record")))]];
178
159
  }),
179
160
  boolcase_not: (args, checker) =>
180
161
  getBoolCaseSpec(checker, args, (operand) => operand.kind === "not"),
@@ -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,
@@ -43,6 +40,40 @@ const getSetEqualSpec = (formula: Term, isNegated: boolean, checker: Checker): R
43
40
  return { premises: [formula], branches: [[isNegated ? not(extensional) : extensional]] };
44
41
  };
45
42
 
43
+ const getUnionSpec = (formula: Term, isNegated: boolean, checker: Checker): RuleSpec => {
44
+ const spec = getMembershipSpec(formula, isNegated, "TLA.UNION", 1);
45
+ const exists = checker.bind("ex", "", (bound) =>
46
+ and(member(bound, spec.operands[0]), member(spec.element, bound)),
47
+ );
48
+ return { premises: [formula], branches: [[isNegated ? not(exists) : exists]] };
49
+ };
50
+
51
+ const getSetOfAllSpec = (formula: Term, isNegated: boolean, checker: Checker): RuleSpec => {
52
+ const spec = getMembershipSpec(formula, isNegated, "TLA.setOfAll", 2);
53
+ const mapping = spec.operands[1];
54
+ ensure(mapping.kind === "lam");
55
+ const exists = checker.bind("ex", "", (bound) =>
56
+ and(member(bound, spec.operands[0]), equal(spec.element, instantiate(mapping, bound))),
57
+ );
58
+ return { premises: [formula], branches: [[isNegated ? not(exists) : exists]] };
59
+ };
60
+
61
+ const getFuncSetSpec = (formula: Term, isNegated: boolean, checker: Checker): RuleSpec => {
62
+ const spec = getMembershipSpec(formula, isNegated, "TLA.FuncSet", 2);
63
+ const fcn = spec.element;
64
+ const conjuncts = [
65
+ app("TLA.isAFcn", [fcn]),
66
+ equal(domain(fcn), spec.operands[0]),
67
+ checker.bind("all", "", (bound) =>
68
+ imply(member(bound, spec.operands[0]), member(fapply(fcn, bound), spec.operands[1])),
69
+ ),
70
+ ];
71
+ return {
72
+ premises: [formula],
73
+ branches: isNegated ? conjuncts.map((inner) => [not(inner)]) : [conjuncts],
74
+ };
75
+ };
76
+
46
77
  export const SET_RULES = {
47
78
  in_emptyset: (args) => {
48
79
  ensure(isVariable(expectApp(args[0], "TLA.in", 2)[1], "TLA.emptyset"));
@@ -115,20 +146,8 @@ export const SET_RULES = {
115
146
  branches: [[not(app("TLA.subseteq", [spec.element, spec.operands[0]]))]],
116
147
  };
117
148
  },
118
- in_UNION: (args, checker) => {
119
- const spec = getMembershipSpec(args[0], false, "TLA.UNION", 1);
120
- const exists = checker.bind("ex", "", (bound) =>
121
- and(member(bound, spec.operands[0]), member(spec.element, bound)),
122
- );
123
- return { premises: [args[0]], branches: [[exists]] };
124
- },
125
- notin_UNION: (args, checker) => {
126
- const spec = getMembershipSpec(args[0], true, "TLA.UNION", 1);
127
- const exists = checker.bind("ex", "", (bound) =>
128
- and(member(bound, spec.operands[0]), member(spec.element, bound)),
129
- );
130
- return { premises: [args[0]], branches: [[not(exists)]] };
131
- },
149
+ in_UNION: (args, checker) => getUnionSpec(args[0], false, checker),
150
+ notin_UNION: (args, checker) => getUnionSpec(args[0], true, checker),
132
151
  in_cup: (args) => {
133
152
  const spec = getMembershipSpec(args[0], false, "TLA.cup", 2);
134
153
  return {
@@ -197,50 +216,10 @@ export const SET_RULES = {
197
216
  ],
198
217
  };
199
218
  },
200
- in_setofall: (args, checker) => {
201
- const spec = getMembershipSpec(args[0], false, "TLA.setOfAll", 2);
202
- const mapping = spec.operands[1];
203
- ensure(mapping.kind === "lam");
204
- const exists = checker.bind("ex", "", (bound) =>
205
- and(member(bound, spec.operands[0]), equal(spec.element, instantiate(mapping, bound))),
206
- );
207
- return { premises: [args[0]], branches: [[exists]] };
208
- },
209
- notin_setofall: (args, checker) => {
210
- const spec = getMembershipSpec(args[0], true, "TLA.setOfAll", 2);
211
- const mapping = spec.operands[1];
212
- ensure(mapping.kind === "lam");
213
- const exists = checker.bind("ex", "", (bound) =>
214
- and(member(bound, spec.operands[0]), equal(spec.element, instantiate(mapping, bound))),
215
- );
216
- return { premises: [args[0]], branches: [[not(exists)]] };
217
- },
218
- in_funcset: (args, checker) => {
219
- const spec = getMembershipSpec(args[0], false, "TLA.FuncSet", 2);
220
- const fcn = spec.element;
221
- const maps = checker.bind("all", "", (bound) =>
222
- imply(member(bound, spec.operands[0]), member(fapply(fcn, bound), spec.operands[1])),
223
- );
224
- return {
225
- premises: [args[0]],
226
- branches: [[app("TLA.isAFcn", [fcn]), equal(domain(fcn), spec.operands[0]), maps]],
227
- };
228
- },
229
- notin_funcset: (args, checker) => {
230
- const spec = getMembershipSpec(args[0], true, "TLA.FuncSet", 2);
231
- const fcn = spec.element;
232
- const maps = checker.bind("all", "", (bound) =>
233
- imply(member(bound, spec.operands[0]), member(fapply(fcn, bound), spec.operands[1])),
234
- );
235
- return {
236
- premises: [args[0]],
237
- branches: [
238
- [not(app("TLA.isAFcn", [fcn]))],
239
- [not(equal(domain(fcn), spec.operands[0]))],
240
- [not(maps)],
241
- ],
242
- };
243
- },
219
+ in_setofall: (args, checker) => getSetOfAllSpec(args[0], false, checker),
220
+ notin_setofall: (args, checker) => getSetOfAllSpec(args[0], true, checker),
221
+ in_funcset: (args, checker) => getFuncSetSpec(args[0], false, checker),
222
+ notin_funcset: (args, checker) => getFuncSetSpec(args[0], true, checker),
244
223
  except_notin_funcset: (args) => {
245
224
  const spec = getMembershipSpec(args[0], true, "TLA.FuncSet", 2);
246
225
  const except = expectApp(spec.element, "TLA.except", 3);
@@ -1,14 +1,10 @@
1
- // What the rule checks share: the formulas they build and take apart, and how a check rejects a
2
- // proof.
3
-
1
+ import type { RelationProperty } from "../eqrel";
4
2
  import type { ExprKind } from "../expr";
5
3
  import type { Definition } from "../parse";
6
4
  import type { PlainRuleName, RuleArgs } from "../proof";
7
5
 
8
6
  type TermKind = ExprKind | "subst";
9
7
 
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
8
  export interface Term {
13
9
  kind: TermKind;
14
10
  symbol: string;
@@ -20,42 +16,30 @@ export interface CheckContext {
20
16
  definitions: Definition[];
21
17
  }
22
18
 
23
- // What a rule needs on its branch: its premises, and the formulas each of its branches adds.
24
19
  export interface RuleSpec {
25
20
  premises: Term[];
26
21
  branches: Term[][];
27
22
  }
28
23
 
29
- export type RelationProperty = "reflexive" | "symmetric" | "transitive";
30
-
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
24
  export type Binding = number | { formula: Term; env: Env; operators?: Operators };
35
25
 
36
26
  export type Env = Map<string, Binding>;
37
27
 
38
28
  export type Operators = Map<string, Term>;
39
29
 
40
- // One check of a proof, with the caches that last as long as it does.
41
30
  export interface Checker {
42
31
  context: CheckContext;
43
- // A canonical text for a formula up to the names of bound variables.
44
32
  getKey: (formula: Term, env: Env, depth: number, operators?: Operators) => string;
45
33
  getTopKey: (formula: Term) => string;
46
34
  isSame: (left: Term, right: Term) => boolean;
47
- // A binder whose variable can't clash with any name in the input.
48
35
  bind: (kind: "all" | "ex", type: string, build: (bound: Term) => Term) => Term;
49
- // Rejects the proof unless the hypotheses give the relation these properties.
50
36
  ensureRelation: (symbol: string, properties: RelationProperty[]) => void;
51
37
  }
52
38
 
53
- // The check of each rule, given the rule's arguments and the formulas the proof says it uses.
54
39
  export type SpecTable<Name extends PlainRuleName> = {
55
40
  [Key in Name]: (args: RuleArgs<Key, Term>, checker: Checker, uses: Term[]) => RuleSpec;
56
41
  };
57
42
 
58
- // Raised inside a rule check to reject the proof.
59
43
  export class UncheckedError extends Error {}
60
44
 
61
45
  export const ensure: (condition: boolean) => asserts condition = (condition) => {
@@ -81,7 +65,6 @@ export const domain = (fcn: Term) => app("TLA.DOMAIN", [fcn]);
81
65
  export const TRUE = term("true", "", []);
82
66
  export const FALSE = term("false", "", []);
83
67
 
84
- // Instantiates the body of a binder with a term.
85
68
  export const instantiate = (binder: Term, value: Term) =>
86
69
  term("subst", binder.args[0].symbol, [binder.args[1], value]);
87
70
 
@@ -105,7 +88,6 @@ export const expectNot = (formula: Term) => expectKind(formula, "not")[0];
105
88
  export const isVariable = (formula: Term, name: string) =>
106
89
  formula.kind === "var" && formula.symbol === name;
107
90
 
108
- // The text of a string literal. Escapes could spell one string two ways, so they don't count.
109
91
  export const getStringText = (formula: Term) => {
110
92
  ensure(isApp(formula, "$string", 1) && formula.args[0].kind === "var");
111
93
  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,11 @@
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.
7
+ export type RelationProperty = "reflexive" | "symmetric" | "transitive";
8
+
13
9
  export interface Origin {
14
10
  formula: Expr;
15
11
  directions: Direction[];
@@ -21,7 +17,6 @@ interface RelationInfo {
21
17
  symmetric: Origin | undefined;
22
18
  transitive: Origin | undefined;
23
19
  transitiveSymmetric: Origin | undefined;
24
- // The type of the relation's arguments.
25
20
  type: string;
26
21
  }
27
22
 
@@ -30,8 +25,6 @@ interface Bound {
30
25
  type: string;
31
26
  }
32
27
 
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
28
  interface Leaves {
36
29
  directions: Direction[];
37
30
  env: Bound[];
@@ -125,7 +118,6 @@ const getPair = (leaf: Expr) => {
125
118
  return [args[0].symbol, args[1].symbol];
126
119
  };
127
120
 
128
- // The leaves as Zenon's partition returns them: positive and negative, each reversed.
129
121
  const partition = (leaves: Expr[]) => ({
130
122
  positive: leaves
131
123
  .filter((leaf) => leaf.kind !== "not")
@@ -137,8 +129,6 @@ const partition = (leaves: Expr[]) => ({
137
129
  .map(getPair),
138
130
  });
139
131
 
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
132
  const getReflexive = (leaves: Expr[]) => {
143
133
  if (leaves.length !== 1 || leaves[0].kind === "not") return undefined;
144
134
  const pair = getPair(leaves[0]);
@@ -292,7 +282,6 @@ export const createRelations = (exprs: Expressions) => {
292
282
  record.transitive !== undefined)
293
283
  );
294
284
  },
295
- // Where the hypotheses state a relation's properties, for the translation to Isar.
296
285
  get,
297
286
  };
298
287
  };
@@ -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,
@@ -231,6 +217,11 @@ export const isApp = <Symbol extends string>(
231
217
  expression.symbol === symbol &&
232
218
  (arity === undefined || expression.args.length === arity);
233
219
 
220
+ export const getStringName = (expression: Expr) =>
221
+ isApp(expression, "$string", 1) && expression.args[0].kind === "var"
222
+ ? expression.args[0].symbol
223
+ : undefined;
224
+
234
225
  export const isMeta = (expression: Expr): expression is MetaExpr => expression.kind === "meta";
235
226
 
236
227
  export const isRelation = (expression: Expr): expression is RelationExpr =>
@@ -239,7 +230,6 @@ export const isRelation = (expression: Expr): expression is RelationExpr =>
239
230
  export const isNegatedRelation = (expression: Expr): expression is NegatedRelationExpr =>
240
231
  expression.kind === "not" && isRelation(expression.args[0]);
241
232
 
242
- // Zenon orders by hash, and only breaks ties structurally.
243
233
  export const compareExprs = (left: Expr, right: Expr): number => {
244
234
  if (left.hash !== right.hash) return left.hash < right.hash ? -1 : 1;
245
235
  if (left === right) return 0;
@@ -263,20 +253,14 @@ const isIrrelevant = (names: string[], map: Substitution) =>
263
253
  const hasConflict = (variable: Expr, map: Substitution) =>
264
254
  map.some((pair) => pair[1].freeVars.includes(variable.symbol));
265
255
 
266
- // The store of one run's expressions, and the operations that build expressions in it.
267
256
  export const createExpressions = () => {
268
257
  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
258
  const binders = new Map<number, BinderExpr[]>();
273
259
  const interned = new Map<number, Expr[]>();
274
- // Numbers for the symbols, so an expression hashes by its symbol and children without strings.
275
260
  const symbolIds = new Map<string, number>();
276
261
  let nextId = FALSE.id + 1;
277
262
  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.
263
+ // Zenon's Ext_focal takes the first five fresh names at startup, so the first name Zenon gives out is zenon_Vf.
280
264
  let nameCounter = "e";
281
265
 
282
266
  const create = <Shape extends Pick<Expr, "kind" | "symbol" | "args">>(
@@ -437,8 +421,6 @@ export const createExpressions = () => {
437
421
  return evar(VAR_PREFIX + nameCounter);
438
422
  };
439
423
 
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
424
  const enterBinder = (expression: BinderExpr, map: Substitution): [VarExpr, Substitution] => {
443
425
  const variable = expression.args[0];
444
426
  const rest = map.filter((pair) => pair[0] !== variable);
@@ -486,8 +468,6 @@ export const createExpressions = () => {
486
468
  return results;
487
469
  };
488
470
 
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
471
  const substituteSecondOrder = (map: Substitution, expression: Expr): Expr | undefined => {
492
472
  switch (expression.kind) {
493
473
  case "var":
@@ -529,6 +509,8 @@ export const createExpressions = () => {
529
509
  emeta,
530
510
  eapp,
531
511
  enot,
512
+ binary,
513
+ binder,
532
514
  eand: (left: Expr, right: Expr) => binary("and", left, right),
533
515
  eor: (left: Expr, right: Expr) => binary("or", left, right),
534
516
  eimply: (left: Expr, right: Expr) => binary("imply", left, right),