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,10 +1,7 @@
1
1
  // Ported from Zenon's mltoll.ml, as shipped in tlapm. Copyright 2004 INRIA, see LICENSE.
2
- //
3
- // Translates the proof that the search finds into a low-level proof: the derived rules expand into
4
- // core rules, and each proof that the search reused becomes a lemma.
5
2
 
6
3
  import { TlaZenonError } from "../../errors";
7
- import type { Direction, Origin, Relations } from "./eqrel";
4
+ import type { Direction, Origin, RelationProperty, Relations } from "./eqrel";
8
5
  import {
9
6
  difference,
10
7
  union,
@@ -13,13 +10,12 @@ import {
13
10
  type Expressions,
14
11
  type VarExpr,
15
12
  } from "./expr";
16
- import { connect, type Connective, type Lemma, type LlProof, type LlRule } from "./llproof";
13
+ import type { Connective, Lemma, LlProof, LlRule } from "./llproof";
17
14
  import type { Definition, Phrase } from "./parse";
18
15
  import type { Rule } from "./proof";
19
16
  import { getTlaLlProof } from "./tla/llproof";
20
17
 
21
- // The search's proofs, and the rule that only the translation builds.
22
- export type MlRule = Rule | { name: "notall" | "notallex"; args: [Expr] };
18
+ type MlRule = Rule | { name: "notall" | "notallex"; args: [Expr] };
23
19
 
24
20
  export interface MlProof {
25
21
  conclusions: Expr[];
@@ -27,22 +23,15 @@ export interface MlProof {
27
23
  subproofs: MlProof[];
28
24
  }
29
25
 
30
- // A translated proof, with the hypotheses it uses that aren't conclusions of the node.
31
26
  export type Translated = [LlProof, Expr[]];
32
27
 
33
28
  interface TranslateContext {
34
29
  exprs: Expressions;
35
- // Zenon's Index.get_number, which also names the formulas in the Isar output.
36
30
  getNumber: (expression: Expr) => number;
37
- // The proofs that the search reused, which Zenon counts in mlrefc.
38
31
  sharedProofs: ReadonlySet<MlProof>;
39
32
  relations: Relations;
40
33
  }
41
34
 
42
- type RelationProperty = "reflexive" | "symmetric" | "transitive";
43
-
44
- // Zenon's Eqrel.hyp_kind: how to prove a hypothesis about a relation. A relation is also
45
- // symmetric or transitive when it's reflexive and transitive in the symmetric sense.
46
35
  type HypothesisKind =
47
36
  | { kind: "reflexive"; origin: Origin }
48
37
  | { kind: "symmetric"; origin: Origin }
@@ -61,7 +50,6 @@ export const isMetaName = (name: string) => name.startsWith(META_PREFIX);
61
50
 
62
51
  const isAlphanumeric = (char: string) => /^[A-Za-z0-9]$/.test(char);
63
52
 
64
- // Zenon's type_to_ident.
65
53
  const toIdentifier = (type: string) =>
66
54
  [...type]
67
55
  .map((char) =>
@@ -79,7 +67,6 @@ const getSingle = (proof: MlProof) => {
79
67
  return proof.subproofs[0];
80
68
  };
81
69
 
82
- // Zenon's Mlproof.make_node: the node's conclusions and those its subproofs leave open.
83
70
  const makeNode = (
84
71
  conclusions: Expr[],
85
72
  rule: MlRule,
@@ -119,7 +106,6 @@ const isDerived = (rule: MlRule) => {
119
106
  }
120
107
  };
121
108
 
122
- // The rules that tr_rule translates directly: the core rules and the extension rules named "".
123
109
  const CORE_RULES = new Set<string>([
124
110
  "close",
125
111
  "false",
@@ -150,7 +136,6 @@ const CORE_RULES = new Set<string>([
150
136
  "stringdiffrr",
151
137
  ]);
152
138
 
153
- // Zenon's Mltoll.translate: the lemmas in the order they were made, then the theorem.
154
139
  export const translateProof = (
155
140
  context: TranslateContext,
156
141
  phrases: Phrase[],
@@ -158,14 +143,11 @@ export const translateProof = (
158
143
  ): Lemma[] => {
159
144
  const exprs = context.exprs;
160
145
  const translatedExprs = new Map<Expr, Expr>();
161
- const lemmaNumbers = new Map<MlProof, number>();
162
- const lemmaTable = new Map<string, [Lemma, Expr[]]>();
146
+ const lemmaTable = new Map<MlProof, [Lemma, Expr[]]>();
163
147
  const lemmas: Lemma[] = [];
164
- const getLemmaName = (number: number) => `${LEMMA_PREFIX}${number}_`;
165
148
 
166
149
  const equal = (left: Expr, right: Expr) => exprs.eapp("=", [left, right]);
167
150
 
168
- // Zenon's tr_expr: metavariables become variables named after their quantifier.
169
151
  const translateExpr = (expression: Expr): Expr => {
170
152
  if (expression.metas.length === 0) return expression;
171
153
  const cached = translatedExprs.get(expression);
@@ -189,13 +171,13 @@ export const translateProof = (
189
171
  case "imply":
190
172
  case "equiv": {
191
173
  const right = translateExpr(expression.args[1]);
192
- return connect(exprs, expression.kind, translateExpr(expression.args[0]), right);
174
+ return exprs.binary(expression.kind, translateExpr(expression.args[0]), right);
193
175
  }
194
176
  case "all":
195
177
  case "ex":
196
178
  case "tau":
197
179
  case "lam":
198
- return makeBinder(
180
+ return exprs.binder(
199
181
  expression.kind,
200
182
  expression.args[0],
201
183
  expression.symbol,
@@ -209,41 +191,31 @@ export const translateProof = (
209
191
  return result;
210
192
  };
211
193
 
212
- const makeBinder = (kind: BinderExpr["kind"], variable: VarExpr, type: string, body: Expr) =>
213
- kind === "all"
214
- ? exprs.eall(variable, type, body)
215
- : kind === "ex"
216
- ? exprs.eex(variable, type, body)
217
- : kind === "tau"
218
- ? exprs.etau(variable, type, body)
219
- : exprs.elam(variable, type, body);
220
-
221
194
  const translateRule = (rule: MlRule): LlRule => {
222
- const tr = translateExpr;
223
195
  switch (rule.name) {
224
196
  case "close":
225
- return { kind: "axiom", formula: tr(rule.args[0]) };
197
+ return { kind: "axiom", formula: translateExpr(rule.args[0]) };
226
198
  case "close_refl":
227
- return { kind: "noteq", term: tr(rule.args[0]) };
199
+ return { kind: "noteq", term: translateExpr(rule.args[0]) };
228
200
  case "close_sym": {
229
- const right = tr(rule.args[1]);
230
- return { kind: "eqsym", left: tr(rule.args[0]), right };
201
+ const right = translateExpr(rule.args[1]);
202
+ return { kind: "eqsym", left: translateExpr(rule.args[0]), right };
231
203
  }
232
204
  case "false":
233
205
  return { kind: "false" };
234
206
  case "not_true":
235
207
  return { kind: "nottrue" };
236
208
  case "not_not":
237
- return { kind: "notnot", formula: tr(rule.args[0]) };
209
+ return { kind: "notnot", formula: translateExpr(rule.args[0]) };
238
210
  case "and":
239
211
  case "or":
240
212
  case "impl":
241
213
  case "equiv": {
242
- const right = tr(rule.args[1]);
214
+ const right = translateExpr(rule.args[1]);
243
215
  return {
244
216
  kind: "connect",
245
217
  connective: RULE_CONNECTIVES[rule.name],
246
- left: tr(rule.args[0]),
218
+ left: translateExpr(rule.args[0]),
247
219
  right,
248
220
  };
249
221
  }
@@ -251,57 +223,59 @@ export const translateProof = (
251
223
  case "not_impl":
252
224
  case "not_and":
253
225
  case "not_equiv": {
254
- const right = tr(rule.args[1]);
226
+ const right = translateExpr(rule.args[1]);
255
227
  return {
256
228
  kind: "notconnect",
257
229
  connective: RULE_CONNECTIVES[rule.name],
258
- left: tr(rule.args[0]),
230
+ left: translateExpr(rule.args[0]),
259
231
  right,
260
232
  };
261
233
  }
262
234
  case "ex": {
263
235
  const quantified = getBinder(rule.args[0], "ex");
264
- const term = tr(exprs.etau(quantified.args[0], quantified.symbol, quantified.args[1]));
265
- return { kind: "ex", quantified: tr(quantified), term };
236
+ const term = translateExpr(
237
+ exprs.etau(quantified.args[0], quantified.symbol, quantified.args[1]),
238
+ );
239
+ return { kind: "ex", quantified: translateExpr(quantified), term };
266
240
  }
267
241
  case "all": {
268
- const term = tr(rule.args[1]);
269
- return { kind: "all", quantified: tr(rule.args[0]), term };
242
+ const term = translateExpr(rule.args[1]);
243
+ return { kind: "all", quantified: translateExpr(rule.args[0]), term };
270
244
  }
271
245
  case "not_ex": {
272
246
  const negation = rule.args[0];
273
247
  if (negation.kind !== "not") throw new TlaZenonError("Zenon: not_ex without a negation");
274
- const term = tr(rule.args[1]);
275
- return { kind: "notex", quantified: tr(negation.args[0]), term };
248
+ const term = translateExpr(rule.args[1]);
249
+ return { kind: "notex", quantified: translateExpr(negation.args[0]), term };
276
250
  }
277
251
  case "p_not_p": {
278
- const negative = tr(rule.args[1]);
279
- return { kind: "pnotp", positive: tr(rule.args[0]), negative };
252
+ const negative = translateExpr(rule.args[1]);
253
+ return { kind: "pnotp", positive: translateExpr(rule.args[0]), negative };
280
254
  }
281
255
  case "not_equal": {
282
- const right = tr(rule.args[1]);
283
- return { kind: "notequal", left: tr(rule.args[0]), right };
256
+ const right = translateExpr(rule.args[1]);
257
+ return { kind: "notequal", left: translateExpr(rule.args[0]), right };
284
258
  }
285
259
  case "definition": {
286
260
  if (rule.definition.kind !== "real")
287
261
  throw new TlaZenonError("Zenon: a pseudo-definition in tr_rule");
288
- const unfolded = tr(rule.args[1]);
262
+ const unfolded = translateExpr(rule.args[1]);
289
263
  return {
290
264
  kind: "definition",
291
265
  name: rule.definition.name,
292
- folded: tr(rule.args[0]),
266
+ folded: translateExpr(rule.args[0]),
293
267
  unfolded,
294
268
  };
295
269
  }
296
270
  case "cut":
297
- return { kind: "cut", formula: tr(rule.args[0]) };
271
+ return { kind: "cut", formula: translateExpr(rule.args[0]) };
298
272
  case "congruence_lr":
299
273
  case "congruence_rl": {
300
- const right = tr(rule.args[2]);
301
- const left = tr(rule.args[1]);
274
+ const right = translateExpr(rule.args[2]);
275
+ const left = translateExpr(rule.args[1]);
302
276
  return {
303
277
  kind: rule.name === "congruence_lr" ? "congruencelr" : "congruencerl",
304
- context: tr(rule.args[0]),
278
+ context: translateExpr(rule.args[0]),
305
279
  left,
306
280
  right,
307
281
  };
@@ -309,10 +283,10 @@ export const translateProof = (
309
283
  case "notall": {
310
284
  const negation = rule.args[0];
311
285
  const quantified = getBinder(negation.kind === "not" ? negation.args[0] : negation, "all");
312
- const term = tr(
286
+ const term = translateExpr(
313
287
  exprs.etau(quantified.args[0], quantified.symbol, exprs.enot(quantified.args[1])),
314
288
  );
315
- return { kind: "notall", quantified: tr(quantified), term };
289
+ return { kind: "notall", quantified: translateExpr(quantified), term };
316
290
  }
317
291
  case "notallex": {
318
292
  const lambda = getBinder(rule.args[0], "lam");
@@ -344,7 +318,10 @@ export const translateProof = (
344
318
  case "stringdifflr":
345
319
  case "stringdiffrl":
346
320
  case "stringdiffrr": {
347
- const [first, firstValue, second, secondValue] = rule.args;
321
+ const first = rule.args[0];
322
+ const firstValue = rule.args[1];
323
+ const second = rule.args[2];
324
+ const secondValue = rule.args[3];
348
325
  const isFirstLeft = rule.name === "stringdiffll" || rule.name === "stringdifflr";
349
326
  const isSecondLeft = rule.name === "stringdiffll" || rule.name === "stringdiffrl";
350
327
  const firstConclusion = isFirstLeft ? equal(first, firstValue) : equal(firstValue, first);
@@ -366,7 +343,6 @@ export const translateProof = (
366
343
  }
367
344
  };
368
345
 
369
- // Zenon's get_params: the free taus of a lemma's conclusions, each with its type.
370
346
  const getParams = (accumulated: [string, Expr][], expression: Expr): [string, Expr][] => {
371
347
  const merge = (type: string, term: Expr): [string, Expr][] =>
372
348
  accumulated.some((param) => param[1] === term) ? accumulated : [[type, term], ...accumulated];
@@ -385,8 +361,7 @@ export const translateProof = (
385
361
  };
386
362
 
387
363
  const getLemmaReference = (proof: MlProof): Translated => {
388
- const number = lemmaNumbers.get(proof);
389
- const entry = number === undefined ? undefined : lemmaTable.get(getLemmaName(number));
364
+ const entry = lemmaTable.get(proof);
390
365
  if (entry === undefined) throw new TlaZenonError("Zenon: a lemma that was never made");
391
366
  const lemma = entry[0];
392
367
  return [
@@ -400,19 +375,17 @@ export const translateProof = (
400
375
  };
401
376
 
402
377
  const makeLemma = (translated: LlProof, extras: Expr[], proof: MlProof) => {
403
- const number = lemmas.length + 1;
404
- lemmaNumbers.set(proof, number);
405
378
  const lemma = {
406
- name: getLemmaName(number),
379
+ name: `${LEMMA_PREFIX}${lemmas.length + 1}_`,
407
380
  params: translated.conclusions.reduce(getParams, []),
408
381
  proof: translated,
409
382
  };
410
- lemmaTable.set(lemma.name, [lemma, extras]);
383
+ lemmaTable.set(proof, [lemma, extras]);
411
384
  lemmas.push(lemma);
412
385
  };
413
386
 
414
387
  const translate = (proof: MlProof): Translated => {
415
- if (lemmaNumbers.has(proof)) return getLemmaReference(proof);
388
+ if (lemmaTable.has(proof)) return getLemmaReference(proof);
416
389
  const result = isDerived(proof.rule)
417
390
  ? translateDerived(proof)
418
391
  : ((): Translated => {
@@ -433,9 +406,8 @@ export const translateProof = (
433
406
  };
434
407
 
435
408
  const isSharedProof = (proof: MlProof) =>
436
- context.sharedProofs.has(proof) && !lemmaNumbers.has(proof);
409
+ context.sharedProofs.has(proof) && !lemmaTable.has(proof);
437
410
 
438
- // Zenon's get_sub: the subproofs, and the union of their extras from the right.
439
411
  const translateAll = (proofs: MlProof[]): [LlProof[], Expr[]] => {
440
412
  const translated = proofs.map(translate);
441
413
  return [
@@ -444,7 +416,6 @@ export const translateProof = (
444
416
  ];
445
417
  };
446
418
 
447
- // A node of recomp_conj, with the formulas it removes from its subproof's conclusions.
448
419
  const recompose = (
449
420
  conclusion: Expr,
450
421
  rule: LlRule,
@@ -518,12 +489,11 @@ export const translateProof = (
518
489
  }
519
490
  };
520
491
 
521
- // Zenon's recomp_disj: consumes the translated subproofs, one for each disjunct.
522
492
  const recompDisj = (subs: Translated[], formula: Expr): [LlProof, Expr[], Translated[]] => {
523
493
  const node = (
524
494
  conclusion: Expr,
525
495
  connectiveName: Connective,
526
- negated: boolean,
496
+ isNegated: boolean,
527
497
  left: Expr,
528
498
  right: Expr,
529
499
  first: [LlProof, Expr[], Translated[]],
@@ -540,7 +510,12 @@ export const translateProof = (
540
510
  difference(second[0].conclusions, [secondRemoved]),
541
511
  ),
542
512
  ),
543
- rule: { kind: negated ? "notconnect" : "connect", connective: connectiveName, left, right },
513
+ rule: {
514
+ kind: isNegated ? "notconnect" : "connect",
515
+ connective: connectiveName,
516
+ left,
517
+ right,
518
+ },
544
519
  subproofs: [first[0], second[0]],
545
520
  },
546
521
  difference(union(first[1], second[1]), [extra]),
@@ -643,7 +618,6 @@ export const translateProof = (
643
618
  return [subs[0][0], subs[0][1], subs.slice(1)];
644
619
  };
645
620
 
646
- // The constructors of Zenon's Mlproof, for the proofs that the translation builds.
647
621
  const makeClose = (formula: Expr) =>
648
622
  makeNode([formula, exprs.enot(formula)], { name: "close", args: [formula] }, [], []);
649
623
  const makeCloseRefl = (relation: string, term: Expr) =>
@@ -704,7 +678,6 @@ export const translateProof = (
704
678
  const instance = exprs.substitute([[binder.args[0], terms[0]]], binder.args[1]);
705
679
  return makeAll(quantified, terms[0], makeAlls(instance, terms.slice(1), subproof));
706
680
  };
707
- // Zenon's make_impls: the implications from `hypotheses` to `conclusion`, and their proof.
708
681
  const makeImplies = (
709
682
  hypotheses: Expr[],
710
683
  conclusion: Expr,
@@ -737,8 +710,6 @@ export const translateProof = (
737
710
  [first, second],
738
711
  );
739
712
 
740
- // Zenon's Eqrel.get_refl_hyp, get_sym_hyp and get_trans_hyp: the hypothesis that states a
741
- // property of a relation, which the translation proves from the hypotheses that implied it.
742
713
  const relationHypotheses = new Map<string, Expr>();
743
714
  const hypothesisKinds = new Map<Expr, HypothesisKind>();
744
715
  const getRelationHypothesis = (property: RelationProperty, relation: string) => {
@@ -795,7 +766,6 @@ export const translateProof = (
795
766
  return hypothesis;
796
767
  };
797
768
 
798
- // Zenon's inst_nall: the instance of a negated universal at its counterexample.
799
769
  const instantiateNegation = (negation: Expr): [Expr, Expr] => {
800
770
  if (negation.kind !== "not") throw new TlaZenonError("Zenon: inst_nall without a negation");
801
771
  const binder = getBinder(negation.args[0], "all");
@@ -804,7 +774,6 @@ export const translateProof = (
804
774
  return [exprs.substitute([[binder.args[0], witness]], body), witness];
805
775
  };
806
776
 
807
- // Zenon's decompose_disj: closes each literal of a disjunction with one of `forms`.
808
777
  const decomposeDisjunction = (formula: Expr, forms: Expr[]): MlProof => {
809
778
  const visit = (disjunct: Expr) => decomposeDisjunction(disjunct, forms);
810
779
  const getForm = (form: Expr) => {
@@ -867,8 +836,6 @@ export const translateProof = (
867
836
  }
868
837
  };
869
838
 
870
- // Zenon's decompose_conj: follows `directions` to the conjunct that states a property, and
871
- // instantiates the quantifiers at `variables` with `witnesses`, the others with metavariables.
872
839
  const decomposeConjunction = (
873
840
  position: number,
874
841
  formula: Expr,
@@ -986,8 +953,6 @@ export const translateProof = (
986
953
  return decomposeDisjunction(formula, forms);
987
954
  };
988
955
 
989
- // Zenon's Eqrel.get_proof: proves a relation hypothesis from the hypotheses that implied it,
990
- // and returns the proof with those hypotheses.
991
956
  const getRelationProof = (hypothesis: Expr): [MlProof, Expr[]] => {
992
957
  const kind = hypothesisKinds.get(hypothesis);
993
958
  if (kind === undefined)
@@ -1124,7 +1089,6 @@ export const translateProof = (
1124
1089
 
1125
1090
  const relate = (relation: string, left: Expr, right: Expr) => exprs.eapp(relation, [left, right]);
1126
1091
 
1127
- // Zenon's make_direct_trans: r(a, b), r(b, c) / r(a, c) / (proof).
1128
1092
  const makeDirectTrans = (relation: string, a: Expr, b: Expr, c: Expr, proof: MlProof) => {
1129
1093
  const hypothesis = getRelationHypothesis("transitive", relation);
1130
1094
  const ab = relate(relation, a, b);
@@ -1137,21 +1101,18 @@ export const translateProof = (
1137
1101
  );
1138
1102
  return makeAlls(hypothesis, [a, b, c], implied[1]);
1139
1103
  };
1140
- // Zenon's make_direct_nsym: -r(a, b) / -r(b, a) / (proof).
1141
1104
  const makeDirectNotSym = (relation: string, a: Expr, b: Expr, proof: MlProof) => {
1142
1105
  const hypothesis = getRelationHypothesis("symmetric", relation);
1143
1106
  const ab = relate(relation, a, b);
1144
1107
  const ba = relate(relation, b, a);
1145
1108
  return makeAlls(hypothesis, [b, a], makeImply(ba, ab, proof, makeClose(ab)));
1146
1109
  };
1147
- // Zenon's make_direct_sym_neq: a != b / b != a / (proof).
1148
1110
  const makeSymmetricDisequality = (a: Expr, b: Expr, proof: MlProof) => {
1149
1111
  const reflexive = equal(b, b);
1150
1112
  const refuted = makeCloseRefl("=", b);
1151
1113
  const swapped = makePNotP(reflexive, exprs.enot(equal(a, b)), [proof, refuted]);
1152
1114
  return makeCut(reflexive, swapped, refuted);
1153
1115
  };
1154
- // Zenon's make_direct_sym_eq: a = b / b = a / (proof).
1155
1116
  const makeSymmetricEquality = (a: Expr, b: Expr, proof: MlProof) => {
1156
1117
  const ab = equal(a, b);
1157
1118
  return makeCut(equal(b, a), proof, makeSymmetricDisequality(b, a, makeClose(ab)));
@@ -1265,7 +1226,6 @@ export const translateProof = (
1265
1226
  return [proof.subproofs[0], proof.subproofs[1], proof.subproofs[2]];
1266
1227
  };
1267
1228
 
1268
- // A derived rule's expansion, with the hypotheses it relies on that no phrase may state.
1269
1229
  const translateWith = (expanded: MlProof, hypotheses: Expr[]): Translated => {
1270
1230
  const translated = translate(expanded);
1271
1231
  return [translated[0], union(hypotheses, translated[1])];
@@ -1295,7 +1255,8 @@ export const translateProof = (
1295
1255
  }
1296
1256
  case "close_sym": {
1297
1257
  const hypothesis = getRelationHypothesis("symmetric", rule.relation);
1298
- const [a, b] = rule.args;
1258
+ const a = rule.args[0];
1259
+ const b = rule.args[1];
1299
1260
  const ab = relate(rule.relation, a, b);
1300
1261
  const ba = relate(rule.relation, b, a);
1301
1262
  const implied = makeImply(ab, ba, makeClose(ab), makeClose(ba));
@@ -1310,7 +1271,8 @@ export const translateProof = (
1310
1271
  }
1311
1272
  case "refl": {
1312
1273
  const hypothesis = getRelationHypothesis("reflexive", rule.relation);
1313
- const [a, b] = rule.args;
1274
+ const a = rule.args[0];
1275
+ const b = rule.args[1];
1314
1276
  const reflexive = relate(rule.relation, a, a);
1315
1277
  const negated = exprs.enot(relate(rule.relation, a, b));
1316
1278
  const closed = makePNotP(reflexive, negated, [makeCloseRefl("=", a), getSingle(proof)]);
@@ -1325,7 +1287,8 @@ export const translateProof = (
1325
1287
  return translate(makeSymmetricDisequality(negative.args[0], negative.args[1], node));
1326
1288
  }
1327
1289
  const hypothesis = getRelationHypothesis("symmetric", rule.relation);
1328
- const [a, b] = positive.args;
1290
+ const a = positive.args[0];
1291
+ const b = positive.args[1];
1329
1292
  const ba = relate(rule.relation, b, a);
1330
1293
  const node = makePNotP(ba, rule.args[1], [proof.subproofs[0], proof.subproofs[1]]);
1331
1294
  const implied = makeImply(rule.args[0], ba, makeClose(rule.args[0]), node);
@@ -1335,8 +1298,11 @@ export const translateProof = (
1335
1298
  case "trans_sym": {
1336
1299
  const positive = getRelation(rule.args[0]);
1337
1300
  const relation = positive.symbol;
1338
- const [a, b] = positive.args;
1339
- const [c, d] = getRelation(rule.args[1]).args;
1301
+ const a = positive.args[0];
1302
+ const b = positive.args[1];
1303
+ const negative = getRelation(rule.args[1]);
1304
+ const c = negative.args[0];
1305
+ const d = negative.args[1];
1340
1306
  const first = proof.subproofs[0];
1341
1307
  const second = proof.subproofs[1];
1342
1308
  if (relation === "=")
@@ -1365,7 +1331,8 @@ export const translateProof = (
1365
1331
  case "trans_eq_sym": {
1366
1332
  const negative = getRelation(rule.args[2]);
1367
1333
  const relation = negative.symbol;
1368
- const [c, d] = negative.args;
1334
+ const c = negative.args[0];
1335
+ const d = negative.args[1];
1369
1336
  const a = rule.args[0];
1370
1337
  const b = rule.args[1];
1371
1338
  const proofs = getThree(proof);
@@ -1402,7 +1369,6 @@ export const translateProof = (
1402
1369
  }
1403
1370
  };
1404
1371
 
1405
- // Zenon's make_ex.
1406
1372
  const makeExistential = (existential: Expr, subproof: MlProof) => {
1407
1373
  const binder = getBinder(existential, "ex");
1408
1374
  const witness = exprs.etau(binder.args[0], binder.symbol, binder.args[1]);
@@ -1410,7 +1376,6 @@ export const translateProof = (
1410
1376
  return makeNode([existential], { name: "ex", args: [existential] }, [[instance]], [subproof]);
1411
1377
  };
1412
1378
 
1413
- // Zenon's find_diff: the context in which two formulas differ, and the two subterms.
1414
1379
  const findDiff = (variable: VarExpr, left: Expr, right: Expr): [Expr, Expr, Expr] => {
1415
1380
  if (left === right) throw new TlaZenonError("Zenon: find_diff on equal formulas");
1416
1381
  if (left.kind === "app" && right.kind === "app" && left.symbol === right.symbol) {
@@ -1439,10 +1404,10 @@ export const translateProof = (
1439
1404
  ) {
1440
1405
  if (left.args[0] === right.args[0]) {
1441
1406
  const diff = findDiff(variable, left.args[1], right.args[1]);
1442
- return [connect(exprs, left.kind, left.args[0], diff[0]), diff[1], diff[2]];
1407
+ return [exprs.binary(left.kind, left.args[0], diff[0]), diff[1], diff[2]];
1443
1408
  }
1444
1409
  const diff = findDiff(variable, left.args[0], right.args[0]);
1445
- return [connect(exprs, left.kind, diff[0], left.args[1]), diff[1], diff[2]];
1410
+ return [exprs.binary(left.kind, diff[0], left.args[1]), diff[1], diff[2]];
1446
1411
  }
1447
1412
  if (
1448
1413
  left.kind === right.kind &&
@@ -1452,7 +1417,6 @@ export const translateProof = (
1452
1417
  return [variable, left, right];
1453
1418
  };
1454
1419
 
1455
- // Zenon's translate_pseudo_def: instantiates the defining hypothesis, then rewrites with it.
1456
1420
  const translatePseudoDefinition = (
1457
1421
  proof: MlProof,
1458
1422
  definition: Extract<Definition, { kind: "pseudo" }>,
@@ -1535,8 +1499,6 @@ export const translateProof = (
1535
1499
  const translated = translate(proof);
1536
1500
  const isCharged = (formula: Expr) =>
1537
1501
  !phrases.some((phrase) => phrase.kind === "hyp" && phrase.formula === formula);
1538
- // Zenon's discharge_extra: cuts each hypothesis about a relation that the phrases don't state,
1539
- // and proves it from the hypotheses that do.
1540
1502
  const discharged = translated[1].filter(isCharged).reduce((current: LlProof, extra): LlProof => {
1541
1503
  const relationProof = getRelationProof(extra);
1542
1504
  const proved = translate(relationProof[0]);
@@ -1,8 +1,4 @@
1
- // Ported from Zenon's node.ml and heap.ml, as shipped in tlapm. Copyright 2001-2004 INRIA, see
2
- // LICENSE.
3
- //
4
- // Tableau nodes and the queue that orders them. The search keeps the queue of every open branch,
5
- // so the queue is persistent: inserting or removing returns a new queue and shares the rest.
1
+ // Ported from Zenon's node.ml and heap.ml, as shipped in tlapm. Copyright 2001-2004 INRIA, see LICENSE.
6
2
 
7
3
  import type { Expr } from "./expr";
8
4
  import type { Rule } from "./proof";
@@ -32,7 +28,6 @@ const reverse = <Item>(list: List<Item>) => {
32
28
  return result;
33
29
  };
34
30
 
35
- // A node in the instance heap, with the size of the term that instantiates its formula.
36
31
  interface Entry {
37
32
  node: Node;
38
33
  size: number;
@@ -44,7 +39,6 @@ interface Tree {
44
39
  right: Tree | undefined;
45
40
  }
46
41
 
47
- // Zenon's Heap: a persistent binary heap that alternates insertion paths.
48
42
  interface Heap {
49
43
  tree: Tree | undefined;
50
44
  path: number;
@@ -101,8 +95,6 @@ export interface Queue {
101
95
  instSize: List<[number, Heap]>;
102
96
  instFront: List<Node>;
103
97
  instBack: List<Node>;
104
- // The nodes inserted since the root. Removed nodes still count, because the queues of the
105
- // branches above keep them.
106
98
  insertedCount: number;
107
99
  }
108
100
 
@@ -212,8 +204,6 @@ const removeAt = (
212
204
  return [removed[0], cons([list.head[0], removed[1]], list.tail)];
213
205
  };
214
206
 
215
- // On even states, the smallest instance of the most goal-directed formulas; on odd states, the
216
- // smallest instance overall.
217
207
  const removeByGoalness = (state: number, list: List<[number, Heap]>) => {
218
208
  if (state % 2 === 0) return removeAt(0, list);
219
209
  let best = 0;
@@ -1,14 +1,7 @@
1
- // The parts of OCaml's standard library whose exact behavior steers Zenon's search.
2
- //
3
- // Hashtbl.hash on the values Zenon hashes: strings, and the (int, string list) pairs that Expr
4
- // hashes. Zenon orders record fields by these hashes. Ints are 63-bit in OCaml, so an int is a
5
- // high part in [-2^30, 2^30) and a low part in [0, 2^32).
6
-
7
1
  const TWO_32 = 4294967296;
8
2
  const TWO_31 = 2147483648;
9
3
  const TWO_30 = 1073741824;
10
4
 
11
- // A block's header with its color bits cleared: two fields and tag 0, for a pair or a list cell.
12
5
  const PAIR_HEADER = 0x800;
13
6
 
14
7
  const MEANINGFUL_LIMIT = 10;
@@ -28,8 +21,6 @@ const finalMix = (hash: number) => {
28
21
  return ((second ^ (second >>> 16)) >>> 0) & 0x3fffffff;
29
22
  };
30
23
 
31
- // A string's UTF-8 bytes as the little-endian words that caml_hash_mix_string mixes, the last one
32
- // partial.
33
24
  interface StringWords {
34
25
  words: number[];
35
26
  length: number;
@@ -54,15 +45,12 @@ const mixWords = (hash: number, encoded: StringWords) => {
54
45
  return mixed ^ encoded.length;
55
46
  };
56
47
 
57
- // caml_hash_mix_intnat on the tagged value 2n + 1 of the int n.
58
48
  const mixInt = (hash: number, high: number, low: number) => {
59
49
  const taggedLow = (low * 2 + 1) % TWO_32;
60
50
  const taggedHigh = high * 2 + Math.floor((low * 2 + 1) / TWO_32);
61
51
  return mix(hash, (taggedHigh ^ (taggedHigh < 0 ? -1 : 0) ^ taggedLow) | 0);
62
52
  };
63
53
 
64
- // Hashtbl.hash on strings and on (int, string list) pairs. It keeps each string's words and hash,
65
- // because Zenon hashes the same variable names over and over.
66
54
  export const createHasher = () => {
67
55
  const stringWords = new Map<string, StringWords>();
68
56
  const stringHashes = new Map<string, number>();
@@ -103,7 +91,6 @@ export interface Int63 {
103
91
  low: number;
104
92
  }
105
93
 
106
- // Expr's combine: x + y * 131 + 1, wrapping like OCaml's 63-bit ints.
107
94
  export const combine = (left: Int63, right: Int63): Int63 => {
108
95
  const product = right.low * 131;
109
96
  const productCarry = Math.floor(product / TWO_32);
@@ -117,8 +104,6 @@ export const combine = (left: Int63, right: Int63): Int63 => {
117
104
 
118
105
  export const toInt63 = (value: number): Int63 => ({ high: 0, low: value });
119
106
 
120
- // The merges of OCaml's List.stable_sort, on arrays. Each returns its result reversed, as OCaml's
121
- // rev_merge and rev_merge_rev do.
122
107
  const mergeReversed = <Item>(
123
108
  first: Item[],
124
109
  second: Item[],
@@ -136,8 +121,7 @@ const mergeReversed = <Item>(
136
121
  return merged.reverse();
137
122
  };
138
123
 
139
- // OCaml's List.sort, step for step, so that a comparison that isn't a total order still gives
140
- // Zenon's result.
124
+ // OCaml's List.sort, step for step, so that a comparison that isn't a total order still gives Zenon's result.
141
125
  export const stableSort = <Item>(items: Item[], compare: (left: Item, right: Item) => number) => {
142
126
  const sortRun = (count: number, start: number, isReversed: boolean): Item[] => {
143
127
  const isBefore = (left: Item, right: Item) =>