tla-ts 0.0.3 → 0.0.4-dev.2a873ee

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 (370) hide show
  1. package/README.md +46 -115
  2. package/dist/cli.cjs +1 -1
  3. package/dist/cli.js +1 -1
  4. package/dist/deciders.cjs +366 -0
  5. package/dist/deciders.js +366 -0
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +194 -8
  8. package/dist/index.d.ts +194 -8
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -4
  11. package/dist/parallel-worker.js +1 -4
  12. package/dist/prove-worker.cjs +9 -0
  13. package/dist/prove-worker.d.cts +9 -0
  14. package/dist/prove-worker.d.ts +9 -0
  15. package/dist/prove-worker.js +9 -0
  16. package/dist/prove.cjs +996 -0
  17. package/dist/prove.js +996 -0
  18. package/dist/run-cli.cjs +37 -20
  19. package/dist/run-cli.js +37 -20
  20. package/dist/tlapm.cjs +10 -0
  21. package/dist/tlapm.js +10 -0
  22. package/dist/transfer.cjs +1387 -18
  23. package/dist/transfer.js +1387 -18
  24. package/dist/worker.cjs +21 -0
  25. package/dist/worker.js +21 -0
  26. package/package.json +24 -11
  27. package/src/ast.ts +149 -8
  28. package/src/bags.ts +4 -7
  29. package/src/builtins.ts +29 -11
  30. package/src/bundled-modules.ts +3 -3
  31. package/src/canonical.ts +4 -3
  32. package/src/check.ts +1540 -235
  33. package/src/cli-options.ts +12 -6
  34. package/src/cli.ts +8 -1
  35. package/src/codegen.ts +98 -39
  36. package/src/config.ts +254 -181
  37. package/src/dependencies.ts +2 -2
  38. package/src/environment.ts +540 -140
  39. package/src/errors.ts +284 -4
  40. package/src/evaluate.ts +1043 -293
  41. package/src/exit-codes.ts +22 -43
  42. package/src/fingerprints.ts +46 -11
  43. package/src/index.ts +11 -0
  44. package/src/instances.ts +19 -16
  45. package/src/java-overrides.ts +104 -25
  46. package/src/levels.ts +191 -45
  47. package/src/lexer.ts +127 -30
  48. package/src/live-check.ts +867 -0
  49. package/src/liveness.ts +218 -572
  50. package/src/{obligation-action.ts → obligations/action.ts} +247 -69
  51. package/src/{obligation-anon.ts → obligations/anon.ts} +49 -47
  52. package/src/obligations/ctx.ts +64 -0
  53. package/src/{obligation-deref.ts → obligations/deref.ts} +51 -92
  54. package/src/{obligation-expression.ts → obligations/expression.ts} +117 -57
  55. package/src/{obligation-format.ts → obligations/format.ts} +7 -8
  56. package/src/{obligation-generate.ts → obligations/generate.ts} +170 -192
  57. package/src/{obligations.ts → obligations/index.ts} +32 -16
  58. package/src/{obligation-levels.ts → obligations/levels.ts} +26 -28
  59. package/src/{obligation-module.ts → obligations/module.ts} +113 -121
  60. package/src/obligations/pickle.ts +98 -0
  61. package/src/obligations/pragma.ts +189 -0
  62. package/src/{obligation-printer.ts → obligations/printer.ts} +22 -80
  63. package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
  64. package/src/{obligation-source.ts → obligations/source.ts} +156 -99
  65. package/src/obligations/temporal.ts +321 -0
  66. package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
  67. package/src/ocaml-marshal.ts +166 -0
  68. package/src/parallel-worker.ts +169 -224
  69. package/src/parallel.ts +140 -81
  70. package/src/parser.ts +456 -147
  71. package/src/pcal-ast.ts +770 -0
  72. package/src/pcal-parse.ts +1523 -0
  73. package/src/pcal-tokenize.ts +516 -0
  74. package/src/pcal-translate.ts +1230 -0
  75. package/src/pcal-validate.ts +454 -0
  76. package/src/prove/decide-pool.ts +95 -0
  77. package/src/prove/deciders.ts +33 -0
  78. package/src/prove/first-order.ts +78 -0
  79. package/src/prove/isabelle/LICENSE +36 -0
  80. package/src/prove/isabelle/LICENSE-tlapm +26 -0
  81. package/src/prove/isabelle/decide.ts +47 -0
  82. package/src/prove/isabelle/encode.ts +446 -0
  83. package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
  84. package/src/prove/isabelle/isar/method.ts +367 -0
  85. package/src/prove/isabelle/isar/proof.ts +28 -0
  86. package/src/prove/isabelle/isar/statement.ts +57 -0
  87. package/src/prove/isabelle/isar/theory.ts +192 -0
  88. package/src/prove/isabelle/isar/type-check.ts +278 -0
  89. package/src/prove/isabelle/provers/blast/blast.ts +258 -0
  90. package/src/prove/isabelle/provers/blast/branch.ts +322 -0
  91. package/src/prove/isabelle/provers/blast/prove.ts +347 -0
  92. package/src/prove/isabelle/provers/blast/rules.ts +330 -0
  93. package/src/prove/isabelle/provers/blast/state.ts +180 -0
  94. package/src/prove/isabelle/provers/blast/term.ts +546 -0
  95. package/src/prove/isabelle/provers/clasimp.ts +150 -0
  96. package/src/prove/isabelle/provers/classical.ts +389 -0
  97. package/src/prove/isabelle/provers/hypsubst.ts +433 -0
  98. package/src/prove/isabelle/pure/bicompose.ts +174 -0
  99. package/src/prove/isabelle/pure/consts.ts +32 -0
  100. package/src/prove/isabelle/pure/conv.ts +79 -0
  101. package/src/prove/isabelle/pure/drule.ts +264 -0
  102. package/src/prove/isabelle/pure/envir.ts +331 -0
  103. package/src/prove/isabelle/pure/goal.ts +53 -0
  104. package/src/prove/isabelle/pure/interrupt.ts +16 -0
  105. package/src/prove/isabelle/pure/list.ts +12 -0
  106. package/src/prove/isabelle/pure/logic.ts +330 -0
  107. package/src/prove/isabelle/pure/name.ts +98 -0
  108. package/src/prove/isabelle/pure/net.ts +215 -0
  109. package/src/prove/isabelle/pure/object-logic.ts +41 -0
  110. package/src/prove/isabelle/pure/pattern.ts +631 -0
  111. package/src/prove/isabelle/pure/raw-simplifier.ts +338 -0
  112. package/src/prove/isabelle/pure/rewriter.ts +602 -0
  113. package/src/prove/isabelle/pure/search.ts +68 -0
  114. package/src/prove/isabelle/pure/seq.ts +133 -0
  115. package/src/prove/isabelle/pure/simplifier.ts +106 -0
  116. package/src/prove/isabelle/pure/table.ts +201 -0
  117. package/src/prove/isabelle/pure/tactic.ts +168 -0
  118. package/src/prove/isabelle/pure/tactical.ts +264 -0
  119. package/src/prove/isabelle/pure/term-ord.ts +105 -0
  120. package/src/prove/isabelle/pure/term.ts +688 -0
  121. package/src/prove/isabelle/pure/thm.ts +783 -0
  122. package/src/prove/isabelle/pure/type.ts +121 -0
  123. package/src/prove/isabelle/pure/unify.ts +753 -0
  124. package/src/prove/isabelle/pure/variable.ts +25 -0
  125. package/src/prove/isabelle/tla/classical-setup.ts +101 -0
  126. package/src/prove/isabelle/tla/context.ts +74 -0
  127. package/src/prove/isabelle/tla/logic-data.ts +5 -0
  128. package/src/prove/isabelle/tla/logic.ts +215 -0
  129. package/src/prove/isabelle/tla/simpdata.ts +241 -0
  130. package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
  131. package/src/prove/ocaml.ts +22 -0
  132. package/src/prove/prep/action.ts +508 -0
  133. package/src/prove/prep/defs.ts +33 -0
  134. package/src/prove/prep/elab.ts +156 -0
  135. package/src/prove/prep/enabled-axioms.ts +189 -0
  136. package/src/prove/prep/enabled.ts +43 -0
  137. package/src/prove/prep/fingerprint.ts +388 -0
  138. package/src/prove/prep/flatten.ts +70 -0
  139. package/src/prove/prep/level-comparison.ts +529 -0
  140. package/src/prove/prep/md5.ts +67 -0
  141. package/src/prove/prep/pragma.ts +221 -0
  142. package/src/prove/prep/trivial.ts +22 -0
  143. package/src/prove/prove-worker.ts +22 -0
  144. package/src/prove/prove.ts +498 -0
  145. package/src/prove/ptl/decide.ts +68 -0
  146. package/src/prove/ptl/encode.ts +255 -0
  147. package/src/prove/ptl/sat.ts +151 -0
  148. package/src/prove/ptl/tableau.ts +276 -0
  149. package/src/prove/smt/axiomatize.ts +69 -0
  150. package/src/prove/smt/axioms.ts +209 -0
  151. package/src/prove/smt/context.ts +108 -0
  152. package/src/prove/smt/data.ts +636 -0
  153. package/src/prove/smt/encode.ts +164 -0
  154. package/src/prove/smt/extensionality.ts +65 -0
  155. package/src/prove/smt/flatten.ts +112 -0
  156. package/src/prove/smt/format.ts +154 -0
  157. package/src/prove/smt/instances.ts +181 -0
  158. package/src/prove/smt/rewrite.ts +772 -0
  159. package/src/prove/smt/simplify.ts +57 -0
  160. package/src/prove/smt/solver/act-cache.ts +265 -0
  161. package/src/prove/smt/solver/arith-rewriter.ts +962 -0
  162. package/src/prove/smt/solver/array.ts +22 -0
  163. package/src/prove/smt/solver/asserted-formulas.ts +469 -0
  164. package/src/prove/smt/solver/ast-lt.ts +157 -0
  165. package/src/prove/smt/solver/ast-util.ts +91 -0
  166. package/src/prove/smt/solver/ast.ts +1315 -0
  167. package/src/prove/smt/solver/auf-solver.ts +572 -0
  168. package/src/prove/smt/solver/case-split-queue.ts +178 -0
  169. package/src/prove/smt/solver/cg-table.ts +175 -0
  170. package/src/prove/smt/solver/clause.ts +276 -0
  171. package/src/prove/smt/solver/conflict-resolution.ts +343 -0
  172. package/src/prove/smt/solver/context.ts +1292 -0
  173. package/src/prove/smt/solver/ctx-simplify.ts +334 -0
  174. package/src/prove/smt/solver/der.ts +224 -0
  175. package/src/prove/smt/solver/dyn-ack.ts +141 -0
  176. package/src/prove/smt/solver/e-matching.ts +659 -0
  177. package/src/prove/smt/solver/enode.ts +259 -0
  178. package/src/prove/smt/solver/expr-ref.ts +21 -0
  179. package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
  180. package/src/prove/smt/solver/fingerprints.ts +92 -0
  181. package/src/prove/smt/solver/flat-literals.ts +51 -0
  182. package/src/prove/smt/solver/goal.ts +138 -0
  183. package/src/prove/smt/solver/hash.ts +173 -0
  184. package/src/prove/smt/solver/hashtable.ts +166 -0
  185. package/src/prove/smt/solver/internalizer.ts +1381 -0
  186. package/src/prove/smt/solver/lbool.ts +5 -0
  187. package/src/prove/smt/solver/literal.ts +24 -0
  188. package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
  189. package/src/prove/smt/solver/lp/constraints.ts +78 -0
  190. package/src/prove/smt/solver/lp/containers.ts +296 -0
  191. package/src/prove/smt/solver/lp/core-solver.ts +504 -0
  192. package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
  193. package/src/prove/smt/solver/lp/dep-intervals.ts +642 -0
  194. package/src/prove/smt/solver/lp/dependency.ts +51 -0
  195. package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
  196. package/src/prove/smt/solver/lp/explanation.ts +46 -0
  197. package/src/prove/smt/solver/lp/gomory.ts +255 -0
  198. package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
  199. package/src/prove/smt/solver/lp/hnf.ts +281 -0
  200. package/src/prove/smt/solver/lp/int-cube.ts +295 -0
  201. package/src/prove/smt/solver/lp/int-solver.ts +514 -0
  202. package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
  203. package/src/prove/smt/solver/lp/lar-term.ts +62 -0
  204. package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
  205. package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
  206. package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
  207. package/src/prove/smt/solver/lp/nex.ts +120 -0
  208. package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
  209. package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
  210. package/src/prove/smt/solver/lp/nla-core.ts +968 -0
  211. package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
  212. package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
  213. package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
  214. package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
  215. package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
  216. package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
  217. package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
  218. package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
  219. package/src/prove/smt/solver/lp/nla-order.ts +307 -0
  220. package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
  221. package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
  222. package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
  223. package/src/prove/smt/solver/lp/nla-types.ts +124 -0
  224. package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
  225. package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
  226. package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
  227. package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
  228. package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
  229. package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
  230. package/src/prove/smt/solver/lp/pdd.ts +971 -0
  231. package/src/prove/smt/solver/lp/random-updater.ts +138 -0
  232. package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
  233. package/src/prove/smt/solver/lp/union-find.ts +96 -0
  234. package/src/prove/smt/solver/mam-compiler.ts +847 -0
  235. package/src/prove/smt/solver/mam-interpreter.ts +400 -0
  236. package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
  237. package/src/prove/smt/solver/model-checker.ts +347 -0
  238. package/src/prove/smt/solver/model-evaluator.ts +262 -0
  239. package/src/prove/smt/solver/model-finder.ts +155 -0
  240. package/src/prove/smt/solver/model-generator.ts +97 -0
  241. package/src/prove/smt/solver/model-macro-solver.ts +728 -0
  242. package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
  243. package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
  244. package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
  245. package/src/prove/smt/solver/nlsat/explain.ts +607 -0
  246. package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
  247. package/src/prove/smt/solver/nlsat/levelwise.ts +737 -0
  248. package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
  249. package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
  250. package/src/prove/smt/solver/nlsat/solver.ts +911 -0
  251. package/src/prove/smt/solver/nlsat/types.ts +43 -0
  252. package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
  253. package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
  254. package/src/prove/smt/solver/nnf.ts +469 -0
  255. package/src/prove/smt/solver/pattern-inference.ts +351 -0
  256. package/src/prove/smt/solver/poly-rewriter.ts +477 -0
  257. package/src/prove/smt/solver/propagate-values.ts +83 -0
  258. package/src/prove/smt/solver/proto-model.ts +551 -0
  259. package/src/prove/smt/solver/pull-quant.ts +139 -0
  260. package/src/prove/smt/solver/qe-lite-der.ts +526 -0
  261. package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
  262. package/src/prove/smt/solver/qe-lite.ts +381 -0
  263. package/src/prove/smt/solver/qi-queue.ts +362 -0
  264. package/src/prove/smt/solver/quant-tactics.ts +117 -0
  265. package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
  266. package/src/prove/smt/solver/quantifier-manager.ts +186 -0
  267. package/src/prove/smt/solver/random-gen.ts +10 -0
  268. package/src/prove/smt/solver/rational.ts +165 -0
  269. package/src/prove/smt/solver/ref-vector.ts +62 -0
  270. package/src/prove/smt/solver/relevancy.ts +247 -0
  271. package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
  272. package/src/prove/smt/solver/rewriter.ts +843 -0
  273. package/src/prove/smt/solver/rlimit.ts +79 -0
  274. package/src/prove/smt/solver/smtlib-parser.ts +526 -0
  275. package/src/prove/smt/solver/solver.ts +71 -0
  276. package/src/prove/smt/solver/sort.ts +35 -0
  277. package/src/prove/smt/solver/sticky-generations.ts +69 -0
  278. package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
  279. package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
  280. package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
  281. package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
  282. package/src/prove/smt/solver/theory-lra-model.ts +243 -0
  283. package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
  284. package/src/prove/smt/solver/theory-lra-state.ts +43 -0
  285. package/src/prove/smt/solver/theory-lra.ts +56 -0
  286. package/src/prove/smt/solver/var-subst.ts +258 -0
  287. package/src/prove/smt/solver/z3-license.txt +10 -0
  288. package/src/prove/smt/table.ts +170 -0
  289. package/src/prove/tlapm/tlapm.ts +96 -0
  290. package/src/prove/tlaps-module.ts +510 -0
  291. package/src/prove/verdict.ts +18 -0
  292. package/src/prove/zenon/LICENSE +32 -0
  293. package/src/prove/zenon/check/check.ts +105 -0
  294. package/src/prove/zenon/check/definitions.ts +144 -0
  295. package/src/prove/zenon/check/equality.ts +182 -0
  296. package/src/prove/zenon/check/functions.ts +62 -0
  297. package/src/prove/zenon/check/keys.ts +125 -0
  298. package/src/prove/zenon/check/propositional.ts +104 -0
  299. package/src/prove/zenon/check/records.ts +188 -0
  300. package/src/prove/zenon/check/relations.ts +121 -0
  301. package/src/prove/zenon/check/rewrites.ts +224 -0
  302. package/src/prove/zenon/check/sets.ts +302 -0
  303. package/src/prove/zenon/check/terms.ts +127 -0
  304. package/src/prove/zenon/check/tla.ts +126 -0
  305. package/src/prove/zenon/decide.ts +113 -0
  306. package/src/prove/zenon/encode.ts +379 -0
  307. package/src/prove/zenon/eqrel.ts +300 -0
  308. package/src/prove/zenon/equality-rules.ts +435 -0
  309. package/src/prove/zenon/expr.ts +551 -0
  310. package/src/prove/zenon/index-table.ts +350 -0
  311. package/src/prove/zenon/isar-case.ts +513 -0
  312. package/src/prove/zenon/isar.ts +1249 -0
  313. package/src/prove/zenon/limits.ts +15 -0
  314. package/src/prove/zenon/llproof.ts +173 -0
  315. package/src/prove/zenon/mltoll.ts +1566 -0
  316. package/src/prove/zenon/node.ts +297 -0
  317. package/src/prove/zenon/ocaml.ts +169 -0
  318. package/src/prove/zenon/parse.ts +247 -0
  319. package/src/prove/zenon/phrase.ts +191 -0
  320. package/src/prove/zenon/proof.ts +198 -0
  321. package/src/prove/zenon/propositional-rules.ts +387 -0
  322. package/src/prove/zenon/rules.ts +94 -0
  323. package/src/prove/zenon/search.ts +288 -0
  324. package/src/prove/zenon/tla/functions.ts +151 -0
  325. package/src/prove/zenon/tla/llproof.ts +480 -0
  326. package/src/prove/zenon/tla/records.ts +225 -0
  327. package/src/prove/zenon/tla/rewrites.ts +447 -0
  328. package/src/prove/zenon/tla/sets.ts +304 -0
  329. package/src/prove/zenon/tla/terms.ts +162 -0
  330. package/src/prove/zenon/tla/tla.ts +506 -0
  331. package/src/randomization.ts +24 -7
  332. package/src/resolve.ts +1481 -426
  333. package/src/run-cli.ts +1483 -212
  334. package/src/runtime.ts +19 -1
  335. package/src/sany-builtins.ts +147 -0
  336. package/src/sany-generator.ts +3128 -0
  337. package/src/sany-levels.ts +1208 -0
  338. package/src/sany-lexer.ts +545 -0
  339. package/src/sany-linter.ts +122 -0
  340. package/src/sany-modules.ts +1398 -0
  341. package/src/sany-nodes.ts +463 -0
  342. package/src/sany-parse-error.ts +2161 -0
  343. package/src/sany-report.ts +356 -0
  344. package/src/sany-selectors.ts +738 -0
  345. package/src/sany-source.ts +248 -0
  346. package/src/sany-xml.ts +1017 -0
  347. package/src/spec-description.ts +42 -11
  348. package/src/standard-modules.ts +203 -148
  349. package/src/standard-ranges.ts +116 -0
  350. package/src/state-graph.ts +180 -0
  351. package/src/subexpressions.ts +231 -171
  352. package/src/substitution-levels.ts +38 -17
  353. package/src/successors.ts +241 -110
  354. package/src/symmetry.ts +194 -54
  355. package/src/tableau.ts +54 -25
  356. package/src/tlapm-cache.ts +236 -0
  357. package/src/tlc-ext.ts +42 -29
  358. package/src/tlc-messages.ts +329 -0
  359. package/src/tlc-module.ts +52 -43
  360. package/src/tlc-modules.ts +4 -0
  361. package/src/tlc-order.ts +78 -10
  362. package/src/tlc-random.ts +84 -33
  363. package/src/tlc-replay.ts +655 -0
  364. package/src/tlc-summary.ts +20 -5
  365. package/src/tlc-version.ts +19 -0
  366. package/src/transfer.ts +15 -3
  367. package/src/values.ts +787 -190
  368. package/src/worker.ts +65 -0
  369. package/dist/parallel.cjs +0 -12
  370. package/dist/parallel.js +0 -12
@@ -0,0 +1,454 @@
1
+ import { PcalError, PcalRuntimeError } from "./errors";
2
+ import {
3
+ formatPcalNode,
4
+ getPcalLocation,
5
+ getPcalVersionNumber,
6
+ PCAL_VERSION_WEIGHT,
7
+ type PcalAlgorithm,
8
+ } from "./pcal-ast";
9
+ import { parsePcalAlgorithm, type PcalSession } from "./pcal-parse";
10
+ import { createPcalCharReader } from "./pcal-tokenize";
11
+ import { translatePcalAlgorithm } from "./pcal-translate";
12
+ import type { TlcVersion } from "./tlc-version";
13
+
14
+ // Validator.ValidationResult.
15
+ type PcalValidationResult =
16
+ | "NO_PLUSCAL_EXISTS"
17
+ | "NO_TRANSLATION_EXISTS"
18
+ | "NO_PCAL_CHECKSUMS_EXIST"
19
+ | "TLA_DIVERGENCE_EXISTS"
20
+ | "PCAL_DIVERGENCE_EXISTS"
21
+ | "ERROR_ENCOUNTERED"
22
+ | "NO_DIVERGENCE";
23
+
24
+ // Java's \s, which unlike JavaScript's matches no Unicode spaces.
25
+ const SPACE = "[ \\t\\n\\x0B\\f\\r]";
26
+
27
+ // Validator.CHECKSUM_PATTERN, whose (?i) groups become character classes.
28
+ const CHECKSUM_PATTERN = new RegExp(
29
+ `\\\\\\* BEGIN TRANSLATION${SPACE}+\\(${SPACE}*([cC][hH]([eE][cC])?[kK][sS][uU][mM]\\([pP]([lL][uU][sS])?[cC][aA][lL]\\))${SPACE}*(=${SPACE}*"(?<pcal>[0-9A-Fa-f]*)"|\\\\in${SPACE}*STRING)${SPACE}*\\/\\\\${SPACE}*([cC][hH]([eE][cC])?[kK][sS][uU][mM]\\([tT][lL][aA]\\+?\\))${SPACE}*(=${SPACE}*"(?<tla>[0-9A-Fa-f]*)"|\\\\in${SPACE}*STRING)${SPACE}*\\)`,
30
+ );
31
+
32
+ // Validator.checksum: CRC32 of the string's bytes, in Long.toHexString's unpadded lowercase hex.
33
+ // Only a spec with PlusCal needs node:zlib, so it loads then rather than at startup.
34
+ const getChecksum = (text: string) =>
35
+ process.getBuiltinModule("node:zlib").crc32(Buffer.from(text, "utf8")).toString(16);
36
+
37
+ const reportUnrecoverableError = (session: PcalSession, message: string) =>
38
+ session.log(`\nUnrecoverable error:\n -- ${message}.\n`);
39
+
40
+ // PcalDebug.reportError: an UnrecoverablePositionedException names its statement's position.
41
+ const reportPcalError = (session: PcalSession, error: PcalError) =>
42
+ reportUnrecoverableError(
43
+ session,
44
+ error.node === undefined || error.node.line === 0
45
+ ? error.message
46
+ : `${error.message}\n at ${getPcalLocation(error.node)}`,
47
+ );
48
+
49
+ // trans.removeTabs: tabs reach the next multiple of 8, and every line gets a trailing space.
50
+ const removeTabs = (lines: string[]) =>
51
+ lines.map(
52
+ (line) =>
53
+ `${Array.from(line).reduce(
54
+ (result, char) =>
55
+ char === "\t" ? result + " ".repeat(8 - (result.length % 8)) : result + char,
56
+ "",
57
+ )} `,
58
+ );
59
+
60
+ // trans.findTokenPair: the first line from start with first followed by second after spaces.
61
+ const findTokenPair = (lines: string[], start: number, first: string, second: string) => {
62
+ for (let index = Math.max(start, 0); index < lines.length; index++) {
63
+ const line = lines[index];
64
+ const column = line.indexOf(first);
65
+ if (column === -1) continue;
66
+ const afterFirst = column + first.length;
67
+ const spaces = line.slice(afterFirst).search(/[^ ]/);
68
+ if (spaces !== -1 && afterFirst + spaces === line.indexOf(second)) return index;
69
+ }
70
+ return -1;
71
+ };
72
+
73
+ interface PcalSearchLocation {
74
+ line: number;
75
+ column: number;
76
+ }
77
+
78
+ // ParseAlgorithm.GotoNextNonSpace: moves the location to the next character that isn't a space,
79
+ // returning its line, or "" past the last line.
80
+ const gotoNextNonSpace = (lines: string[], location: PcalSearchLocation) => {
81
+ while (location.line < lines.length) {
82
+ const line = lines[location.line];
83
+ while (location.column < line.length && line[location.column] === " ") location.column += 1;
84
+ if (location.column < line.length) return line;
85
+ location.line += 1;
86
+ location.column = 0;
87
+ }
88
+ return "";
89
+ };
90
+
91
+ // ParseAlgorithm.NextSpaceCol and NextDelimiterCol: the first delimiter from column on, or the
92
+ // end of the line.
93
+ const getNextDelimiter = (line: string, column: number, delimiters: string) => {
94
+ const index = Array.from(line.slice(column)).findIndex((char) => delimiters.includes(char));
95
+ return index === -1 ? line.length : column + line.slice(column, column + index).length;
96
+ };
97
+
98
+ const isIdChar = (char: string) => /^[\p{L}\p{Nd}_]$/u.test(char);
99
+
100
+ // ParseAlgorithm.FindToken: moves the location past the next occurrence of token that starts a
101
+ // word and isn't followed by a letter or "_".
102
+ const findToken = (lines: string[], location: PcalSearchLocation, token: string) => {
103
+ while (location.line < lines.length) {
104
+ const line = gotoNextNonSpace(lines, location);
105
+ if (line.slice(location.column).startsWith(token)) {
106
+ const end = location.column + token.length;
107
+ if (end >= line.length || !/^[\p{L}_]$/u.test(line[end])) {
108
+ location.column = getNextDelimiter(line, end, " ");
109
+ return true;
110
+ }
111
+ }
112
+ location.column = getNextDelimiter(line, location.column, " ");
113
+ }
114
+ return false;
115
+ };
116
+
117
+ // trans.CommandLineError.
118
+ const reportCommandLineError = (session: PcalSession, message: string) =>
119
+ reportUnrecoverableError(session, `Command-line error: ${message}`);
120
+
121
+ // trans.parseAndProcessArguments for the options of a "PlusCal options" statement, which set the
122
+ // translator's options for the rest of SANY's run.
123
+ const processOptionArguments = (session: PcalSession, args: string[]) => {
124
+ const params = session.params;
125
+ const fairness = { isFirst: true, isExplicitNof: false };
126
+ const setFairness = (option: string) => {
127
+ if (fairness.isFirst) {
128
+ params.fairnessOption = "";
129
+ fairness.isFirst = false;
130
+ }
131
+ if (params.fairnessOption !== "") {
132
+ reportCommandLineError(session, "Can only have one of -wf, -sf, -wfNext, and -nof options");
133
+ return false;
134
+ }
135
+ params.fairnessOption = option;
136
+ return true;
137
+ };
138
+ for (let index = 0; index < args.length; index++) {
139
+ const option = args[index];
140
+ const argument = args[index + 1];
141
+ switch (option) {
142
+ case "-spec":
143
+ case "spec":
144
+ case "-myspec":
145
+ case "myspec": {
146
+ const isMyspec = option.endsWith("myspec");
147
+ params[isMyspec ? "myspecOption" : "specOption"] = true;
148
+ if (params.specOption && params.myspecOption) {
149
+ reportCommandLineError(
150
+ session,
151
+ "\nCan have at most one of the options -spec, -myspec, -spec2, -myspec2, writeAST",
152
+ );
153
+ return;
154
+ }
155
+ if (argument === undefined) {
156
+ reportCommandLineError(
157
+ session,
158
+ `Specification name must follow \`-${isMyspec ? "myspec" : "spec"}' option`,
159
+ );
160
+ return;
161
+ }
162
+ params.specFile = argument;
163
+ index += 1;
164
+ continue;
165
+ }
166
+ case "-termination":
167
+ case "termination":
168
+ params.checkTermination = true;
169
+ continue;
170
+ case "-noold":
171
+ params.noOld = true;
172
+ continue;
173
+ case "-nocfg":
174
+ params.nocfg = true;
175
+ continue;
176
+ case "-noDoneDisjunct":
177
+ case "noDoneDisjunct":
178
+ params.noDoneDisjunct = true;
179
+ continue;
180
+ case "-wf":
181
+ case "wf":
182
+ case "-sf":
183
+ case "sf":
184
+ case "-wfNext":
185
+ case "wfNext":
186
+ case "-nof":
187
+ case "nof":
188
+ if (!setFairness(option.replace(/^-/, ""))) return;
189
+ if (option.endsWith("nof")) fairness.isExplicitNof = true;
190
+ continue;
191
+ case "-label":
192
+ case "label":
193
+ params.labelFlag = true;
194
+ continue;
195
+ case "-labelRoot":
196
+ case "labelRoot":
197
+ if (argument === undefined) {
198
+ reportCommandLineError(session, "Label root must follow `-labelRoot' option");
199
+ return;
200
+ }
201
+ if (!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(argument)) {
202
+ reportCommandLineError(
203
+ session,
204
+ "Label root must be a valid PlusCal identifier (must start with a letter and contain only letters, numbers, and underscores)",
205
+ );
206
+ return;
207
+ }
208
+ params.labelRoot = argument;
209
+ index += 1;
210
+ continue;
211
+ case "-version":
212
+ case "version": {
213
+ if (argument === undefined) {
214
+ reportCommandLineError(session, "Version number must follow `-version' option");
215
+ return;
216
+ }
217
+ // PcalParams.ProcessVersion.
218
+ const version = getPcalVersionNumber(argument);
219
+ if (version < 0 || version > PCAL_VERSION_WEIGHT) {
220
+ reportUnrecoverableError(
221
+ session,
222
+ version < 0
223
+ ? `Illegal version ${argument} specified.`
224
+ : `Specified version ${argument} later than current version 1.12`,
225
+ );
226
+ reportCommandLineError(session, "Bad version number");
227
+ return;
228
+ }
229
+ params.inputVersionNumber = version;
230
+ index += 1;
231
+ continue;
232
+ }
233
+ case "-lineWidth":
234
+ // PcalTLAGen's line width only shapes the translation's text.
235
+ if (!/^[+-]?\d+$/.test(argument ?? "") || Number(argument) < 60) {
236
+ reportCommandLineError(
237
+ session,
238
+ "Integer value at least 60 must follow `-lineWidth' option",
239
+ );
240
+ return;
241
+ }
242
+ index += 1;
243
+ continue;
244
+ default:
245
+ reportCommandLineError(
246
+ session,
247
+ `Unknown or illegal option in options statement: ${option}`,
248
+ );
249
+ return;
250
+ }
251
+ }
252
+ if (params.checkTermination && params.fairnessOption === "" && !fairness.isExplicitNof) {
253
+ params.fairnessOption = "wf";
254
+ }
255
+ };
256
+
257
+ // ParseAlgorithm.ProcessOptions: the location is just past "PlusCal".
258
+ const processOptions = (session: PcalSession, lines: string[], location: PcalSearchLocation) => {
259
+ gotoNextNonSpace(lines, location);
260
+ location.column += "options".length;
261
+ const afterOptions = gotoNextNonSpace(lines, location);
262
+ if (!afterOptions.slice(location.column).startsWith("(")) {
263
+ reportUnrecoverableError(session, "`PlusCal options' not followed by '('");
264
+ return;
265
+ }
266
+ location.column += 1;
267
+ const args: string[] = [];
268
+ for (;;) {
269
+ const line = gotoNextNonSpace(lines, location);
270
+ if (location.line >= lines.length || line[location.column] === ")") break;
271
+ if (line[location.column] === ",") {
272
+ location.column += 1;
273
+ continue;
274
+ }
275
+ const end = getNextDelimiter(line, location.column, " ,)");
276
+ args.push(line.slice(location.column, end));
277
+ location.column = end;
278
+ }
279
+ if (location.line >= lines.length) {
280
+ reportUnrecoverableError(session, "No closing ')' found in options statement");
281
+ return;
282
+ }
283
+ processOptionArguments(session, args);
284
+ };
285
+
286
+ // ParseAlgorithm.uncomment: blanks out the comment delimiters and nested comments from the
287
+ // algorithm's start to the "*)" that ends the comment it is in, dropping the rest of that line,
288
+ // and returns the error it throws for a line that ends in a string.
289
+ const uncomment = (lines: string[], startLine: number, startColumn: number) => {
290
+ const scan = { depth: 0, isDone: false, isInString: false };
291
+ for (let index = startLine; !scan.isDone && index < lines.length; index++) {
292
+ const line = lines[index];
293
+ const start = index === startLine ? startColumn : 0;
294
+ const output = [line.slice(0, start)];
295
+ scan.isInString = false;
296
+ for (let column = start; !scan.isDone && column < line.length; column++) {
297
+ const char = line[column];
298
+ const pair = line.slice(column, column + 2);
299
+ if (pair === "(*" && !scan.isInString) {
300
+ scan.depth += 1;
301
+ output.push(" ");
302
+ column += 1;
303
+ continue;
304
+ }
305
+ if (pair === "*)" && !scan.isInString && scan.depth === 0) {
306
+ output.push(pair);
307
+ scan.isDone = true;
308
+ continue;
309
+ }
310
+ if (pair === "*)" && !scan.isInString) {
311
+ scan.depth -= 1;
312
+ output.push(" ");
313
+ column += 1;
314
+ continue;
315
+ }
316
+ if (scan.depth > 0) {
317
+ output.push(" ");
318
+ continue;
319
+ }
320
+ if (scan.isInString && char === "\\" && pair.length === 2) {
321
+ output.push(pair);
322
+ column += 1;
323
+ continue;
324
+ }
325
+ if (!scan.isInString && pair === "\\*") {
326
+ output.push(" ");
327
+ break;
328
+ }
329
+ if (char === '"') scan.isInString = !scan.isInString;
330
+ output.push(char);
331
+ }
332
+ if (scan.isInString) return new PcalError(`Unterminated string in line ${index + 1}`);
333
+ lines[index] = output.join("");
334
+ }
335
+ return undefined;
336
+ };
337
+
338
+ // Vector.get on an index out of its range, whose message names the vector's capacity: the 10 it
339
+ // starts with, doubled as it grows.
340
+ const throwIndexOutOfBounds = (index: number, size: number): never => {
341
+ const capacity = 10 * 2 ** Math.max(0, Math.ceil(Math.log2(size / 10)));
342
+ throw new PcalRuntimeError(
343
+ `java.lang.ArrayIndexOutOfBoundsException: Index ${index} out of bounds for length ${capacity}`,
344
+ );
345
+ };
346
+
347
+ // Validator.validate: checks the PlusCal algorithm of the module whose lines are given, from its
348
+ // first to its last, against the checksums its translation records.
349
+ export const validatePcalModule = (
350
+ session: PcalSession,
351
+ specificationText: string[],
352
+ version?: TlcVersion,
353
+ ): Set<PcalValidationResult> => {
354
+ if (!specificationText.some((line) => line.indexOf("algorithm") > 0)) {
355
+ return new Set(["NO_PLUSCAL_EXISTS"]);
356
+ }
357
+ const lines = removeTabs(specificationText);
358
+ const searchLocation = { line: 0, column: 0 };
359
+ while (findToken(lines, searchLocation, "PlusCal")) {
360
+ const line = gotoNextNonSpace(lines, searchLocation);
361
+ const rest = line.slice(searchLocation.column);
362
+ const idEnd = Array.from(rest).findIndex((char) => !isIdChar(char));
363
+ if (rest.startsWith("options") && (idEnd === -1 ? rest.length : idEnd) === 7) {
364
+ session.params.optionsInFile = true;
365
+ processOptions(session, lines, searchLocation);
366
+ break;
367
+ }
368
+ }
369
+ const begin = { line: 0, column: -1, isFound: false, isFair: false };
370
+ for (; begin.line < lines.length; begin.line++) {
371
+ const line = lines[begin.line];
372
+ // TLAConstants.MODULE_CLOSING_REGEX, which the trailing space removeTabs adds keeps from
373
+ // matching.
374
+ if (/^=+$/.test(line)) break;
375
+ const algorithmColumn = line.indexOf("--algorithm");
376
+ const fairColumn = line.indexOf("--fair");
377
+ if (algorithmColumn !== -1) {
378
+ begin.column = algorithmColumn + "--algorithm".length;
379
+ begin.isFound = true;
380
+ break;
381
+ }
382
+ if (fairColumn !== -1) {
383
+ begin.column = fairColumn + "--fair".length;
384
+ begin.isFound = true;
385
+ begin.isFair = true;
386
+ break;
387
+ }
388
+ }
389
+ const results = new Set<PcalValidationResult>();
390
+ const translationLine = findTokenPair(lines, 0, "BEGIN", "TRANSLATION");
391
+ if (translationLine === -1) results.add("NO_TRANSLATION_EXISTS");
392
+ const endTranslationLine = findTokenPair(lines, translationLine + 1, "END", "TRANSLATION");
393
+ if (endTranslationLine === -1) results.add("NO_TRANSLATION_EXISTS");
394
+ if (translationLine === -1 && endTranslationLine === -1) return results;
395
+ if (!begin.isFound) {
396
+ results.add("NO_PLUSCAL_EXISTS");
397
+ return results;
398
+ }
399
+ const uncommentError = uncomment(lines, begin.line, begin.column);
400
+ if (uncommentError !== undefined) {
401
+ reportPcalError(session, uncommentError);
402
+ return new Set(["ERROR_ENCOUNTERED"]);
403
+ }
404
+ const parsed: { ast: PcalAlgorithm | undefined } = { ast: undefined };
405
+ // HACK: Validator reports the exceptions of ParseAlgorithm.getAlgorithm and PCalTLAGenerator
406
+ // and goes on to compare the checksums.
407
+ try {
408
+ const reader = createPcalCharReader(
409
+ lines,
410
+ begin.line,
411
+ begin.column,
412
+ specificationText.length,
413
+ 0,
414
+ );
415
+ const result = parsePcalAlgorithm(session, reader, begin.isFair);
416
+ parsed.ast = result.ast;
417
+ translatePcalAlgorithm(result.ast, result.omitPC, result.hasDefaultInitialization, session.log);
418
+ } catch (error) {
419
+ if (!(error instanceof PcalError)) throw error;
420
+ reportPcalError(session, error);
421
+ }
422
+ if (translationLine === -1) throwIndexOutOfBounds(-1, lines.length);
423
+ const match = CHECKSUM_PATTERN.exec(lines[translationLine]);
424
+ if (match === null) {
425
+ results.add("NO_PCAL_CHECKSUMS_EXIST");
426
+ return results;
427
+ }
428
+ const pcalChecksum = match.groups?.pcal;
429
+ // The Java checksums the string "fair" for a --fair algorithm, unlike TLC 1.7.4's, and a failed
430
+ // parse leaves an AST whose text, Object.toString's class name and hash code, matches no checksum.
431
+ const algorithmText =
432
+ begin.isFair && version !== "1.7.4"
433
+ ? "fair"
434
+ : parsed.ast === undefined
435
+ ? undefined
436
+ : formatPcalNode(parsed.ast, session.params.inputVersionNumber, version);
437
+ if (
438
+ pcalChecksum !== undefined &&
439
+ (algorithmText === undefined || pcalChecksum !== getChecksum(algorithmText))
440
+ ) {
441
+ results.add("PCAL_DIVERGENCE_EXISTS");
442
+ }
443
+ const tlaChecksum = match.groups?.tla;
444
+ if (tlaChecksum !== undefined) {
445
+ if (endTranslationLine === -1) {
446
+ throw new PcalRuntimeError(
447
+ `java.lang.IllegalArgumentException: fromIndex(${translationLine + 1}) > toIndex(-1)`,
448
+ );
449
+ }
450
+ const translation = specificationText.slice(translationLine + 1, endTranslationLine).join("");
451
+ if (tlaChecksum !== getChecksum(translation)) results.add("TLA_DIVERGENCE_EXISTS");
452
+ }
453
+ return results.size === 0 ? new Set(["NO_DIVERGENCE"]) : results;
454
+ };
@@ -0,0 +1,95 @@
1
+ // Worker threads that decide the obligations prove sends them, the earliest obligation first.
2
+
3
+ import { TlaProverError } from "../errors";
4
+ import { spawnWorker, type WorkerHandle } from "../worker";
5
+ import type { DecideOptions, Decision } from "./verdict";
6
+
7
+ export interface DecideRequest {
8
+ prover: string;
9
+ text: string;
10
+ timeLimitMs: number;
11
+ }
12
+
13
+ // A backend's decision, or the message of the TlaProverError it threw, which prove turns into a
14
+ // result.
15
+ export type DecideResponse = Decision | { error: string };
16
+
17
+ interface PendingDecision {
18
+ request: DecideRequest;
19
+ priority: number;
20
+ resolve: (decision: Decision) => void;
21
+ reject: (error: unknown) => void;
22
+ }
23
+
24
+ export interface DecidePool {
25
+ decide: (
26
+ prover: string,
27
+ text: string,
28
+ options: DecideOptions,
29
+ priority: number,
30
+ ) => Promise<Decision>;
31
+ // Rejects every decision not yet made with reason, and stops the workers.
32
+ terminate: (reason: unknown) => void;
33
+ }
34
+
35
+ export const createDecidePool = async (count: number): Promise<DecidePool> => {
36
+ const workers: WorkerHandle[] = [];
37
+ const queue: PendingDecision[] = [];
38
+ const running = new Map<number, PendingDecision>();
39
+ const idle: number[] = [];
40
+ const state: { failure: { reason: unknown } | undefined } = { failure: undefined };
41
+ const dispatch = () => {
42
+ while (idle.length > 0 && queue.length > 0) {
43
+ const earliest = queue.reduce(
44
+ (best, decision, position) => (decision.priority < queue[best].priority ? position : best),
45
+ 0,
46
+ );
47
+ const [decision] = queue.splice(earliest, 1);
48
+ const index = idle.pop() ?? 0;
49
+ running.set(index, decision);
50
+ workers[index].postMessage(decision.request);
51
+ }
52
+ };
53
+ const onResponse = (index: number, message: unknown) => {
54
+ const response = message as DecideResponse;
55
+ const decision = running.get(index);
56
+ running.delete(index);
57
+ idle.push(index);
58
+ if ("verdict" in response) decision?.resolve(response);
59
+ if ("error" in response) decision?.reject(new TlaProverError(response.error));
60
+ dispatch();
61
+ };
62
+ const terminate = (reason: unknown) => {
63
+ if (state.failure) return;
64
+ state.failure = { reason };
65
+ [...queue.splice(0), ...running.values()].forEach((decision) => decision.reject(reason));
66
+ running.clear();
67
+ workers.forEach((worker) => worker.terminate());
68
+ };
69
+ workers.push(
70
+ ...(await Promise.all(
71
+ Array.from({ length: count }, (_, index) =>
72
+ spawnWorker(
73
+ new URL("./prove-worker.js", import.meta.url),
74
+ (message) => onResponse(index, message),
75
+ terminate,
76
+ ),
77
+ ),
78
+ )),
79
+ );
80
+ idle.push(...workers.keys());
81
+ return {
82
+ decide: (prover, text, options, priority) =>
83
+ new Promise((resolve, reject) => {
84
+ if (state.failure) return reject(state.failure.reason);
85
+ queue.push({
86
+ request: { prover, text, timeLimitMs: options.timeLimitMs },
87
+ priority,
88
+ resolve,
89
+ reject,
90
+ });
91
+ dispatch();
92
+ }),
93
+ terminate,
94
+ };
95
+ };
@@ -0,0 +1,33 @@
1
+ // How each of tla-ts's backends decides the text tlapm would send its prover, by the prover of the
2
+ // method that selects it.
3
+
4
+ import { SmtParseError, TlaProverError } from "../errors";
5
+ import { decideIsabelle } from "./isabelle/decide";
6
+ import { decidePtl } from "./ptl/decide";
7
+ import { decideSmt } from "./smt/solver/solver";
8
+ import type { DecideOptions, Decision, Verdict } from "./verdict";
9
+ import { decideZenon } from "./zenon/decide";
10
+
11
+ // Z3 rejects malformed input with an error, and tlapm counts that as a failure.
12
+ const decideZ3 = (text: string, options: DecideOptions) => {
13
+ try {
14
+ return decideSmt(text, options);
15
+ } catch (error) {
16
+ if (error instanceof SmtParseError) throw new TlaProverError(error.message, error);
17
+ throw error;
18
+ }
19
+ };
20
+
21
+ export const DECIDERS: Record<string, (text: string, options: DecideOptions) => Verdict> = {
22
+ smt: decideZ3,
23
+ z3: decideZ3,
24
+ zenon: (text, options) => decideZenon(text, options).verdict,
25
+ isabelle: decideIsabelle,
26
+ ls4: decidePtl,
27
+ };
28
+
29
+ export const decide = (prover: string, text: string, options: DecideOptions): Decision => {
30
+ const start = performance.now();
31
+ const verdict = DECIDERS[prover](text, options);
32
+ return { verdict, timeUsedMs: performance.now() - start };
33
+ };
@@ -0,0 +1,78 @@
1
+ // What backend/zenon.ml and backend/isabelle.ml share in printing an obligation that Backend.Prep
2
+ // has shipped.
3
+
4
+ import { TlapmBugError, TlaProverError, TlaUnsupportedError } from "../errors";
5
+ import { popNames, type Context } from "../obligations/ctx";
6
+ import { shiftExpr, type Bound, type Builtin, type Expr } from "../obligations/expression";
7
+
8
+ // The temporal operators neither backend has a counterpart for, by the name tlapm reports.
9
+ const TEMPORAL_OPERATORS: Partial<Record<Builtin, [string, number]>> = {
10
+ Leadsto: ["Leadsto", 2],
11
+ ENABLED: ["ENABLED", 1],
12
+ Cdot: ["\\cdot", 2],
13
+ Actplus: ["-+->", 2],
14
+ BoxTrue: ["[]", 1],
15
+ BoxFalse: ["[]", 1],
16
+ Diamond: ["<>", 1],
17
+ };
18
+
19
+ // Why a backend can't print an application of builtin, which it reports as where.
20
+ export const getUnprintableError = (builtin: Builtin, arity: number, where: string) => {
21
+ const isFrontend = builtin === "Prime" || builtin === "StrongPrime" || builtin === "UNCHANGED";
22
+ if (isFrontend && arity === 1) return new TlapmBugError();
23
+ const temporal = TEMPORAL_OPERATORS[builtin];
24
+ return temporal && temporal[1] === arity
25
+ ? new TlaProverError(`Unsupported operator \`${temporal[0]}\`.\n`)
26
+ : new TlaProverError(where);
27
+ };
28
+
29
+ interface SplitQuantifier {
30
+ first: Bound;
31
+ inner: Expr;
32
+ }
33
+
34
+ // A quantifier's first bound binds around a quantifier over the others, which move under it. A
35
+ // ditto after the first bound copies its domain.
36
+ export const splitFirstBound = (
37
+ quantifier: "Forall" | "Exists",
38
+ bounds: Bound[],
39
+ body: Expr,
40
+ ): SplitQuantifier => {
41
+ const first = bounds[0];
42
+ const rest = bounds.slice(1);
43
+ const undittoed =
44
+ rest[0]?.domain.kind === "Ditto"
45
+ ? [{ ...rest[0], domain: first.domain }, ...rest.slice(1)]
46
+ : rest;
47
+ if (undittoed.length === 0) return { first, inner: body };
48
+ return {
49
+ first,
50
+ inner: {
51
+ kind: "Quant",
52
+ quantifier,
53
+ bounds: undittoed.map((other) =>
54
+ other.domain.kind === "Domain"
55
+ ? {
56
+ ...other,
57
+ domain: { kind: "Domain", expression: shiftExpr(1, other.domain.expression) },
58
+ }
59
+ : other,
60
+ ),
61
+ body,
62
+ location: body.location,
63
+ },
64
+ };
65
+ };
66
+
67
+ // tlapm prints a fact to a formatter that drops its output first, to omit an unsupported one: the
68
+ // fact's print, or the error that omits it once the names it bound are out of scope.
69
+ export const printFact = <Printed>(context: Context, print: () => Printed) => {
70
+ const depth = context.stack.length;
71
+ try {
72
+ return print();
73
+ } catch (error) {
74
+ if (!(error instanceof TlaUnsupportedError)) throw error;
75
+ popNames(context, context.stack.length - depth);
76
+ return error;
77
+ }
78
+ };
@@ -0,0 +1,36 @@
1
+ ISABELLE COPYRIGHT NOTICE, LICENCE AND DISCLAIMER.
2
+
3
+ Copyright (c) 1986-2025,
4
+ University of Cambridge,
5
+ Technische Universitaet Muenchen,
6
+ and contributors.
7
+
8
+ All rights reserved.
9
+
10
+ Redistribution and use in source and binary forms, with or without
11
+ modification, are permitted provided that the following conditions are
12
+ met:
13
+
14
+ * Redistributions of source code must retain the above copyright
15
+ notice, this list of conditions and the following disclaimer.
16
+
17
+ * Redistributions in binary form must reproduce the above copyright
18
+ notice, this list of conditions and the following disclaimer in the
19
+ documentation and/or other materials provided with the distribution.
20
+
21
+ * Neither the name of the University of Cambridge or the Technische
22
+ Universitaet Muenchen nor the names of their contributors may be used
23
+ to endorse or promote products derived from this software without
24
+ specific prior written permission.
25
+
26
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28
+ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
29
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.