tla-ts 0.0.10-dev.f16792fed → 0.0.10-dev.f57f64938

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 (568) hide show
  1. package/README.md +2 -1
  2. package/dist/compile.cjs +6 -6
  3. package/dist/compile.js +10 -10
  4. package/dist/deciders.cjs +41 -37
  5. package/dist/deciders.js +57 -53
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +3 -0
  8. package/dist/index.d.ts +3 -0
  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.cjs +2682 -426
  13. package/dist/prove.js +2681 -425
  14. package/dist/run.cjs +45 -42
  15. package/dist/run.js +47 -44
  16. package/dist/tlapm.cjs +2 -2
  17. package/dist/tlapm.js +2 -2
  18. package/dist/transfer.cjs +42 -39
  19. package/dist/transfer.js +42 -39
  20. package/dist/worker.cjs +7 -7
  21. package/dist/worker.js +7 -7
  22. package/package.json +1 -1
  23. package/src/ast.ts +41 -36
  24. package/src/builtins.ts +4 -13
  25. package/src/check-failure.ts +116 -0
  26. package/src/check-trace.ts +282 -0
  27. package/src/check.ts +353 -549
  28. package/src/cli/options.ts +6 -31
  29. package/src/cli/shared.ts +1 -1
  30. package/src/cli/tlapm.ts +433 -70
  31. package/src/cli/tlc-arguments.ts +222 -210
  32. package/src/cli/tlc-output.ts +687 -0
  33. package/src/cli/tlc-usage.ts +1 -2
  34. package/src/cli/tlc.ts +49 -702
  35. package/src/cli/xml-exporter.ts +23 -33
  36. package/src/codegen.ts +5 -10
  37. package/src/coverage.ts +0 -2
  38. package/src/dependencies.ts +30 -14
  39. package/src/dfid.ts +16 -16
  40. package/src/environment-config.ts +315 -0
  41. package/src/environment.ts +55 -338
  42. package/src/errors.ts +33 -5
  43. package/src/evaluate.ts +5 -4
  44. package/src/exit-codes.ts +1 -0
  45. package/src/fingerprints.ts +65 -1
  46. package/src/instances.ts +47 -10
  47. package/src/json.ts +4 -7
  48. package/src/levels.ts +39 -42
  49. package/src/lexer.ts +5 -3
  50. package/src/liveness-checker.ts +553 -237
  51. package/src/liveness.ts +94 -86
  52. package/src/obligations/action.ts +14 -17
  53. package/src/obligations/anonymize.ts +37 -16
  54. package/src/obligations/enabled-axioms.ts +218 -0
  55. package/src/obligations/equality.ts +1 -3
  56. package/src/obligations/expression.ts +36 -8
  57. package/src/obligations/format.ts +0 -2
  58. package/src/obligations/generate.ts +66 -54
  59. package/src/obligations/index.ts +38 -8
  60. package/src/obligations/levels.ts +24 -11
  61. package/src/obligations/module.ts +28 -41
  62. package/src/obligations/normalize.ts +26 -14
  63. package/src/obligations/operators.ts +0 -2
  64. package/src/obligations/pragma.ts +53 -16
  65. package/src/obligations/printer.ts +43 -13
  66. package/src/obligations/proof.ts +3 -2
  67. package/src/obligations/regroup.ts +0 -2
  68. package/src/obligations/simplify.ts +55 -50
  69. package/src/obligations/source.ts +118 -74
  70. package/src/obligations/subexpression.ts +45 -18
  71. package/src/obligations/substitution.ts +1 -3
  72. package/src/obligations/temporal.ts +5 -7
  73. package/src/obligations/tuples.ts +0 -2
  74. package/src/parallel-worker.ts +10 -30
  75. package/src/parallel.ts +24 -47
  76. package/src/parser.ts +580 -180
  77. package/src/pretty-print.ts +1 -1
  78. package/src/prover/decide-pool.ts +3 -3
  79. package/src/prover/deciders.ts +12 -9
  80. package/src/prover/isabelle/decide.ts +3 -25
  81. package/src/prover/isabelle/encode.ts +72 -42
  82. package/src/prover/isabelle/isar/attrib.ts +250 -0
  83. package/src/prover/isabelle/isar/context.ts +335 -0
  84. package/src/prover/isabelle/isar/induct.ts +382 -0
  85. package/src/prover/isabelle/isar/inner-syntax.ts +158 -7
  86. package/src/prover/isabelle/isar/method.ts +509 -212
  87. package/src/prover/isabelle/isar/proof.ts +570 -14
  88. package/src/prover/isabelle/isar/rule-cases.ts +224 -0
  89. package/src/prover/isabelle/isar/theory.ts +487 -76
  90. package/src/prover/isabelle/isar/toplevel.ts +331 -0
  91. package/src/prover/isabelle/isar/type-check.ts +89 -14
  92. package/src/prover/isabelle/provers/blast/blast.ts +7 -65
  93. package/src/prover/isabelle/provers/blast/branch.ts +0 -2
  94. package/src/prover/isabelle/provers/blast/prove.ts +0 -2
  95. package/src/prover/isabelle/provers/blast/rules.ts +0 -2
  96. package/src/prover/isabelle/provers/blast/state.ts +0 -2
  97. package/src/prover/isabelle/provers/blast/term.ts +0 -2
  98. package/src/prover/isabelle/provers/clasimp.ts +0 -2
  99. package/src/prover/isabelle/provers/classical.ts +45 -20
  100. package/src/prover/isabelle/provers/hypsubst.ts +17 -28
  101. package/src/prover/isabelle/pure/bicompose.ts +9 -27
  102. package/src/prover/isabelle/pure/consts.ts +0 -2
  103. package/src/prover/isabelle/pure/conv.ts +2 -10
  104. package/src/prover/isabelle/pure/drule.ts +72 -6
  105. package/src/prover/isabelle/pure/envir.ts +0 -2
  106. package/src/prover/isabelle/pure/goal.ts +1 -3
  107. package/src/prover/isabelle/pure/logic.ts +1 -3
  108. package/src/prover/isabelle/pure/name.ts +0 -2
  109. package/src/prover/isabelle/pure/net.ts +0 -2
  110. package/src/prover/isabelle/pure/object-logic.ts +13 -7
  111. package/src/prover/isabelle/pure/pattern.ts +0 -2
  112. package/src/prover/isabelle/pure/raw-simplifier.ts +4 -15
  113. package/src/prover/isabelle/pure/rewriter.ts +6 -17
  114. package/src/prover/isabelle/pure/search.ts +0 -2
  115. package/src/prover/isabelle/pure/seq.ts +0 -2
  116. package/src/prover/isabelle/pure/simplifier.ts +26 -7
  117. package/src/prover/isabelle/pure/table.ts +2 -3
  118. package/src/prover/isabelle/pure/tactic.ts +0 -2
  119. package/src/prover/isabelle/pure/tactical.ts +42 -37
  120. package/src/prover/isabelle/pure/term-ord.ts +0 -2
  121. package/src/prover/isabelle/pure/term.ts +0 -2
  122. package/src/prover/isabelle/pure/thm.ts +14 -13
  123. package/src/prover/isabelle/pure/type.ts +0 -2
  124. package/src/prover/isabelle/pure/unify.ts +0 -2
  125. package/src/prover/isabelle/pure/variable.ts +0 -2
  126. package/src/prover/isabelle/tla/classical-setup.ts +18 -16
  127. package/src/prover/isabelle/tla/context.ts +58 -11
  128. package/src/prover/isabelle/tla/logic-data.ts +1 -1
  129. package/src/prover/isabelle/tla/logic.ts +49 -21
  130. package/src/prover/isabelle/tla/simpdata.ts +1 -12
  131. package/src/prover/isabelle/tools/intuitionistic.ts +28 -12
  132. package/src/prover/ocaml.ts +4 -1
  133. package/src/prover/prep/action.ts +30 -31
  134. package/src/prover/prep/enabled-axioms.ts +11 -2
  135. package/src/prover/prep/fingerprint.ts +2 -5
  136. package/src/prover/prep/methods.ts +181 -51
  137. package/src/prover/prep/normalize.ts +38 -9
  138. package/src/prover/prove.ts +395 -94
  139. package/src/prover/ptl/decide.ts +95 -50
  140. package/src/prover/ptl/encode.ts +2 -3
  141. package/src/prover/ptl/tableau.ts +28 -2
  142. package/src/prover/smt/arithmetic.ts +310 -0
  143. package/src/prover/smt/axioms.ts +12 -8
  144. package/src/prover/smt/context.ts +43 -8
  145. package/src/prover/smt/data.ts +498 -379
  146. package/src/prover/smt/encode.ts +148 -57
  147. package/src/prover/smt/extensionality.ts +5 -3
  148. package/src/prover/smt/flatten.ts +4 -6
  149. package/src/prover/smt/format.ts +28 -4
  150. package/src/prover/smt/instances.ts +7 -1
  151. package/src/prover/smt/layout.ts +91 -0
  152. package/src/prover/smt/rewrite.ts +1021 -618
  153. package/src/prover/smt/simplify.ts +441 -0
  154. package/src/prover/smt/solver/ackermannize-bv-tactic.ts +61 -0
  155. package/src/prover/smt/solver/ackr-helper.ts +179 -0
  156. package/src/prover/smt/solver/ackr-model-converter.ts +105 -0
  157. package/src/prover/smt/solver/act-cache.ts +0 -1
  158. package/src/prover/smt/solver/add-bounds-tactic.ts +59 -0
  159. package/src/prover/smt/solver/aig-tactic.ts +52 -0
  160. package/src/prover/smt/solver/aig.ts +889 -0
  161. package/src/prover/smt/solver/arith-rewriter.ts +613 -6
  162. package/src/prover/smt/solver/arith-terms.ts +121 -0
  163. package/src/prover/smt/solver/array-decl-plugin.ts +175 -0
  164. package/src/prover/smt/solver/array-rewriter.ts +309 -0
  165. package/src/prover/smt/solver/asserted-formulas.ts +87 -16
  166. package/src/prover/smt/solver/ast-lt.ts +166 -12
  167. package/src/prover/smt/solver/ast-util.ts +160 -2
  168. package/src/prover/smt/solver/ast.ts +1427 -41
  169. package/src/prover/smt/solver/auf-solver.ts +2 -6
  170. package/src/prover/smt/solver/bit-blast-tactic.ts +582 -0
  171. package/src/prover/smt/solver/bit-blaster.ts +871 -0
  172. package/src/prover/smt/solver/bound-manager.ts +196 -0
  173. package/src/prover/smt/solver/bound-simplifier.ts +600 -0
  174. package/src/prover/smt/solver/bv-bound-chk.ts +492 -0
  175. package/src/prover/smt/solver/bv-decl-plugin.ts +338 -0
  176. package/src/prover/smt/solver/bv-divrem-bounds.ts +95 -0
  177. package/src/prover/smt/solver/bv-rewriter.ts +1901 -0
  178. package/src/prover/smt/solver/bv1-blast.ts +214 -0
  179. package/src/prover/smt/solver/bv2fpa-converter.ts +174 -0
  180. package/src/prover/smt/solver/bv2int-rewriter.ts +544 -0
  181. package/src/prover/smt/solver/bv2real-rewriter.ts +533 -0
  182. package/src/prover/smt/solver/card2bv.ts +110 -0
  183. package/src/prover/smt/solver/case-split-queue.ts +0 -2
  184. package/src/prover/smt/solver/cg-table.ts +39 -25
  185. package/src/prover/smt/solver/check-logic.ts +330 -0
  186. package/src/prover/smt/solver/clause.ts +0 -1
  187. package/src/prover/smt/solver/cofactor-elim-term-ite.ts +278 -0
  188. package/src/prover/smt/solver/conflict-resolution.ts +78 -2
  189. package/src/prover/smt/solver/context.ts +516 -115
  190. package/src/prover/smt/solver/ctx-simplify.ts +20 -10
  191. package/src/prover/smt/solver/ctx-solver-simplify.ts +122 -0
  192. package/src/prover/smt/solver/datatype-decl-plugin.ts +572 -0
  193. package/src/prover/smt/solver/datatype-rewriter.ts +82 -0
  194. package/src/prover/smt/solver/demodulator.ts +786 -0
  195. package/src/prover/smt/solver/dependent-expr-state.ts +81 -0
  196. package/src/prover/smt/solver/der.ts +38 -10
  197. package/src/prover/smt/solver/diff-neq.ts +206 -0
  198. package/src/prover/smt/solver/distribute-forall.ts +57 -0
  199. package/src/prover/smt/solver/dom-simplify.ts +511 -0
  200. package/src/prover/smt/solver/dt2bv-tactic.ts +260 -0
  201. package/src/prover/smt/solver/dyn-ack.ts +0 -1
  202. package/src/prover/smt/solver/e-matching.ts +7 -8
  203. package/src/prover/smt/solver/elim-small-bv-tactic.ts +129 -0
  204. package/src/prover/smt/solver/elim-uncnstr.ts +545 -0
  205. package/src/prover/smt/solver/enode.ts +100 -3
  206. package/src/prover/smt/solver/eq2bv-tactic.ts +218 -0
  207. package/src/prover/smt/solver/euf/arith-axioms.ts +403 -0
  208. package/src/prover/smt/solver/euf/arith-internalize.ts +653 -0
  209. package/src/prover/smt/solver/euf/arith-solver.ts +889 -0
  210. package/src/prover/smt/solver/euf/array-axioms.ts +527 -0
  211. package/src/prover/smt/solver/euf/array-internalize.ts +428 -0
  212. package/src/prover/smt/solver/euf/array-solver.ts +306 -0
  213. package/src/prover/smt/solver/euf/bv-ackerman.ts +162 -0
  214. package/src/prover/smt/solver/euf/bv-internalize.ts +748 -0
  215. package/src/prover/smt/solver/euf/bv-solver.ts +449 -0
  216. package/src/prover/smt/solver/euf/dt-solver.ts +618 -0
  217. package/src/prover/smt/solver/euf/egraph.ts +907 -0
  218. package/src/prover/smt/solver/euf/euf-solver.ts +1205 -0
  219. package/src/prover/smt/solver/euf/fpa-solver.ts +317 -0
  220. package/src/prover/smt/solver/euf/mam.ts +1050 -0
  221. package/src/prover/smt/solver/euf/q-ematch.ts +830 -0
  222. package/src/prover/smt/solver/euf/q-mbi.ts +587 -0
  223. package/src/prover/smt/solver/euf/q-model-fixer.ts +296 -0
  224. package/src/prover/smt/solver/euf/q-solver.ts +361 -0
  225. package/src/prover/smt/solver/euf/th-solver.ts +335 -0
  226. package/src/prover/smt/solver/euf/th-solvers.ts +30 -0
  227. package/src/prover/smt/solver/expr-ref.ts +0 -1
  228. package/src/prover/smt/solver/expr-safe-replace.ts +26 -2
  229. package/src/prover/smt/solver/expr2polynomial.ts +146 -0
  230. package/src/prover/smt/solver/factor.ts +141 -0
  231. package/src/prover/smt/solver/fd-solver.ts +265 -0
  232. package/src/prover/smt/solver/fingerprints.ts +15 -15
  233. package/src/prover/smt/solver/fix-dl-var.ts +148 -0
  234. package/src/prover/smt/solver/flat-literals.ts +0 -1
  235. package/src/prover/smt/solver/fm-tactic.ts +884 -0
  236. package/src/prover/smt/solver/fpa-decl-plugin.ts +618 -0
  237. package/src/prover/smt/solver/fpa-rewriter.ts +640 -0
  238. package/src/prover/smt/solver/fpa2bv-converter.ts +2249 -0
  239. package/src/prover/smt/solver/fpa2bv-rewriter.ts +348 -0
  240. package/src/prover/smt/solver/fpa2bv-tactic.ts +73 -0
  241. package/src/prover/smt/solver/goal.ts +175 -15
  242. package/src/prover/smt/solver/goal2nlsat.ts +189 -0
  243. package/src/prover/smt/solver/guard-set.ts +219 -0
  244. package/src/prover/smt/solver/hash.ts +0 -1
  245. package/src/prover/smt/solver/hashtable.ts +30 -16
  246. package/src/prover/smt/solver/inf-eps.ts +63 -0
  247. package/src/prover/smt/solver/inj-axiom.ts +101 -0
  248. package/src/prover/smt/solver/internalizer.ts +110 -38
  249. package/src/prover/smt/solver/lackr.ts +381 -0
  250. package/src/prover/smt/solver/lbool.ts +0 -1
  251. package/src/prover/smt/solver/lia2card.ts +268 -0
  252. package/src/prover/smt/solver/lia2pb.ts +154 -0
  253. package/src/prover/smt/solver/literal.ts +0 -1
  254. package/src/prover/smt/solver/logic-tactics.ts +345 -0
  255. package/src/prover/smt/solver/lp/bound-propagator.ts +0 -1
  256. package/src/prover/smt/solver/lp/constraints.ts +0 -1
  257. package/src/prover/smt/solver/lp/containers.ts +0 -1
  258. package/src/prover/smt/solver/lp/core-solver.ts +18 -3
  259. package/src/prover/smt/solver/lp/cross-nested.ts +0 -1
  260. package/src/prover/smt/solver/lp/dep-intervals.ts +0 -3
  261. package/src/prover/smt/solver/lp/dependency.ts +0 -2
  262. package/src/prover/smt/solver/lp/dioph-eq.ts +1 -10
  263. package/src/prover/smt/solver/lp/explanation.ts +0 -1
  264. package/src/prover/smt/solver/lp/gomory.ts +0 -1
  265. package/src/prover/smt/solver/lp/hnf-cutter.ts +1 -2
  266. package/src/prover/smt/solver/lp/hnf.ts +0 -3
  267. package/src/prover/smt/solver/lp/int-cube.ts +3 -4
  268. package/src/prover/smt/solver/lp/int-solver.ts +0 -2
  269. package/src/prover/smt/solver/lp/lar-solver.ts +40 -4
  270. package/src/prover/smt/solver/lp/lar-term.ts +0 -1
  271. package/src/prover/smt/solver/lp/lp-settings.ts +0 -1
  272. package/src/prover/smt/solver/lp/maximize-term.ts +59 -10
  273. package/src/prover/smt/solver/lp/nex-creator.ts +0 -1
  274. package/src/prover/smt/solver/lp/nex.ts +0 -1
  275. package/src/prover/smt/solver/lp/nla-backoff.ts +0 -2
  276. package/src/prover/smt/solver/lp/nla-basics.ts +0 -2
  277. package/src/prover/smt/solver/lp/nla-core.ts +42 -11
  278. package/src/prover/smt/solver/lp/nla-divisions.ts +0 -2
  279. package/src/prover/smt/solver/lp/nla-emonics.ts +0 -1
  280. package/src/prover/smt/solver/lp/nla-factorization.ts +0 -1
  281. package/src/prover/smt/solver/lp/nla-grobner.ts +9 -4
  282. package/src/prover/smt/solver/lp/nla-horner.ts +0 -2
  283. package/src/prover/smt/solver/lp/nla-intervals.ts +0 -1
  284. package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +0 -2
  285. package/src/prover/smt/solver/lp/nla-monotone.ts +0 -1
  286. package/src/prover/smt/solver/lp/nla-order.ts +0 -2
  287. package/src/prover/smt/solver/lp/nla-patcher.ts +0 -1
  288. package/src/prover/smt/solver/lp/nla-powers.ts +220 -0
  289. package/src/prover/smt/solver/lp/nla-tangents.ts +0 -2
  290. package/src/prover/smt/solver/lp/nla-throttle.ts +0 -1
  291. package/src/prover/smt/solver/lp/nla-transcendentals.ts +324 -0
  292. package/src/prover/smt/solver/lp/nla-types.ts +0 -2
  293. package/src/prover/smt/solver/lp/nla-var-eqs.ts +0 -1
  294. package/src/prover/smt/solver/lp/nra-solver.ts +25 -4
  295. package/src/prover/smt/solver/lp/numeric-pair.ts +0 -1
  296. package/src/prover/smt/solver/lp/pdd-interval.ts +0 -1
  297. package/src/prover/smt/solver/lp/pdd-simplifier.ts +0 -1
  298. package/src/prover/smt/solver/lp/pdd-solver.ts +0 -2
  299. package/src/prover/smt/solver/lp/pdd.ts +2 -2
  300. package/src/prover/smt/solver/lp/random-updater.ts +0 -2
  301. package/src/prover/smt/solver/lp/static-matrix.ts +0 -1
  302. package/src/prover/smt/solver/lp/union-find.ts +7 -2
  303. package/src/prover/smt/solver/macro-finder.ts +530 -0
  304. package/src/prover/smt/solver/mam-compiler.ts +122 -90
  305. package/src/prover/smt/solver/mam-interpreter.ts +0 -1
  306. package/src/prover/smt/solver/max-bv-sharing-tactic.ts +17 -0
  307. package/src/prover/smt/solver/max-cliques.ts +105 -0
  308. package/src/prover/smt/solver/maxcore.ts +309 -0
  309. package/src/prover/smt/solver/maximize-ac-sharing.ts +8 -6
  310. package/src/prover/smt/solver/maxlex.ts +115 -0
  311. package/src/prover/smt/solver/maxsmt-base.ts +105 -0
  312. package/src/prover/smt/solver/maxsmt.ts +92 -0
  313. package/src/prover/smt/solver/mbp/mbp-arith.ts +467 -0
  314. package/src/prover/smt/solver/mbp/mbp-basic-tg.ts +101 -0
  315. package/src/prover/smt/solver/mbp/mbp-plugin.ts +287 -0
  316. package/src/prover/smt/solver/mbp/mbp-qel.ts +48 -0
  317. package/src/prover/smt/solver/mbp/mbp-solve-plugin.ts +271 -0
  318. package/src/prover/smt/solver/mbp/mbp-term-graph.ts +606 -0
  319. package/src/prover/smt/solver/model-based-opt.ts +844 -0
  320. package/src/prover/smt/solver/model-checker.ts +18 -27
  321. package/src/prover/smt/solver/model-evaluator.ts +188 -12
  322. package/src/prover/smt/solver/model-finder.ts +12 -18
  323. package/src/prover/smt/solver/model-generator.ts +56 -29
  324. package/src/prover/smt/solver/model-macro-solver.ts +49 -46
  325. package/src/prover/smt/solver/model-printer.ts +214 -0
  326. package/src/prover/smt/solver/mpf.ts +711 -0
  327. package/src/prover/smt/solver/mus.ts +51 -0
  328. package/src/prover/smt/solver/muz/dl-context.ts +404 -0
  329. package/src/prover/smt/solver/muz/dl-mk-bit-blast.ts +97 -0
  330. package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +167 -0
  331. package/src/prover/smt/solver/muz/dl-mk-elim-term-ite.ts +125 -0
  332. package/src/prover/smt/solver/muz/dl-mk-interp-tail-simplifier.ts +299 -0
  333. package/src/prover/smt/solver/muz/dl-mk-rule-inliner.ts +455 -0
  334. package/src/prover/smt/solver/muz/dl-mk-slice.ts +340 -0
  335. package/src/prover/smt/solver/muz/dl-mk-subsumption-checker.ts +163 -0
  336. package/src/prover/smt/solver/muz/dl-rule-set.ts +273 -0
  337. package/src/prover/smt/solver/muz/dl-rule-transformer.ts +123 -0
  338. package/src/prover/smt/solver/muz/dl-rule.ts +496 -0
  339. package/src/prover/smt/solver/muz/hnf.ts +201 -0
  340. package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +176 -0
  341. package/src/prover/smt/solver/muz/horn-tactic.ts +201 -0
  342. package/src/prover/smt/solver/muz/rule-properties.ts +337 -0
  343. package/src/prover/smt/solver/muz/spacer-context.ts +1406 -0
  344. package/src/prover/smt/solver/muz/spacer-dl-interface.ts +52 -0
  345. package/src/prover/smt/solver/muz/spacer-generalizers.ts +241 -0
  346. package/src/prover/smt/solver/muz/spacer-manager.ts +127 -0
  347. package/src/prover/smt/solver/muz/spacer-pdr.ts +218 -0
  348. package/src/prover/smt/solver/muz/spacer-prop-solver.ts +333 -0
  349. package/src/prover/smt/solver/muz/spacer-util.ts +282 -0
  350. package/src/prover/smt/solver/muz/substitution.ts +203 -0
  351. package/src/prover/smt/solver/nla2bv-tactic.ts +285 -0
  352. package/src/prover/smt/solver/nlqsat.ts +484 -0
  353. package/src/prover/smt/solver/nlsat/algebraic.ts +125 -12
  354. package/src/prover/smt/solver/nlsat/atoms.ts +20 -6
  355. package/src/prover/smt/solver/nlsat/evaluator.ts +0 -1
  356. package/src/prover/smt/solver/nlsat/explain.ts +63 -23
  357. package/src/prover/smt/solver/nlsat/interval-set.ts +1 -2
  358. package/src/prover/smt/solver/nlsat/levelwise.ts +3 -9
  359. package/src/prover/smt/solver/nlsat/mpbq.ts +45 -1
  360. package/src/prover/smt/solver/nlsat/polynomial.ts +13 -6
  361. package/src/prover/smt/solver/nlsat/solver.ts +234 -36
  362. package/src/prover/smt/solver/nlsat/transcendental-eval.ts +310 -0
  363. package/src/prover/smt/solver/nlsat/transcendentals.ts +367 -0
  364. package/src/prover/smt/solver/nlsat/types.ts +0 -2
  365. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -4
  366. package/src/prover/smt/solver/nlsat/upolynomial.ts +0 -2
  367. package/src/prover/smt/solver/nlsat-tactic.ts +82 -0
  368. package/src/prover/smt/solver/nnf.ts +105 -23
  369. package/src/prover/smt/solver/normalize-bounds.ts +53 -0
  370. package/src/prover/smt/solver/occf.ts +97 -0
  371. package/src/prover/smt/solver/opt-context.ts +787 -0
  372. package/src/prover/smt/solver/opt-nlsat.ts +375 -0
  373. package/src/prover/smt/solver/opt-pareto.ts +282 -0
  374. package/src/prover/smt/solver/opt-preprocess.ts +101 -0
  375. package/src/prover/smt/solver/opt-solver.ts +308 -0
  376. package/src/prover/smt/solver/opt-value.ts +55 -0
  377. package/src/prover/smt/solver/optsmt.ts +692 -0
  378. package/src/prover/smt/solver/parallel-tactic.ts +299 -0
  379. package/src/prover/smt/solver/pattern-inference.ts +19 -11
  380. package/src/prover/smt/solver/pb-rewriter.ts +284 -0
  381. package/src/prover/smt/solver/pb2bv-tactic.ts +540 -0
  382. package/src/prover/smt/solver/poly-rewriter.ts +202 -57
  383. package/src/prover/smt/solver/probes.ts +512 -0
  384. package/src/prover/smt/solver/propagate-values.ts +37 -21
  385. package/src/prover/smt/solver/proto-model.ts +648 -19
  386. package/src/prover/smt/solver/pull-quant.ts +28 -12
  387. package/src/prover/smt/solver/purify-arith.ts +632 -0
  388. package/src/prover/smt/solver/qe-arith-plugin.ts +1098 -0
  389. package/src/prover/smt/solver/qe-lite-der.ts +2 -3
  390. package/src/prover/smt/solver/qe-lite-fm.ts +3 -4
  391. package/src/prover/smt/solver/qe-lite.ts +37 -17
  392. package/src/prover/smt/solver/qe-mbp.ts +270 -0
  393. package/src/prover/smt/solver/qe.ts +1498 -0
  394. package/src/prover/smt/solver/qel.ts +25 -0
  395. package/src/prover/smt/solver/qi-queue.ts +0 -1
  396. package/src/prover/smt/solver/qsat.ts +814 -0
  397. package/src/prover/smt/solver/quant-hoist.ts +196 -0
  398. package/src/prover/smt/solver/quant-tactics.ts +16 -56
  399. package/src/prover/smt/solver/quantifier-analyzer.ts +19 -20
  400. package/src/prover/smt/solver/quantifier-manager.ts +8 -16
  401. package/src/prover/smt/solver/quasi-macros.ts +243 -0
  402. package/src/prover/smt/solver/random-gen.ts +0 -1
  403. package/src/prover/smt/solver/rational.ts +45 -1
  404. package/src/prover/smt/solver/recfun-decl-plugin.ts +261 -0
  405. package/src/prover/smt/solver/recfun-rewriter.ts +107 -0
  406. package/src/prover/smt/solver/reduce-args.ts +225 -0
  407. package/src/prover/smt/solver/reduce-bv-size.ts +119 -0
  408. package/src/prover/smt/solver/ref-vector.ts +0 -1
  409. package/src/prover/smt/solver/relevancy.ts +1 -2
  410. package/src/prover/smt/solver/rewriter-tpl.ts +77 -10
  411. package/src/prover/smt/solver/rewriter.ts +475 -36
  412. package/src/prover/smt/solver/rlimit.ts +25 -2
  413. package/src/prover/smt/solver/sat/asymm-branch.ts +325 -0
  414. package/src/prover/smt/solver/sat/big.ts +177 -0
  415. package/src/prover/smt/solver/sat/clause-use-list.ts +71 -0
  416. package/src/prover/smt/solver/sat/clause.ts +203 -0
  417. package/src/prover/smt/solver/sat/cleaner.ts +94 -0
  418. package/src/prover/smt/solver/sat/config.ts +122 -0
  419. package/src/prover/smt/solver/sat/consequences.ts +203 -0
  420. package/src/prover/smt/solver/sat/elim-eqs.ts +142 -0
  421. package/src/prover/smt/solver/sat/goal2sat.ts +526 -0
  422. package/src/prover/smt/solver/sat/inc-sat-solver.ts +378 -0
  423. package/src/prover/smt/solver/sat/model-converter.ts +136 -0
  424. package/src/prover/smt/solver/sat/pb-constraint.ts +261 -0
  425. package/src/prover/smt/solver/sat/pb-solver.ts +1577 -0
  426. package/src/prover/smt/solver/sat/probing.ts +170 -0
  427. package/src/prover/smt/solver/sat/sat-tactic.ts +43 -0
  428. package/src/prover/smt/solver/sat/sat2goal.ts +165 -0
  429. package/src/prover/smt/solver/sat/scc.ts +142 -0
  430. package/src/prover/smt/solver/sat/simplifier.ts +1618 -0
  431. package/src/prover/smt/solver/sat/solver.ts +2127 -0
  432. package/src/prover/smt/solver/sat/var-queue.ts +117 -0
  433. package/src/prover/smt/solver/sat/watch-list.ts +140 -0
  434. package/src/prover/smt/solver/search-tree.ts +284 -0
  435. package/src/prover/smt/solver/seq-axioms.ts +1010 -0
  436. package/src/prover/smt/solver/seq-decl-plugin.ts +819 -0
  437. package/src/prover/smt/solver/seq-derive.ts +1301 -0
  438. package/src/prover/smt/solver/seq-eq-approx.ts +236 -0
  439. package/src/prover/smt/solver/seq-eq-solver.ts +439 -0
  440. package/src/prover/smt/solver/seq-factory.ts +89 -0
  441. package/src/prover/smt/solver/seq-monadic.ts +728 -0
  442. package/src/prover/smt/solver/seq-range-predicate.ts +235 -0
  443. package/src/prover/smt/solver/seq-re-rewriter.ts +1170 -0
  444. package/src/prover/smt/solver/seq-re-util.ts +758 -0
  445. package/src/prover/smt/solver/seq-regex-bisim.ts +144 -0
  446. package/src/prover/smt/solver/seq-regex-live.ts +200 -0
  447. package/src/prover/smt/solver/seq-rewriter.ts +2402 -0
  448. package/src/prover/smt/solver/seq-skolem.ts +317 -0
  449. package/src/prover/smt/solver/seq-subset.ts +165 -0
  450. package/src/prover/smt/solver/seq-view-witness.ts +353 -0
  451. package/src/prover/smt/solver/smt-consequences.ts +297 -0
  452. package/src/prover/smt/solver/smt-kernel.ts +83 -0
  453. package/src/prover/smt/solver/smt-logics.ts +66 -0
  454. package/src/prover/smt/solver/smt-setup.ts +496 -0
  455. package/src/prover/smt/solver/smt2-printer.ts +765 -0
  456. package/src/prover/smt/solver/smtlib-parser.ts +3126 -316
  457. package/src/prover/smt/solver/smtlib-script.ts +1631 -0
  458. package/src/prover/smt/solver/solve-eqs.ts +929 -0
  459. package/src/prover/smt/solver/solver.ts +113 -22
  460. package/src/prover/smt/solver/static-features.ts +314 -0
  461. package/src/prover/smt/solver/sticky-generations.ts +0 -1
  462. package/src/prover/smt/solver/tactic.ts +1986 -0
  463. package/src/prover/smt/solver/term-enumeration.ts +205 -0
  464. package/src/prover/smt/solver/theory-array.ts +1240 -0
  465. package/src/prover/smt/solver/theory-bv.ts +1200 -0
  466. package/src/prover/smt/solver/theory-char.ts +355 -0
  467. package/src/prover/smt/solver/theory-datatype.ts +598 -0
  468. package/src/prover/smt/solver/theory-finite-set.ts +30 -0
  469. package/src/prover/smt/solver/theory-fpa.ts +389 -0
  470. package/src/prover/smt/solver/theory-lra-axioms.ts +53 -2
  471. package/src/prover/smt/solver/theory-lra-bounds.ts +31 -6
  472. package/src/prover/smt/solver/theory-lra-final-check.ts +56 -70
  473. package/src/prover/smt/solver/theory-lra-internalize.ts +86 -27
  474. package/src/prover/smt/solver/theory-lra-model.ts +20 -35
  475. package/src/prover/smt/solver/theory-lra-propagate.ts +24 -26
  476. package/src/prover/smt/solver/theory-lra-state.ts +6 -22
  477. package/src/prover/smt/solver/theory-lra.ts +188 -1
  478. package/src/prover/smt/solver/theory-pb.ts +934 -0
  479. package/src/prover/smt/solver/theory-polymorphism.ts +58 -0
  480. package/src/prover/smt/solver/theory-recfun.ts +307 -0
  481. package/src/prover/smt/solver/theory-seq-regex.ts +867 -0
  482. package/src/prover/smt/solver/theory-seq-solve.ts +1373 -0
  483. package/src/prover/smt/solver/theory-seq-state.ts +871 -0
  484. package/src/prover/smt/solver/theory-seq.ts +961 -0
  485. package/src/prover/smt/solver/theory.ts +189 -0
  486. package/src/prover/smt/solver/tseitin-cnf.ts +485 -0
  487. package/src/prover/smt/solver/var-subst.ts +36 -14
  488. package/src/prover/smt/table.ts +3 -2
  489. package/src/prover/smt/types.ts +146 -0
  490. package/src/prover/tlapm/cache.ts +50 -19
  491. package/src/prover/tlapm/tlapm.ts +15 -9
  492. package/src/prover/tlapm-library.ts +3208 -0
  493. package/src/prover/verdict.ts +9 -0
  494. package/src/prover/zenon/check/check.ts +1 -2
  495. package/src/prover/zenon/check/records.ts +1 -1
  496. package/src/prover/zenon/check/relations.ts +2 -1
  497. package/src/prover/zenon/check/rewrites.ts +2 -15
  498. package/src/prover/zenon/check/sets.ts +40 -58
  499. package/src/prover/zenon/check/terms.ts +1 -2
  500. package/src/prover/zenon/decide.ts +10 -7
  501. package/src/prover/zenon/encode.ts +0 -2
  502. package/src/prover/zenon/eqrel.ts +2 -2
  503. package/src/prover/zenon/equality-rules.ts +0 -2
  504. package/src/prover/zenon/expr.ts +7 -2
  505. package/src/prover/zenon/index-table.ts +9 -21
  506. package/src/prover/zenon/isar-case.ts +0 -2
  507. package/src/prover/zenon/isar.ts +35 -37
  508. package/src/prover/zenon/llproof.ts +2 -13
  509. package/src/prover/zenon/mltoll.ts +12 -30
  510. package/src/prover/zenon/node.ts +20 -5
  511. package/src/prover/zenon/parse.ts +9 -8
  512. package/src/prover/zenon/phrase.ts +0 -2
  513. package/src/prover/zenon/proof.ts +0 -2
  514. package/src/prover/zenon/propositional-rules.ts +0 -2
  515. package/src/prover/zenon/rules.ts +0 -2
  516. package/src/prover/zenon/search.ts +11 -19
  517. package/src/prover/zenon/tla/functions.ts +2 -4
  518. package/src/prover/zenon/tla/llproof.ts +9 -13
  519. package/src/prover/zenon/tla/records.ts +1 -8
  520. package/src/prover/zenon/tla/rewrites.ts +0 -2
  521. package/src/prover/zenon/tla/sets.ts +22 -22
  522. package/src/prover/zenon/tla/terms.ts +0 -2
  523. package/src/prover/zenon/tla/tla.ts +7 -8
  524. package/src/resolve.ts +56 -74
  525. package/src/runtime.ts +4 -0
  526. package/src/sany/generation.ts +394 -0
  527. package/src/sany/generator-def-entries.ts +210 -0
  528. package/src/sany/generator-definitions.ts +686 -0
  529. package/src/sany/generator-expressions.ts +1100 -0
  530. package/src/sany/generator-proofs.ts +662 -0
  531. package/src/sany/generator.ts +155 -2625
  532. package/src/sany/levels.ts +0 -2
  533. package/src/sany/lexer.ts +17 -16
  534. package/src/sany/linter.ts +0 -2
  535. package/src/sany/nodes.ts +2 -3
  536. package/src/sany/report.ts +3 -6
  537. package/src/sany/selectors.ts +35 -38
  538. package/src/sany/xml.ts +23 -55
  539. package/src/search.ts +205 -43
  540. package/src/simulate.ts +157 -133
  541. package/src/spec-description.ts +33 -48
  542. package/src/standard-definitions.ts +4 -0
  543. package/src/standard-modules.ts +16 -32
  544. package/src/state-graph.ts +0 -2
  545. package/src/substitution-levels.ts +5 -4
  546. package/src/successors.ts +6 -8
  547. package/src/symmetry.ts +2 -2
  548. package/src/tableau.ts +2 -2
  549. package/src/tlc/fingerprint.ts +81 -9
  550. package/src/tlc/messages.ts +20 -15
  551. package/src/tlc/random.ts +4 -4
  552. package/src/tlc/replay.ts +8 -15
  553. package/src/tlc/summary.ts +29 -14
  554. package/src/tlc/tlc-operators.ts +2 -3
  555. package/src/tlc/tlcext-operators.ts +44 -12
  556. package/src/tlc/trace-spec.ts +21 -40
  557. package/src/typed-tier.ts +6535 -0
  558. package/src/typescript/actions.ts +2 -4
  559. package/src/typescript/collections.ts +34 -20
  560. package/src/typescript/compile.ts +1 -3
  561. package/src/typescript/formula.ts +5 -3
  562. package/src/typescript/model.ts +4 -5
  563. package/src/typescript/steps.ts +20 -18
  564. package/src/values.ts +62 -152
  565. package/src/prover/isabelle/isar/statement.ts +0 -52
  566. package/src/prover/smt/solver/z3-license.txt +0 -10
  567. package/src/prover/tlaps-module.ts +0 -510
  568. package/src/prover/zenon/LICENSE +0 -32
@@ -1,5 +1,5 @@
1
1
  import ts from "@typescript/typescript6";
2
- import { getUpdatedValue, MUTATING_METHODS } from "./collections";
2
+ import { getUpdatedValue, MUTATING_METHODS, REMOVALS } from "./collections";
3
3
  import {
4
4
  type Context,
5
5
  getFunction,
@@ -177,9 +177,7 @@ const getRemovedValue = (
177
177
  const sequence = translateExpression(receiver, path.scope, context);
178
178
  return {
179
179
  value: method === "shift" ? `Head(${sequence})` : `${wrap(sequence)}[Len(${sequence})]`,
180
- path: assign(receiver, path, context, (current) =>
181
- method === "shift" ? `Tail(${current})` : `SubSeq(${current}, 1, Len(${current}) - 1)`,
182
- ),
180
+ path: assign(receiver, path, context, REMOVALS[method]),
183
181
  };
184
182
  };
185
183
 
@@ -278,6 +278,12 @@ const translateFirstIndex = (
278
278
  };
279
279
  };
280
280
 
281
+ const orUndefined = (exists: string, value: string, isDefined: boolean, context: Context) => {
282
+ if (isDefined) return value;
283
+ context.prelude.add("Undefined");
284
+ return `IF ${exists} THEN ${value} ELSE Undefined`;
285
+ };
286
+
281
287
  const translateSequenceOperation = (
282
288
  node: MethodCall,
283
289
  sequence: string,
@@ -293,11 +299,6 @@ const translateSequenceOperation = (
293
299
  ts.isPrefixUnaryExpression(inner) && inner.operator === ts.SyntaxKind.MinusToken;
294
300
  const getOffset = (inner: ts.Expression) =>
295
301
  isNegative(inner) ? `Len(${sequence}) - ${wrap(translate(inner.operand))}` : translate(inner);
296
- const orUndefined = (exists: string, value: string) => {
297
- if (isDefined) return value;
298
- context.prelude.add("Undefined");
299
- return `IF ${exists} THEN ${value} ELSE Undefined`;
300
- };
301
302
  const translateEach = (format: (index: string, body: string) => string) => () => {
302
303
  const index = context.names.getFresh("index");
303
304
  const inner = bindIndexed(argument, `${wrapped}[${index}]`, index, scope, context);
@@ -310,7 +311,12 @@ const translateSequenceOperation = (
310
311
  const index = isNegative(argument)
311
312
  ? `${getOffset(argument)} + 1`
312
313
  : `${wrap(translate(argument))} + 1`;
313
- return orUndefined(`${index} \\in DOMAIN ${wrapped}`, `${wrapped}[${index}]`);
314
+ return orUndefined(
315
+ `${index} \\in DOMAIN ${wrapped}`,
316
+ `${wrapped}[${index}]`,
317
+ isDefined,
318
+ context,
319
+ );
314
320
  },
315
321
  ],
316
322
  [
@@ -383,7 +389,7 @@ const translateSequenceOperation = (
383
389
  "find",
384
390
  () => {
385
391
  const result = translateFirstIndex(sequence, argument, scope, context);
386
- return orUndefined(result.exists, `${wrapped}[${result.first}]`);
392
+ return orUndefined(result.exists, `${wrapped}[${result.first}]`, isDefined, context);
387
393
  },
388
394
  ],
389
395
  [
@@ -421,9 +427,7 @@ const translateUnorderedMethod = (
421
427
  const binding = `${element.variable} \\in ${wrap(source.set)} : ${body}`;
422
428
  if (method === "every") return `\\A ${binding}`;
423
429
  if (method === "some") return `\\E ${binding}`;
424
- if (isDefined) return `CHOOSE ${binding}`;
425
- context.prelude.add("Undefined");
426
- return `IF \\E ${binding} THEN CHOOSE ${binding} ELSE Undefined`;
430
+ return orUndefined(`\\E ${binding}`, `CHOOSE ${binding}`, isDefined, context);
427
431
  };
428
432
 
429
433
  const translateSetMethod = (node: MethodCall, scope: Scope, context: Context) => {
@@ -446,6 +450,8 @@ const translateSetMethod = (node: MethodCall, scope: Scope, context: Context) =>
446
450
  const operation = operations.get(method);
447
451
  if (operation === undefined)
448
452
  throw new TlaTypeScriptError(`Unsupported Set method: ${method}`, node);
453
+ if (node.arguments[0] === undefined)
454
+ throw new TlaTypeScriptError(`Set method needs an argument: ${method}`, node);
449
455
  return operation;
450
456
  };
451
457
 
@@ -461,21 +467,29 @@ const translateMapMethod = (
461
467
  node.arguments[0] === undefined
462
468
  ? ""
463
469
  : wrap(translateExpression(node.arguments[0], scope, context));
470
+ if (method !== "has" && method !== "get")
471
+ throw new TlaTypeScriptError(`Unsupported Map method: ${method}`, node);
472
+ if (node.arguments[0] === undefined)
473
+ throw new TlaTypeScriptError(`Map method needs a key: ${method}`, node);
464
474
  if (method === "has") return `${key} \\in DOMAIN ${map}`;
465
- if (method !== "get") throw new TlaTypeScriptError(`Unsupported Map method: ${method}`, node);
466
475
  if (isDefined) return `${map}[${key}]`;
467
- context.prelude.add("Undefined");
468
476
  return share(map, "map", context, (sharedMap) =>
469
- share(
470
- key,
471
- "key",
472
- context,
473
- (sharedKey) =>
474
- `IF ${sharedKey} \\in DOMAIN ${sharedMap} THEN ${sharedMap}[${sharedKey}] ELSE Undefined`,
477
+ share(key, "key", context, (sharedKey) =>
478
+ orUndefined(
479
+ `${sharedKey} \\in DOMAIN ${sharedMap}`,
480
+ `${sharedMap}[${sharedKey}]`,
481
+ isDefined,
482
+ context,
483
+ ),
475
484
  ),
476
485
  );
477
486
  };
478
487
 
488
+ export const REMOVALS = {
489
+ pop: (current: string) => `SubSeq(${current}, 1, Len(${current}) - 1)`,
490
+ shift: (current: string) => `Tail(${current})`,
491
+ };
492
+
479
493
  const UPDATES = new Map<Kind, Map<string, Update>>([
480
494
  [
481
495
  "sequence",
@@ -488,8 +502,8 @@ const UPDATES = new Map<Kind, Map<string, Update>>([
488
502
  : `${wrap(current)} \\o <<${values.join(", ")}>>`,
489
503
  ],
490
504
  ["unshift", (current, values) => `<<${values.join(", ")}>> \\o ${wrap(current)}`],
491
- ["pop", (current) => `SubSeq(${current}, 1, Len(${current}) - 1)`],
492
- ["shift", (current) => `Tail(${current})`],
505
+ ["pop", REMOVALS.pop],
506
+ ["shift", REMOVALS.shift],
493
507
  ]),
494
508
  ],
495
509
  [
@@ -31,11 +31,9 @@ const translateExported = (
31
31
  ) => {
32
32
  const tag = [...definition.tags.keys()].find((candidate) => VALUE_TAGS.has(candidate));
33
33
  if (tag !== undefined) return translateProperty(definition, tag, model, sections, context);
34
- if (writesState(definition.body, context)) {
35
- return translateStep(definition, sections, context);
36
- }
37
34
  const returnType = context.checker.getSignatureFromDeclaration(definition.node)?.getReturnType();
38
35
  if (
36
+ writesState(definition.body, context) ||
39
37
  returnType === undefined ||
40
38
  (returnType.flags & (ts.TypeFlags.Void | ts.TypeFlags.Undefined)) !== 0
41
39
  ) {
@@ -142,11 +142,13 @@ const LOOSE_OPERATORS = [
142
142
  " ~> ",
143
143
  ];
144
144
 
145
- export const wrapEquated = (expression: string) =>
146
- expression.startsWith("~") ||
147
- LOOSE_OPERATORS.some((operator) => getSurface(expression).includes(operator))
145
+ export const wrapEquated = (expression: string) => {
146
+ if (expression.startsWith("~")) return `(${expression})`;
147
+ const surface = getSurface(expression);
148
+ return LOOSE_OPERATORS.some((operator) => surface.includes(operator))
148
149
  ? `(${expression})`
149
150
  : expression;
151
+ };
150
152
 
151
153
  export const indent = (expression: string, prefix: string) =>
152
154
  expression.split("\n").join(`\n${prefix}`);
@@ -66,9 +66,8 @@ const getTags = (node: ts.Node) =>
66
66
  const isExported = (node: ts.Declaration) =>
67
67
  (ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Export) !== 0;
68
68
 
69
- const isLet = (declared: Declared) =>
70
- ts.isVariableDeclaration(declared.declaration) &&
71
- (declared.declaration.parent.flags & ts.NodeFlags.Let) !== 0;
69
+ const isLet = (declaration: ts.Declaration): declaration is ts.VariableDeclaration =>
70
+ ts.isVariableDeclaration(declaration) && (declaration.parent.flags & ts.NodeFlags.Let) !== 0;
72
71
 
73
72
  const declareModelValues = (statement: ts.TypeAliasDeclaration, context: Context) => {
74
73
  const type = context.checker.getTypeAtLocation(statement.name);
@@ -126,7 +125,7 @@ export const readModel = (sourceFile: ts.SourceFile, context: Context): Model =>
126
125
  const declarations = statements.flatMap(getDeclarations);
127
126
  const variables = declarations.flatMap((declared) => {
128
127
  const declaration = declared.declaration;
129
- if (!isLet(declared) || !ts.isVariableDeclaration(declaration)) return [];
128
+ if (!isLet(declaration)) return [];
130
129
  const symbol = getSymbol(declaration.name, context.checker);
131
130
  if (isExported(declaration) || symbol === undefined) {
132
131
  throw new TlaTypeScriptError("State variables can't be exported", declaration);
@@ -135,7 +134,7 @@ export const readModel = (sourceFile: ts.SourceFile, context: Context): Model =>
135
134
  context.variables.set(symbol, name);
136
135
  return [{ name, declaration }];
137
136
  });
138
- const helpers = declarations.filter((declared) => !isLet(declared));
137
+ const helpers = declarations.filter((declared) => !isLet(declared.declaration));
139
138
  const exported = helpers.flatMap((declared) => {
140
139
  const declaration = declared.declaration;
141
140
  const node = getFunction(declaration);
@@ -130,15 +130,16 @@ export const translateStep = (definition: Exported, sections: Sections, context:
130
130
  return;
131
131
  }
132
132
  const getType = (parameter: Parameter) => context.checker.getTypeAtLocation(parameter.node.name);
133
- const domains = parameters.map(
134
- (parameter) =>
135
- guards.chosen.get(parameter)?.domain ??
136
- getDomain(getType(parameter), parameter.node, context),
137
- );
138
- const independent = parameters.flatMap((parameter, index) =>
139
- guards.chosen.get(parameter)?.isDependent === true
140
- ? []
141
- : [`${parameter.name} \\in ${domains[index]}`],
133
+ const choices = parameters.map((parameter) => {
134
+ const chosen = guards.chosen.get(parameter);
135
+ return {
136
+ parameter,
137
+ chosen,
138
+ domain: chosen?.domain ?? getDomain(getType(parameter), parameter.node, context),
139
+ };
140
+ });
141
+ const independent = choices.flatMap((choice) =>
142
+ choice.chosen?.isDependent === true ? [] : [`${choice.parameter.name} \\in ${choice.domain}`],
142
143
  );
143
144
  const dependent = [...guards.chosen]
144
145
  .filter((entry) => entry[1].isDependent)
@@ -146,18 +147,19 @@ export const translateStep = (definition: Exported, sections: Sections, context:
146
147
  const step = `\\E ${independent.join(", ")} : ${dependent.join("")}${head}`;
147
148
  sections.next.push(step);
148
149
  if (fairness === undefined) return;
149
- const typeDomains = parameters.map((parameter, index) =>
150
- guards.chosen.has(parameter) ? findDomain(getType(parameter), context) : domains[index],
151
- );
152
- const conditions = parameters.flatMap((parameter, index) =>
153
- guards.chosen.has(parameter) ? [`${parameter.name} \\in ${wrap(domains[index])}`] : [],
154
- );
155
- if (!typeDomains.every((domain): domain is string => typeof domain === "string")) {
150
+ const forAll = choices.map((choice) => {
151
+ const typeDomain =
152
+ choice.chosen === undefined ? choice.domain : findDomain(getType(choice.parameter), context);
153
+ return typeof typeDomain === "string"
154
+ ? `${choice.parameter.name} \\in ${typeDomain}`
155
+ : undefined;
156
+ });
157
+ if (!forAll.every((bound) => bound !== undefined)) {
156
158
  sections.fairness.push(`${fairness}(${step})`);
157
159
  return;
158
160
  }
159
- const forAll = parameters.map(
160
- (parameter, index) => `${parameter.name} \\in ${typeDomains[index]}`,
161
+ const conditions = choices.flatMap((choice) =>
162
+ choice.chosen === undefined ? [] : [`${choice.parameter.name} \\in ${wrap(choice.domain)}`],
161
163
  );
162
164
  sections.fairness.push(
163
165
  `\\A ${forAll.join(", ")} : ${fairness}(${[...conditions, head].join(" /\\ ")})`,
package/src/values.ts CHANGED
@@ -359,18 +359,17 @@ interface StringOrder {
359
359
  unorderedString: string | undefined;
360
360
  }
361
361
 
362
- const stringOrder: StringOrder = {
362
+ const createStringOrder = (): StringOrder => ({
363
363
  ranks: Object.create(null),
364
364
  size: 0,
365
365
  searchRank: undefined,
366
366
  unorderedString: undefined,
367
- };
367
+ });
368
+
369
+ const stringOrder = createStringOrder();
368
370
 
369
371
  export const setStringOrder = (texts: Iterable<string>) => {
370
- stringOrder.ranks = Object.create(null);
371
- stringOrder.size = 0;
372
- stringOrder.searchRank = undefined;
373
- stringOrder.unorderedString = undefined;
372
+ Object.assign(stringOrder, createStringOrder());
374
373
  modelValues.clear();
375
374
  for (const text of texts) rankString(text);
376
375
  };
@@ -844,26 +843,11 @@ const toTlcRecord = (value: Value) => {
844
843
  return isRecordDomain(functionValue.domain) ? functionValue : undefined;
845
844
  };
846
845
 
847
- const compareModelValueWith = (modelValue: ModelValue, other: Value) => {
848
- checkModelValueTypes(other, modelValue, false);
846
+ const compareModelValueWith = (modelValue: ModelValue, other: Value, isEquality: boolean) => {
847
+ checkModelValueTypes(other, modelValue, isEquality);
849
848
  return 1;
850
849
  };
851
850
 
852
- const equalsModelValueWith = (modelValue: ModelValue, other: Value) => {
853
- checkModelValueTypes(other, modelValue, true);
854
- return false;
855
- };
856
-
857
- const compareModelValue = (left: ModelValue, right: Value) => {
858
- if (left.type !== undefined) checkModelValueTypes(left, right, false);
859
- return isModelValue(right) ? left.rank - right.rank : -1;
860
- };
861
-
862
- const equalsModelValue = (left: ModelValue, right: Value) => {
863
- if (left.type !== undefined) checkModelValueTypes(left, right, true);
864
- return isModelValue(right) && left.name === right.name;
865
- };
866
-
867
851
  const SCALAR_KINDS = {
868
852
  number: { name: "integer", other: "non-integer", equality: "check equality of" },
869
853
  string: { name: "string", other: "non-string", equality: "check equality of" },
@@ -882,31 +866,40 @@ const describeScalarMismatch = (
882
866
  return `Attempted to ${isEquality ? kind.equality : "compare"} ${kind.name} ${formatValue(left)} with ${kind.other}:\n${formatValue(right)}`;
883
867
  };
884
868
 
885
- const compareTlcFunctions = (functionValue: TlcFunction, left: Value, right: Value) => {
869
+ const getComparisonVerb = (isEquality: boolean) => (isEquality ? "check equality of" : "compare");
870
+
871
+ const compareTlcFunctions = (
872
+ functionValue: TlcFunction,
873
+ left: Value,
874
+ right: Value,
875
+ isEquality: boolean,
876
+ ) => {
886
877
  const other = toTlcFunction(right);
887
878
  if (!other) {
888
- if (isModelValue(right)) return compareModelValueWith(right, left);
879
+ if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
889
880
  throw new TlaEvaluationError(
890
- `Attempted to compare the function ${formatValue(left)} with the value:\n${formatValue(right)}`,
881
+ `Attempted to ${getComparisonVerb(isEquality)} the function ${formatValue(left)} with the value:\n${formatValue(right)}`,
891
882
  );
892
883
  }
893
884
  if (functionValue.range.length !== other.range.length)
894
885
  return functionValue.range.length - other.range.length;
895
- const compareRanges = () => compareElementsLikeTlc(functionValue.range, other.range);
886
+ const compareRanges = () => compareElementsLikeTlc(functionValue.range, other.range, isEquality);
896
887
  if (functionValue.low !== undefined && functionValue.range.length === 0) return 0;
897
888
  if (functionValue.low !== undefined && other.low !== undefined) {
898
889
  return functionValue.low === other.low ? compareRanges() : functionValue.low - other.low;
899
890
  }
900
891
  const intervalLow = functionValue.low ?? other.low;
901
892
  if (intervalLow === undefined) {
902
- return compareElementsLikeTlc(functionValue.domain, other.domain) || compareRanges();
893
+ return (
894
+ compareElementsLikeTlc(functionValue.domain, other.domain, isEquality) || compareRanges()
895
+ );
903
896
  }
904
897
  const keys = functionValue.low === undefined ? functionValue.domain : other.domain;
905
898
  for (let index = 0; index < keys.length; index++) {
906
899
  const key = keys[index];
907
900
  if (typeof key !== "number") {
908
901
  throw new TlaEvaluationError(
909
- `Attempted to compare integer with non-integer${functionValue.low === undefined ? "" : ":"}\n${formatValue(key)}.`,
902
+ `Attempted to compare ${isEquality ? "an " : ""}integer with non-integer${isEquality || functionValue.low !== undefined ? ":" : ""}\n${formatValue(key)}.`,
910
903
  );
911
904
  }
912
905
  const difference =
@@ -916,42 +909,47 @@ const compareTlcFunctions = (functionValue: TlcFunction, left: Value, right: Val
916
909
  return compareRanges();
917
910
  };
918
911
 
919
- const compareElementsLikeTlc = (left: Value[], right: Value[]) => {
912
+ const compareElementsLikeTlc = (left: Value[], right: Value[], isEquality: boolean) => {
920
913
  for (let index = 0; index < left.length; index++) {
921
- const comparison = compareLikeTlc(left[index], right[index]);
914
+ const comparison = compareOrEqualLikeTlc(left[index], right[index], isEquality);
922
915
  if (comparison !== 0) return comparison;
923
916
  }
924
917
  return 0;
925
918
  };
926
919
 
927
- const compareFunctionLikeTlc = (left: FunctionValue | LazyFunctionValue, right: Value) => {
920
+ const compareFunctionLikeTlc = (
921
+ left: FunctionValue | LazyFunctionValue,
922
+ right: Value,
923
+ isEquality: boolean,
924
+ ) => {
928
925
  const functionValue = toFiniteFunction(left);
929
926
  if (getFunctionClass(left) === "tuple") {
930
927
  const tuple = isFunctionValue(right) ? getSequenceElements(right) : undefined;
931
- if (!tuple) return compareTlcFunctions({ ...functionValue, low: 1 }, left, right);
928
+ if (!tuple) return compareTlcFunctions({ ...functionValue, low: 1 }, left, right, isEquality);
932
929
  return (
933
930
  functionValue.range.length - tuple.length ||
934
- compareElementsLikeTlc(functionValue.range, tuple)
931
+ compareElementsLikeTlc(functionValue.range, tuple, isEquality)
935
932
  );
936
933
  }
937
934
  if (getFunctionClass(left) === "record") {
938
935
  const record = toTlcRecord(right);
939
936
  if (!record) {
940
- if (isModelValue(right)) return compareModelValueWith(right, left);
937
+ if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
941
938
  throw new TlaEvaluationError(
942
- `Attempted to compare record:\n${formatValue(left)}\nwith non-record\n${formatValue(right)}`,
939
+ `Attempted to ${getComparisonVerb(isEquality)} record:\n${formatValue(left)}\nwith non-record\n${formatValue(right)}`,
943
940
  );
944
941
  }
945
942
  return (
946
943
  functionValue.domain.length - record.domain.length ||
947
- compareElementsLikeTlc(functionValue.domain, record.domain) ||
948
- compareElementsLikeTlc(functionValue.range, record.range)
944
+ compareElementsLikeTlc(functionValue.domain, record.domain, isEquality) ||
945
+ compareElementsLikeTlc(functionValue.range, record.range, isEquality)
949
946
  );
950
947
  }
951
948
  return compareTlcFunctions(
952
949
  { ...functionValue, low: getIntervalLow(left, functionValue.domain) },
953
950
  left,
954
951
  right,
952
+ isEquality,
955
953
  );
956
954
  };
957
955
 
@@ -971,128 +969,47 @@ const getSetElementsLikeTlc = (left: SetValue | MixedSetValue, right: Value) =>
971
969
  return { elements: toFiniteSet(left).elements, otherElements: toFiniteSet(other).elements };
972
970
  };
973
971
 
974
- const compareSetLikeTlc = (left: ObjectValue, right: Value): number => {
975
- if (isComparedByClass(left, right)) return compareValues(left, right);
976
- if (!isEnumeratedSet(left)) return compareSetLikeTlc(toFiniteSet(left), right);
972
+ const compareSetLikeTlc = (left: ObjectValue, right: Value, isEquality: boolean): number => {
973
+ if (isComparedByClass(left, right)) {
974
+ if (!isEquality) return compareValues(left, right);
975
+ return valuesEqual(left, right) ? 0 : 1;
976
+ }
977
+ if (!isEnumeratedSet(left)) return compareSetLikeTlc(toFiniteSet(left), right, isEquality);
977
978
  if (!isSetValue(right)) {
978
- if (isModelValue(right)) return compareModelValueWith(right, left);
979
+ if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
979
980
  throw new TlaEvaluationError(
980
- `Attempted to compare the set ${formatValue(left)} with the value:\n${formatValue(right)}`,
981
+ `Attempted to ${getComparisonVerb(isEquality)} the set ${formatValue(left)} with the value:\n${formatValue(right)}`,
981
982
  );
982
983
  }
983
984
  const sets = getSetElementsLikeTlc(left, right);
984
985
  return (
985
986
  sets.elements.length - sets.otherElements.length ||
986
- compareElementsLikeTlc(sets.elements, sets.otherElements)
987
+ compareElementsLikeTlc(sets.elements, sets.otherElements, isEquality)
987
988
  );
988
989
  };
989
990
 
990
- const compareLikeTlc = (left: Value, right: Value): number => {
991
+ const compareOrEqualLikeTlc = (left: Value, right: Value, isEquality: boolean): number => {
991
992
  if (typeof left !== "object") {
992
- if (typeof right === typeof left) return compareValues(left, right);
993
- if (isModelValue(right)) return compareModelValueWith(right, left);
994
- throw new TlaEvaluationError(describeScalarMismatch(left, right, false));
995
- }
996
- if (left.kind === "ModelValue") return compareModelValue(left, right);
997
- if (isFunctionValue(left)) return compareFunctionLikeTlc(left, right);
998
- return compareSetLikeTlc(left, right);
999
- };
1000
-
1001
- const equalsElementsLikeTlc = (left: Value[], right: Value[]) =>
1002
- left.every((element, index) => equalsLikeTlc(element, right[index]));
1003
-
1004
- const equalsTlcFunctions = (functionValue: TlcFunction, left: Value, right: Value) => {
1005
- const other = toTlcFunction(right);
1006
- if (!other) {
1007
- if (isModelValue(right)) return equalsModelValueWith(right, left);
1008
- throw new TlaEvaluationError(
1009
- `Attempted to check equality of the function ${formatValue(left)} with the value:\n${formatValue(right)}`,
1010
- );
1011
- }
1012
- if (functionValue.range.length !== other.range.length) return false;
1013
- if (functionValue.low !== undefined && other.low !== undefined) {
1014
- return (
1015
- (functionValue.range.length === 0 || functionValue.low === other.low) &&
1016
- equalsElementsLikeTlc(functionValue.range, other.range)
1017
- );
1018
- }
1019
- const intervalLow = functionValue.low ?? other.low;
1020
- if (intervalLow === undefined) {
1021
- return (
1022
- equalsElementsLikeTlc(functionValue.domain, other.domain) &&
1023
- equalsElementsLikeTlc(functionValue.range, other.range)
1024
- );
1025
- }
1026
- const keys = functionValue.low === undefined ? functionValue.domain : other.domain;
1027
- return (
1028
- keys.every((key, index) => {
1029
- if (typeof key !== "number") {
1030
- throw new TlaEvaluationError(
1031
- `Attempted to compare an integer with non-integer:\n${formatValue(key)}.`,
1032
- );
1033
- }
1034
- return key === intervalLow + index;
1035
- }) && equalsElementsLikeTlc(functionValue.range, other.range)
1036
- );
1037
- };
1038
-
1039
- const equalsFunctionLikeTlc = (left: FunctionValue | LazyFunctionValue, right: Value) => {
1040
- const functionValue = toFiniteFunction(left);
1041
- if (getFunctionClass(left) === "tuple") {
1042
- const tuple = isFunctionValue(right) ? getSequenceElements(right) : undefined;
1043
- if (!tuple) return equalsTlcFunctions({ ...functionValue, low: 1 }, left, right);
1044
- return (
1045
- functionValue.range.length === tuple.length &&
1046
- equalsElementsLikeTlc(functionValue.range, tuple)
1047
- );
1048
- }
1049
- if (getFunctionClass(left) === "record") {
1050
- const record = toTlcRecord(right);
1051
- if (!record) {
1052
- if (isModelValue(right)) return equalsModelValueWith(right, left);
1053
- throw new TlaEvaluationError(
1054
- `Attempted to check equality of record:\n${formatValue(left)}\nwith non-record\n${formatValue(right)}`,
1055
- );
993
+ if (typeof right === typeof left) {
994
+ if (!isEquality) return compareValues(left, right);
995
+ return left === right ? 0 : 1;
1056
996
  }
1057
- return (
1058
- functionValue.domain.length === record.domain.length &&
1059
- equalsElementsLikeTlc(functionValue.domain, record.domain) &&
1060
- equalsElementsLikeTlc(functionValue.range, record.range)
1061
- );
997
+ if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
998
+ throw new TlaEvaluationError(describeScalarMismatch(left, right, isEquality));
1062
999
  }
1063
- return equalsTlcFunctions(
1064
- { ...functionValue, low: getIntervalLow(left, functionValue.domain) },
1065
- left,
1066
- right,
1067
- );
1068
- };
1069
-
1070
- const equalsSetLikeTlc = (left: ObjectValue, right: Value): boolean => {
1071
- if (isComparedByClass(left, right)) return valuesEqual(left, right);
1072
- if (!isEnumeratedSet(left)) return equalsSetLikeTlc(toFiniteSet(left), right);
1073
- if (!isSetValue(right)) {
1074
- if (isModelValue(right)) return equalsModelValueWith(right, left);
1075
- throw new TlaEvaluationError(
1076
- `Attempted to check equality of the set ${formatValue(left)} with the value:\n${formatValue(right)}`,
1077
- );
1000
+ if (left.kind === "ModelValue") {
1001
+ if (left.type !== undefined) checkModelValueTypes(left, right, isEquality);
1002
+ if (!isModelValue(right)) return -1;
1003
+ if (!isEquality) return left.rank - right.rank;
1004
+ return left.name === right.name ? 0 : 1;
1078
1005
  }
1079
- const sets = getSetElementsLikeTlc(left, right);
1080
- return (
1081
- sets.elements.length === sets.otherElements.length &&
1082
- equalsElementsLikeTlc(sets.elements, sets.otherElements)
1083
- );
1006
+ if (isFunctionValue(left)) return compareFunctionLikeTlc(left, right, isEquality);
1007
+ return compareSetLikeTlc(left, right, isEquality);
1084
1008
  };
1085
1009
 
1086
- const equalsLikeTlc = (left: Value, right: Value): boolean => {
1087
- if (typeof left !== "object") {
1088
- if (typeof right === typeof left) return left === right;
1089
- if (isModelValue(right)) return equalsModelValueWith(right, left);
1090
- throw new TlaEvaluationError(describeScalarMismatch(left, right, true));
1091
- }
1092
- if (left.kind === "ModelValue") return equalsModelValue(left, right);
1093
- if (isFunctionValue(left)) return equalsFunctionLikeTlc(left, right);
1094
- return equalsSetLikeTlc(left, right);
1095
- };
1010
+ const compareLikeTlc = (left: Value, right: Value) => compareOrEqualLikeTlc(left, right, false);
1011
+
1012
+ const equalsLikeTlc = (left: Value, right: Value) => compareOrEqualLikeTlc(left, right, true) === 0;
1096
1013
 
1097
1014
  const sortLikeTlc = (elements: Value[]) => {
1098
1015
  const sorted: Value[] = [];
@@ -2895,14 +2812,7 @@ const PRINTED_ESCAPES: Record<string, string> = {
2895
2812
  const formatString = (value: string) =>
2896
2813
  `"${value.replace(/["\\\t\n\f\r]/g, (character) => PRINTED_ESCAPES[character])}"`;
2897
2814
 
2898
- type LazySetValue =
2899
- | SubsetValue
2900
- | FunctionSetValue
2901
- | RecordSetValue
2902
- | ProductSetValue
2903
- | SetOperationValue
2904
- | FilteredSetValue
2905
- | UnionValue;
2815
+ type LazySetValue = Exclude<ConvertibleSetValue, MixedSetValue | SequenceSetValue>;
2906
2816
 
2907
2817
  const MAXIMUM_EXPANDED_SUBSET_BASE = 6;
2908
2818
  const MAXIMUM_EXPANDED_PRODUCT = 1999;
@@ -1,52 +0,0 @@
1
- // Ported from Isabelle2025's Pure/Isar/expression.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
2
-
3
- import { typargsOf } from "../pure/consts";
4
- import type { Term } from "../pure/term";
5
- import type { TlaLogic } from "../tla/logic";
6
- import { parseProp, parseType } from "./inner-syntax";
7
- import type { TheoryText } from "./theory";
8
- import { checkProps, type PropToCheck } from "./type-check";
9
-
10
- export interface Statement {
11
- readonly assumptions: readonly Term[];
12
- readonly conclusion: Term;
13
- }
14
-
15
- export const readStatement = (logic: TlaLogic, theory: TheoryText): Statement => {
16
- const theoryConsts = theory.consts.map((constant) => ({
17
- base: constant.name,
18
- name: `${theory.name}.${constant.name}`,
19
- type: parseType(constant.type),
20
- }));
21
- const scope = {
22
- consts: new Map([
23
- ...logic.consts,
24
- ...theoryConsts.map(
25
- (constant) =>
26
- [
27
- constant.name,
28
- { type: constant.type, typargs: typargsOf(constant.type), abbreviation: undefined },
29
- ] as const,
30
- ),
31
- ]),
32
- constNames: new Map([
33
- ...logic.constNames,
34
- ...theoryConsts.map((constant) => [constant.base, constant.name] as const),
35
- ]),
36
- };
37
- const props = theory.elements.reduce<{ fixed: ReadonlySet<string>; props: PropToCheck[] }>(
38
- (state, element) =>
39
- element.kind === "fixes"
40
- ? { fixed: new Set([...state.fixed, ...element.names]), props: state.props }
41
- : {
42
- fixed: state.fixed,
43
- props: [...state.props, { ast: parseProp(element.prop), fixed: state.fixed }],
44
- },
45
- { fixed: new Set(), props: [] },
46
- );
47
- const checked = checkProps(scope, [
48
- ...props.props,
49
- { ast: parseProp(theory.shows), fixed: props.fixed },
50
- ]);
51
- return { assumptions: checked.slice(0, -1), conclusion: checked[checked.length - 1] };
52
- };
@@ -1,10 +0,0 @@
1
- Z3
2
- Copyright (c) Microsoft Corporation
3
- All rights reserved.
4
- MIT License
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
-
8
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
-
10
- THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.