tla-ts 0.0.4-dev.4c0ab96 → 0.0.4-dev.55f2117

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 (359) hide show
  1. package/README.md +37 -126
  2. package/dist/cli.cjs +1 -1
  3. package/dist/cli.js +1 -1
  4. package/dist/deciders.cjs +366 -0
  5. package/dist/deciders.js +366 -0
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +33 -1
  8. package/dist/index.d.ts +33 -1
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -4
  11. package/dist/parallel-worker.js +1 -4
  12. package/dist/prove-worker.cjs +9 -0
  13. package/dist/prove-worker.d.cts +9 -0
  14. package/dist/prove-worker.d.ts +9 -0
  15. package/dist/prove-worker.js +9 -0
  16. package/dist/prove.cjs +996 -0
  17. package/dist/prove.js +996 -0
  18. package/dist/run.cjs +45 -0
  19. package/dist/run.js +45 -0
  20. package/dist/tlapm.cjs +10 -0
  21. package/dist/tlapm.js +10 -0
  22. package/dist/transfer.cjs +38 -44
  23. package/dist/transfer.js +38 -44
  24. package/dist/worker.cjs +21 -0
  25. package/dist/worker.js +21 -0
  26. package/package.json +21 -12
  27. package/src/ast.ts +2 -2
  28. package/src/check.ts +7 -7
  29. package/src/{cli-options.ts → cli/options.ts} +1 -1
  30. package/src/{run-cli.ts → cli/run.ts} +293 -91
  31. package/src/cli.ts +1 -1
  32. package/src/config.ts +2 -2
  33. package/src/environment.ts +9 -9
  34. package/src/errors.ts +89 -30
  35. package/src/evaluate.ts +32 -11
  36. package/src/index.ts +10 -0
  37. package/src/levels.ts +1 -1
  38. package/src/live-check.ts +1 -1
  39. package/src/liveness.ts +1 -1
  40. package/src/{obligation-action.ts → obligations/action.ts} +247 -69
  41. package/src/{obligation-anon.ts → obligations/anon.ts} +49 -47
  42. package/src/obligations/ctx.ts +64 -0
  43. package/src/{obligation-deref.ts → obligations/deref.ts} +51 -92
  44. package/src/{obligation-expression.ts → obligations/expression.ts} +117 -57
  45. package/src/{obligation-format.ts → obligations/format.ts} +7 -8
  46. package/src/{obligation-generate.ts → obligations/generate.ts} +170 -192
  47. package/src/{obligations.ts → obligations/index.ts} +32 -16
  48. package/src/{obligation-levels.ts → obligations/levels.ts} +26 -28
  49. package/src/{obligation-module.ts → obligations/module.ts} +113 -121
  50. package/src/obligations/pickle.ts +98 -0
  51. package/src/obligations/pragma.ts +189 -0
  52. package/src/{obligation-printer.ts → obligations/printer.ts} +22 -80
  53. package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
  54. package/src/{obligation-source.ts → obligations/source.ts} +154 -99
  55. package/src/obligations/temporal.ts +321 -0
  56. package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
  57. package/src/parallel-worker.ts +4 -20
  58. package/src/parallel.ts +13 -46
  59. package/src/parser.ts +1 -1
  60. package/src/{pcal-ast.ts → pcal/ast.ts} +2 -2
  61. package/src/{pcal-parse.ts → pcal/parse.ts} +3 -3
  62. package/src/{pcal-tokenize.ts → pcal/tokenize.ts} +2 -2
  63. package/src/{pcal-translate.ts → pcal/translate.ts} +2 -2
  64. package/src/{pcal-validate.ts → pcal/validate.ts} +6 -6
  65. package/src/prove/decide-pool.ts +95 -0
  66. package/src/prove/deciders.ts +33 -0
  67. package/src/prove/first-order.ts +78 -0
  68. package/src/prove/isabelle/LICENSE +36 -0
  69. package/src/prove/isabelle/LICENSE-tlapm +26 -0
  70. package/src/prove/isabelle/decide.ts +47 -0
  71. package/src/prove/isabelle/encode.ts +446 -0
  72. package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
  73. package/src/prove/isabelle/isar/method.ts +367 -0
  74. package/src/prove/isabelle/isar/proof.ts +28 -0
  75. package/src/prove/isabelle/isar/statement.ts +57 -0
  76. package/src/prove/isabelle/isar/theory.ts +192 -0
  77. package/src/prove/isabelle/isar/type-check.ts +278 -0
  78. package/src/prove/isabelle/provers/blast/blast.ts +258 -0
  79. package/src/prove/isabelle/provers/blast/branch.ts +322 -0
  80. package/src/prove/isabelle/provers/blast/prove.ts +347 -0
  81. package/src/prove/isabelle/provers/blast/rules.ts +330 -0
  82. package/src/prove/isabelle/provers/blast/state.ts +180 -0
  83. package/src/prove/isabelle/provers/blast/term.ts +546 -0
  84. package/src/prove/isabelle/provers/clasimp.ts +150 -0
  85. package/src/prove/isabelle/provers/classical.ts +389 -0
  86. package/src/prove/isabelle/provers/hypsubst.ts +433 -0
  87. package/src/prove/isabelle/pure/bicompose.ts +174 -0
  88. package/src/prove/isabelle/pure/consts.ts +32 -0
  89. package/src/prove/isabelle/pure/conv.ts +79 -0
  90. package/src/prove/isabelle/pure/drule.ts +264 -0
  91. package/src/prove/isabelle/pure/envir.ts +331 -0
  92. package/src/prove/isabelle/pure/goal.ts +53 -0
  93. package/src/prove/isabelle/pure/interrupt.ts +16 -0
  94. package/src/prove/isabelle/pure/list.ts +12 -0
  95. package/src/prove/isabelle/pure/logic.ts +330 -0
  96. package/src/prove/isabelle/pure/name.ts +98 -0
  97. package/src/prove/isabelle/pure/net.ts +215 -0
  98. package/src/prove/isabelle/pure/object-logic.ts +41 -0
  99. package/src/prove/isabelle/pure/pattern.ts +631 -0
  100. package/src/prove/isabelle/pure/raw-simplifier.ts +338 -0
  101. package/src/prove/isabelle/pure/rewriter.ts +602 -0
  102. package/src/prove/isabelle/pure/search.ts +68 -0
  103. package/src/prove/isabelle/pure/seq.ts +133 -0
  104. package/src/prove/isabelle/pure/simplifier.ts +106 -0
  105. package/src/prove/isabelle/pure/table.ts +201 -0
  106. package/src/prove/isabelle/pure/tactic.ts +168 -0
  107. package/src/prove/isabelle/pure/tactical.ts +264 -0
  108. package/src/prove/isabelle/pure/term-ord.ts +105 -0
  109. package/src/prove/isabelle/pure/term.ts +688 -0
  110. package/src/prove/isabelle/pure/thm.ts +783 -0
  111. package/src/prove/isabelle/pure/type.ts +121 -0
  112. package/src/prove/isabelle/pure/unify.ts +753 -0
  113. package/src/prove/isabelle/pure/variable.ts +25 -0
  114. package/src/prove/isabelle/tla/classical-setup.ts +101 -0
  115. package/src/prove/isabelle/tla/context.ts +74 -0
  116. package/src/prove/isabelle/tla/logic-data.ts +5 -0
  117. package/src/prove/isabelle/tla/logic.ts +215 -0
  118. package/src/prove/isabelle/tla/simpdata.ts +241 -0
  119. package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
  120. package/src/prove/ocaml.ts +22 -0
  121. package/src/prove/prep/action.ts +508 -0
  122. package/src/prove/prep/defs.ts +33 -0
  123. package/src/prove/prep/elab.ts +156 -0
  124. package/src/prove/prep/enabled-axioms.ts +189 -0
  125. package/src/prove/prep/enabled.ts +43 -0
  126. package/src/prove/prep/fingerprint.ts +388 -0
  127. package/src/prove/prep/flatten.ts +70 -0
  128. package/src/prove/prep/level-comparison.ts +529 -0
  129. package/src/prove/prep/md5.ts +67 -0
  130. package/src/prove/prep/pragma.ts +221 -0
  131. package/src/prove/prep/trivial.ts +22 -0
  132. package/src/prove/prove-worker.ts +22 -0
  133. package/src/prove/prove.ts +498 -0
  134. package/src/prove/ptl/decide.ts +68 -0
  135. package/src/prove/ptl/encode.ts +255 -0
  136. package/src/prove/ptl/sat.ts +151 -0
  137. package/src/prove/ptl/tableau.ts +276 -0
  138. package/src/prove/smt/axiomatize.ts +69 -0
  139. package/src/prove/smt/axioms.ts +209 -0
  140. package/src/prove/smt/context.ts +108 -0
  141. package/src/prove/smt/data.ts +636 -0
  142. package/src/prove/smt/encode.ts +164 -0
  143. package/src/prove/smt/extensionality.ts +65 -0
  144. package/src/prove/smt/flatten.ts +112 -0
  145. package/src/prove/smt/format.ts +154 -0
  146. package/src/prove/smt/instances.ts +181 -0
  147. package/src/prove/smt/rewrite.ts +772 -0
  148. package/src/prove/smt/simplify.ts +57 -0
  149. package/src/prove/smt/solver/act-cache.ts +265 -0
  150. package/src/prove/smt/solver/arith-rewriter.ts +962 -0
  151. package/src/prove/smt/solver/array.ts +22 -0
  152. package/src/prove/smt/solver/asserted-formulas.ts +469 -0
  153. package/src/prove/smt/solver/ast-lt.ts +157 -0
  154. package/src/prove/smt/solver/ast-util.ts +91 -0
  155. package/src/prove/smt/solver/ast.ts +1315 -0
  156. package/src/prove/smt/solver/auf-solver.ts +572 -0
  157. package/src/prove/smt/solver/case-split-queue.ts +178 -0
  158. package/src/prove/smt/solver/cg-table.ts +175 -0
  159. package/src/prove/smt/solver/clause.ts +276 -0
  160. package/src/prove/smt/solver/conflict-resolution.ts +343 -0
  161. package/src/prove/smt/solver/context.ts +1292 -0
  162. package/src/prove/smt/solver/ctx-simplify.ts +334 -0
  163. package/src/prove/smt/solver/der.ts +224 -0
  164. package/src/prove/smt/solver/dyn-ack.ts +141 -0
  165. package/src/prove/smt/solver/e-matching.ts +659 -0
  166. package/src/prove/smt/solver/enode.ts +259 -0
  167. package/src/prove/smt/solver/expr-ref.ts +21 -0
  168. package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
  169. package/src/prove/smt/solver/fingerprints.ts +92 -0
  170. package/src/prove/smt/solver/flat-literals.ts +51 -0
  171. package/src/prove/smt/solver/goal.ts +138 -0
  172. package/src/prove/smt/solver/hash.ts +173 -0
  173. package/src/prove/smt/solver/hashtable.ts +166 -0
  174. package/src/prove/smt/solver/internalizer.ts +1381 -0
  175. package/src/prove/smt/solver/lbool.ts +5 -0
  176. package/src/prove/smt/solver/literal.ts +24 -0
  177. package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
  178. package/src/prove/smt/solver/lp/constraints.ts +78 -0
  179. package/src/prove/smt/solver/lp/containers.ts +296 -0
  180. package/src/prove/smt/solver/lp/core-solver.ts +504 -0
  181. package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
  182. package/src/prove/smt/solver/lp/dep-intervals.ts +642 -0
  183. package/src/prove/smt/solver/lp/dependency.ts +51 -0
  184. package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
  185. package/src/prove/smt/solver/lp/explanation.ts +46 -0
  186. package/src/prove/smt/solver/lp/gomory.ts +255 -0
  187. package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
  188. package/src/prove/smt/solver/lp/hnf.ts +281 -0
  189. package/src/prove/smt/solver/lp/int-cube.ts +295 -0
  190. package/src/prove/smt/solver/lp/int-solver.ts +514 -0
  191. package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
  192. package/src/prove/smt/solver/lp/lar-term.ts +62 -0
  193. package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
  194. package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
  195. package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
  196. package/src/prove/smt/solver/lp/nex.ts +120 -0
  197. package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
  198. package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
  199. package/src/prove/smt/solver/lp/nla-core.ts +968 -0
  200. package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
  201. package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
  202. package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
  203. package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
  204. package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
  205. package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
  206. package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
  207. package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
  208. package/src/prove/smt/solver/lp/nla-order.ts +307 -0
  209. package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
  210. package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
  211. package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
  212. package/src/prove/smt/solver/lp/nla-types.ts +124 -0
  213. package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
  214. package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
  215. package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
  216. package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
  217. package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
  218. package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
  219. package/src/prove/smt/solver/lp/pdd.ts +971 -0
  220. package/src/prove/smt/solver/lp/random-updater.ts +138 -0
  221. package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
  222. package/src/prove/smt/solver/lp/union-find.ts +96 -0
  223. package/src/prove/smt/solver/mam-compiler.ts +847 -0
  224. package/src/prove/smt/solver/mam-interpreter.ts +400 -0
  225. package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
  226. package/src/prove/smt/solver/model-checker.ts +347 -0
  227. package/src/prove/smt/solver/model-evaluator.ts +262 -0
  228. package/src/prove/smt/solver/model-finder.ts +155 -0
  229. package/src/prove/smt/solver/model-generator.ts +97 -0
  230. package/src/prove/smt/solver/model-macro-solver.ts +728 -0
  231. package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
  232. package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
  233. package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
  234. package/src/prove/smt/solver/nlsat/explain.ts +607 -0
  235. package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
  236. package/src/prove/smt/solver/nlsat/levelwise.ts +737 -0
  237. package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
  238. package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
  239. package/src/prove/smt/solver/nlsat/solver.ts +911 -0
  240. package/src/prove/smt/solver/nlsat/types.ts +43 -0
  241. package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
  242. package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
  243. package/src/prove/smt/solver/nnf.ts +469 -0
  244. package/src/prove/smt/solver/pattern-inference.ts +351 -0
  245. package/src/prove/smt/solver/poly-rewriter.ts +477 -0
  246. package/src/prove/smt/solver/propagate-values.ts +83 -0
  247. package/src/prove/smt/solver/proto-model.ts +551 -0
  248. package/src/prove/smt/solver/pull-quant.ts +139 -0
  249. package/src/prove/smt/solver/qe-lite-der.ts +526 -0
  250. package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
  251. package/src/prove/smt/solver/qe-lite.ts +381 -0
  252. package/src/prove/smt/solver/qi-queue.ts +362 -0
  253. package/src/prove/smt/solver/quant-tactics.ts +117 -0
  254. package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
  255. package/src/prove/smt/solver/quantifier-manager.ts +186 -0
  256. package/src/prove/smt/solver/random-gen.ts +10 -0
  257. package/src/prove/smt/solver/rational.ts +165 -0
  258. package/src/prove/smt/solver/ref-vector.ts +62 -0
  259. package/src/prove/smt/solver/relevancy.ts +247 -0
  260. package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
  261. package/src/prove/smt/solver/rewriter.ts +843 -0
  262. package/src/prove/smt/solver/rlimit.ts +79 -0
  263. package/src/prove/smt/solver/smtlib-parser.ts +526 -0
  264. package/src/prove/smt/solver/solver.ts +71 -0
  265. package/src/prove/smt/solver/sort.ts +35 -0
  266. package/src/prove/smt/solver/sticky-generations.ts +69 -0
  267. package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
  268. package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
  269. package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
  270. package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
  271. package/src/prove/smt/solver/theory-lra-model.ts +243 -0
  272. package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
  273. package/src/prove/smt/solver/theory-lra-state.ts +43 -0
  274. package/src/prove/smt/solver/theory-lra.ts +56 -0
  275. package/src/prove/smt/solver/var-subst.ts +258 -0
  276. package/src/prove/smt/solver/z3-license.txt +10 -0
  277. package/src/prove/smt/table.ts +170 -0
  278. package/src/prove/tlapm/cache.ts +236 -0
  279. package/src/prove/tlapm/ocaml-marshal.ts +166 -0
  280. package/src/prove/tlapm/tlapm.ts +96 -0
  281. package/src/prove/tlaps-module.ts +510 -0
  282. package/src/prove/verdict.ts +18 -0
  283. package/src/prove/zenon/LICENSE +32 -0
  284. package/src/prove/zenon/check/check.ts +105 -0
  285. package/src/prove/zenon/check/definitions.ts +144 -0
  286. package/src/prove/zenon/check/equality.ts +182 -0
  287. package/src/prove/zenon/check/functions.ts +62 -0
  288. package/src/prove/zenon/check/keys.ts +125 -0
  289. package/src/prove/zenon/check/propositional.ts +104 -0
  290. package/src/prove/zenon/check/records.ts +188 -0
  291. package/src/prove/zenon/check/relations.ts +121 -0
  292. package/src/prove/zenon/check/rewrites.ts +224 -0
  293. package/src/prove/zenon/check/sets.ts +302 -0
  294. package/src/prove/zenon/check/terms.ts +127 -0
  295. package/src/prove/zenon/check/tla.ts +126 -0
  296. package/src/prove/zenon/decide.ts +113 -0
  297. package/src/prove/zenon/encode.ts +379 -0
  298. package/src/prove/zenon/eqrel.ts +300 -0
  299. package/src/prove/zenon/equality-rules.ts +435 -0
  300. package/src/prove/zenon/expr.ts +551 -0
  301. package/src/prove/zenon/index-table.ts +350 -0
  302. package/src/prove/zenon/isar-case.ts +513 -0
  303. package/src/prove/zenon/isar.ts +1249 -0
  304. package/src/prove/zenon/limits.ts +15 -0
  305. package/src/prove/zenon/llproof.ts +173 -0
  306. package/src/prove/zenon/mltoll.ts +1566 -0
  307. package/src/prove/zenon/node.ts +297 -0
  308. package/src/prove/zenon/ocaml.ts +169 -0
  309. package/src/prove/zenon/parse.ts +247 -0
  310. package/src/prove/zenon/phrase.ts +191 -0
  311. package/src/prove/zenon/proof.ts +198 -0
  312. package/src/prove/zenon/propositional-rules.ts +387 -0
  313. package/src/prove/zenon/rules.ts +94 -0
  314. package/src/prove/zenon/search.ts +288 -0
  315. package/src/prove/zenon/tla/functions.ts +151 -0
  316. package/src/prove/zenon/tla/llproof.ts +480 -0
  317. package/src/prove/zenon/tla/records.ts +225 -0
  318. package/src/prove/zenon/tla/rewrites.ts +447 -0
  319. package/src/prove/zenon/tla/sets.ts +304 -0
  320. package/src/prove/zenon/tla/terms.ts +162 -0
  321. package/src/prove/zenon/tla/tla.ts +506 -0
  322. package/src/randomization.ts +1 -1
  323. package/src/resolve.ts +1 -1
  324. package/src/runtime.ts +2 -2
  325. package/src/{sany-builtins.ts → sany/builtins.ts} +1 -1
  326. package/src/{sany-generator.ts → sany/generator.ts} +14 -14
  327. package/src/{sany-levels.ts → sany/levels.ts} +2 -2
  328. package/src/{sany-lexer.ts → sany/lexer.ts} +1 -1
  329. package/src/{sany-linter.ts → sany/linter.ts} +1 -1
  330. package/src/{sany-modules.ts → sany/modules.ts} +2 -2
  331. package/src/{sany-parse-error.ts → sany/parse-error.ts} +2 -2
  332. package/src/{sany-report.ts → sany/report.ts} +15 -15
  333. package/src/{sany-selectors.ts → sany/selectors.ts} +3 -3
  334. package/src/{sany-source.ts → sany/source.ts} +6 -6
  335. package/src/{sany-xml.ts → sany/xml.ts} +5 -5
  336. package/src/spec-description.ts +1 -1
  337. package/src/{standard-levels.ts → standard/levels.ts} +1 -1
  338. package/src/{standard-modules.ts → standard/modules.ts} +12 -12
  339. package/src/{standard-ranges.ts → standard/ranges.ts} +1 -1
  340. package/src/state-graph.ts +1 -1
  341. package/src/successors.ts +1 -1
  342. package/src/symmetry.ts +1 -1
  343. package/src/{tlc-messages.ts → tlc/messages.ts} +2 -2
  344. package/src/{tlc-order.ts → tlc/order.ts} +7 -7
  345. package/src/{tlc-random.ts → tlc/random.ts} +3 -3
  346. package/src/{tlc-replay.ts → tlc/replay.ts} +5 -5
  347. package/src/{tlc-module.ts → tlc/tlc-operators.ts} +9 -9
  348. package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +14 -8
  349. package/src/values.ts +1 -1
  350. package/src/worker.ts +65 -0
  351. package/dist/parallel.cjs +0 -12
  352. package/dist/parallel.js +0 -12
  353. package/dist/run-cli.cjs +0 -55
  354. package/dist/run-cli.js +0 -55
  355. package/src/value-sources.ts +0 -29
  356. /package/src/{sany-nodes.ts → sany/nodes.ts} +0 -0
  357. /package/src/{tlc-modules.ts → tlc/jar-data.ts} +0 -0
  358. /package/src/{tlc-summary.ts → tlc/summary.ts} +0 -0
  359. /package/src/{tlc-version.ts → tlc/version.ts} +0 -0
@@ -0,0 +1,178 @@
1
+ // Ported from Z3 (src/smt/smt_case_split_queue.cpp, src/util/heap.h), MIT license, see
2
+ // z3-license.txt. Z3's default CS_ACTIVITY_DELAY_NEW queue: Boolean variables ordered by activity,
3
+ // where variables created during the search wait in a delayed queue until the main one runs dry.
4
+ // Without the delay, it is the CS_ACTIVITY queue of the model checker's auxiliary context.
5
+
6
+ import { BoolVar, toBoolVar } from "./literal";
7
+
8
+ // heap<bool_var_act_lt>: a binary min-heap over activities negated, so the most active is first.
9
+ class ActivityHeap {
10
+ // The heap is 1-based, so the first slot is unused.
11
+ private values: BoolVar[] = [toBoolVar(-1)];
12
+ // The position of each variable, or 0. A typed array keeps the loads of variables that were never
13
+ // inserted in bounds.
14
+ private indices = new Int32Array(1024);
15
+
16
+ constructor(private activity: number[]) {}
17
+
18
+ private isLess(first: BoolVar, second: BoolVar) {
19
+ return this.activity[first] > this.activity[second];
20
+ }
21
+
22
+ contains(value: BoolVar) {
23
+ return value < this.indices.length && this.indices[value] !== 0;
24
+ }
25
+
26
+ isEmpty() {
27
+ return this.values.length === 1;
28
+ }
29
+
30
+ insert(value: BoolVar) {
31
+ if (value >= this.indices.length) {
32
+ const indices = new Int32Array(Math.max(2 * this.indices.length, value + 1));
33
+ indices.set(this.indices);
34
+ this.indices = indices;
35
+ }
36
+ this.values.push(value);
37
+ this.indices[value] = this.values.length - 1;
38
+ this.moveUp(this.values.length - 1);
39
+ }
40
+
41
+ eraseMin() {
42
+ const result = this.values[1];
43
+ const last = this.values[this.values.length - 1];
44
+ this.values.pop();
45
+ this.indices[result] = 0;
46
+ if (this.values.length > 1) {
47
+ this.values[1] = last;
48
+ this.indices[last] = 1;
49
+ this.moveDown(1);
50
+ }
51
+ return result;
52
+ }
53
+
54
+ erase(value: BoolVar) {
55
+ const index = this.indices[value];
56
+ if (index === this.values.length - 1) {
57
+ this.indices[value] = 0;
58
+ this.values.pop();
59
+ return;
60
+ }
61
+ const last = this.values[this.values.length - 1];
62
+ this.values.pop();
63
+ this.values[index] = last;
64
+ this.indices[last] = index;
65
+ this.indices[value] = 0;
66
+ const parentIndex = index >> 1;
67
+ if (parentIndex !== 0 && this.isLess(last, this.values[parentIndex])) this.moveUp(index);
68
+ else this.moveDown(index);
69
+ }
70
+
71
+ decreased(value: BoolVar) {
72
+ this.moveUp(this.indices[value]);
73
+ }
74
+
75
+ swap(other: ActivityHeap) {
76
+ const values = this.values;
77
+ const indices = this.indices;
78
+ this.values = other.values;
79
+ this.indices = other.indices;
80
+ other.values = values;
81
+ other.indices = indices;
82
+ }
83
+
84
+ private moveUp(start: number) {
85
+ let index = start;
86
+ const value = this.values[index];
87
+ for (;;) {
88
+ const parentIndex = index >> 1;
89
+ if (parentIndex === 0 || !this.isLess(value, this.values[parentIndex])) break;
90
+ this.values[index] = this.values[parentIndex];
91
+ this.indices[this.values[index]] = index;
92
+ index = parentIndex;
93
+ }
94
+ this.values[index] = value;
95
+ this.indices[value] = index;
96
+ }
97
+
98
+ private moveDown(start: number) {
99
+ let index = start;
100
+ const value = this.values[index];
101
+ const size = this.values.length;
102
+ for (;;) {
103
+ const left = index * 2;
104
+ if (left >= size) break;
105
+ const right = left + 1;
106
+ const minIndex =
107
+ right < size && this.isLess(this.values[right], this.values[left]) ? right : left;
108
+ if (!this.isLess(this.values[minIndex], value)) break;
109
+ this.values[index] = this.values[minIndex];
110
+ this.indices[this.values[index]] = index;
111
+ index = minIndex;
112
+ }
113
+ this.values[index] = value;
114
+ this.indices[value] = index;
115
+ }
116
+ }
117
+
118
+ interface CaseSplitContext {
119
+ activity: number[];
120
+ getIsSearching(): boolean;
121
+ getRandomValue(): number;
122
+ getNumBoolVars(): number;
123
+ isUnassigned(boolVar: BoolVar): boolean;
124
+ }
125
+
126
+ const RANDOM_VAR_FREQ = 0.01;
127
+ const RANDOM_MAX_VALUE = 0x7fff;
128
+
129
+ export class CaseSplitQueue {
130
+ private queue: ActivityHeap;
131
+ private delayedQueue: ActivityHeap;
132
+
133
+ constructor(
134
+ private context: CaseSplitContext,
135
+ private isDelayingNew: boolean,
136
+ ) {
137
+ this.queue = new ActivityHeap(context.activity);
138
+ this.delayedQueue = new ActivityHeap(context.activity);
139
+ }
140
+
141
+ activityIncreased(boolVar: BoolVar) {
142
+ if (this.queue.contains(boolVar)) this.queue.decreased(boolVar);
143
+ if (this.delayedQueue.contains(boolVar)) this.delayedQueue.decreased(boolVar);
144
+ }
145
+
146
+ mkVar(boolVar: BoolVar) {
147
+ if (this.isDelayingNew && this.context.getIsSearching()) this.delayedQueue.insert(boolVar);
148
+ else this.queue.insert(boolVar);
149
+ }
150
+
151
+ delVar(boolVar: BoolVar) {
152
+ if (this.queue.contains(boolVar)) this.queue.erase(boolVar);
153
+ if (this.delayedQueue.contains(boolVar)) this.delayedQueue.erase(boolVar);
154
+ }
155
+
156
+ unassignVar(boolVar: BoolVar) {
157
+ if (!this.queue.contains(boolVar)) this.queue.insert(boolVar);
158
+ }
159
+
160
+ // Returns the next variable to split on, or undefined when every variable is assigned.
161
+ nextCaseSplit() {
162
+ const context = this.context;
163
+ if (context.getRandomValue() < Math.trunc(RANDOM_VAR_FREQ * RANDOM_MAX_VALUE)) {
164
+ const next = toBoolVar(context.getRandomValue() % context.getNumBoolVars());
165
+ if (context.isUnassigned(next)) return next;
166
+ }
167
+ while (!this.queue.isEmpty()) {
168
+ const next = this.queue.eraseMin();
169
+ if (context.isUnassigned(next)) return next;
170
+ }
171
+ this.queue.swap(this.delayedQueue);
172
+ while (!this.queue.isEmpty()) {
173
+ const next = this.queue.eraseMin();
174
+ if (context.isUnassigned(next)) return next;
175
+ }
176
+ return undefined;
177
+ }
178
+ }
@@ -0,0 +1,175 @@
1
+ // Ported from Z3 (src/smt/smt_cg_table.h, src/smt/smt_cg_table.cpp), MIT license, see
2
+ // z3-license.txt. The congruence table maps a declaration and the roots of its arguments to the
3
+ // congruence root, so f(a) and f(b) meet when a and b are merged. Equalities are commutative.
4
+ import { CONGRUENCE_JUSTIFICATIONS, type Enode } from "./enode";
5
+
6
+ // The hash of an equality between the classes of first and second, in either order.
7
+ const getEqHash = (decl: number, first: number, second: number) =>
8
+ first < second
9
+ ? (Math.imul(Math.imul(decl, 0x9e3779b1) + first, 0x85ebca6b) + second) | 0
10
+ : (Math.imul(Math.imul(decl, 0x9e3779b1) + second, 0x85ebca6b) + first) | 0;
11
+
12
+ const getHash = (decl: number, args: Enode[], isEq: boolean) => {
13
+ if (isEq) return getEqHash(decl, args[0].root.owner, args[1].root.owner);
14
+ let hash = decl;
15
+ for (let index = 0; index < args.length; index++)
16
+ hash = (Math.imul(hash, 0x9e3779b1) + args[index].root.owner) | 0;
17
+ return hash;
18
+ };
19
+
20
+ const getNodeHash = (node: Enode) => {
21
+ if (node.isEq) return getEqHash(node.decl, node.getArg(0).root.owner, node.getArg(1).root.owner);
22
+ let hash = node.decl;
23
+ for (let index = 0; index < node.numArgs; index++)
24
+ hash = (Math.imul(hash, 0x9e3779b1) + node.getArg(index).root.owner) | 0;
25
+ return hash;
26
+ };
27
+
28
+ // Whether node is decl applied to nodes equal to first and second, in either order for an equality.
29
+ const isPairCongruentTo = (node: Enode, first: Enode, second: Enode, isEq: boolean) => {
30
+ const nodeFirst = node.getArg(0).root;
31
+ const nodeSecond = node.getArg(1).root;
32
+ return (
33
+ (nodeFirst === first.root && nodeSecond === second.root) ||
34
+ (isEq && nodeFirst === second.root && nodeSecond === first.root)
35
+ );
36
+ };
37
+
38
+ const isCongruentTo = (node: Enode, decl: number, args: Enode[], isEq: boolean) => {
39
+ if (node.decl !== decl || node.numArgs !== args.length) return false;
40
+ if (isEq) return isPairCongruentTo(node, args[0], args[1], true);
41
+ for (let index = 0; index < args.length; index++)
42
+ if (node.getArg(index).root !== args[index].root) return false;
43
+ return true;
44
+ };
45
+
46
+ // congruent: whether two nodes apply one declaration to equal arguments. Only equalities are
47
+ // commutative.
48
+ export const isCongruent = (first: Enode, second: Enode) => {
49
+ if (first.decl !== second.decl || first.numArgs !== second.numArgs) return false;
50
+ if (first.numArgs === 2)
51
+ return isPairCongruentTo(first, second.getArg(0), second.getArg(1), first.isEq);
52
+ for (let index = 0; index < first.numArgs; index++)
53
+ if (first.getArg(index).root !== second.getArg(index).root) return false;
54
+ return true;
55
+ };
56
+
57
+ // The justification of a node's equality with the congruent node that the table returned for it.
58
+ export const getCongruenceJustification = (node: Enode, congruent: Enode) =>
59
+ CONGRUENCE_JUSTIFICATIONS[node.isEq && congruent.getArg(0).root !== node.getArg(0).root ? 1 : 0];
60
+
61
+ const EMPTY = 0;
62
+ const FULL = 1;
63
+ const DELETED = 2;
64
+
65
+ // Open addressing with linear probing. An erased node leaves a deleted slot, which probes pass over,
66
+ // until the table is rebuilt.
67
+ export class CgTable {
68
+ private nodes = Array<Enode | null>(1024).fill(null);
69
+ private hashes = new Int32Array(1024);
70
+ private states = new Uint8Array(1024);
71
+ private numFull = 0;
72
+ private numDeleted = 0;
73
+
74
+ private find(decl: number, args: Enode[], isEq: boolean, hash: number) {
75
+ const mask = this.states.length - 1;
76
+ for (let slot = hash & mask; this.states[slot] !== EMPTY; slot = (slot + 1) & mask) {
77
+ const node = this.nodes[slot];
78
+ if (
79
+ this.states[slot] === FULL &&
80
+ this.hashes[slot] === hash &&
81
+ node !== null &&
82
+ isCongruentTo(node, decl, args, isEq)
83
+ )
84
+ return node;
85
+ }
86
+ return undefined;
87
+ }
88
+
89
+ private findNode(node: Enode, hash: number) {
90
+ const mask = this.states.length - 1;
91
+ for (let slot = hash & mask; this.states[slot] !== EMPTY; slot = (slot + 1) & mask) {
92
+ const candidate = this.nodes[slot];
93
+ if (
94
+ this.states[slot] === FULL &&
95
+ this.hashes[slot] === hash &&
96
+ candidate !== null &&
97
+ isCongruent(candidate, node)
98
+ )
99
+ return candidate;
100
+ }
101
+ return undefined;
102
+ }
103
+
104
+ // Returns the congruence root for node, which is node itself when it is new.
105
+ insert(node: Enode) {
106
+ const hash = getNodeHash(node);
107
+ const existing = this.findNode(node, hash);
108
+ if (existing !== undefined) return existing;
109
+ if (2 * (this.numFull + this.numDeleted + 1) > this.states.length) this.rebuild();
110
+ const mask = this.states.length - 1;
111
+ let slot = hash & mask;
112
+ while (this.states[slot] === FULL) slot = (slot + 1) & mask;
113
+ if (this.states[slot] === DELETED) this.numDeleted--;
114
+ this.place(slot, node, hash);
115
+ return node;
116
+ }
117
+
118
+ private place(slot: number, node: Enode, hash: number) {
119
+ this.nodes[slot] = node;
120
+ this.hashes[slot] = hash;
121
+ this.states[slot] = FULL;
122
+ this.numFull++;
123
+ }
124
+
125
+ // Drops the deleted slots, and doubles the table when it is more than a quarter full.
126
+ private rebuild() {
127
+ const nodes = this.nodes;
128
+ const hashes = this.hashes;
129
+ const states = this.states;
130
+ const size = 4 * this.numFull > states.length ? 2 * states.length : states.length;
131
+ this.nodes = Array<Enode | null>(size).fill(null);
132
+ this.hashes = new Int32Array(size);
133
+ this.states = new Uint8Array(size);
134
+ this.numFull = 0;
135
+ this.numDeleted = 0;
136
+ const mask = size - 1;
137
+ for (let index = 0; index < states.length; index++) {
138
+ const node = nodes[index];
139
+ if (states[index] !== FULL || node === null) continue;
140
+ let slot = hashes[index] & mask;
141
+ while (this.states[slot] === FULL) slot = (slot + 1) & mask;
142
+ this.place(slot, node, hashes[index]);
143
+ }
144
+ }
145
+
146
+ // get_enode_eq_to: the congruence root of decl applied to nodes equal to args, if any.
147
+ findFor(decl: number, args: Enode[], isEq: boolean) {
148
+ return this.find(decl, args, isEq, getHash(decl, args, isEq));
149
+ }
150
+
151
+ // The congruence root of a node congruent to node.
152
+ findCongruent(node: Enode) {
153
+ return this.findNode(node, getNodeHash(node));
154
+ }
155
+
156
+ private getSlot(node: Enode) {
157
+ const mask = this.states.length - 1;
158
+ for (let slot = getNodeHash(node) & mask; this.states[slot] !== EMPTY; slot = (slot + 1) & mask)
159
+ if (this.nodes[slot] === node) return slot;
160
+ return -1;
161
+ }
162
+
163
+ erase(node: Enode) {
164
+ const slot = this.getSlot(node);
165
+ if (slot === -1) return;
166
+ this.nodes[slot] = null;
167
+ this.states[slot] = DELETED;
168
+ this.numFull--;
169
+ this.numDeleted++;
170
+ }
171
+
172
+ contains(node: Enode) {
173
+ return this.getSlot(node) !== -1;
174
+ }
175
+ }
@@ -0,0 +1,276 @@
1
+ // Ported from Z3 (src/smt/smt_clause.h, src/smt/smt_b_justification.h,
2
+ // src/util/small_object_allocator.cpp), MIT license, see z3-license.txt. Disjunctions of literals,
3
+ // and the reasons a literal is assigned.
4
+ import { SmtInvariantError } from "../../../errors";
5
+ import type { Justification } from "./enode";
6
+ import type { Literal } from "./literal";
7
+ import { setAt } from "./array";
8
+
9
+ export const CLS_AUX = 0;
10
+ export const CLS_LEARNED = 1;
11
+ export const CLS_TH_AXIOM = 2;
12
+ export const CLS_TH_LEMMA = 3;
13
+
14
+ // b_justification(l) of BIN_CLAUSE kind: a binary clause propagated because the literal l became true.
15
+ export class BinJustification {
16
+ constructor(readonly literal: Literal) {}
17
+ }
18
+
19
+ // b_justification: a clause, a binary clause, a theory justification, an axiom, or a decision (null).
20
+ export type BJustification = number | BinJustification | Justification | "axiom" | null;
21
+
22
+ // The second header word packs Z3's bit fields: m_capacity:24, m_kind:2, m_reinit,
23
+ // m_reinternalize_atoms, m_has_atoms, m_has_del_eh, m_has_justification and m_deleted.
24
+ const CAPACITY_MASK = 0xffffff;
25
+ const KIND_SHIFT = 24;
26
+ const IS_REINIT = 1 << 26;
27
+ const IS_REINTERNALIZE_ATOMS = 1 << 27;
28
+ const HAS_ATOMS = 1 << 28;
29
+ const HAS_DEL_EH = 1 << 29;
30
+ const HAS_JUSTIFICATION = 1 << 30;
31
+ const IS_DELETED = 1 << 31;
32
+ // The words before the literals: m_num_literals and the bit fields.
33
+ export const HEADER_SIZE = 2;
34
+ // An atom word of a clause whose atoms were released.
35
+ const NO_ATOM = -1;
36
+
37
+ // The clauses live in one Int32Array, and a clause is the offset of its block, as a clause is the
38
+ // address of its memory in Z3. A block holds the header, the literals, then the activity of a lemma,
39
+ // the slots of the deletion handler and the justification, and the atoms with their signs, each
40
+ // present only when used. Like small_object_allocator, a freed block goes on the free list of its size
41
+ // for the next clause of that size, and the array never shrinks. A freed block keeps the next free
42
+ // block in its first word and 0 in its second, which no clause has.
43
+ export class ClauseStore {
44
+ // Literal i of clause c is data[c + 2 + i]. Making a clause can replace the array, so a loop that
45
+ // makes clauses reads it again.
46
+ data = new Int32Array(1 << 16);
47
+ private top = 0;
48
+ private freeLists: (number | undefined)[] = [];
49
+ // The deletion handlers and justifications, which a block refers to by slot.
50
+ private delEhs: ((() => void) | null)[] = [];
51
+ private freeDelEhSlots: number[] = [];
52
+ private justifications: (Justification | null)[] = [];
53
+ private freeJustificationSlots: number[] = [];
54
+
55
+ // get_obj_size, in words.
56
+ private getSize(flags: number) {
57
+ const capacity = flags & CAPACITY_MASK;
58
+ return (
59
+ HEADER_SIZE +
60
+ capacity +
61
+ (isLemmaKind((flags >>> KIND_SHIFT) & 3) ? 1 : 0) +
62
+ (flags & HAS_DEL_EH ? 1 : 0) +
63
+ (flags & HAS_JUSTIFICATION ? 1 : 0) +
64
+ (flags & HAS_ATOMS ? capacity : 0)
65
+ );
66
+ }
67
+
68
+ private allocate(size: number) {
69
+ const head = this.freeLists[size];
70
+ if (head !== undefined && head !== -1) {
71
+ this.freeLists[size] = this.data[head];
72
+ return head;
73
+ }
74
+ const block = this.top;
75
+ this.top += size;
76
+ if (this.top > this.data.length) {
77
+ const grown = new Int32Array(Math.max(2 * this.data.length, this.top));
78
+ grown.set(this.data);
79
+ this.data = grown;
80
+ }
81
+ return block;
82
+ }
83
+
84
+ // clause::mk. The atoms are the atom of each literal, which the clause keeps with the literal's sign.
85
+ mk(
86
+ literals: Literal[],
87
+ kind: number,
88
+ justification: Justification | null,
89
+ delEh: (() => void) | null,
90
+ atoms: number[] | null,
91
+ ) {
92
+ const numLiterals = literals.length;
93
+ const flags =
94
+ numLiterals |
95
+ (kind << KIND_SHIFT) |
96
+ (atoms !== null ? HAS_ATOMS : 0) |
97
+ (delEh !== null ? HAS_DEL_EH : 0) |
98
+ (justification !== null ? HAS_JUSTIFICATION : 0);
99
+ const clause = this.allocate(this.getSize(flags));
100
+ const data = this.data;
101
+ data[clause] = numLiterals;
102
+ data[clause + 1] = flags;
103
+ for (let index = 0; index < numLiterals; index++)
104
+ data[clause + HEADER_SIZE + index] = literals[index];
105
+ let extra = clause + HEADER_SIZE + numLiterals;
106
+ if (isLemmaKind(kind)) data[extra++] = 1;
107
+ if (delEh !== null) data[extra++] = this.mkSlot(this.delEhs, this.freeDelEhSlots, delEh);
108
+ if (justification !== null)
109
+ data[extra++] = this.mkSlot(this.justifications, this.freeJustificationSlots, justification);
110
+ if (atoms !== null)
111
+ for (let index = 0; index < numLiterals; index++)
112
+ data[extra + index] = 2 * atoms[index] + (literals[index] & 1);
113
+ return clause;
114
+ }
115
+
116
+ private mkSlot<T>(values: (T | null)[], freeSlots: number[], value: T) {
117
+ const slot = freeSlots.pop() ?? values.length;
118
+ setAt(values, slot, value);
119
+ return slot;
120
+ }
121
+
122
+ // deallocate: the block goes on its free list. The atoms must be released first.
123
+ free(clause: Clause) {
124
+ const data = this.data;
125
+ const flags = data[clause + 1];
126
+ if (flags & HAS_DEL_EH) {
127
+ const slot = data[this.getSlotAddress(clause, HAS_DEL_EH)];
128
+ this.delEhs[slot] = null;
129
+ this.freeDelEhSlots.push(slot);
130
+ }
131
+ if (flags & HAS_JUSTIFICATION) {
132
+ const slot = data[this.getSlotAddress(clause, HAS_JUSTIFICATION)];
133
+ this.justifications[slot] = null;
134
+ this.freeJustificationSlots.push(slot);
135
+ }
136
+ const size = this.getSize(flags);
137
+ const head = this.freeLists[size];
138
+ data[clause] = head ?? -1;
139
+ data[clause + 1] = 0;
140
+ setAt(this.freeLists, size, clause);
141
+ }
142
+
143
+ // The first word after the literals, where the activity of a lemma is.
144
+ private getExtra(clause: Clause) {
145
+ return clause + HEADER_SIZE + (this.data[clause + 1] & CAPACITY_MASK);
146
+ }
147
+
148
+ // A clause that was freed is not one any more, which the slower paths check.
149
+ checkLive(clause: Clause) {
150
+ if ((this.data[clause + 1] & CAPACITY_MASK) === 0)
151
+ throw new SmtInvariantError("the clause was freed");
152
+ }
153
+
154
+ getNumLiterals(clause: Clause) {
155
+ return this.data[clause];
156
+ }
157
+
158
+ getLiteral(clause: Clause, index: number) {
159
+ return this.data[clause + HEADER_SIZE + index] as Literal;
160
+ }
161
+
162
+ setLiteral(clause: Clause, index: number, literal: Literal) {
163
+ this.data[clause + HEADER_SIZE + index] = literal;
164
+ }
165
+
166
+ getLiterals(clause: Clause) {
167
+ const literals: Literal[] = [];
168
+ for (let index = 0; index < this.data[clause]; index++)
169
+ literals.push(this.getLiteral(clause, index));
170
+ return literals;
171
+ }
172
+
173
+ swapLiterals(clause: Clause, first: number, second: number) {
174
+ const data = this.data;
175
+ const saved = data[clause + HEADER_SIZE + first];
176
+ data[clause + HEADER_SIZE + first] = data[clause + HEADER_SIZE + second];
177
+ data[clause + HEADER_SIZE + second] = saved;
178
+ }
179
+
180
+ getKind(clause: Clause) {
181
+ return (this.data[clause + 1] >>> KIND_SHIFT) & 3;
182
+ }
183
+
184
+ isLemma(clause: Clause) {
185
+ return isLemmaKind(this.getKind(clause));
186
+ }
187
+
188
+ private setFlag(clause: Clause, flag: number, value: boolean) {
189
+ this.data[clause + 1] = value ? this.data[clause + 1] | flag : this.data[clause + 1] & ~flag;
190
+ }
191
+
192
+ isDeleted(clause: Clause) {
193
+ return (this.data[clause + 1] & IS_DELETED) !== 0;
194
+ }
195
+
196
+ markAsDeleted(clause: Clause) {
197
+ this.setFlag(clause, IS_DELETED, true);
198
+ }
199
+
200
+ isReinit(clause: Clause) {
201
+ return (this.data[clause + 1] & IS_REINIT) !== 0;
202
+ }
203
+
204
+ setReinit(clause: Clause, value: boolean) {
205
+ this.setFlag(clause, IS_REINIT, value);
206
+ }
207
+
208
+ isReinternalizeAtoms(clause: Clause) {
209
+ return (this.data[clause + 1] & IS_REINTERNALIZE_ATOMS) !== 0;
210
+ }
211
+
212
+ setReinternalizeAtoms(clause: Clause, value: boolean) {
213
+ this.setFlag(clause, IS_REINTERNALIZE_ATOMS, value);
214
+ }
215
+
216
+ getActivity(clause: Clause) {
217
+ return this.data[this.getExtra(clause)];
218
+ }
219
+
220
+ incActivity(clause: Clause) {
221
+ this.data[this.getExtra(clause)]++;
222
+ }
223
+
224
+ private getSlotAddress(clause: Clause, flag: number) {
225
+ const flags = this.data[clause + 1];
226
+ return (
227
+ this.getExtra(clause) +
228
+ (isLemmaKind((flags >>> KIND_SHIFT) & 3) ? 1 : 0) +
229
+ (flag === HAS_JUSTIFICATION && flags & HAS_DEL_EH ? 1 : 0)
230
+ );
231
+ }
232
+
233
+ getDelEh(clause: Clause) {
234
+ if ((this.data[clause + 1] & HAS_DEL_EH) === 0) return null;
235
+ return this.delEhs[this.data[this.getSlotAddress(clause, HAS_DEL_EH)]];
236
+ }
237
+
238
+ getJustification(clause: Clause) {
239
+ if ((this.data[clause + 1] & HAS_JUSTIFICATION) === 0) return null;
240
+ return this.justifications[this.data[this.getSlotAddress(clause, HAS_JUSTIFICATION)]];
241
+ }
242
+
243
+ private getAtomsAddress(clause: Clause) {
244
+ const flags = this.data[clause + 1];
245
+ if ((flags & HAS_ATOMS) === 0) return -1;
246
+ return this.getSlotAddress(clause, HAS_JUSTIFICATION) + (flags & HAS_JUSTIFICATION ? 1 : 0);
247
+ }
248
+
249
+ // The atoms the clause still holds, or none once they are released.
250
+ getAtoms(clause: Clause) {
251
+ const address = this.getAtomsAddress(clause);
252
+ if (address === -1 || this.data[address] === NO_ATOM) return [];
253
+ const atoms: number[] = [];
254
+ for (let index = 0; index < this.data[clause]; index++)
255
+ atoms.push(this.data[address + index] >> 1);
256
+ return atoms;
257
+ }
258
+
259
+ // The sign of the literal of atom i, as the clause was made.
260
+ getAtomSign(clause: Clause, index: number) {
261
+ return (this.data[this.getAtomsAddress(clause) + index] & 1) === 1;
262
+ }
263
+
264
+ // Marks the atoms released, after their references are dropped.
265
+ clearAtoms(clause: Clause) {
266
+ const address = this.getAtomsAddress(clause);
267
+ if (address === -1) return;
268
+ for (let index = 0; index < (this.data[clause + 1] & CAPACITY_MASK); index++)
269
+ this.data[address + index] = NO_ATOM;
270
+ }
271
+ }
272
+
273
+ // A clause is the offset of its block in the ClauseStore.
274
+ export type Clause = number;
275
+
276
+ const isLemmaKind = (kind: number) => kind === CLS_LEARNED || kind === CLS_TH_LEMMA;