tla-ts 0.0.9 → 0.0.10-dev.28c823e4b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (390) hide show
  1. package/README.md +29 -1
  2. package/dist/compile.cjs +23 -0
  3. package/dist/compile.js +23 -0
  4. package/dist/deciders.cjs +28 -28
  5. package/dist/deciders.js +43 -43
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +106 -10
  8. package/dist/index.d.ts +106 -10
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +116 -36
  15. package/dist/prove.js +116 -36
  16. package/dist/run.cjs +143 -31
  17. package/dist/run.js +143 -31
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +2 -2
  20. package/dist/transfer.cjs +129 -104
  21. package/dist/transfer.js +129 -104
  22. package/dist/worker.cjs +7 -7
  23. package/dist/worker.js +7 -7
  24. package/package.json +3 -1
  25. package/src/ast.ts +4 -23
  26. package/src/bags.ts +99 -102
  27. package/src/builtins.ts +40 -78
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check.ts +599 -388
  30. package/src/cli/options.ts +11 -6
  31. package/src/cli/run.ts +0 -2
  32. package/src/cli/runtime-invariants.ts +136 -0
  33. package/src/cli/shared.ts +18 -11
  34. package/src/cli/tlapm.ts +0 -12
  35. package/src/cli/tlc-arguments.ts +640 -0
  36. package/src/cli/tlc-usage.ts +361 -0
  37. package/src/cli/tlc.ts +538 -220
  38. package/src/cli/typescript.ts +23 -0
  39. package/src/cli/xml-exporter.ts +4 -16
  40. package/src/cli.ts +0 -1
  41. package/src/codegen.ts +191 -64
  42. package/src/config.ts +140 -109
  43. package/src/coverage.ts +837 -0
  44. package/src/dependencies.ts +6 -40
  45. package/src/dfid.ts +618 -0
  46. package/src/environment.ts +240 -118
  47. package/src/errors.ts +70 -55
  48. package/src/evaluate.ts +596 -339
  49. package/src/exit-codes.ts +37 -3
  50. package/src/fingerprints.ts +10 -10
  51. package/src/index.ts +3 -0
  52. package/src/instances.ts +79 -11
  53. package/src/java-overrides.ts +4 -19
  54. package/src/json-reader.ts +455 -0
  55. package/src/json.ts +255 -139
  56. package/src/levels.ts +8 -17
  57. package/src/lexer.ts +80 -100
  58. package/src/liveness-checker.ts +82 -119
  59. package/src/liveness.ts +112 -64
  60. package/src/obligations/action.ts +4 -28
  61. package/src/obligations/anonymize.ts +84 -80
  62. package/src/obligations/equality.ts +1 -1
  63. package/src/obligations/expression.ts +2 -19
  64. package/src/obligations/format.ts +1 -9
  65. package/src/obligations/generate.ts +1 -11
  66. package/src/obligations/index.ts +0 -11
  67. package/src/obligations/levels.ts +4 -8
  68. package/src/obligations/module.ts +1 -15
  69. package/src/obligations/normalize.ts +5 -24
  70. package/src/obligations/operators.ts +1 -2
  71. package/src/obligations/pragma.ts +1 -10
  72. package/src/obligations/printer.ts +47 -46
  73. package/src/obligations/proof.ts +1 -5
  74. package/src/obligations/regroup.ts +1 -4
  75. package/src/obligations/simplify.ts +3 -14
  76. package/src/obligations/source.ts +1 -21
  77. package/src/obligations/subexpression.ts +5 -11
  78. package/src/obligations/substitution.ts +1 -3
  79. package/src/obligations/temporal.ts +8 -14
  80. package/src/obligations/tuples.ts +3 -9
  81. package/src/parallel-worker.ts +29 -39
  82. package/src/parallel.ts +53 -44
  83. package/src/parser.ts +565 -282
  84. package/src/pcal/ast.ts +53 -86
  85. package/src/pcal/parse.ts +144 -219
  86. package/src/pcal/tokenize.ts +91 -131
  87. package/src/pcal/translate.ts +83 -130
  88. package/src/pcal/validate.ts +48 -68
  89. package/src/pretty-print.ts +7 -8
  90. package/src/prover/decide-pool.ts +5 -10
  91. package/src/prover/deciders.ts +0 -4
  92. package/src/prover/first-order.ts +0 -11
  93. package/src/prover/isabelle/decide.ts +0 -6
  94. package/src/prover/isabelle/encode.ts +11 -23
  95. package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
  96. package/src/prover/isabelle/isar/method.ts +25 -38
  97. package/src/prover/isabelle/isar/proof.ts +1 -10
  98. package/src/prover/isabelle/isar/statement.ts +1 -6
  99. package/src/prover/isabelle/isar/theory.ts +15 -26
  100. package/src/prover/isabelle/isar/type-check.ts +11 -25
  101. package/src/prover/isabelle/provers/blast/blast.ts +10 -41
  102. package/src/prover/isabelle/provers/blast/branch.ts +1 -32
  103. package/src/prover/isabelle/provers/blast/prove.ts +1 -35
  104. package/src/prover/isabelle/provers/blast/rules.ts +6 -44
  105. package/src/prover/isabelle/provers/blast/state.ts +2 -28
  106. package/src/prover/isabelle/provers/blast/term.ts +9 -36
  107. package/src/prover/isabelle/provers/clasimp.ts +1 -13
  108. package/src/prover/isabelle/provers/classical.ts +14 -42
  109. package/src/prover/isabelle/provers/hypsubst.ts +11 -25
  110. package/src/prover/isabelle/pure/bicompose.ts +16 -13
  111. package/src/prover/isabelle/pure/consts.ts +1 -7
  112. package/src/prover/isabelle/pure/conv.ts +1 -9
  113. package/src/prover/isabelle/pure/drule.ts +24 -40
  114. package/src/prover/isabelle/pure/envir.ts +3 -52
  115. package/src/prover/isabelle/pure/goal.ts +1 -7
  116. package/src/prover/isabelle/pure/interrupt.ts +0 -5
  117. package/src/prover/isabelle/pure/list.ts +0 -3
  118. package/src/prover/isabelle/pure/logic.ts +1 -14
  119. package/src/prover/isabelle/pure/name.ts +2 -9
  120. package/src/prover/isabelle/pure/net.ts +3 -59
  121. package/src/prover/isabelle/pure/object-logic.ts +3 -10
  122. package/src/prover/isabelle/pure/pattern.ts +2 -19
  123. package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
  124. package/src/prover/isabelle/pure/rewriter.ts +26 -58
  125. package/src/prover/isabelle/pure/search.ts +3 -10
  126. package/src/prover/isabelle/pure/seq.ts +1 -10
  127. package/src/prover/isabelle/pure/simplifier.ts +4 -12
  128. package/src/prover/isabelle/pure/table.ts +1 -31
  129. package/src/prover/isabelle/pure/tactic.ts +12 -22
  130. package/src/prover/isabelle/pure/tactical.ts +6 -12
  131. package/src/prover/isabelle/pure/term-ord.ts +2 -6
  132. package/src/prover/isabelle/pure/term.ts +2 -43
  133. package/src/prover/isabelle/pure/thm.ts +13 -36
  134. package/src/prover/isabelle/pure/type.ts +2 -15
  135. package/src/prover/isabelle/pure/unify.ts +20 -30
  136. package/src/prover/isabelle/pure/variable.ts +3 -7
  137. package/src/prover/isabelle/tla/classical-setup.ts +9 -19
  138. package/src/prover/isabelle/tla/context.ts +8 -16
  139. package/src/prover/isabelle/tla/logic.ts +4 -11
  140. package/src/prover/isabelle/tla/simpdata.ts +46 -34
  141. package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
  142. package/src/prover/ocaml.ts +0 -6
  143. package/src/prover/prep/action.ts +4 -36
  144. package/src/prover/prep/enabled-axioms.ts +12 -19
  145. package/src/prover/prep/fingerprint.ts +0 -16
  146. package/src/prover/prep/level-comparison.ts +8 -12
  147. package/src/prover/prep/md5.ts +0 -2
  148. package/src/prover/prep/methods.ts +9 -36
  149. package/src/prover/prep/normalize.ts +4 -28
  150. package/src/prover/prove-worker.ts +0 -2
  151. package/src/prover/prove.ts +0 -36
  152. package/src/prover/ptl/decide.ts +7 -12
  153. package/src/prover/ptl/encode.ts +14 -36
  154. package/src/prover/ptl/sat.ts +24 -32
  155. package/src/prover/ptl/tableau.ts +12 -26
  156. package/src/prover/smt/axioms.ts +0 -7
  157. package/src/prover/smt/context.ts +19 -26
  158. package/src/prover/smt/data.ts +51 -54
  159. package/src/prover/smt/encode.ts +14 -35
  160. package/src/prover/smt/extensionality.ts +0 -10
  161. package/src/prover/smt/flatten.ts +3 -22
  162. package/src/prover/smt/format.ts +5 -10
  163. package/src/prover/smt/instances.ts +0 -10
  164. package/src/prover/smt/rewrite.ts +66 -101
  165. package/src/prover/smt/solver/act-cache.ts +0 -15
  166. package/src/prover/smt/solver/arith-rewriter.ts +3 -48
  167. package/src/prover/smt/solver/array.ts +1 -3
  168. package/src/prover/smt/solver/asserted-formulas.ts +1 -43
  169. package/src/prover/smt/solver/ast-lt.ts +1 -11
  170. package/src/prover/smt/solver/ast-util.ts +1 -6
  171. package/src/prover/smt/solver/ast.ts +1 -143
  172. package/src/prover/smt/solver/auf-solver.ts +6 -39
  173. package/src/prover/smt/solver/case-split-queue.ts +1 -9
  174. package/src/prover/smt/solver/cg-table.ts +1 -18
  175. package/src/prover/smt/solver/clause.ts +1 -27
  176. package/src/prover/smt/solver/conflict-resolution.ts +0 -9
  177. package/src/prover/smt/solver/context.ts +4 -61
  178. package/src/prover/smt/solver/ctx-simplify.ts +14 -41
  179. package/src/prover/smt/solver/der.ts +2 -21
  180. package/src/prover/smt/solver/dyn-ack.ts +1 -11
  181. package/src/prover/smt/solver/e-matching.ts +3 -34
  182. package/src/prover/smt/solver/enode.ts +1 -21
  183. package/src/prover/smt/solver/expr-ref.ts +1 -5
  184. package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
  185. package/src/prover/smt/solver/fingerprints.ts +1 -12
  186. package/src/prover/smt/solver/flat-literals.ts +1 -9
  187. package/src/prover/smt/solver/goal.ts +2 -14
  188. package/src/prover/smt/solver/hash.ts +0 -8
  189. package/src/prover/smt/solver/hashtable.ts +1 -12
  190. package/src/prover/smt/solver/internalizer.ts +6 -98
  191. package/src/prover/smt/solver/lbool.ts +1 -2
  192. package/src/prover/smt/solver/literal.ts +0 -3
  193. package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
  194. package/src/prover/smt/solver/lp/constraints.ts +2 -8
  195. package/src/prover/smt/solver/lp/containers.ts +12 -30
  196. package/src/prover/smt/solver/lp/core-solver.ts +10 -31
  197. package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
  198. package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
  199. package/src/prover/smt/solver/lp/dependency.ts +1 -4
  200. package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
  201. package/src/prover/smt/solver/lp/explanation.ts +1 -6
  202. package/src/prover/smt/solver/lp/gomory.ts +9 -22
  203. package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
  204. package/src/prover/smt/solver/lp/hnf.ts +11 -26
  205. package/src/prover/smt/solver/lp/int-cube.ts +15 -36
  206. package/src/prover/smt/solver/lp/int-solver.ts +4 -34
  207. package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
  208. package/src/prover/smt/solver/lp/lar-term.ts +1 -5
  209. package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
  210. package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
  211. package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
  212. package/src/prover/smt/solver/lp/nex.ts +1 -6
  213. package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
  214. package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
  215. package/src/prover/smt/solver/lp/nla-core.ts +35 -130
  216. package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
  217. package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
  218. package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
  219. package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
  220. package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
  221. package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
  222. package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
  223. package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
  224. package/src/prover/smt/solver/lp/nla-order.ts +2 -13
  225. package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
  226. package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
  227. package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
  228. package/src/prover/smt/solver/lp/nla-types.ts +1 -11
  229. package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
  230. package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
  231. package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
  232. package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
  233. package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
  234. package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
  235. package/src/prover/smt/solver/lp/pdd.ts +7 -70
  236. package/src/prover/smt/solver/lp/random-updater.ts +1 -8
  237. package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
  238. package/src/prover/smt/solver/lp/union-find.ts +1 -6
  239. package/src/prover/smt/solver/mam-compiler.ts +14 -56
  240. package/src/prover/smt/solver/mam-interpreter.ts +1 -21
  241. package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
  242. package/src/prover/smt/solver/model-checker.ts +2 -36
  243. package/src/prover/smt/solver/model-evaluator.ts +3 -29
  244. package/src/prover/smt/solver/model-finder.ts +3 -15
  245. package/src/prover/smt/solver/model-generator.ts +1 -12
  246. package/src/prover/smt/solver/model-macro-solver.ts +12 -69
  247. package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
  248. package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
  249. package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
  250. package/src/prover/smt/solver/nlsat/explain.ts +3 -47
  251. package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
  252. package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
  253. package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
  254. package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
  255. package/src/prover/smt/solver/nlsat/solver.ts +7 -67
  256. package/src/prover/smt/solver/nlsat/types.ts +1 -8
  257. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
  258. package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
  259. package/src/prover/smt/solver/nnf.ts +3 -38
  260. package/src/prover/smt/solver/pattern-inference.ts +2 -15
  261. package/src/prover/smt/solver/poly-rewriter.ts +3 -23
  262. package/src/prover/smt/solver/propagate-values.ts +1 -10
  263. package/src/prover/smt/solver/proto-model.ts +3 -48
  264. package/src/prover/smt/solver/pull-quant.ts +1 -12
  265. package/src/prover/smt/solver/qe-lite-der.ts +1 -29
  266. package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
  267. package/src/prover/smt/solver/qe-lite.ts +3 -33
  268. package/src/prover/smt/solver/qi-queue.ts +1 -16
  269. package/src/prover/smt/solver/quant-tactics.ts +5 -22
  270. package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
  271. package/src/prover/smt/solver/quantifier-manager.ts +1 -8
  272. package/src/prover/smt/solver/random-gen.ts +1 -2
  273. package/src/prover/smt/solver/rational.ts +1 -8
  274. package/src/prover/smt/solver/ref-vector.ts +1 -6
  275. package/src/prover/smt/solver/relevancy.ts +2 -15
  276. package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
  277. package/src/prover/smt/solver/rewriter.ts +3 -85
  278. package/src/prover/smt/solver/rlimit.ts +2 -20
  279. package/src/prover/smt/solver/smtlib-parser.ts +2 -37
  280. package/src/prover/smt/solver/solver.ts +23 -34
  281. package/src/prover/smt/solver/sort.ts +1 -5
  282. package/src/prover/smt/solver/sticky-generations.ts +0 -5
  283. package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
  284. package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
  285. package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
  286. package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
  287. package/src/prover/smt/solver/theory-lra-model.ts +4 -19
  288. package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
  289. package/src/prover/smt/solver/theory-lra-state.ts +3 -8
  290. package/src/prover/smt/solver/theory-lra.ts +1 -8
  291. package/src/prover/smt/solver/var-subst.ts +2 -26
  292. package/src/prover/smt/table.ts +0 -8
  293. package/src/prover/tlapm/cache.ts +20 -25
  294. package/src/prover/tlapm/ocaml-marshal.ts +19 -21
  295. package/src/prover/tlapm/tlapm.ts +12 -17
  296. package/src/prover/verdict.ts +0 -2
  297. package/src/prover/zenon/check/check.ts +0 -9
  298. package/src/prover/zenon/check/definitions.ts +5 -15
  299. package/src/prover/zenon/check/equality.ts +0 -8
  300. package/src/prover/zenon/check/functions.ts +0 -4
  301. package/src/prover/zenon/check/keys.ts +0 -7
  302. package/src/prover/zenon/check/propositional.ts +0 -3
  303. package/src/prover/zenon/check/records.ts +0 -5
  304. package/src/prover/zenon/check/relations.ts +0 -13
  305. package/src/prover/zenon/check/rewrites.ts +0 -6
  306. package/src/prover/zenon/check/sets.ts +0 -3
  307. package/src/prover/zenon/check/terms.ts +0 -17
  308. package/src/prover/zenon/check/tla.ts +0 -6
  309. package/src/prover/zenon/decide.ts +0 -12
  310. package/src/prover/zenon/encode.ts +1 -8
  311. package/src/prover/zenon/eqrel.ts +0 -13
  312. package/src/prover/zenon/equality-rules.ts +0 -4
  313. package/src/prover/zenon/expr.ts +1 -26
  314. package/src/prover/zenon/index-table.ts +17 -38
  315. package/src/prover/zenon/isar-case.ts +9 -19
  316. package/src/prover/zenon/isar.ts +1 -29
  317. package/src/prover/zenon/limits.ts +0 -4
  318. package/src/prover/zenon/llproof.ts +0 -9
  319. package/src/prover/zenon/mltoll.ts +54 -76
  320. package/src/prover/zenon/node.ts +1 -11
  321. package/src/prover/zenon/ocaml.ts +1 -17
  322. package/src/prover/zenon/parse.ts +2 -7
  323. package/src/prover/zenon/phrase.ts +1 -11
  324. package/src/prover/zenon/proof.ts +0 -9
  325. package/src/prover/zenon/propositional-rules.ts +0 -5
  326. package/src/prover/zenon/rules.ts +2 -6
  327. package/src/prover/zenon/search.ts +1 -17
  328. package/src/prover/zenon/tla/functions.ts +57 -29
  329. package/src/prover/zenon/tla/llproof.ts +63 -70
  330. package/src/prover/zenon/tla/records.ts +56 -27
  331. package/src/prover/zenon/tla/rewrites.ts +12 -19
  332. package/src/prover/zenon/tla/sets.ts +68 -39
  333. package/src/prover/zenon/tla/terms.ts +0 -6
  334. package/src/prover/zenon/tla/tla.ts +59 -58
  335. package/src/randomization.ts +81 -35
  336. package/src/resolve.ts +12 -112
  337. package/src/runtime.ts +22 -22
  338. package/src/sany/builtins.ts +2 -5
  339. package/src/sany/generator.ts +149 -252
  340. package/src/sany/levels.ts +6 -34
  341. package/src/sany/lexer.ts +41 -61
  342. package/src/sany/linter.ts +1 -9
  343. package/src/sany/modules.ts +1 -5
  344. package/src/sany/nodes.ts +0 -31
  345. package/src/sany/parse-error.ts +39 -117
  346. package/src/sany/report.ts +29 -63
  347. package/src/sany/selectors.ts +15 -39
  348. package/src/sany/source.ts +1 -17
  349. package/src/sany/xml.ts +13 -63
  350. package/src/search.ts +495 -155
  351. package/src/simulate.ts +685 -0
  352. package/src/spec-description.ts +176 -69
  353. package/src/standard-definitions.ts +0 -4
  354. package/src/standard-modules.ts +254 -69
  355. package/src/state-graph.ts +50 -24
  356. package/src/subexpressions.ts +69 -52
  357. package/src/substitution-levels.ts +2 -3
  358. package/src/successors.ts +263 -94
  359. package/src/symmetry.ts +33 -25
  360. package/src/tableau.ts +27 -24
  361. package/src/tlc/fingerprint.ts +183 -67
  362. package/src/tlc/jar-data.ts +112 -6
  363. package/src/tlc/messages.ts +110 -44
  364. package/src/tlc/order.ts +37 -60
  365. package/src/tlc/random.ts +33 -45
  366. package/src/tlc/replay.ts +549 -217
  367. package/src/tlc/summary.ts +36 -47
  368. package/src/tlc/tlc-operators.ts +76 -41
  369. package/src/tlc/tlcext-operators.ts +139 -122
  370. package/src/tlc/trace-spec.ts +269 -0
  371. package/src/tlc/value-stream.ts +139 -0
  372. package/src/tlc/version.ts +1 -4
  373. package/src/transfer.ts +22 -25
  374. package/src/typescript/actions.ts +481 -0
  375. package/src/typescript/collections.ts +600 -0
  376. package/src/typescript/compile.ts +65 -0
  377. package/src/typescript/context.ts +94 -0
  378. package/src/typescript/emit.ts +121 -0
  379. package/src/typescript/expressions.ts +496 -0
  380. package/src/typescript/formula.ts +152 -0
  381. package/src/typescript/functions.ts +284 -0
  382. package/src/typescript/model.ts +163 -0
  383. package/src/typescript/names.ts +114 -0
  384. package/src/typescript/program.ts +48 -0
  385. package/src/typescript/properties.ts +139 -0
  386. package/src/typescript/scope.ts +112 -0
  387. package/src/typescript/steps.ts +165 -0
  388. package/src/typescript/types.ts +171 -0
  389. package/src/values.ts +780 -337
  390. package/src/worker.ts +7 -8
@@ -1,5 +1,4 @@
1
1
  // Ported from Z3 (src/ast/ast.h, src/ast/ast.cpp), MIT license, see z3-license.txt.
2
- // A hash-consed DAG of applications, de Bruijn variables and quantifiers, as in Z3's ast_manager.
3
2
  import { SmtInvariantError } from "../../../errors";
4
3
  import { FlatLiterals } from "./flat-literals";
5
4
  import { astArrayHash, bytesHash, combineHash, getCompositeHash, mkMix, stringHash } from "./hash";
@@ -19,7 +18,6 @@ export const SORT_REAL = 2;
19
18
  export const FAMILY_BASIC = 0;
20
19
  export const FAMILY_ARITH = 1;
21
20
  export const FAMILY_USER = 2;
22
- // Model values: the elements that a model gives to an uninterpreted sort.
23
21
  export const FAMILY_MODEL_VALUE = 3;
24
22
 
25
23
  export const OP_TRUE = 0;
@@ -49,15 +47,12 @@ export const OP_DIV = 23;
49
47
  export const OP_TO_REAL = 24;
50
48
  export const OP_TO_INT = 25;
51
49
  export const OP_IS_INT = 26;
52
- // Z3's div0, idiv0 and mod0: division by zero, which theory_lra's found_underspecified equates with
53
- // the division it stands for.
54
50
  export const OP_DIV0 = 27;
55
51
  export const OP_IDIV0 = 28;
56
52
  export const OP_MOD0 = 29;
57
53
  export const OP_UNINTERPRETED = 30;
58
54
  const OP_MODEL_VALUE = 31;
59
55
 
60
- // A Z3 symbol: a string, or a number for a numerical symbol, which Z3 prints as k!n.
61
56
  export type SmtSymbol = string | number;
62
57
 
63
58
  const getSymbolName = (symbol: SmtSymbol) => (typeof symbol === "number" ? `k!${symbol}` : symbol);
@@ -69,17 +64,14 @@ export interface FuncDecl {
69
64
  domain: number[];
70
65
  range: number;
71
66
  isSkolem: boolean;
72
- // Z3's small id of the declaration, which its matcher hashes.
73
67
  smallId: number;
74
68
  }
75
69
 
76
70
  interface QuantifierData {
77
71
  isForall: boolean;
78
72
  sorts: number[];
79
- // The names of the variables, which tell apart quantifiers that differ only in them, as in Z3.
80
73
  names: SmtSymbol[];
81
74
  body: number;
82
- // Applications of the pattern declaration to the terms of each multi-pattern.
83
75
  patterns: number[];
84
76
  weight: number;
85
77
  qid: string;
@@ -118,7 +110,6 @@ const BUILTIN_DECLS: [string, number, number, number][] = [
118
110
  ["mod0", FAMILY_ARITH, OP_MOD0, SORT_INT],
119
111
  ];
120
112
 
121
- // Z3's family ids and decl kinds, which its AST hashes include.
122
113
  const Z3_BASIC_FAMILY = 0;
123
114
  const Z3_PATTERN_FAMILY = 2;
124
115
  const Z3_MODEL_VALUE_FAMILY = 3;
@@ -126,8 +117,6 @@ const Z3_USER_SORT_FAMILY = 4;
126
117
  const Z3_ARITH_FAMILY = 5;
127
118
  const Z3_RECFUN_FAMILY = 10;
128
119
  const Z3_NULL = 0xffffffff;
129
- // The name, Z3 decl kind and arity of each builtin, whose Z3 declaration has this many arguments
130
- // whatever the number of arguments of the application (-1 for the arguments' own number).
131
120
  const Z3_BUILTINS = new Map<number, [string, number, number]>([
132
121
  [OP_TRUE, ["true", 0, 0]],
133
122
  [OP_FALSE, ["false", 1, 0]],
@@ -160,11 +149,6 @@ const Z3_BUILTINS = new Map<number, [string, number, number]>([
160
149
  [OP_MOD0, ["mod0", 17, 2]],
161
150
  ]);
162
151
 
163
- // The small ids of the Int declarations Z3 makes when it starts, from arith_decl_plugin::set_manager,
164
- // which Real terms share. The declarations of Real terms only have the ids of Real's /, Int's
165
- // to_real, Real's to_int and is_int. Z3 makes =, ite, distinct, pattern, numeral, /0, div0 and mod0
166
- // declarations per signature on first use, so they get -1 here, and their small ids are kept by
167
- // signature.
168
152
  const Z3_SMALL_IDS = new Map([
169
153
  [OP_TRUE, 1],
170
154
  [OP_FALSE, 2],
@@ -190,26 +174,17 @@ const Z3_SMALL_IDS = new Map([
190
174
  [OP_IS_INT, 47],
191
175
  ]);
192
176
 
193
- // The small id of the first sort or declaration a problem declares, after Z3's own.
194
177
  const FIRST_DECLARED_SMALL_ID = 143;
195
178
 
196
- // The ids of Z3's own expressions when it starts: the undef proof, true and false, then pi, euler, a
197
- // bit-vector numeral, fifteen real variables and a sum of two of them, which no problem shares.
198
179
  const FIRST_FREE_ID = 22;
199
- // MAX_SMALL_NUM_TO_CACHE: arith_decl_plugin holds the numerals below it once it makes them.
200
180
  const MAX_SMALL_NUM_TO_CACHE = 16;
201
- // The sorts that finite_set_decl_plugin::init makes.
202
181
  const NUM_FINITE_SET_PLUGIN_SORTS = 7;
203
182
 
204
- // symbol::hash: a numerical symbol hashes to its number.
205
183
  const getSymbolHash = (symbol: SmtSymbol) =>
206
184
  typeof symbol === "number" ? symbol : stringHash(symbol, 17);
207
185
 
208
- // Whether a sort is Int or Real.
209
186
  export const isArithSort = (sort: number) => sort === SORT_INT || sort === SORT_REAL;
210
187
 
211
- // mpz_manager::hash: the absolute value of an integer below 2^32, else the hash of its 32-bit digits,
212
- // least significant first.
213
188
  const getIntegerHash = (value: bigint) => {
214
189
  const magnitude = value < 0n ? -value : value;
215
190
  if (magnitude <= 0xffffffffn) return Number(magnitude);
@@ -218,51 +193,35 @@ const getIntegerHash = (value: bigint) => {
218
193
  return bytesHash(new Uint8Array(Uint32Array.from(digits).buffer), 17);
219
194
  };
220
195
 
221
- // decl_info::hash.
222
196
  const getInfoHash = (family: number, kind: number, parameterHashes: number[]) =>
223
197
  mkMix(family, kind, parameterHashes.length === 0 ? 0 : getCompositeHash(parameterHashes));
224
198
 
225
- // The kinds of an integer signature, in its low three bits.
226
199
  const SIGNATURE_EQ = 0;
227
200
  const SIGNATURE_ITE = 1;
228
201
  const SIGNATURE_DIV0 = 2;
229
202
  const SIGNATURE_MODEL_VALUE = 3;
230
203
  const SIGNATURE_NUMERAL = 4;
231
204
 
232
- // A builtin declaration that Z3 makes once per signature: its small id, and the references that
233
- // applications and model values hold to it.
234
205
  interface SignatureDecl {
235
206
  smallId: number;
236
207
  refCount: number;
237
208
  }
238
209
 
239
210
  export class AstManager {
240
- // The tables of the expressions are typed arrays indexed by expression, which the collector does
241
- // not scan. They have room for more expressions than numNodes and double when full, which
242
- // replaces them, so a caller does not keep one across the creation of an expression.
243
211
  private numNodes = 0;
244
212
  kinds = new Uint8Array(1024);
245
- // The declaration of an application.
246
213
  decls = new Int32Array(1024);
247
- // The arguments of every expression end to end: those of expr are argPool[argStarts[expr]] up to
248
- // argPool[argStarts[expr + 1]]. Variables and constants take an empty range and a quantifier
249
- // takes its body. Both grow by doubling, which replaces the arrays.
250
214
  private argPool = new Int32Array(1024);
251
215
  private argStarts = new Int32Array(1024);
252
216
  sorts = new Int32Array(1024);
253
- // The index of a variable or model value, or of a numeral's value in numeralValues.
254
217
  values = new Int32Array(1024);
255
218
  private numeralValues: Rational[] = [];
256
- // The integer numerals by value, which finds one without building its key in the table.
257
219
  private intNumerals = new Map<bigint, number>();
258
- // One more than the largest free de Bruijn index, so 0 means the expression is ground.
259
220
  freeVarBounds = new Int32Array(1024);
260
221
  hasQuantifierFlags = new Uint8Array(1024);
261
222
  depths = new Int32Array(1024);
262
- // Z3's hash of each expression, which orders Z3's hash tables.
263
223
  hashes = new Uint32Array(1024);
264
224
  quantifiers = new Map<number, QuantifierData>();
265
- // The marks that the rewriters of this manager share to flatten conjunctions and disjunctions.
266
225
  readonly flatLiterals = new FlatLiterals(this);
267
226
  funcDecls: FuncDecl[] = [];
268
227
  sortNames: string[] = ["Bool", "Int", "Real"];
@@ -271,57 +230,31 @@ export class AstManager {
271
230
  combineHash(getSymbolHash("Int"), getInfoHash(Z3_ARITH_FAMILY, 1, [])),
272
231
  combineHash(getSymbolHash("Real"), getInfoHash(Z3_ARITH_FAMILY, 0, [])),
273
232
  ];
274
- // The hash of each uninterpreted declaration, and of each builtin by its Z3 declaration.
275
233
  private declHashes: number[] = [];
276
- // The hash of each builtin declaration other than pattern by op, argument sort, range and number
277
- // of arguments: open addressing with linear probing, with the four keys of slot i at 4 i in
278
- // builtinKeys and -1 for an empty slot.
279
234
  private builtinKeys = new Int32Array(4 * 256).fill(-1);
280
235
  private builtinHashes = new Uint32Array(256);
281
236
  private numBuiltinHashes = 0;
282
- // The hash of each pattern declaration by its domain and range.
283
237
  private patternHashes = new Map<string, number>();
284
238
  private table = new Map<string, number>();
285
- // The hash-consing table of applications: open addressing with linear probing over the handles,
286
- // -1 for an empty slot, which takes a few bytes per application where a map of buckets takes
287
- // dozens. Applications stay in it when they are deleted, so a lookup can create them again.
288
239
  private appHandles = new Int32Array(1024).fill(-1);
289
240
  private appHashes = new Int32Array(1024);
290
241
  private numApps = 0;
291
- // id_gen for sorts and declarations: the small id of the next one, and the ids of deleted ones,
292
- // which Z3 reuses the last freed first. Z3 keeps the declarations of = and ite, and deletes the
293
- // others with their last reference.
294
242
  private nextSmallId = FIRST_DECLARED_SMALL_ID;
295
243
  private freeSmallIds: number[] = [];
296
244
  private numDecls = FIRST_DECLARED_SMALL_ID;
297
- // The small id and the number of live applications of each builtin declaration that Z3 makes
298
- // per signature, by its signature.
299
245
  private signatureDecls = new Map<number | string, SignatureDecl>();
300
- // The references to each user declaration: the script holds the declared ones, and applications
301
- // and models hold the fresh ones. A deleted declaration keeps its small id here, in case an
302
- // application of it is created again.
303
246
  private declRefCounts: number[] = [];
304
- // The named expressions of the recfun plugin, by declaration.
305
247
  readonly macros = new ObjMap<number>((decl) => this.declHashes[decl]);
306
248
  private deletedDecls = new Set<number>();
307
- // ast_manager::m_fresh_id, which numbers fresh declarations and variable names.
308
249
  private freshId = 0;
309
- // Z3's id of each expression, which orders Z3's sorts. Like Z3, the manager counts references and
310
- // gives the id of a deleted expression to the next expression it creates, so its ids follow
311
- // Z3's. A deleted expression stays in the tables with the id -1 until it is created again.
312
250
  ids = new Int32Array(1024);
313
251
  private refCounts = new Int32Array(1024);
314
252
  private freeIds: number[] = [];
315
253
  private nextId = 1;
316
254
  private numLive = 0;
317
- // The expressions that the open withTemporaries hold, like the expr_ref temporaries of Z3
318
- // functions on the C++ stack: the innermost holds those from temporariesMark on, and -1 marks that
319
- // no temporaries are held.
320
255
  private temporaries: number[] = [];
321
256
  private temporariesMark = -1;
322
- // The arguments mkApp copies out of a caller's array that starts past index 0.
323
257
  private argBuffer: number[] = [];
324
- // m_small_ints and m_small_reals: the numerals below MAX_SMALL_NUM_TO_CACHE, which are held.
325
258
  private smallInts: number[] = [];
326
259
  private smallReals: number[] = [];
327
260
  private isFiniteSetPluginInitialized = false;
@@ -350,12 +283,10 @@ export class AstManager {
350
283
  return this.refCounts[expr];
351
284
  }
352
285
 
353
- // get_num_asts: the live expressions, declarations and sorts, with Z3's own expressions.
354
286
  getNumAsts() {
355
287
  return this.numLive + FIRST_FREE_ID - 2 + this.numDecls;
356
288
  }
357
289
 
358
- // The declaration that a held signature names.
359
290
  private getSignatureDecl(key: number | string) {
360
291
  const signatureDecl = this.signatureDecls.get(key);
361
292
  if (signatureDecl === undefined)
@@ -368,9 +299,6 @@ export class AstManager {
368
299
  return this.freeSmallIds.pop() ?? this.nextSmallId++;
369
300
  }
370
301
 
371
- // finite_set_decl_plugin::init, which the first final check of theory_finite_set runs when it
372
- // makes a set.range declaration: the plugin makes the sorts A and B, three FiniteSet sorts and two
373
- // Array sorts, which the manager keeps. The set.range declaration is released at once.
374
302
  initFiniteSetPlugin() {
375
303
  if (this.isFiniteSetPluginInitialized) return;
376
304
  this.isFiniteSetPluginInitialized = true;
@@ -379,9 +307,6 @@ export class AstManager {
379
307
  this.numDecls--;
380
308
  }
381
309
 
382
- // insert_macro: cmd_context keeps a named expression as a recursive function with one case, whose
383
- // declaration and case predicate it holds. The recfun plugin maps the declaration to the
384
- // expression, which a model of the context takes as the declaration's interpretation.
385
310
  mkMacro(name: string, expr: number) {
386
311
  const decl = this.funcDecls.length;
387
312
  this.declHashes[decl] = this.getFuncDeclHash(
@@ -404,10 +329,6 @@ export class AstManager {
404
329
  this.macros.set(decl, expr);
405
330
  }
406
331
 
407
- // The signature of a builtin declaration that Z3 makes on first use, or null for a declaration
408
- // that is not one. The low three bits of an integer signature tell its kind: an equality or ite
409
- // by sort, a division by zero or model value by declaration, or a numeral by its value, which a
410
- // numeral expression has alone. A distinct or pattern is keyed by its domain.
411
332
  private getSignature(expr: number) {
412
333
  const decl = this.decls[expr];
413
334
  if (decl === OP_NUM) return 8 * this.values[expr] + SIGNATURE_NUMERAL;
@@ -420,7 +341,6 @@ export class AstManager {
420
341
  return null;
421
342
  }
422
343
 
423
- // The id that Z3 gives the declaration of an application.
424
344
  getDeclId(expr: number) {
425
345
  const signature = this.getSignature(expr);
426
346
  return signature === null
@@ -428,7 +348,6 @@ export class AstManager {
428
348
  : this.getSignatureDecl(signature).smallId;
429
349
  }
430
350
 
431
- // An application holds its declaration, which Z3 makes with its first application.
432
351
  private holdDecl(expr: number) {
433
352
  const decl = this.decls[expr];
434
353
  if (this.funcDecls[decl].family === FAMILY_USER) {
@@ -443,14 +362,11 @@ export class AstManager {
443
362
  return;
444
363
  }
445
364
  const smallId = this.mkSmallId();
446
- // Z3 keeps the equality and ite declarations once it makes them.
447
365
  this.signatureDecls.set(key, { smallId, refCount: decl === OP_EQ || decl === OP_ITE ? 2 : 1 });
448
366
  if (decl !== OP_NUM && this.funcDecls[decl].family === FAMILY_MODEL_VALUE)
449
367
  this.funcDecls[decl].smallId = smallId;
450
368
  }
451
369
 
452
- // The small id of the declaration a deleted application releases for good, or -1 when the
453
- // declaration stays.
454
370
  private releaseDecl(expr: number) {
455
371
  const decl = this.decls[expr];
456
372
  if (this.funcDecls[decl].family === FAMILY_USER) {
@@ -472,7 +388,6 @@ export class AstManager {
472
388
  this.refCounts[expr]++;
473
389
  }
474
390
 
475
- // A model value's declaration is counted under its signature, like the applications that hold it.
476
391
  incDeclRef(decl: number) {
477
392
  if (this.funcDecls[decl].family === FAMILY_MODEL_VALUE) {
478
393
  const key = 8 * decl + SIGNATURE_MODEL_VALUE;
@@ -508,9 +423,6 @@ export class AstManager {
508
423
  this.numDecls--;
509
424
  }
510
425
 
511
- // Runs body, holding each expression it creates until it returns, then releases them, the last
512
- // created first. The caller gets a reference to each expression that getKept picks from the
513
- // result, by default the result itself, and releases it.
514
426
  withTemporaries<T>(
515
427
  body: () => T,
516
428
  getKept: (result: T) => number[] = (result) => [result as number],
@@ -522,8 +434,6 @@ export class AstManager {
522
434
  return result;
523
435
  }
524
436
 
525
- // withTemporaries without closures, for the hot paths: the caller passes what beginTemporaries
526
- // returns to endTemporaries, and takes its references before it.
527
437
  beginTemporaries() {
528
438
  const outer = this.temporariesMark;
529
439
  this.temporariesMark = this.temporaries.length;
@@ -539,7 +449,6 @@ export class AstManager {
539
449
  shrink(temporaries, mark);
540
450
  }
541
451
 
542
- // Runs body without temporaries, for code whose references are counted explicitly.
543
452
  withoutTemporaries<T>(body: () => T) {
544
453
  const outer = this.temporariesMark;
545
454
  this.temporariesMark = -1;
@@ -548,15 +457,11 @@ export class AstManager {
548
457
  return result;
549
458
  }
550
459
 
551
- // Hands a reference the caller owns to the innermost withTemporaries, or releases it now.
552
460
  releaseLater(expr: number) {
553
461
  if (this.temporariesMark === -1) this.decRef(expr);
554
462
  else this.temporaries.push(expr);
555
463
  }
556
464
 
557
- // dec_ref and delete_node: an expression without references is deleted, and so are its children
558
- // and declaration that lose their last reference, in the order of Z3's worklist. A released
559
- // declaration's small id goes on the worklist as -1 - id.
560
465
  decRef(expr: number) {
561
466
  if (this.ids[expr] === -1) return;
562
467
  this.refCounts[expr]--;
@@ -573,8 +478,6 @@ export class AstManager {
573
478
  const smallId = this.releaseDecl(node);
574
479
  if (smallId !== -1) worklist.push(-1 - smallId);
575
480
  }
576
- // The children: the arguments of an application, and the body and then the patterns of a
577
- // quantifier.
578
481
  if (this.kinds[node] !== KIND_QUANTIFIER) {
579
482
  const end = this.argStarts[node + 1];
580
483
  for (let index = this.argStarts[node]; index < end; index++)
@@ -598,13 +501,10 @@ export class AstManager {
598
501
  this.ids[expr] = -1;
599
502
  }
600
503
 
601
- // register_node_core: a new expression takes an id and a reference to each child.
602
504
  private registerNode(expr: number) {
603
505
  this.ids[expr] = this.freeIds.pop() ?? this.nextId++;
604
506
  this.numLive++;
605
507
  this.refCounts[expr] = 0;
606
- // The children: the arguments of an application, and the body and then the patterns of a
607
- // quantifier.
608
508
  if (this.kinds[expr] !== KIND_QUANTIFIER) {
609
509
  const end = this.argStarts[expr + 1];
610
510
  for (let index = this.argStarts[expr]; index < end; index++)
@@ -620,7 +520,6 @@ export class AstManager {
620
520
  this.temporaries.push(expr);
621
521
  }
622
522
 
623
- // The arguments of an application, and the body of a quantifier as its one argument.
624
523
  getNumArgs(expr: number) {
625
524
  return this.argStarts[expr + 1] - this.argStarts[expr];
626
525
  }
@@ -629,20 +528,17 @@ export class AstManager {
629
528
  return this.argPool[this.argStarts[expr] + index];
630
529
  }
631
530
 
632
- // Appends the arguments to target, for a caller that needs them as an array.
633
531
  pushArgs(expr: number, target: number[]) {
634
532
  const end = this.argStarts[expr + 1];
635
533
  for (let index = this.argStarts[expr]; index < end; index++) target.push(this.argPool[index]);
636
534
  }
637
535
 
638
- // A new array of the arguments.
639
536
  getArgs(expr: number) {
640
537
  const args: number[] = [];
641
538
  this.pushArgs(expr, args);
642
539
  return args;
643
540
  }
644
541
 
645
- // The callbacks may create expressions, which can replace argPool, so each argument is read anew.
646
542
  mapArgs<T>(expr: number, map: (arg: number, index: number) => T) {
647
543
  const result: T[] = [];
648
544
  for (let index = 0; index < this.getNumArgs(expr); index++)
@@ -662,7 +558,6 @@ export class AstManager {
662
558
  return true;
663
559
  }
664
560
 
665
- // A lookup that finds a deleted expression creates it again.
666
561
  private revive(expr: number) {
667
562
  if (this.ids[expr] === -1) this.registerNode(expr);
668
563
  return expr;
@@ -680,7 +575,6 @@ export class AstManager {
680
575
  return this.sortNames.length - 1;
681
576
  }
682
577
 
683
- // The hash of a func_decl node: its name, range, info and domain.
684
578
  private getFuncDeclHash(name: SmtSymbol, domain: number[], range: number, infoHash: number) {
685
579
  return astArrayHash(
686
580
  domain,
@@ -689,7 +583,6 @@ export class AstManager {
689
583
  );
690
584
  }
691
585
 
692
- // The name, Z3 decl kind and domain of the Z3 declaration of a builtin application.
693
586
  getBuiltinSignature(op: number, args: number[]) {
694
587
  const builtin = Z3_BUILTINS.get(op);
695
588
  if (builtin === undefined)
@@ -706,7 +599,6 @@ export class AstManager {
706
599
  return { name: builtin[0], kind: builtin[1], domain };
707
600
  }
708
601
 
709
- // The hash of a pattern's Z3 declaration.
710
602
  private getPatternHash(args: number[], range: number) {
711
603
  const key = `${args.map((arg) => this.sorts[arg]).join(",")}:${range}`;
712
604
  const existing = this.patternHashes.get(key);
@@ -716,9 +608,7 @@ export class AstManager {
716
608
  return hash;
717
609
  }
718
610
 
719
- // The slot in builtinHashes of the hash of a builtin's Z3 declaration, other than a pattern's. The
720
- // domain depends only on the sort of an argument and the number of arguments, which key the cache
721
- // with the op and range. It returns the slot, a small integer, because V8 boxes a hash it returns.
611
+ // Returns the slot, a small integer, because V8 boxes a hash it returns.
722
612
  private getBuiltinSlot(op: number, args: number[], range: number) {
723
613
  const argSort = args.length === 0 ? 0 : this.sorts[op === OP_ITE ? args[1] : args[0]];
724
614
  const count = args.length;
@@ -744,7 +634,6 @@ export class AstManager {
744
634
  return this.insertBuiltinHash(op, argSort, range, count, hash);
745
635
  }
746
636
 
747
- // The slot of the builtin hash with these keys, or the free slot where it goes.
748
637
  private findBuiltinSlot(op: number, argSort: number, range: number, count: number) {
749
638
  const keys = this.builtinKeys;
750
639
  const mask = this.builtinHashes.length - 1;
@@ -789,7 +678,6 @@ export class AstManager {
789
678
  );
790
679
  }
791
680
 
792
- // The hash of a user declaration, which Z3's tables of declarations hash.
793
681
  getDeclHash(decl: number) {
794
682
  return this.declHashes[decl];
795
683
  }
@@ -814,7 +702,6 @@ export class AstManager {
814
702
  return this.funcDecls.length - 1;
815
703
  }
816
704
 
817
- // mk_fresh_func_decl: without a prefix the name is the numerical symbol of the fresh id.
818
705
  mkFreshFuncDecl(prefix: SmtSymbol | null, domain: number[], range: number, isSkolem = true) {
819
706
  const name = prefix === null ? this.freshId : `${getSymbolName(prefix)}!${this.freshId}`;
820
707
  this.freshId++;
@@ -823,7 +710,6 @@ export class AstManager {
823
710
  return decl;
824
711
  }
825
712
 
826
- // mk_fresh_var_name.
827
713
  mkFreshVarName(prefix: string | null) {
828
714
  const name = `${prefix ?? "var"}!${this.freshId}`;
829
715
  this.freshId++;
@@ -871,7 +757,6 @@ export class AstManager {
871
757
  this.hashes[id] = hash;
872
758
  this.kinds[id] = kind;
873
759
  this.decls[id] = decl;
874
- // Like Z3, a node keeps its own copy of the arguments, so callers may reuse their arrays.
875
760
  const start = this.argStarts[id];
876
761
  const end = start + args.length;
877
762
  if (end > this.argPool.length) {
@@ -903,11 +788,8 @@ export class AstManager {
903
788
  return id;
904
789
  }
905
790
 
906
- // The op of a builtin declaration doubles as its index in funcDecls. The arguments are those of
907
- // args from start on, so that a rewriter passes its result stack without copying it.
908
791
  mkApp(decl: number, args: number[], sort: number, start = 0) {
909
792
  const funcDecl = this.funcDecls[decl];
910
- // Numerals and model values carry their value, so only mkNumeral and mkModelValue create them.
911
793
  if (decl === OP_NUM || funcDecl.family === FAMILY_MODEL_VALUE)
912
794
  throw new SmtInvariantError(`${funcDecl.name} needs a value`);
913
795
  let hash = decl;
@@ -931,7 +813,6 @@ export class AstManager {
931
813
  for (let index = start; index < args.length; index++) this.argBuffer.push(args[index]);
932
814
  }
933
815
  const nodeArgs = start > 0 ? this.argBuffer : args;
934
- // The slot comes first, since finding it may replace builtinHashes with one twice the size.
935
816
  const builtinSlot =
936
817
  funcDecl.family === FAMILY_USER || funcDecl.op === OP_PATTERN
937
818
  ? -1
@@ -950,7 +831,6 @@ export class AstManager {
950
831
  0,
951
832
  astArrayHash(nodeArgs, this.hashes, declHash),
952
833
  );
953
- // The lookup ended at a free slot, which the application takes unless the table doubles.
954
834
  if (2 * (this.numApps + 1) > this.appHandles.length) {
955
835
  const handles = this.appHandles;
956
836
  const hashes = this.appHashes;
@@ -978,8 +858,6 @@ export class AstManager {
978
858
  this.numApps++;
979
859
  }
980
860
 
981
- // A numeral's declaration has the parameters (value, is_int), and a rational hashes as
982
- // hash(numerator) + 3 hash(denominator).
983
861
  private internNumeral(key: string, value: Rational, sort: number) {
984
862
  const existing = this.table.get(key);
985
863
  if (existing !== undefined) return this.revive(existing);
@@ -1021,12 +899,10 @@ export class AstManager {
1021
899
  return numeral;
1022
900
  }
1023
901
 
1024
- // mk_numeral(value, is_int).
1025
902
  mkNumeralOfSort(value: Rational, sort: number) {
1026
903
  return sort === SORT_INT ? this.mkNumeral(value.num) : this.mkRealNumeral(value);
1027
904
  }
1028
905
 
1029
- // mk_model_value: the element with this index in the universe of an uninterpreted sort.
1030
906
  mkModelValue(index: number, sort: number) {
1031
907
  const key = `m${sort}:${index}`;
1032
908
  const existing = this.table.get(key);
@@ -1093,7 +969,6 @@ export class AstManager {
1093
969
  return id;
1094
970
  }
1095
971
 
1096
- // mk_pattern: a multi-pattern of a quantifier.
1097
972
  mkPattern(terms: number[]) {
1098
973
  return this.mkApp(OP_PATTERN, terms, SORT_BOOL);
1099
974
  }
@@ -1104,10 +979,6 @@ export class AstManager {
1104
979
  return data;
1105
980
  }
1106
981
 
1107
- isApp(expr: number) {
1108
- return this.kinds[expr] === KIND_APP;
1109
- }
1110
-
1111
982
  isVar(expr: number) {
1112
983
  return this.kinds[expr] === KIND_VAR;
1113
984
  }
@@ -1116,7 +987,6 @@ export class AstManager {
1116
987
  return this.freeVarBounds[expr] === 0;
1117
988
  }
1118
989
 
1119
- // Z3's is_ground: an application without variables or quantifiers.
1120
990
  isGroundApp(expr: number) {
1121
991
  return (
1122
992
  this.kinds[expr] === KIND_APP &&
@@ -1170,32 +1040,25 @@ export class AstManager {
1170
1040
  return this.getOp(expr) === OP_NUM;
1171
1041
  }
1172
1042
 
1173
- // The value of an integer numeral.
1174
1043
  getNumeral(expr: number) {
1175
1044
  return this.isNumeral(expr) && this.sorts[expr] === SORT_INT
1176
1045
  ? this.getNumeralValue(expr)
1177
1046
  : undefined;
1178
1047
  }
1179
1048
 
1180
- // The value of an expression that is an integer numeral.
1181
1049
  getNumeralValue(expr: number) {
1182
1050
  return this.numeralValues[this.values[expr]].num;
1183
1051
  }
1184
1052
 
1185
- // The value of an expression that is a numeral of either sort.
1186
1053
  getRationalValue(expr: number) {
1187
1054
  return this.numeralValues[this.values[expr]];
1188
1055
  }
1189
1056
 
1190
- // Unique values are interpreted constants that are distinct from each other, as in Z3.
1191
1057
  isUniqueValue(expr: number) {
1192
1058
  const op = this.getOp(expr);
1193
1059
  return op === OP_NUM || op === OP_TRUE || op === OP_FALSE || op === OP_MODEL_VALUE;
1194
1060
  }
1195
1061
 
1196
- // are_distinct: the plugin of the first term's family, or of the second's for a user term, tells
1197
- // two terms apart. Every plugin separates distinct unique values, and arith also separates b from
1198
- // (+ b k) and (+ k b) for a nonzero numeral k.
1199
1062
  areDistinct(first: number, second: number) {
1200
1063
  if (this.kinds[first] !== KIND_APP || this.kinds[second] !== KIND_APP) return false;
1201
1064
  if (first !== second && this.isUniqueValue(first) && this.isUniqueValue(second)) return true;
@@ -1223,7 +1086,6 @@ export class AstManager {
1223
1086
  return sort > SORT_REAL;
1224
1087
  }
1225
1088
 
1226
- // An uninterpreted constant, such as a declared constant or a Skolem constant.
1227
1089
  isUninterpretedConst(expr: number) {
1228
1090
  return this.isUninterpreted(expr) && this.getNumArgs(expr) === 0;
1229
1091
  }
@@ -1232,7 +1094,6 @@ export class AstManager {
1232
1094
  return this.getFamily(expr) === FAMILY_USER;
1233
1095
  }
1234
1096
 
1235
- // arith_util::is_times_minus_one: the t of (* -1 t).
1236
1097
  getTimesMinusOneArg(expr: number) {
1237
1098
  if (this.getOp(expr) !== OP_MUL || this.getNumArgs(expr) !== 2) return undefined;
1238
1099
  const coefficient = this.getArg(expr, 0);
@@ -1242,7 +1103,6 @@ export class AstManager {
1242
1103
  : undefined;
1243
1104
  }
1244
1105
 
1245
- // occurs: decl is applied somewhere in expr.
1246
1106
  isOccurring(decl: number, expr: number) {
1247
1107
  return this.someSubterm(expr, (current) => this.decls[current] === decl);
1248
1108
  }
@@ -1251,8 +1111,6 @@ export class AstManager {
1251
1111
  return this.someSubterm(expr, (current) => this.isModelValue(current));
1252
1112
  }
1253
1113
 
1254
- // for_each_expr: visits the subterms with a stack of its own, so deep terms do not exhaust the call
1255
- // stack.
1256
1114
  private someSubterm(expr: number, predicate: (expr: number) => boolean) {
1257
1115
  const visited = new Set<number>();
1258
1116
  const todo = [expr];