tla-ts 0.0.4-dev.702eb98 → 0.0.4-dev.7714e32

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 (382) hide show
  1. package/README.md +32 -6
  2. package/dist/cli.cjs +1 -1
  3. package/dist/cli.js +1 -1
  4. package/dist/deciders.cjs +27 -27
  5. package/dist/deciders.js +34 -34
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +12 -14
  8. package/dist/index.d.ts +12 -14
  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 +516 -25
  15. package/dist/prove.js +518 -27
  16. package/dist/run.cjs +45 -0
  17. package/dist/run.js +45 -0
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +2 -2
  20. package/dist/transfer.cjs +76 -86
  21. package/dist/transfer.js +73 -83
  22. package/dist/worker.cjs +6 -6
  23. package/dist/worker.js +6 -6
  24. package/package.json +1 -1
  25. package/src/ast.ts +2 -2
  26. package/src/bags.ts +22 -23
  27. package/src/builtins.ts +16 -8
  28. package/src/check.ts +131 -1154
  29. package/src/{cli-options.ts → cli/options.ts} +54 -9
  30. package/src/cli/run.ts +63 -0
  31. package/src/cli/shared.ts +106 -0
  32. package/src/cli/tlapm.ts +374 -0
  33. package/src/{run-cli.ts → cli/tlc.ts} +112 -761
  34. package/src/cli/xml-exporter.ts +221 -0
  35. package/src/cli.ts +1 -1
  36. package/src/codegen.ts +17 -15
  37. package/src/config.ts +5 -5
  38. package/src/dependencies.ts +4 -6
  39. package/src/environment.ts +55 -60
  40. package/src/errors.ts +12 -36
  41. package/src/evaluate.ts +81 -101
  42. package/src/exit-codes.ts +1 -1
  43. package/src/fingerprints.ts +3 -3
  44. package/src/index.ts +2 -2
  45. package/src/instances.ts +56 -46
  46. package/src/java-overrides.ts +79 -41
  47. package/src/json.ts +31 -36
  48. package/src/levels.ts +10 -13
  49. package/src/{live-check.ts → liveness-checker.ts} +169 -142
  50. package/src/liveness.ts +38 -34
  51. package/src/obligations/action.ts +58 -105
  52. package/src/obligations/{anon.ts → anonymize.ts} +44 -52
  53. package/src/obligations/equality.ts +260 -0
  54. package/src/obligations/expression.ts +42 -530
  55. package/src/obligations/format.ts +7 -8
  56. package/src/obligations/generate.ts +93 -783
  57. package/src/obligations/index.ts +23 -23
  58. package/src/obligations/levels.ts +38 -44
  59. package/src/obligations/module.ts +106 -729
  60. package/src/obligations/normalize.ts +554 -0
  61. package/src/obligations/operators.ts +176 -0
  62. package/src/obligations/pragma.ts +35 -29
  63. package/src/obligations/printer.ts +98 -209
  64. package/src/obligations/proof.ts +0 -1
  65. package/src/obligations/regroup.ts +100 -0
  66. package/src/obligations/simplify.ts +668 -0
  67. package/src/obligations/source.ts +92 -192
  68. package/src/obligations/{deref.ts → subexpression.ts} +82 -113
  69. package/src/obligations/substitution.ts +261 -0
  70. package/src/obligations/temporal.ts +32 -30
  71. package/src/obligations/tuples.ts +37 -53
  72. package/src/parallel-worker.ts +37 -33
  73. package/src/parallel.ts +30 -24
  74. package/src/parser.ts +67 -74
  75. package/src/{pcal-ast.ts → pcal/ast.ts} +2 -17
  76. package/src/{pcal-parse.ts → pcal/parse.ts} +28 -64
  77. package/src/{pcal-tokenize.ts → pcal/tokenize.ts} +10 -39
  78. package/src/{pcal-translate.ts → pcal/translate.ts} +30 -109
  79. package/src/{pcal-validate.ts → pcal/validate.ts} +10 -20
  80. package/src/{prove → prover}/decide-pool.ts +14 -19
  81. package/src/{prove → prover}/deciders.ts +7 -1
  82. package/src/{obligations/pickle.ts → prover/first-order.ts} +79 -4
  83. package/src/{prove → prover}/isabelle/decide.ts +3 -6
  84. package/src/{prove → prover}/isabelle/encode.ts +106 -138
  85. package/src/{prove → prover}/isabelle/isar/inner-syntax.ts +1 -1
  86. package/src/{prove → prover}/isabelle/isar/method.ts +3 -3
  87. package/src/{prove → prover}/isabelle/isar/type-check.ts +1 -1
  88. package/src/{prove → prover}/isabelle/provers/blast/blast.ts +1 -1
  89. package/src/{prove → prover}/isabelle/provers/blast/branch.ts +1 -1
  90. package/src/{prove → prover}/isabelle/provers/blast/term.ts +3 -4
  91. package/src/{prove → prover}/isabelle/provers/clasimp.ts +1 -1
  92. package/src/{prove → prover}/isabelle/provers/classical.ts +3 -3
  93. package/src/{prove → prover}/isabelle/provers/hypsubst.ts +1 -9
  94. package/src/{prove → prover}/isabelle/pure/conv.ts +1 -1
  95. package/src/{prove → prover}/isabelle/pure/drule.ts +2 -2
  96. package/src/{prove → prover}/isabelle/pure/envir.ts +3 -35
  97. package/src/{prove → prover}/isabelle/pure/logic.ts +4 -76
  98. package/src/{prove → prover}/isabelle/pure/name.ts +1 -13
  99. package/src/{prove → prover}/isabelle/pure/net.ts +2 -49
  100. package/src/{prove → prover}/isabelle/pure/pattern.ts +3 -22
  101. package/src/{prove → prover}/isabelle/pure/raw-simplifier.ts +3 -18
  102. package/src/{prove → prover}/isabelle/pure/seq.ts +0 -23
  103. package/src/{prove → prover}/isabelle/pure/simplifier.ts +2 -8
  104. package/src/{prove → prover}/isabelle/pure/table.ts +1 -8
  105. package/src/{prove → prover}/isabelle/pure/tactic.ts +5 -113
  106. package/src/{prove → prover}/isabelle/pure/tactical.ts +1 -84
  107. package/src/{prove → prover}/isabelle/pure/term-ord.ts +1 -55
  108. package/src/{prove → prover}/isabelle/pure/term.ts +8 -128
  109. package/src/{prove → prover}/isabelle/pure/thm.ts +4 -27
  110. package/src/{prove → prover}/isabelle/pure/type.ts +0 -12
  111. package/src/{prove → prover}/isabelle/pure/unify.ts +1 -1
  112. package/src/{prove → prover}/isabelle/tla/classical-setup.ts +1 -1
  113. package/src/{prove → prover}/ocaml.ts +1 -1
  114. package/src/{prove → prover}/prep/action.ts +54 -66
  115. package/src/{prove → prover}/prep/enabled-axioms.ts +2 -2
  116. package/src/{prove → prover}/prep/fingerprint.ts +3 -3
  117. package/src/{prove → prover}/prep/level-comparison.ts +15 -38
  118. package/src/{prove → prover}/prep/md5.ts +2 -9
  119. package/src/{prove/prep/pragma.ts → prover/prep/methods.ts} +4 -4
  120. package/src/prover/prep/normalize.ts +309 -0
  121. package/src/{prove → prover}/prove-worker.ts +4 -11
  122. package/src/prover/prove.ts +492 -0
  123. package/src/{prove → prover}/ptl/encode.ts +19 -31
  124. package/src/{prove → prover}/smt/axioms.ts +78 -79
  125. package/src/{prove → prover}/smt/data.ts +16 -45
  126. package/src/{prove → prover}/smt/encode.ts +134 -28
  127. package/src/{prove → prover}/smt/extensionality.ts +14 -12
  128. package/src/{prove → prover}/smt/flatten.ts +3 -18
  129. package/src/{prove → prover}/smt/format.ts +14 -3
  130. package/src/{prove → prover}/smt/instances.ts +4 -5
  131. package/src/{prove → prover}/smt/rewrite.ts +41 -59
  132. package/src/{prove → prover}/smt/solver/ast-util.ts +0 -56
  133. package/src/{prove → prover}/smt/solver/case-split-queue.ts +1 -1
  134. package/src/{prove → prover}/smt/solver/enode.ts +1 -1
  135. package/src/{prove → prover}/smt/solver/lp/dep-intervals.ts +0 -14
  136. package/src/{prove → prover}/smt/solver/model-macro-solver.ts +1 -1
  137. package/src/{prove → prover}/smt/solver/nlsat/algebraic.ts +3 -3
  138. package/src/{prove → prover}/smt/solver/nlsat/atoms.ts +1 -1
  139. package/src/{prove → prover}/smt/solver/nlsat/explain.ts +1 -1
  140. package/src/{prove → prover}/smt/solver/nlsat/interval-set.ts +1 -1
  141. package/src/{prove → prover}/smt/solver/nlsat/levelwise.ts +4 -7
  142. package/src/{prove → prover}/smt/solver/nlsat/polynomial.ts +4 -4
  143. package/src/{prove → prover}/smt/solver/nlsat/upolynomial.ts +2 -2
  144. package/src/{prove → prover}/smt/solver/pattern-inference.ts +1 -1
  145. package/src/{prove → prover}/smt/solver/relevancy.ts +2 -2
  146. package/src/{prove → prover}/smt/solver/rewriter.ts +1 -1
  147. package/src/{prove → prover}/smt/solver/solver.ts +2 -2
  148. package/src/prover/tlapm/cache.ts +236 -0
  149. package/src/prover/tlapm/ocaml-marshal.ts +166 -0
  150. package/src/{prove → prover}/tlapm/tlapm.ts +1 -2
  151. package/src/prover/verdict.ts +13 -0
  152. package/src/{prove → prover}/zenon/decide.ts +5 -11
  153. package/src/{prove → prover}/zenon/encode.ts +40 -106
  154. package/src/{prove → prover}/zenon/eqrel.ts +1 -1
  155. package/src/{prove → prover}/zenon/equality-rules.ts +1 -1
  156. package/src/{prove → prover}/zenon/expr.ts +2 -2
  157. package/src/{prove → prover}/zenon/index-table.ts +1 -1
  158. package/src/{prove → prover}/zenon/isar.ts +1 -1
  159. package/src/{prove → prover}/zenon/llproof.ts +1 -1
  160. package/src/{prove → prover}/zenon/mltoll.ts +1 -1
  161. package/src/{prove → prover}/zenon/node.ts +1 -1
  162. package/src/{prove → prover}/zenon/search.ts +1 -1
  163. package/src/{prove → prover}/zenon/tla/terms.ts +1 -20
  164. package/src/{prove → prover}/zenon/tla/tla.ts +1 -1
  165. package/src/randomization.ts +19 -24
  166. package/src/resolve.ts +15 -22
  167. package/src/runtime.ts +8 -8
  168. package/src/{sany-builtins.ts → sany/builtins.ts} +1 -1
  169. package/src/{sany-generator.ts → sany/generator.ts} +38 -55
  170. package/src/{sany-levels.ts → sany/levels.ts} +45 -48
  171. package/src/{sany-lexer.ts → sany/lexer.ts} +2 -3
  172. package/src/{sany-linter.ts → sany/linter.ts} +1 -1
  173. package/src/{sany-modules.ts → sany/modules.ts} +2 -2
  174. package/src/{sany-nodes.ts → sany/nodes.ts} +2 -2
  175. package/src/{sany-parse-error.ts → sany/parse-error.ts} +2 -2
  176. package/src/{sany-report.ts → sany/report.ts} +16 -17
  177. package/src/{sany-selectors.ts → sany/selectors.ts} +3 -5
  178. package/src/{sany-source.ts → sany/source.ts} +6 -7
  179. package/src/{sany-xml.ts → sany/xml.ts} +5 -6
  180. package/src/search.ts +969 -0
  181. package/src/spec-description.ts +26 -20
  182. package/src/{standard-levels.ts → standard-definitions.ts} +118 -2
  183. package/src/standard-modules.ts +16 -20
  184. package/src/state-graph.ts +9 -8
  185. package/src/substitution-levels.ts +2 -2
  186. package/src/successors.ts +16 -19
  187. package/src/symmetry.ts +1 -1
  188. package/src/tableau.ts +6 -7
  189. package/src/tlc/fingerprint.ts +214 -0
  190. package/src/{tlc-messages.ts → tlc/messages.ts} +119 -7
  191. package/src/{tlc-order.ts → tlc/order.ts} +7 -7
  192. package/src/{tlc-random.ts → tlc/random.ts} +3 -213
  193. package/src/{tlc-replay.ts → tlc/replay.ts} +40 -36
  194. package/src/{tlc-module.ts → tlc/tlc-operators.ts} +9 -9
  195. package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +30 -25
  196. package/src/transfer.ts +32 -32
  197. package/src/values.ts +72 -67
  198. package/src/worker.ts +1 -4
  199. package/dist/run-cli.cjs +0 -38
  200. package/dist/run-cli.js +0 -38
  201. package/src/canonical.ts +0 -40
  202. package/src/obligations/ctx.ts +0 -64
  203. package/src/prove/prep/defs.ts +0 -27
  204. package/src/prove/prep/elab.ts +0 -156
  205. package/src/prove/prep/enabled.ts +0 -43
  206. package/src/prove/prep/flatten.ts +0 -70
  207. package/src/prove/prep/trivial.ts +0 -22
  208. package/src/prove/prove.ts +0 -417
  209. package/src/prove/smt/axiomatize.ts +0 -69
  210. package/src/prove/smt/simplify.ts +0 -57
  211. package/src/prove/verdict.ts +0 -13
  212. package/src/standard-ranges.ts +0 -116
  213. package/src/value-sources.ts +0 -29
  214. /package/src/{prove → prover}/isabelle/LICENSE +0 -0
  215. /package/src/{prove → prover}/isabelle/LICENSE-tlapm +0 -0
  216. /package/src/{prove → prover}/isabelle/isar/proof.ts +0 -0
  217. /package/src/{prove → prover}/isabelle/isar/statement.ts +0 -0
  218. /package/src/{prove → prover}/isabelle/isar/theory.ts +0 -0
  219. /package/src/{prove → prover}/isabelle/provers/blast/prove.ts +0 -0
  220. /package/src/{prove → prover}/isabelle/provers/blast/rules.ts +0 -0
  221. /package/src/{prove → prover}/isabelle/provers/blast/state.ts +0 -0
  222. /package/src/{prove → prover}/isabelle/pure/bicompose.ts +0 -0
  223. /package/src/{prove → prover}/isabelle/pure/consts.ts +0 -0
  224. /package/src/{prove → prover}/isabelle/pure/goal.ts +0 -0
  225. /package/src/{prove → prover}/isabelle/pure/interrupt.ts +0 -0
  226. /package/src/{prove → prover}/isabelle/pure/list.ts +0 -0
  227. /package/src/{prove → prover}/isabelle/pure/object-logic.ts +0 -0
  228. /package/src/{prove → prover}/isabelle/pure/rewriter.ts +0 -0
  229. /package/src/{prove → prover}/isabelle/pure/search.ts +0 -0
  230. /package/src/{prove → prover}/isabelle/pure/variable.ts +0 -0
  231. /package/src/{prove → prover}/isabelle/tla/context.ts +0 -0
  232. /package/src/{prove → prover}/isabelle/tla/logic-data.ts +0 -0
  233. /package/src/{prove → prover}/isabelle/tla/logic.ts +0 -0
  234. /package/src/{prove → prover}/isabelle/tla/simpdata.ts +0 -0
  235. /package/src/{prove → prover}/isabelle/tools/intuitionistic.ts +0 -0
  236. /package/src/{prove → prover}/ptl/decide.ts +0 -0
  237. /package/src/{prove → prover}/ptl/sat.ts +0 -0
  238. /package/src/{prove → prover}/ptl/tableau.ts +0 -0
  239. /package/src/{prove → prover}/smt/context.ts +0 -0
  240. /package/src/{prove → prover}/smt/solver/act-cache.ts +0 -0
  241. /package/src/{prove → prover}/smt/solver/arith-rewriter.ts +0 -0
  242. /package/src/{prove → prover}/smt/solver/array.ts +0 -0
  243. /package/src/{prove → prover}/smt/solver/asserted-formulas.ts +0 -0
  244. /package/src/{prove → prover}/smt/solver/ast-lt.ts +0 -0
  245. /package/src/{prove → prover}/smt/solver/ast.ts +0 -0
  246. /package/src/{prove → prover}/smt/solver/auf-solver.ts +0 -0
  247. /package/src/{prove → prover}/smt/solver/cg-table.ts +0 -0
  248. /package/src/{prove → prover}/smt/solver/clause.ts +0 -0
  249. /package/src/{prove → prover}/smt/solver/conflict-resolution.ts +0 -0
  250. /package/src/{prove → prover}/smt/solver/context.ts +0 -0
  251. /package/src/{prove → prover}/smt/solver/ctx-simplify.ts +0 -0
  252. /package/src/{prove → prover}/smt/solver/der.ts +0 -0
  253. /package/src/{prove → prover}/smt/solver/dyn-ack.ts +0 -0
  254. /package/src/{prove → prover}/smt/solver/e-matching.ts +0 -0
  255. /package/src/{prove → prover}/smt/solver/expr-ref.ts +0 -0
  256. /package/src/{prove → prover}/smt/solver/expr-safe-replace.ts +0 -0
  257. /package/src/{prove → prover}/smt/solver/fingerprints.ts +0 -0
  258. /package/src/{prove → prover}/smt/solver/flat-literals.ts +0 -0
  259. /package/src/{prove → prover}/smt/solver/goal.ts +0 -0
  260. /package/src/{prove → prover}/smt/solver/hash.ts +0 -0
  261. /package/src/{prove → prover}/smt/solver/hashtable.ts +0 -0
  262. /package/src/{prove → prover}/smt/solver/internalizer.ts +0 -0
  263. /package/src/{prove → prover}/smt/solver/lbool.ts +0 -0
  264. /package/src/{prove → prover}/smt/solver/literal.ts +0 -0
  265. /package/src/{prove → prover}/smt/solver/lp/bound-propagator.ts +0 -0
  266. /package/src/{prove → prover}/smt/solver/lp/constraints.ts +0 -0
  267. /package/src/{prove → prover}/smt/solver/lp/containers.ts +0 -0
  268. /package/src/{prove → prover}/smt/solver/lp/core-solver.ts +0 -0
  269. /package/src/{prove → prover}/smt/solver/lp/cross-nested.ts +0 -0
  270. /package/src/{prove → prover}/smt/solver/lp/dependency.ts +0 -0
  271. /package/src/{prove → prover}/smt/solver/lp/dioph-eq.ts +0 -0
  272. /package/src/{prove → prover}/smt/solver/lp/explanation.ts +0 -0
  273. /package/src/{prove → prover}/smt/solver/lp/gomory.ts +0 -0
  274. /package/src/{prove → prover}/smt/solver/lp/hnf-cutter.ts +0 -0
  275. /package/src/{prove → prover}/smt/solver/lp/hnf.ts +0 -0
  276. /package/src/{prove → prover}/smt/solver/lp/int-cube.ts +0 -0
  277. /package/src/{prove → prover}/smt/solver/lp/int-solver.ts +0 -0
  278. /package/src/{prove → prover}/smt/solver/lp/lar-solver.ts +0 -0
  279. /package/src/{prove → prover}/smt/solver/lp/lar-term.ts +0 -0
  280. /package/src/{prove → prover}/smt/solver/lp/lp-settings.ts +0 -0
  281. /package/src/{prove → prover}/smt/solver/lp/maximize-term.ts +0 -0
  282. /package/src/{prove → prover}/smt/solver/lp/nex-creator.ts +0 -0
  283. /package/src/{prove → prover}/smt/solver/lp/nex.ts +0 -0
  284. /package/src/{prove → prover}/smt/solver/lp/nla-backoff.ts +0 -0
  285. /package/src/{prove → prover}/smt/solver/lp/nla-basics.ts +0 -0
  286. /package/src/{prove → prover}/smt/solver/lp/nla-core.ts +0 -0
  287. /package/src/{prove → prover}/smt/solver/lp/nla-divisions.ts +0 -0
  288. /package/src/{prove → prover}/smt/solver/lp/nla-emonics.ts +0 -0
  289. /package/src/{prove → prover}/smt/solver/lp/nla-factorization.ts +0 -0
  290. /package/src/{prove → prover}/smt/solver/lp/nla-grobner.ts +0 -0
  291. /package/src/{prove → prover}/smt/solver/lp/nla-horner.ts +0 -0
  292. /package/src/{prove → prover}/smt/solver/lp/nla-intervals.ts +0 -0
  293. /package/src/{prove → prover}/smt/solver/lp/nla-monomial-bounds.ts +0 -0
  294. /package/src/{prove → prover}/smt/solver/lp/nla-monotone.ts +0 -0
  295. /package/src/{prove → prover}/smt/solver/lp/nla-order.ts +0 -0
  296. /package/src/{prove → prover}/smt/solver/lp/nla-patcher.ts +0 -0
  297. /package/src/{prove → prover}/smt/solver/lp/nla-tangents.ts +0 -0
  298. /package/src/{prove → prover}/smt/solver/lp/nla-throttle.ts +0 -0
  299. /package/src/{prove → prover}/smt/solver/lp/nla-types.ts +0 -0
  300. /package/src/{prove → prover}/smt/solver/lp/nla-var-eqs.ts +0 -0
  301. /package/src/{prove → prover}/smt/solver/lp/nra-solver.ts +0 -0
  302. /package/src/{prove → prover}/smt/solver/lp/numeric-pair.ts +0 -0
  303. /package/src/{prove → prover}/smt/solver/lp/pdd-interval.ts +0 -0
  304. /package/src/{prove → prover}/smt/solver/lp/pdd-simplifier.ts +0 -0
  305. /package/src/{prove → prover}/smt/solver/lp/pdd-solver.ts +0 -0
  306. /package/src/{prove → prover}/smt/solver/lp/pdd.ts +0 -0
  307. /package/src/{prove → prover}/smt/solver/lp/random-updater.ts +0 -0
  308. /package/src/{prove → prover}/smt/solver/lp/static-matrix.ts +0 -0
  309. /package/src/{prove → prover}/smt/solver/lp/union-find.ts +0 -0
  310. /package/src/{prove → prover}/smt/solver/mam-compiler.ts +0 -0
  311. /package/src/{prove → prover}/smt/solver/mam-interpreter.ts +0 -0
  312. /package/src/{prove → prover}/smt/solver/maximize-ac-sharing.ts +0 -0
  313. /package/src/{prove → prover}/smt/solver/model-checker.ts +0 -0
  314. /package/src/{prove → prover}/smt/solver/model-evaluator.ts +0 -0
  315. /package/src/{prove → prover}/smt/solver/model-finder.ts +0 -0
  316. /package/src/{prove → prover}/smt/solver/model-generator.ts +0 -0
  317. /package/src/{prove → prover}/smt/solver/nlsat/evaluator.ts +0 -0
  318. /package/src/{prove → prover}/smt/solver/nlsat/mpbq.ts +0 -0
  319. /package/src/{prove → prover}/smt/solver/nlsat/solver.ts +0 -0
  320. /package/src/{prove → prover}/smt/solver/nlsat/types.ts +0 -0
  321. /package/src/{prove → prover}/smt/solver/nlsat/upolynomial-factorization.ts +0 -0
  322. /package/src/{prove → prover}/smt/solver/nnf.ts +0 -0
  323. /package/src/{prove → prover}/smt/solver/poly-rewriter.ts +0 -0
  324. /package/src/{prove → prover}/smt/solver/propagate-values.ts +0 -0
  325. /package/src/{prove → prover}/smt/solver/proto-model.ts +0 -0
  326. /package/src/{prove → prover}/smt/solver/pull-quant.ts +0 -0
  327. /package/src/{prove → prover}/smt/solver/qe-lite-der.ts +0 -0
  328. /package/src/{prove → prover}/smt/solver/qe-lite-fm.ts +0 -0
  329. /package/src/{prove → prover}/smt/solver/qe-lite.ts +0 -0
  330. /package/src/{prove → prover}/smt/solver/qi-queue.ts +0 -0
  331. /package/src/{prove → prover}/smt/solver/quant-tactics.ts +0 -0
  332. /package/src/{prove → prover}/smt/solver/quantifier-analyzer.ts +0 -0
  333. /package/src/{prove → prover}/smt/solver/quantifier-manager.ts +0 -0
  334. /package/src/{prove → prover}/smt/solver/random-gen.ts +0 -0
  335. /package/src/{prove → prover}/smt/solver/rational.ts +0 -0
  336. /package/src/{prove → prover}/smt/solver/ref-vector.ts +0 -0
  337. /package/src/{prove → prover}/smt/solver/rewriter-tpl.ts +0 -0
  338. /package/src/{prove → prover}/smt/solver/rlimit.ts +0 -0
  339. /package/src/{prove → prover}/smt/solver/smtlib-parser.ts +0 -0
  340. /package/src/{prove → prover}/smt/solver/sort.ts +0 -0
  341. /package/src/{prove → prover}/smt/solver/sticky-generations.ts +0 -0
  342. /package/src/{prove → prover}/smt/solver/theory-lra-axioms.ts +0 -0
  343. /package/src/{prove → prover}/smt/solver/theory-lra-bounds.ts +0 -0
  344. /package/src/{prove → prover}/smt/solver/theory-lra-final-check.ts +0 -0
  345. /package/src/{prove → prover}/smt/solver/theory-lra-internalize.ts +0 -0
  346. /package/src/{prove → prover}/smt/solver/theory-lra-model.ts +0 -0
  347. /package/src/{prove → prover}/smt/solver/theory-lra-propagate.ts +0 -0
  348. /package/src/{prove → prover}/smt/solver/theory-lra-state.ts +0 -0
  349. /package/src/{prove → prover}/smt/solver/theory-lra.ts +0 -0
  350. /package/src/{prove → prover}/smt/solver/var-subst.ts +0 -0
  351. /package/src/{prove → prover}/smt/solver/z3-license.txt +0 -0
  352. /package/src/{prove → prover}/smt/table.ts +0 -0
  353. /package/src/{prove → prover}/tlaps-module.ts +0 -0
  354. /package/src/{prove → prover}/zenon/LICENSE +0 -0
  355. /package/src/{prove → prover}/zenon/check/check.ts +0 -0
  356. /package/src/{prove → prover}/zenon/check/definitions.ts +0 -0
  357. /package/src/{prove → prover}/zenon/check/equality.ts +0 -0
  358. /package/src/{prove → prover}/zenon/check/functions.ts +0 -0
  359. /package/src/{prove → prover}/zenon/check/keys.ts +0 -0
  360. /package/src/{prove → prover}/zenon/check/propositional.ts +0 -0
  361. /package/src/{prove → prover}/zenon/check/records.ts +0 -0
  362. /package/src/{prove → prover}/zenon/check/relations.ts +0 -0
  363. /package/src/{prove → prover}/zenon/check/rewrites.ts +0 -0
  364. /package/src/{prove → prover}/zenon/check/sets.ts +0 -0
  365. /package/src/{prove → prover}/zenon/check/terms.ts +0 -0
  366. /package/src/{prove → prover}/zenon/check/tla.ts +0 -0
  367. /package/src/{prove → prover}/zenon/isar-case.ts +0 -0
  368. /package/src/{prove → prover}/zenon/limits.ts +0 -0
  369. /package/src/{prove → prover}/zenon/ocaml.ts +0 -0
  370. /package/src/{prove → prover}/zenon/parse.ts +0 -0
  371. /package/src/{prove → prover}/zenon/phrase.ts +0 -0
  372. /package/src/{prove → prover}/zenon/proof.ts +0 -0
  373. /package/src/{prove → prover}/zenon/propositional-rules.ts +0 -0
  374. /package/src/{prove → prover}/zenon/rules.ts +0 -0
  375. /package/src/{prove → prover}/zenon/tla/functions.ts +0 -0
  376. /package/src/{prove → prover}/zenon/tla/llproof.ts +0 -0
  377. /package/src/{prove → prover}/zenon/tla/records.ts +0 -0
  378. /package/src/{prove → prover}/zenon/tla/rewrites.ts +0 -0
  379. /package/src/{prove → prover}/zenon/tla/sets.ts +0 -0
  380. /package/src/{tlc-modules.ts → tlc/jar-data.ts} +0 -0
  381. /package/src/{tlc-summary.ts → tlc/summary.ts} +0 -0
  382. /package/src/{tlc-version.ts → tlc/version.ts} +0 -0
@@ -1,53 +1,34 @@
1
- // A port of tlapm's module pipeline: flattening EXTENDS (Module.Flatten), normalization
2
- // (Module.Elab.normalize) and obligation generation (Module.Gen).
1
+ // tlapm's module units, with the standard modules, flattening EXTENDS (Module.Flatten), the
2
+ // modules a module depends on (Module.Dep), and substitution in units (Module.Subst).
3
3
 
4
4
  import { TlaProofError, TlapmBugError } from "../errors";
5
- import { lambdify } from "./action";
6
- import type { Anonymizer } from "./anon";
7
5
  import {
8
- adjoinAll,
9
6
  at,
10
- bumpBy,
11
- consAll,
12
- consSubstitution,
13
7
  exprifySequent,
14
- findNamed,
15
- getAtPrefix,
16
- getLocusText,
17
- getLocusPrefix,
18
- getScopeHyps,
19
- mapAccumulate,
8
+ getFact,
20
9
  getFresh,
21
- isEqualHyp,
22
- shiftExpr,
23
- substituteDefn,
24
- substituteExpr,
25
- substituteExprs,
26
- substituteHyp,
27
- substituteSequent,
28
- shift,
10
+ mapAccumulate,
29
11
  type Builtin,
30
12
  type Defn,
31
13
  type Expr,
32
14
  type Hyp,
33
15
  type InstanceDefinition,
34
16
  type Locus,
35
- type ObligationWarning,
36
- type Scope,
37
17
  type Sequent,
38
- type Substitution,
39
18
  type Visibility,
40
19
  type WhereDefined,
41
20
  } from "./expression";
21
+ import type { Proof, Usable } from "./proof";
42
22
  import {
43
- EMPTY_SUMMARY,
44
- getProofSummary,
45
- joinSummaries,
46
- type Generator,
47
- type ProofSummary,
48
- } from "./generate";
49
- import { getUnique, type Counter, type Obligation, type Proof, type Usable } from "./proof";
50
- import { getScopeTime } from "./temporal";
23
+ bumpBy,
24
+ shift,
25
+ shiftExpr,
26
+ substituteDefn,
27
+ substituteExpr,
28
+ substituteExprs,
29
+ substituteSequent,
30
+ type Substitution,
31
+ } from "./substitution";
51
32
 
52
33
  export type ModuleUnit = ModuleUnitCore & { location?: Locus };
53
34
 
@@ -70,7 +51,7 @@ type ModuleUnitCore =
70
51
  proof: Proof;
71
52
  }
72
53
  | { kind: "Submod"; module: Mule }
73
- | { kind: "Mutate"; mode: "Use" | "Hide"; isSuppressed: boolean; usable: Usable }
54
+ | { kind: "Mutate"; mode: "Use" | "Hide"; usable: Usable }
74
55
  | { kind: "Anoninst"; instance: InstanceDefinition; isLocal: boolean };
75
56
 
76
57
  // depth is the size of the context the module was normalized in, which instantiation shifts
@@ -86,34 +67,29 @@ export interface Mule {
86
67
  location?: Locus;
87
68
  }
88
69
 
89
- const getBuiltinConstant = (name: string, builtin: Builtin): ModuleUnit => ({
90
- kind: "Definition",
91
- definition: { kind: "Operator", name, body: { kind: "Internal", builtin } },
92
- whereDefined: "Builtin",
93
- visibility: "Visible",
94
- isLocal: false,
95
- });
96
-
97
- const getBuiltinOperator = (arity: number, name: string, builtin: Builtin): ModuleUnit => ({
70
+ const defineBuiltin = (arity: number, name: string, builtin: Builtin): ModuleUnit => ({
98
71
  kind: "Definition",
99
72
  definition: {
100
73
  kind: "Operator",
101
74
  name,
102
- body: {
103
- kind: "Lambda",
104
- params: Array.from({ length: arity }, (_item, index) => ({
105
- name: `x${index + 1}`,
106
- shape: 0,
107
- })),
108
- body: {
109
- kind: "Apply",
110
- operator: { kind: "Internal", builtin },
111
- args: Array.from({ length: arity }, (_item, index) => ({
112
- kind: "Ix",
113
- index: arity - index,
114
- })),
115
- },
116
- },
75
+ body:
76
+ arity === 0
77
+ ? { kind: "Internal", builtin }
78
+ : {
79
+ kind: "Lambda",
80
+ params: Array.from({ length: arity }, (_item, index) => ({
81
+ name: `x${index + 1}`,
82
+ shape: 0,
83
+ })),
84
+ body: {
85
+ kind: "Apply",
86
+ operator: { kind: "Internal", builtin },
87
+ args: Array.from({ length: arity }, (_item, index) => ({
88
+ kind: "Ix",
89
+ index: arity - index,
90
+ })),
91
+ },
92
+ },
117
93
  },
118
94
  whereDefined: "Builtin",
119
95
  visibility: "Visible",
@@ -121,62 +97,58 @@ const getBuiltinOperator = (arity: number, name: string, builtin: Builtin): Modu
121
97
  });
122
98
 
123
99
  const NATURALS: ModuleUnit[] = [
124
- getBuiltinConstant("Nat", "Nat"),
125
- getBuiltinOperator(2, "+", "Plus"),
126
- getBuiltinOperator(2, "-", "Minus"),
127
- getBuiltinOperator(2, "*", "Times"),
128
- getBuiltinOperator(2, "^", "Exp"),
129
- getBuiltinOperator(2, "<", "Lt"),
130
- getBuiltinOperator(2, ">", "Gt"),
131
- getBuiltinOperator(2, "=<", "Lteq"),
132
- getBuiltinOperator(2, ">=", "Gteq"),
133
- getBuiltinOperator(2, "%", "Remainder"),
134
- getBuiltinOperator(2, "\\div", "Quotient"),
135
- getBuiltinOperator(2, "..", "Range"),
100
+ defineBuiltin(0, "Nat", "Nat"),
101
+ defineBuiltin(2, "+", "Plus"),
102
+ defineBuiltin(2, "-", "Minus"),
103
+ defineBuiltin(2, "*", "Times"),
104
+ defineBuiltin(2, "^", "Exp"),
105
+ defineBuiltin(2, "<", "Lt"),
106
+ defineBuiltin(2, ">", "Gt"),
107
+ defineBuiltin(2, "=<", "Lteq"),
108
+ defineBuiltin(2, ">=", "Gteq"),
109
+ defineBuiltin(2, "%", "Remainder"),
110
+ defineBuiltin(2, "\\div", "Quotient"),
111
+ defineBuiltin(2, "..", "Range"),
136
112
  ];
137
113
 
138
- const INTEGERS = [
139
- ...NATURALS,
140
- getBuiltinConstant("Int", "Int"),
141
- getBuiltinOperator(1, "-.", "Uminus"),
142
- ];
114
+ const INTEGERS = [...NATURALS, defineBuiltin(0, "Int", "Int"), defineBuiltin(1, "-.", "Uminus")];
143
115
 
144
116
  const REALS = [
145
117
  ...INTEGERS,
146
- getBuiltinConstant("Real", "Real"),
147
- getBuiltinOperator(2, "/", "Ratio"),
148
- getBuiltinConstant("Infinity", "Infinity"),
118
+ defineBuiltin(0, "Real", "Real"),
119
+ defineBuiltin(2, "/", "Ratio"),
120
+ defineBuiltin(0, "Infinity", "Infinity"),
149
121
  ];
150
122
 
151
123
  const SEQUENCES = [
152
- getBuiltinOperator(1, "Seq", "Seq"),
153
- getBuiltinOperator(1, "Len", "Len"),
154
- getBuiltinOperator(2, "BSeq", "BSeq"),
155
- getBuiltinOperator(2, "\\o", "Cat"),
156
- getBuiltinOperator(2, "Append", "Append"),
157
- getBuiltinOperator(1, "Head", "Head"),
158
- getBuiltinOperator(1, "Tail", "Tail"),
159
- getBuiltinOperator(3, "SubSeq", "SubSeq"),
160
- getBuiltinOperator(2, "SelectSeq", "SelectSeq"),
124
+ defineBuiltin(1, "Seq", "Seq"),
125
+ defineBuiltin(1, "Len", "Len"),
126
+ defineBuiltin(2, "BSeq", "BSeq"),
127
+ defineBuiltin(2, "\\o", "Cat"),
128
+ defineBuiltin(2, "Append", "Append"),
129
+ defineBuiltin(1, "Head", "Head"),
130
+ defineBuiltin(1, "Tail", "Tail"),
131
+ defineBuiltin(3, "SubSeq", "SubSeq"),
132
+ defineBuiltin(2, "SelectSeq", "SelectSeq"),
161
133
  ];
162
134
 
163
135
  const TLC = [
164
- getBuiltinOperator(2, "Print", "Print"),
165
- getBuiltinOperator(1, "PrintT", "PrintT"),
166
- getBuiltinOperator(2, "Assert", "Assert"),
167
- getBuiltinConstant("JavaTime", "JavaTime"),
168
- getBuiltinOperator(1, "TLCGet", "TLCGet"),
169
- getBuiltinOperator(2, "TLCSet", "TLCSet"),
170
- getBuiltinOperator(2, ":>", "OneArg"),
171
- getBuiltinOperator(2, "@@", "Extend"),
172
- getBuiltinOperator(1, "Permutations", "Permutations"),
173
- getBuiltinOperator(2, "SortSeq", "SortSeq"),
174
- getBuiltinOperator(1, "RandomElement", "RandomElement"),
175
- getBuiltinConstant("Any", "Any"),
176
- getBuiltinOperator(1, "ToString", "ToString"),
136
+ defineBuiltin(2, "Print", "Print"),
137
+ defineBuiltin(1, "PrintT", "PrintT"),
138
+ defineBuiltin(2, "Assert", "Assert"),
139
+ defineBuiltin(0, "JavaTime", "JavaTime"),
140
+ defineBuiltin(1, "TLCGet", "TLCGet"),
141
+ defineBuiltin(2, "TLCSet", "TLCSet"),
142
+ defineBuiltin(2, ":>", "OneArg"),
143
+ defineBuiltin(2, "@@", "Extend"),
144
+ defineBuiltin(1, "Permutations", "Permutations"),
145
+ defineBuiltin(2, "SortSeq", "SortSeq"),
146
+ defineBuiltin(1, "RandomElement", "RandomElement"),
147
+ defineBuiltin(0, "Any", "Any"),
148
+ defineBuiltin(1, "ToString", "ToString"),
177
149
  ];
178
150
 
179
- const getStandard = (name: string, body: ModuleUnit[]): Mule => ({
151
+ const getStandardModule = (name: string, body: ModuleUnit[]): Mule => ({
180
152
  name,
181
153
  extendees: [],
182
154
  body,
@@ -187,25 +159,20 @@ const getStandard = (name: string, body: ModuleUnit[]): Mule => ({
187
159
  // Module.Standard.initctx, apart from $TLAPM, whose Builtins! names no module of the corpora uses.
188
160
  export const STANDARD_MODULES = new Map(
189
161
  [
190
- getStandard("Naturals", NATURALS),
191
- getStandard("Integers", INTEGERS),
192
- getStandard("Reals", REALS),
193
- getStandard("Sequences", SEQUENCES),
194
- getStandard("TLC", TLC),
162
+ getStandardModule("Naturals", NATURALS),
163
+ getStandardModule("Integers", INTEGERS),
164
+ getStandardModule("Reals", REALS),
165
+ getStandardModule("Sequences", SEQUENCES),
166
+ getStandardModule("TLC", TLC),
195
167
  ].map((module) => [module.name, module]),
196
168
  );
197
169
 
198
- const getUnitHyps = (unit: ModuleUnit): Hyp[] => {
170
+ export const getUnitHyps = (unit: ModuleUnit): Hyp[] => {
199
171
  const location = unit.location;
200
172
  switch (unit.kind) {
201
173
  case "Constants":
202
174
  return unit.declarations.map((declaration) => ({
203
- kind: "Fresh",
204
- name: declaration.name,
205
- shape: declaration.shape,
206
- level: "Constant",
207
- domain: undefined,
208
- domainVisibility: "Visible",
175
+ ...getFresh(declaration.name, "Constant", declaration.shape),
209
176
  location,
210
177
  }));
211
178
  case "Recursives":
@@ -236,36 +203,28 @@ const getUnitHyps = (unit: ModuleUnit): Hyp[] => {
236
203
  },
237
204
  ];
238
205
  case "Axiom":
239
- return unit.name === undefined
240
- ? [
241
- {
242
- kind: "Fact",
243
- expression: unit.expression,
244
- visibility: "Hidden",
245
- time: "Always",
246
- location,
247
- },
248
- ]
249
- : getNamedFact(unit.name, unit.expression, location);
250
206
  case "Theorem": {
251
- const sequent = substituteSequent(shift(-unit.axiomCount), {
252
- ...unit.sequent,
253
- context: unit.sequent.context.slice(unit.axiomCount),
254
- });
255
- const body = at(exprifySequent(sequent), unit);
207
+ const expression =
208
+ unit.kind === "Axiom"
209
+ ? unit.expression
210
+ : at(
211
+ exprifySequent(
212
+ substituteSequent(shift(-unit.axiomCount), {
213
+ ...unit.sequent,
214
+ context: unit.sequent.context.slice(unit.axiomCount),
215
+ }),
216
+ ),
217
+ unit,
218
+ );
256
219
  return unit.name === undefined
257
- ? [{ kind: "Fact", expression: body, visibility: "Hidden", time: "Always", location }]
258
- : getNamedFact(unit.name, body, location);
220
+ ? [getFact(expression, "Hidden", "Always", location)]
221
+ : getNamedFact(unit.name, expression, location);
259
222
  }
260
223
  case "Mutate":
261
224
  return unit.mode === "Use"
262
- ? unit.usable.facts.map((fact, index) => ({
263
- kind: "Fact",
264
- expression: shiftExpr(index, fact),
265
- visibility: "Visible",
266
- time: "Always",
267
- location,
268
- }))
225
+ ? unit.usable.facts.map((fact, index) =>
226
+ getFact(shiftExpr(index, fact), "Visible", "Always", location),
227
+ )
269
228
  : [];
270
229
  case "Submod":
271
230
  case "Anoninst":
@@ -273,7 +232,7 @@ const getUnitHyps = (unit: ModuleUnit): Hyp[] => {
273
232
  }
274
233
  };
275
234
 
276
- const getHypSize = (unit: ModuleUnit) =>
235
+ export const getHypSize = (unit: ModuleUnit) =>
277
236
  unit.kind === "Axiom" || unit.kind === "Theorem"
278
237
  ? unit.name === undefined
279
238
  ? 1
@@ -289,13 +248,7 @@ const getNamedFact = (name: string, expression: Expr, location: Locus | undefine
289
248
  isLocal: false,
290
249
  location,
291
250
  },
292
- {
293
- kind: "Fact",
294
- expression: { kind: "Ix", index: 1, location },
295
- visibility: "Hidden",
296
- time: "Always",
297
- location,
298
- },
251
+ getFact({ kind: "Ix", index: 1, location }, "Hidden", "Always", location),
299
252
  ];
300
253
 
301
254
  // Module.Flatten.exports: what an extending module sees, with local definitions inlined like
@@ -363,11 +316,12 @@ export const getDependencies = (module: Mule) => {
363
316
  }
364
317
  Object.values(value).forEach(addInstances);
365
318
  };
366
- // The hypotheses of each unit, leaving out the proofs of theorems.
319
+ // Leaves out the proofs of theorems.
367
320
  const visit = (unit: ModuleUnit) => {
368
- if (unit.kind === "Theorem") addInstances(unit.sequent);
369
- else if (unit.kind !== "Submod") addInstances(unit);
370
- if (unit.kind !== "Submod") return;
321
+ if (unit.kind !== "Submod") {
322
+ addInstances(unit.kind === "Theorem" ? unit.sequent : unit);
323
+ return;
324
+ }
371
325
  locals.add(unit.module.name);
372
326
  submodules.set(unit.module.name, unit.module);
373
327
  addExtendees(unit.module);
@@ -393,16 +347,6 @@ const isInstanceDefinition = (value: unknown): value is InstanceDefinition =>
393
347
  export const compareNames = (left: string, right: string) =>
394
348
  left < right ? -1 : left > right ? 1 : 0;
395
349
 
396
- // latestModules is the module context of the latest anonymization of an axiom, theorem or USE,
397
- // which tlapm's anonymizer keeps using for the instances inside later definitions.
398
- export interface Pipeline {
399
- anonymizer: Anonymizer;
400
- generator: Generator;
401
- salts: Counter;
402
- latestModules: Map<string, Mule>;
403
- onWarning: (warning: ObligationWarning) => void;
404
- }
405
-
406
350
  const substituteUsable = (substitution: Substitution, usable: Usable): Usable => ({
407
351
  facts: substituteExprs(substitution, usable.facts),
408
352
  defs: usable.defs.map((def) => {
@@ -470,339 +414,11 @@ const substituteUnit = (
470
414
  }
471
415
  };
472
416
 
473
- const substituteUnits = (substitution: Substitution, units: ModuleUnit[]) =>
417
+ export const substituteUnits = (substitution: Substitution, units: ModuleUnit[]) =>
474
418
  mapAccumulate(substitution, units, substituteUnit)[1];
475
419
 
476
- const lambdifyTheorem = (
477
- pipeline: Pipeline,
478
- scope: Scope | undefined,
479
- name: string | undefined,
480
- sequent: Sequent,
481
- ) => {
482
- try {
483
- const lambdified = lambdify(pipeline.anonymizer, pipeline.onWarning, scope, {
484
- kind: "Sequent",
485
- sequent,
486
- });
487
- if (lambdified.kind !== "Sequent") throw new TlapmBugError();
488
- return lambdified.sequent;
489
- } catch (error) {
490
- if (!(error instanceof TlaProofError) || error.failure === undefined) throw error;
491
- const location = sequent.active.location;
492
- const message = `${error.failure}\nCould not instantiate the theorem ${name === undefined ? "" : `named: ${name}, `}at: ${location ? getLocusText(location) : "<unknown location>"}`;
493
- pipeline.onWarning({ text: `${getAtPrefix(location)}[ERROR]${message}`, channel: "stdout" });
494
- pipeline.onWarning({ text: message, channel: "toolboxOnly" });
495
- return { context: [], active: at({ kind: "Internal", builtin: "TRUE" }, sequent.active) };
496
- }
497
- };
498
-
499
- const lambdifyUnit = (pipeline: Pipeline, scope: Scope | undefined, unit: ModuleUnit) => {
500
- if (unit.kind === "Theorem") {
501
- return { ...unit, sequent: lambdifyTheorem(pipeline, scope, unit.name, unit.sequent) };
502
- }
503
- if (unit.kind !== "Definition") return unit;
504
- const definition = unit.definition;
505
- if (definition.kind !== "Operator" && definition.kind !== "Bpragma") return unit;
506
- const body = lambdify(pipeline.anonymizer, pipeline.onWarning, scope, definition.body);
507
- return { ...unit, definition: { ...definition, body } };
508
- };
509
-
510
- // lambdify_enabled_cdot: the ENABLED and \cdot of each definition and theorem statement bind
511
- // their variables before instantiation substitutes for them. A theorem that cannot be lambdified
512
- // states TRUE.
513
- const lambdifyUnits = (
514
- pipeline: Pipeline,
515
- scope: Scope | undefined,
516
- units: ModuleUnit[],
517
- ): [Scope | undefined, ModuleUnit[]] =>
518
- mapAccumulate(scope, units, (current, unit): [Scope | undefined, ModuleUnit] => {
519
- if (unit.kind === "Submod") {
520
- const [inner, body] = lambdifyUnits(pipeline, current, unit.module.body);
521
- return [inner, { ...unit, module: { ...unit.module, body } }];
522
- }
523
- const lambdified = lambdifyUnit(pipeline, current, unit);
524
- return [adjoinAll(current, getUnitHyps(lambdified)), lambdified];
525
- });
526
-
527
- // apply_subst: each parameter declaration of the instancee gives way to its substitute.
528
- const applyParameters = (units: ModuleUnit[], substitutes: Map<string, Expr>) => {
529
- const body: ModuleUnit[] = [];
530
- let size = 0;
531
- let rest = units;
532
- while (rest.length > 0) {
533
- const [unit, ...tail] = rest;
534
- const split =
535
- unit.kind === "Constants"
536
- ? {
537
- name: unit.declarations[0].name,
538
- remaining: { ...unit, declarations: unit.declarations.slice(1) },
539
- }
540
- : unit.kind === "Variables"
541
- ? { name: unit.names[0], remaining: { ...unit, names: unit.names.slice(1) } }
542
- : undefined;
543
- if (split) {
544
- const substitute = substitutes.get(split.name);
545
- if (!substitute) throw new TlaProofError(`Parameter ${split.name} has no substitute`);
546
- const isEmpty = getHypSize(split.remaining) === 0;
547
- rest = substituteUnits(
548
- consSubstitution(shiftExpr(size, substitute), shift(0)),
549
- isEmpty ? tail : [split.remaining, ...tail],
550
- );
551
- continue;
552
- }
553
- body.push(unit);
554
- size += getHypSize(unit);
555
- rest = tail;
556
- }
557
- return body;
558
- };
559
-
560
- // resub_for: references to the instancee's own units become applications to the instance
561
- // arguments, which the definitions now bind themselves.
562
- const getLocalSubstitution = (
563
- count: number,
564
- argumentCount: number,
565
- location: Locus | undefined,
566
- ): Substitution => {
567
- const args = Array.from({ length: argumentCount }, (_item, index) =>
568
- at({ kind: "Ix", index: argumentCount - index }, { location }),
569
- );
570
- const parameters = Array.from({ length: argumentCount }, (_item, index) =>
571
- at({ kind: "Ix", index: index + 1 }, { location }),
572
- );
573
- const locals = Array.from({ length: count }, (_item, index): Expr => {
574
- const operator = at({ kind: "Ix", index: index + argumentCount + 1 }, { location });
575
- return argumentCount > 0 ? at({ kind: "Apply", operator, args }, { location }) : operator;
576
- });
577
- return consAll([...locals, ...parameters].reverse(), shift(count + argumentCount));
578
- };
579
-
580
- const addParameters = (expression: Expr, args: string[]): Expr => {
581
- const params = args.map((name) => ({ name, shape: 0 }));
582
- if (expression.kind === "Lambda")
583
- return { ...expression, params: [...params, ...expression.params] };
584
- return args.length === 0
585
- ? expression
586
- : at({ kind: "Lambda", params, body: expression }, expression);
587
- };
588
-
589
- // localize: renames the instancee's units under the instance name, salts its local definitions
590
- const localize = (
591
- pipeline: Pipeline,
592
- units: ModuleUnit[],
593
- prefix: string,
594
- instance: InstanceDefinition,
595
- isLocal: boolean,
596
- location: Locus | undefined,
597
- ) => {
598
- const getName = (name: string) => (prefix === "" ? name : `${prefix}!${name}`);
599
- const argumentCount = instance.args.length;
600
- const body: ModuleUnit[] = [];
601
- let size = 0;
602
- let rest = units;
603
- let isComplained = argumentCount === 0;
604
- const complain = (text: string) => {
605
- if (isComplained) return;
606
- isComplained = true;
607
- pipeline.onWarning({ text, channel: "stderr" });
608
- };
609
- while (rest.length > 0) {
610
- const [unit, ...tail] = rest;
611
- rest = tail;
612
- const localized = (expression: Expr) =>
613
- addParameters(
614
- substituteExpr(getLocalSubstitution(size, argumentCount, location), expression),
615
- instance.args,
616
- );
617
- switch (unit.kind) {
618
- case "Definition": {
619
- const definition = unit.definition;
620
- if (definition.kind !== "Operator" && definition.kind !== "Bpragma") {
621
- throw new TlaProofError("Module.Elab.localize");
622
- }
623
- const name = unit.isLocal
624
- ? `${definition.name}$${getUnique(pipeline.salts)}`
625
- : definition.name;
626
- body.push({
627
- ...unit,
628
- definition: { ...definition, name: getName(name), body: localized(definition.body) },
629
- whereDefined: unit.isLocal ? "Builtin" : unit.whereDefined,
630
- isLocal: unit.isLocal || isLocal,
631
- });
632
- size += 1;
633
- continue;
634
- }
635
- case "Axiom": {
636
- complain(
637
- `${getLocusPrefix(location)}Instancing produces parametric axioms.\nSuch axioms will be forcibly hidden and cannot be cited.\n(This warning appears at-most once per INSTANCE declaration.)`,
638
- );
639
- const axiom: ModuleUnit = {
640
- ...unit,
641
- name: unit.name === undefined ? undefined : getName(unit.name),
642
- expression: localized(unit.expression),
643
- };
644
- body.push(axiom);
645
- size += getHypSize(axiom);
646
- continue;
647
- }
648
- case "Theorem": {
649
- complain(
650
- `${getAtPrefix(location)}Warning: Instancing produces parametric theorems.\nSuch theorems will be forcibly hidden and cannot be cited.\n(This warning appears at-most once per INSTANCE declaration.)`,
651
- );
652
- const expression = localized(at(exprifySequent(unit.sequent), unit));
653
- body.push({
654
- ...unit,
655
- name: unit.name === undefined ? undefined : getName(unit.name),
656
- sequent:
657
- expression.kind === "Sequent"
658
- ? expression.sequent
659
- : { context: [], active: expression },
660
- proof: { kind: "Omitted", omission: "Elsewhere", location: unit.location },
661
- });
662
- size += 1;
663
- continue;
664
- }
665
- case "Mutate":
666
- if (unit.mode === "Use") rest = substituteUnits(shift(-unit.usable.facts.length), rest);
667
- continue;
668
- case "Submod":
669
- continue;
670
- default:
671
- throw new TlaProofError("Module.Elab.localize");
672
- }
673
- }
674
- return body;
675
- };
676
-
677
- // localize_axioms: an axiom becomes a hypothesis of each theorem after it, and a named one also a
678
- // definition.
679
- const localizeAxioms = (units: ModuleUnit[]) => {
680
- const body: ModuleUnit[] = [];
681
- let rest = units;
682
- while (rest.length > 0) {
683
- const [unit, ...tail] = rest;
684
- if (unit.kind !== "Axiom") {
685
- body.push(unit);
686
- rest = tail;
687
- continue;
688
- }
689
- const location = unit.location;
690
- if (unit.name !== undefined) {
691
- body.push({
692
- kind: "Definition",
693
- definition: { kind: "Operator", name: unit.name, body: unit.expression, location },
694
- whereDefined: { kind: "Proof", time: "Always" },
695
- visibility: "Visible",
696
- isLocal: false,
697
- location,
698
- });
699
- }
700
- const hyp: Hyp = {
701
- kind: "Fact",
702
- expression:
703
- unit.name === undefined
704
- ? shiftExpr(1, unit.expression)
705
- : at({ kind: "Ix", index: 2 }, unit),
706
- visibility: "Visible",
707
- time: "Always",
708
- location,
709
- };
710
- let distance = 0;
711
- const inserted = tail.map((next): ModuleUnit => {
712
- const size = distance;
713
- distance += getHypSize(next);
714
- if (next.kind !== "Theorem") return next;
715
- const sequent = substituteSequent(shift(1), next.sequent);
716
- return {
717
- ...next,
718
- sequent: { ...sequent, context: [substituteHyp(shift(size), hyp), ...sequent.context] },
719
- axiomCount: next.axiomCount + 1,
720
- };
721
- });
722
- rest = substituteUnits(shift(-1), inserted);
723
- }
724
- return body;
725
- };
726
-
727
- const getParameters = (module: Mule) =>
728
- new Set(
729
- module.body.flatMap((unit) =>
730
- unit.kind === "Constants"
731
- ? unit.declarations.map((declaration) => declaration.name)
732
- : unit.kind === "Variables"
733
- ? unit.names
734
- : [],
735
- ),
736
- );
737
-
738
- // Module.Elab.instantiate: the units of an instantiated module, in the context of the instance.
739
- const instantiate = (
740
- pipeline: Pipeline,
741
- modules: Map<string, Mule>,
742
- scope: Scope | undefined,
743
- instance: InstanceDefinition,
744
- isLocal: boolean,
745
- prefix: string,
746
- location: Locus | undefined,
747
- ) => {
748
- const module = modules.get(instance.module);
749
- if (!module) throw new TlaProofError(`Module "${instance.module}" unknown`);
750
- const parameters = getParameters(module);
751
- for (const substitution of instance.substitutions) {
752
- if (!parameters.has(substitution.name)) {
753
- throw new TlaProofError(
754
- `Parameter ${substitution.name} occurs in the statement \`INSTANCE ${instance.module} WITH\`, and is not declared in the module ${instance.module}`,
755
- );
756
- }
757
- }
758
- const instanceScope = adjoinAll(
759
- scope,
760
- instance.args.map((name) => getFresh(name, "Unknown")),
761
- );
762
- const substitutes = new Map(
763
- instance.substitutions.map((entry) => [entry.name, entry.expression]),
764
- );
765
- for (const name of [...parameters].sort(compareNames)) {
766
- if (substitutes.has(name)) continue;
767
- if (!findNamed(instanceScope, name)) {
768
- throw new TlaProofError(
769
- `Required parameter ${name} for module ${instance.module} could not be inferred.`,
770
- );
771
- }
772
- substitutes.set(name, at({ kind: "Opaque", name }, { location }));
773
- }
774
- const anonymized = new Map(
775
- [...substitutes].map(([name, expression]) => [
776
- name,
777
- pipeline.anonymizer.expr(instanceScope, expression),
778
- ]),
779
- );
780
- const body = substituteUnits(
781
- shift((instanceScope?.size ?? 0) - (module.depth ?? 0)),
782
- module.body.map((unit): ModuleUnit =>
783
- unit.kind === "Theorem"
784
- ? {
785
- ...unit,
786
- proof: { kind: "Omitted", omission: "Implicit", location: unit.proof.location },
787
- }
788
- : unit,
789
- ),
790
- );
791
- const [, lambdified] = lambdifyUnits(pipeline, instanceScope, body);
792
- return localizeAxioms(
793
- localize(
794
- pipeline,
795
- applyParameters(lambdified, anonymized),
796
- prefix,
797
- instance,
798
- isLocal,
799
- location,
800
- ),
801
- );
802
- };
803
-
804
420
  // A named theorem binds its name as a proof definition, which its statement shifts past.
805
- const bindTheoremName = (
421
+ export const bindTheoremName = (
806
422
  name: string | undefined,
807
423
  sequent: Sequent,
808
424
  location: Locus | undefined,
@@ -827,242 +443,3 @@ const bindTheoremName = (
827
443
  ],
828
444
  sequent: substituteSequent(shift(1), sequent),
829
445
  };
830
-
831
- // make_defs: the definitions among the units an INSTANCE inside a LET or DEFINE stands for.
832
- export const expandInstance = (
833
- pipeline: Pipeline,
834
- scope: Scope | undefined,
835
- definition: Extract<Defn, { kind: "Instance" }>,
836
- ): Defn[] => {
837
- const name = definition.instance.module;
838
- if (!pipeline.latestModules.has(name)) {
839
- pipeline.onWarning({
840
- text: `${getLocusPrefix(definition.instance.location)}Module ${JSON.stringify(name)} unknown\n`,
841
- channel: "toolbox",
842
- });
843
- throw new TlaProofError(`Module ${JSON.stringify(name)} unknown`, {
844
- failure: "Module.Elab.anon#defns",
845
- });
846
- }
847
- const units = instantiate(
848
- pipeline,
849
- pipeline.latestModules,
850
- scope,
851
- definition.instance,
852
- true,
853
- definition.name,
854
- definition.location,
855
- );
856
- const definitions: Defn[] = [];
857
- let rest = units;
858
- while (rest.length > 0) {
859
- const [unit, ...tail] = rest;
860
- if (unit.kind !== "Definition") {
861
- rest = substituteUnits(shift(-getHypSize(unit)), tail);
862
- continue;
863
- }
864
- definitions.push(unit.definition);
865
- rest = tail;
866
- }
867
- return definitions;
868
- };
869
-
870
- // Module.Elab.normalize: anonymizes each unit in the context of the ones before it, expands
871
- // instances, merges repeated definitions, and simplifies the proofs of important modules. The
872
- // result also joins the modules that later instances can name.
873
- export const normalize = (
874
- pipeline: Pipeline,
875
- modules: Map<string, Mule>,
876
- scope: Scope | undefined,
877
- module: Mule,
878
- ): Mule => {
879
- const body: ModuleUnit[] = [];
880
- let current = scope;
881
- const emit = (unit: ModuleUnit) => {
882
- body.push(unit);
883
- current = adjoinAll(current, getUnitHyps(unit));
884
- };
885
- const isRedundant = (name: string | undefined) =>
886
- name !== undefined && findNamed(current, name) !== undefined;
887
- // Instantiated units arrive anonymized.
888
- const queue = module.body.map((unit) => ({ unit, isAnonymized: false }));
889
- for (let index = 0; index < queue.length; index++) {
890
- const unit = queue[index].unit;
891
- const expand = (instance: InstanceDefinition, isLocal: boolean, prefix: string) => {
892
- const units = instantiate(
893
- pipeline,
894
- modules,
895
- current,
896
- instance,
897
- isLocal,
898
- prefix,
899
- unit.location,
900
- );
901
- queue.splice(index + 1, 0, ...units.map((inner) => ({ unit: inner, isAnonymized: true })));
902
- };
903
- switch (unit.kind) {
904
- case "Anoninst":
905
- expand(unit.instance, unit.isLocal, "");
906
- continue;
907
- case "Definition": {
908
- const definition = unit.definition;
909
- if (definition.kind === "Instance") {
910
- expand(definition.instance, unit.isLocal, definition.name);
911
- continue;
912
- }
913
- const anonymized =
914
- definition.kind === "Recursive" || queue[index].isAnonymized
915
- ? definition
916
- : pipeline.anonymizer.defn(current, definition);
917
- const normalized: ModuleUnit = { ...unit, definition: anonymized };
918
- if (definition.kind === "Recursive") {
919
- emit(normalized);
920
- continue;
921
- }
922
- const hyp = getUnitHyps(normalized)[0];
923
- const found = findNamed(current, definition.name);
924
- if (found?.hyp.kind === "Defn") {
925
- const isMerged =
926
- found.hyp.definition.kind === "Recursive" ||
927
- isEqualHyp(substituteHyp(shift(found.depth + 1), found.hyp), hyp);
928
- if (isMerged) {
929
- const rest = queue.slice(index + 1);
930
- const substituted = substituteUnits(
931
- consSubstitution(at({ kind: "Ix", index: found.depth + 1 }, unit), shift(0)),
932
- rest.map((entry) => entry.unit),
933
- );
934
- queue.splice(
935
- index + 1,
936
- rest.length,
937
- ...rest.map((entry, offset) => ({ ...entry, unit: substituted[offset] })),
938
- );
939
- continue;
940
- }
941
- }
942
- emit(normalized);
943
- continue;
944
- }
945
- case "Recursives":
946
- case "Constants":
947
- case "Variables":
948
- emit(unit);
949
- continue;
950
- case "Axiom":
951
- if (isRedundant(unit.name)) continue;
952
- pipeline.latestModules = new Map(modules);
953
- emit({ ...unit, expression: pipeline.anonymizer.expr(current, unit.expression) });
954
- continue;
955
- case "Theorem": {
956
- const isDuplicate = isRedundant(unit.name);
957
- const name = isDuplicate ? `(redundant)${unit.name}` : unit.name;
958
- const proof: Proof = isDuplicate
959
- ? { kind: "Obvious", location: unit.proof.location }
960
- : unit.proof;
961
- pipeline.latestModules = new Map(modules);
962
- const sequent = pipeline.anonymizer.sequent(current, unit.sequent);
963
- const binding = bindTheoremName(name, sequent, unit.location);
964
- const proofScope = adjoinAll(
965
- adjoinAll(
966
- current,
967
- binding.hyps.map((hyp) => ({ ...hyp, isConstnessUnset: true })),
968
- ),
969
- binding.sequent.context,
970
- );
971
- const anonymized = pipeline.anonymizer.proof(proofScope, proof);
972
- const simplified = module.isImportant
973
- ? pipeline.generator.simplify(
974
- getScopeHyps(proofScope),
975
- binding.sequent.active,
976
- anonymized,
977
- getScopeTime(binding.sequent.context, "Always"),
978
- )
979
- : anonymized;
980
- emit({ ...unit, name, sequent, proof: simplified });
981
- continue;
982
- }
983
- case "Mutate":
984
- pipeline.latestModules = new Map(modules);
985
- emit({ ...unit, usable: pipeline.anonymizer.usable(current, unit.usable) });
986
- continue;
987
- case "Submod":
988
- emit({ ...unit, module: normalize(pipeline, modules, current, unit.module) });
989
- continue;
990
- }
991
- }
992
- const normalized = { ...module, body, depth: scope?.size ?? 0 };
993
- modules.set(module.name, normalized);
994
- return normalized;
995
- };
996
-
997
- export interface TheoremSummary extends ProofSummary {
998
- location: Locus | undefined;
999
- }
1000
-
1001
- export interface ModuleSummary extends ProofSummary {
1002
- theorems: TheoremSummary[];
1003
- }
1004
-
1005
- // Module.Gen.generate: a named theorem binds its name as a proof definition for what follows.
1006
- export const generate = (
1007
- pipeline: Pipeline,
1008
- context: Hyp[],
1009
- module: Mule,
1010
- ): { obligations: Obligation[]; summary: ModuleSummary } => {
1011
- const obligations: Obligation[] = [];
1012
- const theorems: TheoremSummary[] = [];
1013
- let summary = EMPTY_SUMMARY;
1014
- let current = context;
1015
- for (const unit of module.body) {
1016
- switch (unit.kind) {
1017
- case "Theorem": {
1018
- const binding = bindTheoremName(unit.name, unit.sequent, unit.location);
1019
- const named = [...current, ...binding.hyps];
1020
- const context = [...named, ...binding.sequent.context];
1021
- const proof = pipeline.generator.generate(
1022
- { context, active: binding.sequent.active },
1023
- unit.proof,
1024
- getScopeTime(context, "Always"),
1025
- );
1026
- obligations.push(...pipeline.generator.collect(proof));
1027
- const theorem = getProofSummary(proof);
1028
- theorems.push({ ...theorem, location: unit.location });
1029
- summary = joinSummaries(summary, theorem);
1030
- const fact: Expr =
1031
- unit.name === undefined
1032
- ? at(exprifySequent(unit.sequent), unit)
1033
- : { kind: "Ix", index: 1, location: unit.location };
1034
- current = [
1035
- ...named,
1036
- {
1037
- kind: "Fact",
1038
- expression: fact,
1039
- visibility: "Hidden",
1040
- time: "Always",
1041
- location: unit.location,
1042
- },
1043
- ];
1044
- continue;
1045
- }
1046
- case "Submod": {
1047
- const generated = generate(pipeline, current, unit.module);
1048
- obligations.push(...generated.obligations);
1049
- summary = joinSummaries(summary, generated.summary);
1050
- continue;
1051
- }
1052
- case "Mutate": {
1053
- const [next, generated] = pipeline.generator.mutate(
1054
- current,
1055
- unit.mode,
1056
- unit.usable,
1057
- unit.location,
1058
- );
1059
- obligations.push(...generated);
1060
- current = next;
1061
- continue;
1062
- }
1063
- default:
1064
- current = [...current, ...getUnitHyps(unit)];
1065
- }
1066
- }
1067
- return { obligations, summary: { ...summary, theorems } };
1068
- };