tla-ts 0.0.9-dev.8298a52 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (390) hide show
  1. package/README.md +7 -0
  2. package/dist/compile.cjs +3 -3
  3. package/dist/compile.js +3 -3
  4. package/dist/deciders.cjs +28 -28
  5. package/dist/deciders.js +52 -52
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +71 -10
  8. package/dist/index.d.ts +71 -10
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +116 -36
  15. package/dist/prove.js +116 -36
  16. package/dist/run.cjs +141 -29
  17. package/dist/run.js +143 -31
  18. package/dist/tlapm.cjs +1 -1
  19. package/dist/tlapm.js +2 -2
  20. package/dist/transfer.cjs +128 -103
  21. package/dist/transfer.js +128 -103
  22. package/dist/worker.cjs +7 -7
  23. package/dist/worker.js +7 -7
  24. package/package.json +1 -1
  25. package/src/ast.ts +7 -21
  26. package/src/bags.ts +99 -99
  27. package/src/builtins.ts +44 -75
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check.ts +539 -276
  30. package/src/cli/options.ts +10 -5
  31. package/src/cli/run.ts +2 -2
  32. package/src/cli/runtime-invariants.ts +135 -0
  33. package/src/cli/shared.ts +20 -9
  34. package/src/cli/tlapm.ts +0 -12
  35. package/src/cli/tlc-arguments.ts +646 -0
  36. package/src/cli/tlc-usage.ts +362 -0
  37. package/src/cli/tlc.ts +525 -216
  38. package/src/cli/typescript.ts +0 -3
  39. package/src/cli/xml-exporter.ts +4 -16
  40. package/src/cli.ts +0 -1
  41. package/src/codegen.ts +191 -64
  42. package/src/config.ts +140 -109
  43. package/src/coverage.ts +837 -0
  44. package/src/dependencies.ts +6 -40
  45. package/src/dfid.ts +618 -0
  46. package/src/environment.ts +237 -119
  47. package/src/errors.ts +56 -56
  48. package/src/evaluate.ts +567 -289
  49. package/src/exit-codes.ts +37 -3
  50. package/src/fingerprints.ts +10 -10
  51. package/src/index.ts +3 -0
  52. package/src/instances.ts +38 -31
  53. package/src/java-overrides.ts +2 -12
  54. package/src/json-reader.ts +456 -0
  55. package/src/json.ts +262 -139
  56. package/src/levels.ts +2 -3
  57. package/src/lexer.ts +17 -26
  58. package/src/liveness-checker.ts +4 -15
  59. package/src/liveness.ts +115 -47
  60. package/src/obligations/action.ts +4 -28
  61. package/src/obligations/anonymize.ts +84 -80
  62. package/src/obligations/equality.ts +1 -1
  63. package/src/obligations/expression.ts +2 -19
  64. package/src/obligations/format.ts +1 -9
  65. package/src/obligations/generate.ts +1 -11
  66. package/src/obligations/index.ts +0 -11
  67. package/src/obligations/levels.ts +4 -8
  68. package/src/obligations/module.ts +1 -15
  69. package/src/obligations/normalize.ts +5 -24
  70. package/src/obligations/operators.ts +1 -2
  71. package/src/obligations/pragma.ts +1 -10
  72. package/src/obligations/printer.ts +47 -46
  73. package/src/obligations/proof.ts +1 -5
  74. package/src/obligations/regroup.ts +1 -4
  75. package/src/obligations/simplify.ts +3 -14
  76. package/src/obligations/source.ts +1 -21
  77. package/src/obligations/subexpression.ts +5 -11
  78. package/src/obligations/substitution.ts +1 -3
  79. package/src/obligations/temporal.ts +8 -14
  80. package/src/obligations/tuples.ts +3 -9
  81. package/src/parallel-worker.ts +24 -33
  82. package/src/parallel.ts +24 -9
  83. package/src/parser.ts +436 -90
  84. package/src/pcal/ast.ts +7 -28
  85. package/src/pcal/parse.ts +11 -39
  86. package/src/pcal/tokenize.ts +4 -20
  87. package/src/pcal/translate.ts +10 -42
  88. package/src/pcal/validate.ts +3 -21
  89. package/src/pretty-print.ts +1 -2
  90. package/src/prover/decide-pool.ts +5 -10
  91. package/src/prover/deciders.ts +0 -4
  92. package/src/prover/first-order.ts +0 -11
  93. package/src/prover/isabelle/decide.ts +0 -6
  94. package/src/prover/isabelle/encode.ts +11 -23
  95. package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
  96. package/src/prover/isabelle/isar/method.ts +25 -38
  97. package/src/prover/isabelle/isar/proof.ts +1 -10
  98. package/src/prover/isabelle/isar/statement.ts +1 -6
  99. package/src/prover/isabelle/isar/theory.ts +15 -26
  100. package/src/prover/isabelle/isar/type-check.ts +11 -25
  101. package/src/prover/isabelle/provers/blast/blast.ts +10 -41
  102. package/src/prover/isabelle/provers/blast/branch.ts +1 -32
  103. package/src/prover/isabelle/provers/blast/prove.ts +1 -35
  104. package/src/prover/isabelle/provers/blast/rules.ts +6 -44
  105. package/src/prover/isabelle/provers/blast/state.ts +2 -28
  106. package/src/prover/isabelle/provers/blast/term.ts +9 -36
  107. package/src/prover/isabelle/provers/clasimp.ts +1 -13
  108. package/src/prover/isabelle/provers/classical.ts +14 -42
  109. package/src/prover/isabelle/provers/hypsubst.ts +11 -25
  110. package/src/prover/isabelle/pure/bicompose.ts +16 -13
  111. package/src/prover/isabelle/pure/consts.ts +1 -7
  112. package/src/prover/isabelle/pure/conv.ts +1 -9
  113. package/src/prover/isabelle/pure/drule.ts +24 -40
  114. package/src/prover/isabelle/pure/envir.ts +3 -52
  115. package/src/prover/isabelle/pure/goal.ts +1 -7
  116. package/src/prover/isabelle/pure/interrupt.ts +0 -5
  117. package/src/prover/isabelle/pure/list.ts +0 -3
  118. package/src/prover/isabelle/pure/logic.ts +1 -14
  119. package/src/prover/isabelle/pure/name.ts +2 -9
  120. package/src/prover/isabelle/pure/net.ts +3 -59
  121. package/src/prover/isabelle/pure/object-logic.ts +3 -10
  122. package/src/prover/isabelle/pure/pattern.ts +2 -19
  123. package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
  124. package/src/prover/isabelle/pure/rewriter.ts +26 -58
  125. package/src/prover/isabelle/pure/search.ts +3 -10
  126. package/src/prover/isabelle/pure/seq.ts +1 -10
  127. package/src/prover/isabelle/pure/simplifier.ts +4 -12
  128. package/src/prover/isabelle/pure/table.ts +1 -31
  129. package/src/prover/isabelle/pure/tactic.ts +12 -22
  130. package/src/prover/isabelle/pure/tactical.ts +6 -12
  131. package/src/prover/isabelle/pure/term-ord.ts +2 -6
  132. package/src/prover/isabelle/pure/term.ts +2 -43
  133. package/src/prover/isabelle/pure/thm.ts +13 -36
  134. package/src/prover/isabelle/pure/type.ts +2 -15
  135. package/src/prover/isabelle/pure/unify.ts +20 -30
  136. package/src/prover/isabelle/pure/variable.ts +3 -7
  137. package/src/prover/isabelle/tla/classical-setup.ts +9 -19
  138. package/src/prover/isabelle/tla/context.ts +8 -16
  139. package/src/prover/isabelle/tla/logic.ts +4 -11
  140. package/src/prover/isabelle/tla/simpdata.ts +46 -34
  141. package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
  142. package/src/prover/ocaml.ts +0 -6
  143. package/src/prover/prep/action.ts +4 -36
  144. package/src/prover/prep/enabled-axioms.ts +12 -19
  145. package/src/prover/prep/fingerprint.ts +0 -16
  146. package/src/prover/prep/level-comparison.ts +8 -12
  147. package/src/prover/prep/md5.ts +0 -2
  148. package/src/prover/prep/methods.ts +9 -36
  149. package/src/prover/prep/normalize.ts +4 -28
  150. package/src/prover/prove-worker.ts +0 -2
  151. package/src/prover/prove.ts +0 -36
  152. package/src/prover/ptl/decide.ts +7 -12
  153. package/src/prover/ptl/encode.ts +14 -36
  154. package/src/prover/ptl/sat.ts +24 -32
  155. package/src/prover/ptl/tableau.ts +12 -26
  156. package/src/prover/smt/axioms.ts +0 -7
  157. package/src/prover/smt/context.ts +19 -26
  158. package/src/prover/smt/data.ts +51 -54
  159. package/src/prover/smt/encode.ts +14 -35
  160. package/src/prover/smt/extensionality.ts +0 -10
  161. package/src/prover/smt/flatten.ts +3 -22
  162. package/src/prover/smt/format.ts +5 -10
  163. package/src/prover/smt/instances.ts +0 -10
  164. package/src/prover/smt/rewrite.ts +66 -101
  165. package/src/prover/smt/solver/act-cache.ts +0 -15
  166. package/src/prover/smt/solver/arith-rewriter.ts +3 -48
  167. package/src/prover/smt/solver/array.ts +1 -3
  168. package/src/prover/smt/solver/asserted-formulas.ts +1 -43
  169. package/src/prover/smt/solver/ast-lt.ts +1 -11
  170. package/src/prover/smt/solver/ast-util.ts +1 -6
  171. package/src/prover/smt/solver/ast.ts +1 -143
  172. package/src/prover/smt/solver/auf-solver.ts +6 -39
  173. package/src/prover/smt/solver/case-split-queue.ts +1 -9
  174. package/src/prover/smt/solver/cg-table.ts +1 -18
  175. package/src/prover/smt/solver/clause.ts +1 -27
  176. package/src/prover/smt/solver/conflict-resolution.ts +0 -9
  177. package/src/prover/smt/solver/context.ts +4 -61
  178. package/src/prover/smt/solver/ctx-simplify.ts +14 -41
  179. package/src/prover/smt/solver/der.ts +2 -21
  180. package/src/prover/smt/solver/dyn-ack.ts +1 -11
  181. package/src/prover/smt/solver/e-matching.ts +3 -34
  182. package/src/prover/smt/solver/enode.ts +1 -21
  183. package/src/prover/smt/solver/expr-ref.ts +1 -5
  184. package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
  185. package/src/prover/smt/solver/fingerprints.ts +1 -12
  186. package/src/prover/smt/solver/flat-literals.ts +1 -9
  187. package/src/prover/smt/solver/goal.ts +2 -14
  188. package/src/prover/smt/solver/hash.ts +0 -8
  189. package/src/prover/smt/solver/hashtable.ts +1 -12
  190. package/src/prover/smt/solver/internalizer.ts +6 -98
  191. package/src/prover/smt/solver/lbool.ts +1 -2
  192. package/src/prover/smt/solver/literal.ts +0 -3
  193. package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
  194. package/src/prover/smt/solver/lp/constraints.ts +2 -8
  195. package/src/prover/smt/solver/lp/containers.ts +12 -30
  196. package/src/prover/smt/solver/lp/core-solver.ts +10 -31
  197. package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
  198. package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
  199. package/src/prover/smt/solver/lp/dependency.ts +1 -4
  200. package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
  201. package/src/prover/smt/solver/lp/explanation.ts +1 -6
  202. package/src/prover/smt/solver/lp/gomory.ts +9 -22
  203. package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
  204. package/src/prover/smt/solver/lp/hnf.ts +11 -26
  205. package/src/prover/smt/solver/lp/int-cube.ts +15 -36
  206. package/src/prover/smt/solver/lp/int-solver.ts +4 -34
  207. package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
  208. package/src/prover/smt/solver/lp/lar-term.ts +1 -5
  209. package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
  210. package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
  211. package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
  212. package/src/prover/smt/solver/lp/nex.ts +1 -6
  213. package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
  214. package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
  215. package/src/prover/smt/solver/lp/nla-core.ts +35 -130
  216. package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
  217. package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
  218. package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
  219. package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
  220. package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
  221. package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
  222. package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
  223. package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
  224. package/src/prover/smt/solver/lp/nla-order.ts +2 -13
  225. package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
  226. package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
  227. package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
  228. package/src/prover/smt/solver/lp/nla-types.ts +1 -11
  229. package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
  230. package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
  231. package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
  232. package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
  233. package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
  234. package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
  235. package/src/prover/smt/solver/lp/pdd.ts +7 -70
  236. package/src/prover/smt/solver/lp/random-updater.ts +1 -8
  237. package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
  238. package/src/prover/smt/solver/lp/union-find.ts +1 -6
  239. package/src/prover/smt/solver/mam-compiler.ts +14 -56
  240. package/src/prover/smt/solver/mam-interpreter.ts +1 -21
  241. package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
  242. package/src/prover/smt/solver/model-checker.ts +2 -36
  243. package/src/prover/smt/solver/model-evaluator.ts +3 -29
  244. package/src/prover/smt/solver/model-finder.ts +3 -15
  245. package/src/prover/smt/solver/model-generator.ts +1 -12
  246. package/src/prover/smt/solver/model-macro-solver.ts +12 -69
  247. package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
  248. package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
  249. package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
  250. package/src/prover/smt/solver/nlsat/explain.ts +3 -47
  251. package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
  252. package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
  253. package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
  254. package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
  255. package/src/prover/smt/solver/nlsat/solver.ts +7 -67
  256. package/src/prover/smt/solver/nlsat/types.ts +1 -8
  257. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
  258. package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
  259. package/src/prover/smt/solver/nnf.ts +3 -38
  260. package/src/prover/smt/solver/pattern-inference.ts +2 -15
  261. package/src/prover/smt/solver/poly-rewriter.ts +3 -23
  262. package/src/prover/smt/solver/propagate-values.ts +1 -10
  263. package/src/prover/smt/solver/proto-model.ts +3 -48
  264. package/src/prover/smt/solver/pull-quant.ts +1 -12
  265. package/src/prover/smt/solver/qe-lite-der.ts +1 -29
  266. package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
  267. package/src/prover/smt/solver/qe-lite.ts +3 -33
  268. package/src/prover/smt/solver/qi-queue.ts +1 -16
  269. package/src/prover/smt/solver/quant-tactics.ts +5 -22
  270. package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
  271. package/src/prover/smt/solver/quantifier-manager.ts +1 -8
  272. package/src/prover/smt/solver/random-gen.ts +1 -2
  273. package/src/prover/smt/solver/rational.ts +1 -8
  274. package/src/prover/smt/solver/ref-vector.ts +1 -6
  275. package/src/prover/smt/solver/relevancy.ts +2 -15
  276. package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
  277. package/src/prover/smt/solver/rewriter.ts +3 -85
  278. package/src/prover/smt/solver/rlimit.ts +2 -20
  279. package/src/prover/smt/solver/smtlib-parser.ts +2 -37
  280. package/src/prover/smt/solver/solver.ts +1 -16
  281. package/src/prover/smt/solver/sort.ts +1 -5
  282. package/src/prover/smt/solver/sticky-generations.ts +0 -5
  283. package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
  284. package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
  285. package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
  286. package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
  287. package/src/prover/smt/solver/theory-lra-model.ts +4 -19
  288. package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
  289. package/src/prover/smt/solver/theory-lra-state.ts +3 -8
  290. package/src/prover/smt/solver/theory-lra.ts +1 -8
  291. package/src/prover/smt/solver/var-subst.ts +2 -26
  292. package/src/prover/smt/table.ts +0 -8
  293. package/src/prover/tlapm/cache.ts +20 -25
  294. package/src/prover/tlapm/ocaml-marshal.ts +19 -21
  295. package/src/prover/tlapm/tlapm.ts +12 -17
  296. package/src/prover/verdict.ts +0 -2
  297. package/src/prover/zenon/check/check.ts +0 -9
  298. package/src/prover/zenon/check/definitions.ts +5 -15
  299. package/src/prover/zenon/check/equality.ts +0 -8
  300. package/src/prover/zenon/check/functions.ts +0 -4
  301. package/src/prover/zenon/check/keys.ts +0 -7
  302. package/src/prover/zenon/check/propositional.ts +0 -3
  303. package/src/prover/zenon/check/records.ts +0 -5
  304. package/src/prover/zenon/check/relations.ts +0 -13
  305. package/src/prover/zenon/check/rewrites.ts +0 -6
  306. package/src/prover/zenon/check/sets.ts +0 -3
  307. package/src/prover/zenon/check/terms.ts +0 -17
  308. package/src/prover/zenon/check/tla.ts +0 -6
  309. package/src/prover/zenon/decide.ts +0 -12
  310. package/src/prover/zenon/encode.ts +1 -8
  311. package/src/prover/zenon/eqrel.ts +0 -13
  312. package/src/prover/zenon/equality-rules.ts +0 -4
  313. package/src/prover/zenon/expr.ts +1 -26
  314. package/src/prover/zenon/index-table.ts +17 -38
  315. package/src/prover/zenon/isar-case.ts +9 -19
  316. package/src/prover/zenon/isar.ts +1 -29
  317. package/src/prover/zenon/limits.ts +0 -4
  318. package/src/prover/zenon/llproof.ts +0 -9
  319. package/src/prover/zenon/mltoll.ts +54 -76
  320. package/src/prover/zenon/node.ts +1 -11
  321. package/src/prover/zenon/ocaml.ts +1 -17
  322. package/src/prover/zenon/parse.ts +2 -7
  323. package/src/prover/zenon/phrase.ts +1 -11
  324. package/src/prover/zenon/proof.ts +0 -9
  325. package/src/prover/zenon/propositional-rules.ts +0 -5
  326. package/src/prover/zenon/rules.ts +2 -6
  327. package/src/prover/zenon/search.ts +1 -17
  328. package/src/prover/zenon/tla/functions.ts +57 -29
  329. package/src/prover/zenon/tla/llproof.ts +63 -70
  330. package/src/prover/zenon/tla/records.ts +56 -27
  331. package/src/prover/zenon/tla/rewrites.ts +12 -19
  332. package/src/prover/zenon/tla/sets.ts +68 -39
  333. package/src/prover/zenon/tla/terms.ts +0 -6
  334. package/src/prover/zenon/tla/tla.ts +59 -58
  335. package/src/randomization.ts +84 -35
  336. package/src/resolve.ts +18 -60
  337. package/src/runtime.ts +11 -4
  338. package/src/sany/builtins.ts +3 -4
  339. package/src/sany/generator.ts +119 -169
  340. package/src/sany/levels.ts +6 -30
  341. package/src/sany/lexer.ts +7 -23
  342. package/src/sany/linter.ts +1 -8
  343. package/src/sany/modules.ts +1 -5
  344. package/src/sany/nodes.ts +0 -31
  345. package/src/sany/parse-error.ts +39 -117
  346. package/src/sany/report.ts +29 -63
  347. package/src/sany/selectors.ts +15 -39
  348. package/src/sany/source.ts +1 -17
  349. package/src/sany/xml.ts +13 -63
  350. package/src/search.ts +494 -154
  351. package/src/simulate.ts +694 -0
  352. package/src/spec-description.ts +166 -48
  353. package/src/standard-definitions.ts +2 -3
  354. package/src/standard-modules.ts +264 -68
  355. package/src/state-graph.ts +51 -18
  356. package/src/subexpressions.ts +31 -5
  357. package/src/substitution-levels.ts +2 -3
  358. package/src/successors.ts +264 -74
  359. package/src/symmetry.ts +31 -8
  360. package/src/tableau.ts +27 -24
  361. package/src/tlc/fingerprint.ts +183 -61
  362. package/src/tlc/jar-data.ts +113 -6
  363. package/src/tlc/messages.ts +122 -37
  364. package/src/tlc/order.ts +33 -38
  365. package/src/tlc/random.ts +16 -16
  366. package/src/tlc/replay.ts +563 -211
  367. package/src/tlc/summary.ts +2 -4
  368. package/src/tlc/tlc-operators.ts +81 -36
  369. package/src/tlc/tlcext-operators.ts +138 -117
  370. package/src/tlc/trace-spec.ts +273 -0
  371. package/src/tlc/value-stream.ts +143 -0
  372. package/src/tlc/version.ts +2 -4
  373. package/src/transfer.ts +22 -25
  374. package/src/typescript/actions.ts +8 -21
  375. package/src/typescript/collections.ts +0 -15
  376. package/src/typescript/compile.ts +0 -5
  377. package/src/typescript/context.ts +0 -12
  378. package/src/typescript/emit.ts +0 -1
  379. package/src/typescript/expressions.ts +0 -12
  380. package/src/typescript/formula.ts +4 -12
  381. package/src/typescript/functions.ts +6 -17
  382. package/src/typescript/model.ts +10 -11
  383. package/src/typescript/names.ts +0 -2
  384. package/src/typescript/program.ts +0 -3
  385. package/src/typescript/properties.ts +6 -8
  386. package/src/typescript/scope.ts +0 -5
  387. package/src/typescript/steps.ts +0 -10
  388. package/src/typescript/types.ts +1 -8
  389. package/src/values.ts +793 -267
  390. package/src/worker.ts +7 -8
@@ -1,7 +1,4 @@
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
4
  import type { Direction, Origin, Relations } from "./eqrel";
@@ -18,8 +15,7 @@ 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,17 @@ 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
35
  type RelationProperty = "reflexive" | "symmetric" | "transitive";
43
36
 
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
37
  type HypothesisKind =
47
38
  | { kind: "reflexive"; origin: Origin }
48
39
  | { kind: "symmetric"; origin: Origin }
@@ -61,7 +52,6 @@ export const isMetaName = (name: string) => name.startsWith(META_PREFIX);
61
52
 
62
53
  const isAlphanumeric = (char: string) => /^[A-Za-z0-9]$/.test(char);
63
54
 
64
- // Zenon's type_to_ident.
65
55
  const toIdentifier = (type: string) =>
66
56
  [...type]
67
57
  .map((char) =>
@@ -79,7 +69,6 @@ const getSingle = (proof: MlProof) => {
79
69
  return proof.subproofs[0];
80
70
  };
81
71
 
82
- // Zenon's Mlproof.make_node: the node's conclusions and those its subproofs leave open.
83
72
  const makeNode = (
84
73
  conclusions: Expr[],
85
74
  rule: MlRule,
@@ -119,7 +108,6 @@ const isDerived = (rule: MlRule) => {
119
108
  }
120
109
  };
121
110
 
122
- // The rules that tr_rule translates directly: the core rules and the extension rules named "".
123
111
  const CORE_RULES = new Set<string>([
124
112
  "close",
125
113
  "false",
@@ -150,7 +138,6 @@ const CORE_RULES = new Set<string>([
150
138
  "stringdiffrr",
151
139
  ]);
152
140
 
153
- // Zenon's Mltoll.translate: the lemmas in the order they were made, then the theorem.
154
141
  export const translateProof = (
155
142
  context: TranslateContext,
156
143
  phrases: Phrase[],
@@ -165,7 +152,6 @@ export const translateProof = (
165
152
 
166
153
  const equal = (left: Expr, right: Expr) => exprs.eapp("=", [left, right]);
167
154
 
168
- // Zenon's tr_expr: metavariables become variables named after their quantifier.
169
155
  const translateExpr = (expression: Expr): Expr => {
170
156
  if (expression.metas.length === 0) return expression;
171
157
  const cached = translatedExprs.get(expression);
@@ -219,31 +205,30 @@ export const translateProof = (
219
205
  : exprs.elam(variable, type, body);
220
206
 
221
207
  const translateRule = (rule: MlRule): LlRule => {
222
- const tr = translateExpr;
223
208
  switch (rule.name) {
224
209
  case "close":
225
- return { kind: "axiom", formula: tr(rule.args[0]) };
210
+ return { kind: "axiom", formula: translateExpr(rule.args[0]) };
226
211
  case "close_refl":
227
- return { kind: "noteq", term: tr(rule.args[0]) };
212
+ return { kind: "noteq", term: translateExpr(rule.args[0]) };
228
213
  case "close_sym": {
229
- const right = tr(rule.args[1]);
230
- return { kind: "eqsym", left: tr(rule.args[0]), right };
214
+ const right = translateExpr(rule.args[1]);
215
+ return { kind: "eqsym", left: translateExpr(rule.args[0]), right };
231
216
  }
232
217
  case "false":
233
218
  return { kind: "false" };
234
219
  case "not_true":
235
220
  return { kind: "nottrue" };
236
221
  case "not_not":
237
- return { kind: "notnot", formula: tr(rule.args[0]) };
222
+ return { kind: "notnot", formula: translateExpr(rule.args[0]) };
238
223
  case "and":
239
224
  case "or":
240
225
  case "impl":
241
226
  case "equiv": {
242
- const right = tr(rule.args[1]);
227
+ const right = translateExpr(rule.args[1]);
243
228
  return {
244
229
  kind: "connect",
245
230
  connective: RULE_CONNECTIVES[rule.name],
246
- left: tr(rule.args[0]),
231
+ left: translateExpr(rule.args[0]),
247
232
  right,
248
233
  };
249
234
  }
@@ -251,57 +236,59 @@ export const translateProof = (
251
236
  case "not_impl":
252
237
  case "not_and":
253
238
  case "not_equiv": {
254
- const right = tr(rule.args[1]);
239
+ const right = translateExpr(rule.args[1]);
255
240
  return {
256
241
  kind: "notconnect",
257
242
  connective: RULE_CONNECTIVES[rule.name],
258
- left: tr(rule.args[0]),
243
+ left: translateExpr(rule.args[0]),
259
244
  right,
260
245
  };
261
246
  }
262
247
  case "ex": {
263
248
  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 };
249
+ const term = translateExpr(
250
+ exprs.etau(quantified.args[0], quantified.symbol, quantified.args[1]),
251
+ );
252
+ return { kind: "ex", quantified: translateExpr(quantified), term };
266
253
  }
267
254
  case "all": {
268
- const term = tr(rule.args[1]);
269
- return { kind: "all", quantified: tr(rule.args[0]), term };
255
+ const term = translateExpr(rule.args[1]);
256
+ return { kind: "all", quantified: translateExpr(rule.args[0]), term };
270
257
  }
271
258
  case "not_ex": {
272
259
  const negation = rule.args[0];
273
260
  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 };
261
+ const term = translateExpr(rule.args[1]);
262
+ return { kind: "notex", quantified: translateExpr(negation.args[0]), term };
276
263
  }
277
264
  case "p_not_p": {
278
- const negative = tr(rule.args[1]);
279
- return { kind: "pnotp", positive: tr(rule.args[0]), negative };
265
+ const negative = translateExpr(rule.args[1]);
266
+ return { kind: "pnotp", positive: translateExpr(rule.args[0]), negative };
280
267
  }
281
268
  case "not_equal": {
282
- const right = tr(rule.args[1]);
283
- return { kind: "notequal", left: tr(rule.args[0]), right };
269
+ const right = translateExpr(rule.args[1]);
270
+ return { kind: "notequal", left: translateExpr(rule.args[0]), right };
284
271
  }
285
272
  case "definition": {
286
273
  if (rule.definition.kind !== "real")
287
274
  throw new TlaZenonError("Zenon: a pseudo-definition in tr_rule");
288
- const unfolded = tr(rule.args[1]);
275
+ const unfolded = translateExpr(rule.args[1]);
289
276
  return {
290
277
  kind: "definition",
291
278
  name: rule.definition.name,
292
- folded: tr(rule.args[0]),
279
+ folded: translateExpr(rule.args[0]),
293
280
  unfolded,
294
281
  };
295
282
  }
296
283
  case "cut":
297
- return { kind: "cut", formula: tr(rule.args[0]) };
284
+ return { kind: "cut", formula: translateExpr(rule.args[0]) };
298
285
  case "congruence_lr":
299
286
  case "congruence_rl": {
300
- const right = tr(rule.args[2]);
301
- const left = tr(rule.args[1]);
287
+ const right = translateExpr(rule.args[2]);
288
+ const left = translateExpr(rule.args[1]);
302
289
  return {
303
290
  kind: rule.name === "congruence_lr" ? "congruencelr" : "congruencerl",
304
- context: tr(rule.args[0]),
291
+ context: translateExpr(rule.args[0]),
305
292
  left,
306
293
  right,
307
294
  };
@@ -309,10 +296,10 @@ export const translateProof = (
309
296
  case "notall": {
310
297
  const negation = rule.args[0];
311
298
  const quantified = getBinder(negation.kind === "not" ? negation.args[0] : negation, "all");
312
- const term = tr(
299
+ const term = translateExpr(
313
300
  exprs.etau(quantified.args[0], quantified.symbol, exprs.enot(quantified.args[1])),
314
301
  );
315
- return { kind: "notall", quantified: tr(quantified), term };
302
+ return { kind: "notall", quantified: translateExpr(quantified), term };
316
303
  }
317
304
  case "notallex": {
318
305
  const lambda = getBinder(rule.args[0], "lam");
@@ -344,7 +331,10 @@ export const translateProof = (
344
331
  case "stringdifflr":
345
332
  case "stringdiffrl":
346
333
  case "stringdiffrr": {
347
- const [first, firstValue, second, secondValue] = rule.args;
334
+ const first = rule.args[0];
335
+ const firstValue = rule.args[1];
336
+ const second = rule.args[2];
337
+ const secondValue = rule.args[3];
348
338
  const isFirstLeft = rule.name === "stringdiffll" || rule.name === "stringdifflr";
349
339
  const isSecondLeft = rule.name === "stringdiffll" || rule.name === "stringdiffrl";
350
340
  const firstConclusion = isFirstLeft ? equal(first, firstValue) : equal(firstValue, first);
@@ -366,7 +356,6 @@ export const translateProof = (
366
356
  }
367
357
  };
368
358
 
369
- // Zenon's get_params: the free taus of a lemma's conclusions, each with its type.
370
359
  const getParams = (accumulated: [string, Expr][], expression: Expr): [string, Expr][] => {
371
360
  const merge = (type: string, term: Expr): [string, Expr][] =>
372
361
  accumulated.some((param) => param[1] === term) ? accumulated : [[type, term], ...accumulated];
@@ -435,7 +424,6 @@ export const translateProof = (
435
424
  const isSharedProof = (proof: MlProof) =>
436
425
  context.sharedProofs.has(proof) && !lemmaNumbers.has(proof);
437
426
 
438
- // Zenon's get_sub: the subproofs, and the union of their extras from the right.
439
427
  const translateAll = (proofs: MlProof[]): [LlProof[], Expr[]] => {
440
428
  const translated = proofs.map(translate);
441
429
  return [
@@ -444,7 +432,6 @@ export const translateProof = (
444
432
  ];
445
433
  };
446
434
 
447
- // A node of recomp_conj, with the formulas it removes from its subproof's conclusions.
448
435
  const recompose = (
449
436
  conclusion: Expr,
450
437
  rule: LlRule,
@@ -518,12 +505,11 @@ export const translateProof = (
518
505
  }
519
506
  };
520
507
 
521
- // Zenon's recomp_disj: consumes the translated subproofs, one for each disjunct.
522
508
  const recompDisj = (subs: Translated[], formula: Expr): [LlProof, Expr[], Translated[]] => {
523
509
  const node = (
524
510
  conclusion: Expr,
525
511
  connectiveName: Connective,
526
- negated: boolean,
512
+ isNegated: boolean,
527
513
  left: Expr,
528
514
  right: Expr,
529
515
  first: [LlProof, Expr[], Translated[]],
@@ -540,7 +526,12 @@ export const translateProof = (
540
526
  difference(second[0].conclusions, [secondRemoved]),
541
527
  ),
542
528
  ),
543
- rule: { kind: negated ? "notconnect" : "connect", connective: connectiveName, left, right },
529
+ rule: {
530
+ kind: isNegated ? "notconnect" : "connect",
531
+ connective: connectiveName,
532
+ left,
533
+ right,
534
+ },
544
535
  subproofs: [first[0], second[0]],
545
536
  },
546
537
  difference(union(first[1], second[1]), [extra]),
@@ -643,7 +634,6 @@ export const translateProof = (
643
634
  return [subs[0][0], subs[0][1], subs.slice(1)];
644
635
  };
645
636
 
646
- // The constructors of Zenon's Mlproof, for the proofs that the translation builds.
647
637
  const makeClose = (formula: Expr) =>
648
638
  makeNode([formula, exprs.enot(formula)], { name: "close", args: [formula] }, [], []);
649
639
  const makeCloseRefl = (relation: string, term: Expr) =>
@@ -704,7 +694,6 @@ export const translateProof = (
704
694
  const instance = exprs.substitute([[binder.args[0], terms[0]]], binder.args[1]);
705
695
  return makeAll(quantified, terms[0], makeAlls(instance, terms.slice(1), subproof));
706
696
  };
707
- // Zenon's make_impls: the implications from `hypotheses` to `conclusion`, and their proof.
708
697
  const makeImplies = (
709
698
  hypotheses: Expr[],
710
699
  conclusion: Expr,
@@ -737,8 +726,6 @@ export const translateProof = (
737
726
  [first, second],
738
727
  );
739
728
 
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
729
  const relationHypotheses = new Map<string, Expr>();
743
730
  const hypothesisKinds = new Map<Expr, HypothesisKind>();
744
731
  const getRelationHypothesis = (property: RelationProperty, relation: string) => {
@@ -795,7 +782,6 @@ export const translateProof = (
795
782
  return hypothesis;
796
783
  };
797
784
 
798
- // Zenon's inst_nall: the instance of a negated universal at its counterexample.
799
785
  const instantiateNegation = (negation: Expr): [Expr, Expr] => {
800
786
  if (negation.kind !== "not") throw new TlaZenonError("Zenon: inst_nall without a negation");
801
787
  const binder = getBinder(negation.args[0], "all");
@@ -804,7 +790,6 @@ export const translateProof = (
804
790
  return [exprs.substitute([[binder.args[0], witness]], body), witness];
805
791
  };
806
792
 
807
- // Zenon's decompose_disj: closes each literal of a disjunction with one of `forms`.
808
793
  const decomposeDisjunction = (formula: Expr, forms: Expr[]): MlProof => {
809
794
  const visit = (disjunct: Expr) => decomposeDisjunction(disjunct, forms);
810
795
  const getForm = (form: Expr) => {
@@ -867,8 +852,6 @@ export const translateProof = (
867
852
  }
868
853
  };
869
854
 
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
855
  const decomposeConjunction = (
873
856
  position: number,
874
857
  formula: Expr,
@@ -986,8 +969,6 @@ export const translateProof = (
986
969
  return decomposeDisjunction(formula, forms);
987
970
  };
988
971
 
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
972
  const getRelationProof = (hypothesis: Expr): [MlProof, Expr[]] => {
992
973
  const kind = hypothesisKinds.get(hypothesis);
993
974
  if (kind === undefined)
@@ -1124,7 +1105,6 @@ export const translateProof = (
1124
1105
 
1125
1106
  const relate = (relation: string, left: Expr, right: Expr) => exprs.eapp(relation, [left, right]);
1126
1107
 
1127
- // Zenon's make_direct_trans: r(a, b), r(b, c) / r(a, c) / (proof).
1128
1108
  const makeDirectTrans = (relation: string, a: Expr, b: Expr, c: Expr, proof: MlProof) => {
1129
1109
  const hypothesis = getRelationHypothesis("transitive", relation);
1130
1110
  const ab = relate(relation, a, b);
@@ -1137,21 +1117,18 @@ export const translateProof = (
1137
1117
  );
1138
1118
  return makeAlls(hypothesis, [a, b, c], implied[1]);
1139
1119
  };
1140
- // Zenon's make_direct_nsym: -r(a, b) / -r(b, a) / (proof).
1141
1120
  const makeDirectNotSym = (relation: string, a: Expr, b: Expr, proof: MlProof) => {
1142
1121
  const hypothesis = getRelationHypothesis("symmetric", relation);
1143
1122
  const ab = relate(relation, a, b);
1144
1123
  const ba = relate(relation, b, a);
1145
1124
  return makeAlls(hypothesis, [b, a], makeImply(ba, ab, proof, makeClose(ab)));
1146
1125
  };
1147
- // Zenon's make_direct_sym_neq: a != b / b != a / (proof).
1148
1126
  const makeSymmetricDisequality = (a: Expr, b: Expr, proof: MlProof) => {
1149
1127
  const reflexive = equal(b, b);
1150
1128
  const refuted = makeCloseRefl("=", b);
1151
1129
  const swapped = makePNotP(reflexive, exprs.enot(equal(a, b)), [proof, refuted]);
1152
1130
  return makeCut(reflexive, swapped, refuted);
1153
1131
  };
1154
- // Zenon's make_direct_sym_eq: a = b / b = a / (proof).
1155
1132
  const makeSymmetricEquality = (a: Expr, b: Expr, proof: MlProof) => {
1156
1133
  const ab = equal(a, b);
1157
1134
  return makeCut(equal(b, a), proof, makeSymmetricDisequality(b, a, makeClose(ab)));
@@ -1265,7 +1242,6 @@ export const translateProof = (
1265
1242
  return [proof.subproofs[0], proof.subproofs[1], proof.subproofs[2]];
1266
1243
  };
1267
1244
 
1268
- // A derived rule's expansion, with the hypotheses it relies on that no phrase may state.
1269
1245
  const translateWith = (expanded: MlProof, hypotheses: Expr[]): Translated => {
1270
1246
  const translated = translate(expanded);
1271
1247
  return [translated[0], union(hypotheses, translated[1])];
@@ -1295,7 +1271,8 @@ export const translateProof = (
1295
1271
  }
1296
1272
  case "close_sym": {
1297
1273
  const hypothesis = getRelationHypothesis("symmetric", rule.relation);
1298
- const [a, b] = rule.args;
1274
+ const a = rule.args[0];
1275
+ const b = rule.args[1];
1299
1276
  const ab = relate(rule.relation, a, b);
1300
1277
  const ba = relate(rule.relation, b, a);
1301
1278
  const implied = makeImply(ab, ba, makeClose(ab), makeClose(ba));
@@ -1310,7 +1287,8 @@ export const translateProof = (
1310
1287
  }
1311
1288
  case "refl": {
1312
1289
  const hypothesis = getRelationHypothesis("reflexive", rule.relation);
1313
- const [a, b] = rule.args;
1290
+ const a = rule.args[0];
1291
+ const b = rule.args[1];
1314
1292
  const reflexive = relate(rule.relation, a, a);
1315
1293
  const negated = exprs.enot(relate(rule.relation, a, b));
1316
1294
  const closed = makePNotP(reflexive, negated, [makeCloseRefl("=", a), getSingle(proof)]);
@@ -1325,7 +1303,8 @@ export const translateProof = (
1325
1303
  return translate(makeSymmetricDisequality(negative.args[0], negative.args[1], node));
1326
1304
  }
1327
1305
  const hypothesis = getRelationHypothesis("symmetric", rule.relation);
1328
- const [a, b] = positive.args;
1306
+ const a = positive.args[0];
1307
+ const b = positive.args[1];
1329
1308
  const ba = relate(rule.relation, b, a);
1330
1309
  const node = makePNotP(ba, rule.args[1], [proof.subproofs[0], proof.subproofs[1]]);
1331
1310
  const implied = makeImply(rule.args[0], ba, makeClose(rule.args[0]), node);
@@ -1335,8 +1314,11 @@ export const translateProof = (
1335
1314
  case "trans_sym": {
1336
1315
  const positive = getRelation(rule.args[0]);
1337
1316
  const relation = positive.symbol;
1338
- const [a, b] = positive.args;
1339
- const [c, d] = getRelation(rule.args[1]).args;
1317
+ const a = positive.args[0];
1318
+ const b = positive.args[1];
1319
+ const negative = getRelation(rule.args[1]);
1320
+ const c = negative.args[0];
1321
+ const d = negative.args[1];
1340
1322
  const first = proof.subproofs[0];
1341
1323
  const second = proof.subproofs[1];
1342
1324
  if (relation === "=")
@@ -1365,7 +1347,8 @@ export const translateProof = (
1365
1347
  case "trans_eq_sym": {
1366
1348
  const negative = getRelation(rule.args[2]);
1367
1349
  const relation = negative.symbol;
1368
- const [c, d] = negative.args;
1350
+ const c = negative.args[0];
1351
+ const d = negative.args[1];
1369
1352
  const a = rule.args[0];
1370
1353
  const b = rule.args[1];
1371
1354
  const proofs = getThree(proof);
@@ -1402,7 +1385,6 @@ export const translateProof = (
1402
1385
  }
1403
1386
  };
1404
1387
 
1405
- // Zenon's make_ex.
1406
1388
  const makeExistential = (existential: Expr, subproof: MlProof) => {
1407
1389
  const binder = getBinder(existential, "ex");
1408
1390
  const witness = exprs.etau(binder.args[0], binder.symbol, binder.args[1]);
@@ -1410,7 +1392,6 @@ export const translateProof = (
1410
1392
  return makeNode([existential], { name: "ex", args: [existential] }, [[instance]], [subproof]);
1411
1393
  };
1412
1394
 
1413
- // Zenon's find_diff: the context in which two formulas differ, and the two subterms.
1414
1395
  const findDiff = (variable: VarExpr, left: Expr, right: Expr): [Expr, Expr, Expr] => {
1415
1396
  if (left === right) throw new TlaZenonError("Zenon: find_diff on equal formulas");
1416
1397
  if (left.kind === "app" && right.kind === "app" && left.symbol === right.symbol) {
@@ -1452,7 +1433,6 @@ export const translateProof = (
1452
1433
  return [variable, left, right];
1453
1434
  };
1454
1435
 
1455
- // Zenon's translate_pseudo_def: instantiates the defining hypothesis, then rewrites with it.
1456
1436
  const translatePseudoDefinition = (
1457
1437
  proof: MlProof,
1458
1438
  definition: Extract<Definition, { kind: "pseudo" }>,
@@ -1535,8 +1515,6 @@ export const translateProof = (
1535
1515
  const translated = translate(proof);
1536
1516
  const isCharged = (formula: Expr) =>
1537
1517
  !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
1518
  const discharged = translated[1].filter(isCharged).reduce((current: LlProof, extra): LlProof => {
1541
1519
  const relationProof = getRelationProof(extra);
1542
1520
  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) =>
@@ -1,7 +1,4 @@
1
- // Ported from Zenon's lexzen.mll and parsezen.mly, as shipped in tlapm. Copyright 2005 INRIA, see
2
- // LICENSE.
3
- //
4
- // Reads Zenon's native input format, the .znn files that tlapm writes.
1
+ // Ported from Zenon's lexzen.mll and parsezen.mly, as shipped in tlapm. Copyright 2005 INRIA, see LICENSE.
5
2
 
6
3
  import { TlaZenonError } from "../../errors";
7
4
  import {
@@ -109,7 +106,6 @@ const tokenize = (text: string) => {
109
106
  return tokens;
110
107
  };
111
108
 
112
- // Zenon's myfold: an n-ary connective nests to the right.
113
109
  const foldRight = (combine: (left: Expr, right: Expr) => Expr, first: Expr, rest: Expr[]): Expr =>
114
110
  rest.length === 0 ? first : combine(first, foldRight(combine, rest[0], rest.slice(1)));
115
111
 
@@ -127,7 +123,7 @@ export const parseZenon = (exprs: Expressions, text: string): Phrase[] => {
127
123
  };
128
124
  const tokens = tokenize(text);
129
125
  let position = 0;
130
- const peek = (offset = 0) => tokens[position + offset];
126
+ const peek = () => tokens[position];
131
127
  const next = () => tokens[position++];
132
128
  const expect = (kind: TokenKind, value?: string) => {
133
129
  const token = next();
@@ -138,7 +134,6 @@ export const parseZenon = (exprs: Expressions, text: string): Phrase[] => {
138
134
  const isAt = (kind: TokenKind, value?: string) =>
139
135
  peek().kind === kind && (value === undefined || peek().text === value);
140
136
 
141
- // A lambda after its first parenthesis: ((x y "type") body).
142
137
  const parseLambda = () => {
143
138
  expect("open");
144
139
  const names: string[] = [];
@@ -1,7 +1,4 @@
1
1
  // Ported from Zenon's phrase.ml, as shipped in tlapm. Copyright 2004 INRIA, see LICENSE.
2
- //
3
- // Splits the input into definitions and hypotheses. A hypothesis that defines a symbol, such as
4
- // x = e or \A a, b : f(a, b) <=> e, becomes a definition that the prover unfolds.
5
2
 
6
3
  import type { Expr } from "./expr";
7
4
  import type { Definition, Phrase } from "./parse";
@@ -13,7 +10,6 @@ export interface Hypothesis {
13
10
 
14
11
  const hasName = (env: Expr[], name: string) => env.some((variable) => variable.symbol === name);
15
12
 
16
- // Zenon's check_args: the arguments are variables, and exactly the quantified ones.
17
13
  const isParameterList = (env: Expr[], args: Expr[]) => {
18
14
  if (!args.every((arg) => arg.kind === "var")) return false;
19
15
  const envNames = env.map((variable) => variable.symbol).sort();
@@ -50,8 +46,6 @@ interface Shape {
50
46
  body: Expr;
51
47
  }
52
48
 
53
- // The ways a formula can define a symbol, in the order Zenon tries them: a definiendum that is an
54
- // application with its parameters, or a constant.
55
49
  const getShapes = (expression: Expr): Shape[] => {
56
50
  const sides =
57
51
  expression.kind === "equiv" || (expression.kind === "app" && expression.symbol === "=")
@@ -79,8 +73,7 @@ const stripForall = (expression: Expr, env: Expr[]): { env: Expr[]; body: Expr }
79
73
  ? stripForall(expression.args[1], [expression.args[0], ...env])
80
74
  : { env, body: expression };
81
75
 
82
- // Zenon's is_def, then make_def. The two try the shapes with different conditions, so the shape
83
- // that defines the symbol can differ from the one that qualifies the formula.
76
+ // Zenon's is_def and make_def try the shapes with different conditions, so the defining shape can differ from the qualifying one.
84
77
  const getDefinition = (
85
78
  predefined: string[],
86
79
  hypothesis: Hypothesis,
@@ -145,8 +138,6 @@ const isLooping = (symbol: string, symbols: string[], dependencies: Dependency[]
145
138
  (symbols.includes(symbol) ||
146
139
  isLooping(symbol, followDependencies(symbols, dependencies), dependencies));
147
140
 
148
- // Zenon's separate. Definitions come before hypotheses, each in input order, except where a
149
- // symbol is defined twice: then neither formula defines it.
150
141
  export const separate = (predefined: string[], phrases: Phrase[]) => {
151
142
  let dependencies: Dependency[] = [];
152
143
  const multiple: string[] = [];
@@ -165,7 +156,6 @@ export const separate = (predefined: string[], phrases: Phrase[]) => {
165
156
  }
166
157
  const symbol = definition.symbol;
167
158
  const dependency: Dependency = [symbol, getFreeSymbols(definition.params, [], definition.body)];
168
- // The lists are reversed, as in Zenon, so a definition's index 0 is the latest.
169
159
  const previous = definitions.findIndex(
170
160
  (existing) => existing.kind === "pseudo" && existing.symbol === symbol,
171
161
  );