tla-ts 0.0.9 → 0.0.10-dev.06b481ee0

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 (631) hide show
  1. package/README.md +30 -1
  2. package/dist/compile.cjs +23 -0
  3. package/dist/compile.js +23 -0
  4. package/dist/deciders.cjs +41 -37
  5. package/dist/deciders.js +48 -44
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +122 -12
  8. package/dist/index.d.ts +122 -12
  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 +2746 -410
  15. package/dist/prove.js +2745 -409
  16. package/dist/run.cjs +144 -31
  17. package/dist/run.js +144 -31
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +2 -2
  20. package/dist/transfer.cjs +134 -104
  21. package/dist/transfer.js +134 -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 +56 -60
  26. package/src/bags.ts +128 -110
  27. package/src/builtins.ts +31 -77
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check-failure.ts +118 -0
  30. package/src/check-trace.ts +320 -0
  31. package/src/check.ts +1156 -888
  32. package/src/cli/options.ts +12 -32
  33. package/src/cli/run.ts +0 -2
  34. package/src/cli/runtime-invariants.ts +100 -0
  35. package/src/cli/shared.ts +19 -12
  36. package/src/cli/tlapm.ts +433 -82
  37. package/src/cli/tlc-arguments.ts +652 -0
  38. package/src/cli/tlc-output.ts +701 -0
  39. package/src/cli/tlc-usage.ts +360 -0
  40. package/src/cli/tlc.ts +330 -659
  41. package/src/cli/typescript.ts +23 -0
  42. package/src/cli/xml-exporter.ts +27 -49
  43. package/src/cli.ts +0 -1
  44. package/src/codegen.ts +217 -82
  45. package/src/config.ts +140 -109
  46. package/src/coverage.ts +1019 -0
  47. package/src/dependencies.ts +101 -66
  48. package/src/dfid.ts +683 -0
  49. package/src/environment-config.ts +315 -0
  50. package/src/environment.ts +263 -370
  51. package/src/errors.ts +107 -57
  52. package/src/evaluate.ts +898 -369
  53. package/src/exit-codes.ts +63 -13
  54. package/src/fingerprints.ts +75 -11
  55. package/src/index.ts +3 -0
  56. package/src/instances.ts +137 -22
  57. package/src/java-hash.ts +21 -0
  58. package/src/java-overrides.ts +6 -21
  59. package/src/json-reader.ts +455 -0
  60. package/src/json.ts +252 -139
  61. package/src/levels.ts +231 -154
  62. package/src/lexer.ts +83 -101
  63. package/src/liveness-checker.ts +743 -322
  64. package/src/liveness.ts +230 -133
  65. package/src/obligations/action.ts +17 -44
  66. package/src/obligations/anonymize.ts +120 -95
  67. package/src/obligations/enabled-axioms.ts +218 -0
  68. package/src/obligations/equality.ts +1 -3
  69. package/src/obligations/expression.ts +37 -26
  70. package/src/obligations/format.ts +0 -10
  71. package/src/obligations/generate.ts +66 -64
  72. package/src/obligations/index.ts +39 -20
  73. package/src/obligations/levels.ts +27 -18
  74. package/src/obligations/module.ts +28 -55
  75. package/src/obligations/normalize.ts +31 -41
  76. package/src/obligations/operators.ts +0 -3
  77. package/src/obligations/pragma.ts +52 -24
  78. package/src/obligations/printer.ts +94 -63
  79. package/src/obligations/proof.ts +3 -6
  80. package/src/obligations/regroup.ts +0 -5
  81. package/src/obligations/simplify.ts +57 -63
  82. package/src/obligations/source.ts +121 -95
  83. package/src/obligations/subexpression.ts +49 -28
  84. package/src/obligations/substitution.ts +1 -5
  85. package/src/obligations/temporal.ts +12 -20
  86. package/src/obligations/tuples.ts +2 -10
  87. package/src/parallel-worker.ts +36 -60
  88. package/src/parallel.ts +64 -73
  89. package/src/parser.ts +1184 -531
  90. package/src/pcal/ast.ts +53 -86
  91. package/src/pcal/parse.ts +144 -219
  92. package/src/pcal/tokenize.ts +91 -131
  93. package/src/pcal/translate.ts +83 -130
  94. package/src/pcal/validate.ts +48 -68
  95. package/src/pretty-print.ts +7 -8
  96. package/src/prover/decide-pool.ts +8 -13
  97. package/src/prover/deciders.ts +12 -13
  98. package/src/prover/first-order.ts +0 -11
  99. package/src/prover/isabelle/decide.ts +3 -31
  100. package/src/prover/isabelle/encode.ts +82 -64
  101. package/src/prover/isabelle/isar/attrib.ts +250 -0
  102. package/src/prover/isabelle/isar/context.ts +335 -0
  103. package/src/prover/isabelle/isar/induct.ts +382 -0
  104. package/src/prover/isabelle/isar/inner-syntax.ts +262 -117
  105. package/src/prover/isabelle/isar/method.ts +510 -226
  106. package/src/prover/isabelle/isar/proof.ts +570 -23
  107. package/src/prover/isabelle/isar/rule-cases.ts +226 -0
  108. package/src/prover/isabelle/isar/theory.ts +488 -88
  109. package/src/prover/isabelle/isar/toplevel.ts +331 -0
  110. package/src/prover/isabelle/isar/type-check.ts +99 -38
  111. package/src/prover/isabelle/provers/blast/blast.ts +16 -105
  112. package/src/prover/isabelle/provers/blast/branch.ts +0 -33
  113. package/src/prover/isabelle/provers/blast/prove.ts +0 -36
  114. package/src/prover/isabelle/provers/blast/rules.ts +5 -45
  115. package/src/prover/isabelle/provers/blast/state.ts +1 -29
  116. package/src/prover/isabelle/provers/blast/term.ts +8 -37
  117. package/src/prover/isabelle/provers/clasimp.ts +1 -15
  118. package/src/prover/isabelle/provers/classical.ts +58 -61
  119. package/src/prover/isabelle/provers/hypsubst.ts +29 -54
  120. package/src/prover/isabelle/pure/bicompose.ts +24 -39
  121. package/src/prover/isabelle/pure/consts.ts +0 -8
  122. package/src/prover/isabelle/pure/conv.ts +2 -18
  123. package/src/prover/isabelle/pure/drule.ts +95 -45
  124. package/src/prover/isabelle/pure/envir.ts +2 -53
  125. package/src/prover/isabelle/pure/goal.ts +1 -9
  126. package/src/prover/isabelle/pure/interrupt.ts +0 -5
  127. package/src/prover/isabelle/pure/list.ts +0 -3
  128. package/src/prover/isabelle/pure/logic.ts +1 -16
  129. package/src/prover/isabelle/pure/name.ts +1 -10
  130. package/src/prover/isabelle/pure/net.ts +2 -60
  131. package/src/prover/isabelle/pure/object-logic.ts +15 -16
  132. package/src/prover/isabelle/pure/pattern.ts +1 -20
  133. package/src/prover/isabelle/pure/raw-simplifier.ts +16 -63
  134. package/src/prover/isabelle/pure/rewriter.ts +34 -77
  135. package/src/prover/isabelle/pure/search.ts +2 -11
  136. package/src/prover/isabelle/pure/seq.ts +0 -11
  137. package/src/prover/isabelle/pure/simplifier.ts +27 -16
  138. package/src/prover/isabelle/pure/table.ts +2 -33
  139. package/src/prover/isabelle/pure/tactic.ts +11 -23
  140. package/src/prover/isabelle/pure/tactical.ts +47 -48
  141. package/src/prover/isabelle/pure/term-ord.ts +1 -7
  142. package/src/prover/isabelle/pure/term.ts +4 -47
  143. package/src/prover/isabelle/pure/thm.ts +26 -48
  144. package/src/prover/isabelle/pure/type.ts +1 -16
  145. package/src/prover/isabelle/pure/unify.ts +19 -31
  146. package/src/prover/isabelle/pure/variable.ts +2 -8
  147. package/src/prover/isabelle/tla/classical-setup.ts +17 -25
  148. package/src/prover/isabelle/tla/context.ts +65 -26
  149. package/src/prover/isabelle/tla/logic-data.ts +1 -1
  150. package/src/prover/isabelle/tla/logic.ts +53 -32
  151. package/src/prover/isabelle/tla/simpdata.ts +45 -44
  152. package/src/prover/isabelle/tools/intuitionistic.ts +28 -21
  153. package/src/prover/ocaml.ts +4 -7
  154. package/src/prover/prep/action.ts +33 -66
  155. package/src/prover/prep/enabled-axioms.ts +22 -20
  156. package/src/prover/prep/fingerprint.ts +2 -21
  157. package/src/prover/prep/level-comparison.ts +8 -12
  158. package/src/prover/prep/md5.ts +26 -31
  159. package/src/prover/prep/methods.ts +189 -86
  160. package/src/prover/prep/normalize.ts +42 -37
  161. package/src/prover/prove-worker.ts +0 -2
  162. package/src/prover/prove.ts +398 -133
  163. package/src/prover/ptl/decide.ts +96 -56
  164. package/src/prover/ptl/encode.ts +15 -38
  165. package/src/prover/ptl/sat.ts +24 -32
  166. package/src/prover/ptl/tableau.ts +40 -28
  167. package/src/prover/smt/arithmetic.ts +310 -0
  168. package/src/prover/smt/axioms.ts +12 -15
  169. package/src/prover/smt/context.ts +60 -32
  170. package/src/prover/smt/data.ts +517 -401
  171. package/src/prover/smt/encode.ts +155 -85
  172. package/src/prover/smt/extensionality.ts +5 -13
  173. package/src/prover/smt/flatten.ts +7 -28
  174. package/src/prover/smt/format.ts +33 -14
  175. package/src/prover/smt/instances.ts +7 -11
  176. package/src/prover/smt/layout.ts +91 -0
  177. package/src/prover/smt/rewrite.ts +1021 -658
  178. package/src/prover/smt/simplify.ts +441 -0
  179. package/src/prover/smt/solver/ackermannize-bv-tactic.ts +61 -0
  180. package/src/prover/smt/solver/ackr-helper.ts +179 -0
  181. package/src/prover/smt/solver/ackr-model-converter.ts +105 -0
  182. package/src/prover/smt/solver/act-cache.ts +0 -16
  183. package/src/prover/smt/solver/add-bounds-tactic.ts +59 -0
  184. package/src/prover/smt/solver/aig-tactic.ts +52 -0
  185. package/src/prover/smt/solver/aig.ts +889 -0
  186. package/src/prover/smt/solver/arith-rewriter.ts +626 -56
  187. package/src/prover/smt/solver/arith-terms.ts +121 -0
  188. package/src/prover/smt/solver/array-decl-plugin.ts +175 -0
  189. package/src/prover/smt/solver/array-rewriter.ts +319 -0
  190. package/src/prover/smt/solver/array.ts +1 -3
  191. package/src/prover/smt/solver/asserted-formulas.ts +241 -99
  192. package/src/prover/smt/solver/ast-lt.ts +165 -21
  193. package/src/prover/smt/solver/ast-util.ts +160 -7
  194. package/src/prover/smt/solver/ast.ts +1480 -184
  195. package/src/prover/smt/solver/auf-solver.ts +30 -56
  196. package/src/prover/smt/solver/bit-blast-tactic.ts +608 -0
  197. package/src/prover/smt/solver/bit-blaster.ts +871 -0
  198. package/src/prover/smt/solver/blast-term-ite.ts +47 -0
  199. package/src/prover/smt/solver/bound-manager.ts +196 -0
  200. package/src/prover/smt/solver/bound-simplifier.ts +598 -0
  201. package/src/prover/smt/solver/bv-bound-chk.ts +492 -0
  202. package/src/prover/smt/solver/bv-decl-plugin.ts +341 -0
  203. package/src/prover/smt/solver/bv-divrem-bounds.ts +95 -0
  204. package/src/prover/smt/solver/bv-rewriter.ts +1901 -0
  205. package/src/prover/smt/solver/bv1-blast.ts +214 -0
  206. package/src/prover/smt/solver/bv2fpa-converter.ts +174 -0
  207. package/src/prover/smt/solver/bv2int-rewriter.ts +544 -0
  208. package/src/prover/smt/solver/bv2real-rewriter.ts +533 -0
  209. package/src/prover/smt/solver/card2bv.ts +127 -0
  210. package/src/prover/smt/solver/case-split-queue.ts +0 -10
  211. package/src/prover/smt/solver/cg-table.ts +39 -42
  212. package/src/prover/smt/solver/check-logic.ts +330 -0
  213. package/src/prover/smt/solver/clause.ts +0 -27
  214. package/src/prover/smt/solver/cofactor-elim-term-ite.ts +293 -0
  215. package/src/prover/smt/solver/conflict-resolution.ts +78 -11
  216. package/src/prover/smt/solver/context.ts +600 -187
  217. package/src/prover/smt/solver/ctx-simplify.ts +34 -52
  218. package/src/prover/smt/solver/ctx-solver-simplify.ts +122 -0
  219. package/src/prover/smt/solver/datatype-decl-plugin.ts +580 -0
  220. package/src/prover/smt/solver/datatype-rewriter.ts +82 -0
  221. package/src/prover/smt/solver/demodulator.ts +786 -0
  222. package/src/prover/smt/solver/dependent-expr-state.ts +93 -0
  223. package/src/prover/smt/solver/der.ts +39 -30
  224. package/src/prover/smt/solver/diff-neq.ts +205 -0
  225. package/src/prover/smt/solver/distribute-forall.ts +57 -0
  226. package/src/prover/smt/solver/dom-simplify.ts +511 -0
  227. package/src/prover/smt/solver/dt2bv-tactic.ts +296 -0
  228. package/src/prover/smt/solver/dyn-ack.ts +0 -11
  229. package/src/prover/smt/solver/e-matching.ts +9 -41
  230. package/src/prover/smt/solver/elim-bounds.ts +89 -0
  231. package/src/prover/smt/solver/elim-small-bv-tactic.ts +129 -0
  232. package/src/prover/smt/solver/elim-term-ite-tactic.ts +48 -0
  233. package/src/prover/smt/solver/elim-uncnstr.ts +542 -0
  234. package/src/prover/smt/solver/enode.ts +100 -23
  235. package/src/prover/smt/solver/eq2bv-tactic.ts +218 -0
  236. package/src/prover/smt/solver/euf/arith-axioms.ts +403 -0
  237. package/src/prover/smt/solver/euf/arith-internalize.ts +653 -0
  238. package/src/prover/smt/solver/euf/arith-solver.ts +889 -0
  239. package/src/prover/smt/solver/euf/array-axioms.ts +527 -0
  240. package/src/prover/smt/solver/euf/array-internalize.ts +428 -0
  241. package/src/prover/smt/solver/euf/array-solver.ts +306 -0
  242. package/src/prover/smt/solver/euf/bv-ackerman.ts +162 -0
  243. package/src/prover/smt/solver/euf/bv-internalize.ts +748 -0
  244. package/src/prover/smt/solver/euf/bv-solver.ts +449 -0
  245. package/src/prover/smt/solver/euf/dt-solver.ts +618 -0
  246. package/src/prover/smt/solver/euf/egraph.ts +901 -0
  247. package/src/prover/smt/solver/euf/euf-solver.ts +1204 -0
  248. package/src/prover/smt/solver/euf/fpa-solver.ts +317 -0
  249. package/src/prover/smt/solver/euf/mam.ts +1046 -0
  250. package/src/prover/smt/solver/euf/q-ematch.ts +829 -0
  251. package/src/prover/smt/solver/euf/q-mbi.ts +587 -0
  252. package/src/prover/smt/solver/euf/q-model-fixer.ts +296 -0
  253. package/src/prover/smt/solver/euf/q-solver.ts +361 -0
  254. package/src/prover/smt/solver/euf/th-solver.ts +328 -0
  255. package/src/prover/smt/solver/euf/th-solvers.ts +30 -0
  256. package/src/prover/smt/solver/expr-ref.ts +0 -5
  257. package/src/prover/smt/solver/expr-safe-replace.ts +26 -7
  258. package/src/prover/smt/solver/expr2polynomial.ts +271 -0
  259. package/src/prover/smt/solver/factor.ts +163 -0
  260. package/src/prover/smt/solver/fd-solver.ts +734 -0
  261. package/src/prover/smt/solver/fingerprints.ts +15 -26
  262. package/src/prover/smt/solver/fix-dl-var.ts +147 -0
  263. package/src/prover/smt/solver/flat-literals.ts +0 -9
  264. package/src/prover/smt/solver/fm-tactic.ts +884 -0
  265. package/src/prover/smt/solver/fpa-decl-plugin.ts +618 -0
  266. package/src/prover/smt/solver/fpa-rewriter.ts +639 -0
  267. package/src/prover/smt/solver/fpa2bv-converter.ts +2251 -0
  268. package/src/prover/smt/solver/fpa2bv-rewriter.ts +349 -0
  269. package/src/prover/smt/solver/fpa2bv-tactic.ts +73 -0
  270. package/src/prover/smt/solver/goal.ts +179 -28
  271. package/src/prover/smt/solver/goal2nlsat.ts +216 -0
  272. package/src/prover/smt/solver/guard-set.ts +219 -0
  273. package/src/prover/smt/solver/hash.ts +0 -9
  274. package/src/prover/smt/solver/hashtable.ts +30 -23
  275. package/src/prover/smt/solver/inf-eps.ts +63 -0
  276. package/src/prover/smt/solver/inj-axiom.ts +101 -0
  277. package/src/prover/smt/solver/internalizer.ts +113 -133
  278. package/src/prover/smt/solver/lackr.ts +381 -0
  279. package/src/prover/smt/solver/lbool.ts +0 -2
  280. package/src/prover/smt/solver/lia2card.ts +268 -0
  281. package/src/prover/smt/solver/lia2pb.ts +154 -0
  282. package/src/prover/smt/solver/literal.ts +0 -4
  283. package/src/prover/smt/solver/logic-tactics.ts +355 -0
  284. package/src/prover/smt/solver/lp/bound-propagator.ts +7 -26
  285. package/src/prover/smt/solver/lp/constraints.ts +1 -8
  286. package/src/prover/smt/solver/lp/containers.ts +18 -31
  287. package/src/prover/smt/solver/lp/core-solver.ts +35 -37
  288. package/src/prover/smt/solver/lp/cross-nested.ts +4 -21
  289. package/src/prover/smt/solver/lp/dep-intervals.ts +6 -24
  290. package/src/prover/smt/solver/lp/dependency.ts +0 -5
  291. package/src/prover/smt/solver/lp/dioph-eq.ts +8 -103
  292. package/src/prover/smt/solver/lp/explanation.ts +0 -6
  293. package/src/prover/smt/solver/lp/gomory.ts +8 -22
  294. package/src/prover/smt/solver/lp/hnf-cutter.ts +16 -23
  295. package/src/prover/smt/solver/lp/hnf.ts +10 -28
  296. package/src/prover/smt/solver/lp/int-cube.ts +17 -39
  297. package/src/prover/smt/solver/lp/int-solver.ts +3 -35
  298. package/src/prover/smt/solver/lp/lar-solver.ts +70 -83
  299. package/src/prover/smt/solver/lp/lar-term.ts +0 -5
  300. package/src/prover/smt/solver/lp/lp-settings.ts +6 -16
  301. package/src/prover/smt/solver/lp/maximize-term.ts +76 -52
  302. package/src/prover/smt/solver/lp/nex-creator.ts +7 -30
  303. package/src/prover/smt/solver/lp/nex.ts +2 -7
  304. package/src/prover/smt/solver/lp/nla-backoff.ts +0 -5
  305. package/src/prover/smt/solver/lp/nla-basics.ts +48 -30
  306. package/src/prover/smt/solver/lp/nla-core.ts +92 -136
  307. package/src/prover/smt/solver/lp/nla-divisions.ts +31 -43
  308. package/src/prover/smt/solver/lp/nla-emonics.ts +3 -21
  309. package/src/prover/smt/solver/lp/nla-factorization.ts +0 -4
  310. package/src/prover/smt/solver/lp/nla-grobner.ts +177 -149
  311. package/src/prover/smt/solver/lp/nla-horner.ts +2 -12
  312. package/src/prover/smt/solver/lp/nla-intervals.ts +1 -12
  313. package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +15 -42
  314. package/src/prover/smt/solver/lp/nla-monotone.ts +1 -6
  315. package/src/prover/smt/solver/lp/nla-order.ts +0 -13
  316. package/src/prover/smt/solver/lp/nla-patcher.ts +3 -7
  317. package/src/prover/smt/solver/lp/nla-powers.ts +220 -0
  318. package/src/prover/smt/solver/lp/nla-tangents.ts +0 -10
  319. package/src/prover/smt/solver/lp/nla-throttle.ts +0 -6
  320. package/src/prover/smt/solver/lp/nla-transcendentals.ts +324 -0
  321. package/src/prover/smt/solver/lp/nla-types.ts +0 -12
  322. package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -26
  323. package/src/prover/smt/solver/lp/nra-solver.ts +164 -147
  324. package/src/prover/smt/solver/lp/numeric-pair.ts +0 -4
  325. package/src/prover/smt/solver/lp/pdd-interval.ts +6 -5
  326. package/src/prover/smt/solver/lp/pdd-simplifier.ts +61 -34
  327. package/src/prover/smt/solver/lp/pdd-solver.ts +74 -72
  328. package/src/prover/smt/solver/lp/pdd.ts +730 -358
  329. package/src/prover/smt/solver/lp/random-updater.ts +0 -9
  330. package/src/prover/smt/solver/lp/static-matrix.ts +8 -19
  331. package/src/prover/smt/solver/lp/union-find.ts +5 -5
  332. package/src/prover/smt/solver/macro-finder.ts +530 -0
  333. package/src/prover/smt/solver/mam-compiler.ts +129 -139
  334. package/src/prover/smt/solver/mam-interpreter.ts +0 -21
  335. package/src/prover/smt/solver/max-bv-sharing-tactic.ts +17 -0
  336. package/src/prover/smt/solver/max-cliques.ts +105 -0
  337. package/src/prover/smt/solver/maxcore.ts +310 -0
  338. package/src/prover/smt/solver/maximize-ac-sharing.ts +8 -21
  339. package/src/prover/smt/solver/maxlex.ts +115 -0
  340. package/src/prover/smt/solver/maxsmt-base.ts +106 -0
  341. package/src/prover/smt/solver/maxsmt.ts +92 -0
  342. package/src/prover/smt/solver/mbp/mbp-arith.ts +467 -0
  343. package/src/prover/smt/solver/mbp/mbp-basic-tg.ts +101 -0
  344. package/src/prover/smt/solver/mbp/mbp-plugin.ts +287 -0
  345. package/src/prover/smt/solver/mbp/mbp-qel.ts +48 -0
  346. package/src/prover/smt/solver/mbp/mbp-solve-plugin.ts +271 -0
  347. package/src/prover/smt/solver/mbp/mbp-term-graph.ts +606 -0
  348. package/src/prover/smt/solver/model-based-opt.ts +844 -0
  349. package/src/prover/smt/solver/model-checker.ts +20 -63
  350. package/src/prover/smt/solver/model-evaluator.ts +192 -40
  351. package/src/prover/smt/solver/model-finder.ts +14 -32
  352. package/src/prover/smt/solver/model-generator.ts +104 -46
  353. package/src/prover/smt/solver/model-macro-solver.ts +60 -114
  354. package/src/prover/smt/solver/model-printer.ts +214 -0
  355. package/src/prover/smt/solver/mpf.ts +709 -0
  356. package/src/prover/smt/solver/mus.ts +50 -0
  357. package/src/prover/smt/solver/muz/dl-context.ts +382 -0
  358. package/src/prover/smt/solver/muz/dl-mk-bit-blast.ts +97 -0
  359. package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +167 -0
  360. package/src/prover/smt/solver/muz/dl-mk-elim-term-ite.ts +125 -0
  361. package/src/prover/smt/solver/muz/dl-mk-interp-tail-simplifier.ts +299 -0
  362. package/src/prover/smt/solver/muz/dl-mk-rule-inliner.ts +455 -0
  363. package/src/prover/smt/solver/muz/dl-mk-slice.ts +340 -0
  364. package/src/prover/smt/solver/muz/dl-mk-subsumption-checker.ts +163 -0
  365. package/src/prover/smt/solver/muz/dl-rule-set.ts +273 -0
  366. package/src/prover/smt/solver/muz/dl-rule-transformer.ts +123 -0
  367. package/src/prover/smt/solver/muz/dl-rule.ts +495 -0
  368. package/src/prover/smt/solver/muz/hnf.ts +201 -0
  369. package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +176 -0
  370. package/src/prover/smt/solver/muz/horn-tactic.ts +214 -0
  371. package/src/prover/smt/solver/muz/rule-properties.ts +359 -0
  372. package/src/prover/smt/solver/muz/spacer-context.ts +1404 -0
  373. package/src/prover/smt/solver/muz/spacer-dl-interface.ts +52 -0
  374. package/src/prover/smt/solver/muz/spacer-generalizers.ts +241 -0
  375. package/src/prover/smt/solver/muz/spacer-manager.ts +127 -0
  376. package/src/prover/smt/solver/muz/spacer-pdr.ts +219 -0
  377. package/src/prover/smt/solver/muz/spacer-prop-solver.ts +333 -0
  378. package/src/prover/smt/solver/muz/spacer-util.ts +282 -0
  379. package/src/prover/smt/solver/muz/substitution.ts +203 -0
  380. package/src/prover/smt/solver/nla2bv-tactic.ts +285 -0
  381. package/src/prover/smt/solver/nlqsat.ts +484 -0
  382. package/src/prover/smt/solver/nlsat/algebraic.ts +357 -236
  383. package/src/prover/smt/solver/nlsat/atoms.ts +73 -54
  384. package/src/prover/smt/solver/nlsat/evaluator.ts +16 -22
  385. package/src/prover/smt/solver/nlsat/explain.ts +429 -275
  386. package/src/prover/smt/solver/nlsat/interval-set.ts +9 -51
  387. package/src/prover/smt/solver/nlsat/levelwise.ts +477 -344
  388. package/src/prover/smt/solver/nlsat/mpbq.ts +47 -14
  389. package/src/prover/smt/solver/nlsat/polynomial.ts +2385 -832
  390. package/src/prover/smt/solver/nlsat/solver.ts +297 -156
  391. package/src/prover/smt/solver/nlsat/transcendental-eval.ts +310 -0
  392. package/src/prover/smt/solver/nlsat/transcendentals.ts +391 -0
  393. package/src/prover/smt/solver/nlsat/types.ts +0 -9
  394. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +9 -51
  395. package/src/prover/smt/solver/nlsat/upolynomial.ts +49 -109
  396. package/src/prover/smt/solver/nlsat-tactic.ts +82 -0
  397. package/src/prover/smt/solver/nnf.ts +112 -61
  398. package/src/prover/smt/solver/normalize-bounds.ts +53 -0
  399. package/src/prover/smt/solver/occf.ts +97 -0
  400. package/src/prover/smt/solver/opt-context.ts +801 -0
  401. package/src/prover/smt/solver/opt-nlsat.ts +386 -0
  402. package/src/prover/smt/solver/opt-pareto.ts +301 -0
  403. package/src/prover/smt/solver/opt-preprocess.ts +101 -0
  404. package/src/prover/smt/solver/opt-solver.ts +312 -0
  405. package/src/prover/smt/solver/opt-value.ts +55 -0
  406. package/src/prover/smt/solver/optsmt.ts +692 -0
  407. package/src/prover/smt/solver/parallel-tactic.ts +299 -0
  408. package/src/prover/smt/solver/pattern-inference.ts +21 -26
  409. package/src/prover/smt/solver/pb-rewriter.ts +281 -0
  410. package/src/prover/smt/solver/pb2bv-tactic.ts +540 -0
  411. package/src/prover/smt/solver/poly-rewriter.ts +261 -79
  412. package/src/prover/smt/solver/probes.ts +577 -0
  413. package/src/prover/smt/solver/propagate-values.ts +37 -30
  414. package/src/prover/smt/solver/proto-model.ts +650 -66
  415. package/src/prover/smt/solver/pull-quant.ts +28 -23
  416. package/src/prover/smt/solver/purify-arith.ts +632 -0
  417. package/src/prover/smt/solver/push-app-ite.ts +37 -0
  418. package/src/prover/smt/solver/qe-arith-plugin.ts +1096 -0
  419. package/src/prover/smt/solver/qe-lite-der.ts +2 -31
  420. package/src/prover/smt/solver/qe-lite-fm.ts +4 -28
  421. package/src/prover/smt/solver/qe-lite.ts +41 -51
  422. package/src/prover/smt/solver/qe-mbp.ts +270 -0
  423. package/src/prover/smt/solver/qe.ts +1499 -0
  424. package/src/prover/smt/solver/qel.ts +25 -0
  425. package/src/prover/smt/solver/qi-queue.ts +0 -16
  426. package/src/prover/smt/solver/qsat.ts +829 -0
  427. package/src/prover/smt/solver/quant-hoist.ts +196 -0
  428. package/src/prover/smt/solver/quant-tactics.ts +17 -74
  429. package/src/prover/smt/solver/quantifier-analyzer.ts +26 -47
  430. package/src/prover/smt/solver/quantifier-manager.ts +22 -32
  431. package/src/prover/smt/solver/quasi-macros.ts +243 -0
  432. package/src/prover/smt/solver/random-gen.ts +0 -2
  433. package/src/prover/smt/solver/rational.ts +45 -8
  434. package/src/prover/smt/solver/recfun-decl-plugin.ts +262 -0
  435. package/src/prover/smt/solver/recfun-rewriter.ts +107 -0
  436. package/src/prover/smt/solver/reduce-args.ts +225 -0
  437. package/src/prover/smt/solver/reduce-bv-size.ts +119 -0
  438. package/src/prover/smt/solver/ref-vector.ts +0 -6
  439. package/src/prover/smt/solver/relevancy.ts +2 -16
  440. package/src/prover/smt/solver/rewriter-tpl.ts +59 -135
  441. package/src/prover/smt/solver/rewriter.ts +507 -144
  442. package/src/prover/smt/solver/rlimit.ts +46 -24
  443. package/src/prover/smt/solver/sat/asymm-branch.ts +325 -0
  444. package/src/prover/smt/solver/sat/big.ts +177 -0
  445. package/src/prover/smt/solver/sat/clause-use-list.ts +71 -0
  446. package/src/prover/smt/solver/sat/clause.ts +203 -0
  447. package/src/prover/smt/solver/sat/cleaner.ts +94 -0
  448. package/src/prover/smt/solver/sat/config.ts +122 -0
  449. package/src/prover/smt/solver/sat/consequences.ts +203 -0
  450. package/src/prover/smt/solver/sat/elim-eqs.ts +142 -0
  451. package/src/prover/smt/solver/sat/goal2sat.ts +579 -0
  452. package/src/prover/smt/solver/sat/inc-sat-solver.ts +464 -0
  453. package/src/prover/smt/solver/sat/model-converter.ts +136 -0
  454. package/src/prover/smt/solver/sat/pb-constraint.ts +268 -0
  455. package/src/prover/smt/solver/sat/pb-solver.ts +1596 -0
  456. package/src/prover/smt/solver/sat/probing.ts +170 -0
  457. package/src/prover/smt/solver/sat/sat-tactic.ts +53 -0
  458. package/src/prover/smt/solver/sat/sat2goal.ts +189 -0
  459. package/src/prover/smt/solver/sat/scc.ts +142 -0
  460. package/src/prover/smt/solver/sat/simplifier.ts +1618 -0
  461. package/src/prover/smt/solver/sat/solver.ts +2107 -0
  462. package/src/prover/smt/solver/sat/var-queue.ts +117 -0
  463. package/src/prover/smt/solver/sat/watch-list.ts +140 -0
  464. package/src/prover/smt/solver/search-tree.ts +284 -0
  465. package/src/prover/smt/solver/seq-axioms.ts +995 -0
  466. package/src/prover/smt/solver/seq-decl-plugin.ts +819 -0
  467. package/src/prover/smt/solver/seq-derive.ts +1298 -0
  468. package/src/prover/smt/solver/seq-eq-approx.ts +236 -0
  469. package/src/prover/smt/solver/seq-eq-solver.ts +439 -0
  470. package/src/prover/smt/solver/seq-factory.ts +89 -0
  471. package/src/prover/smt/solver/seq-monadic.ts +730 -0
  472. package/src/prover/smt/solver/seq-range-predicate.ts +235 -0
  473. package/src/prover/smt/solver/seq-re-rewriter.ts +1171 -0
  474. package/src/prover/smt/solver/seq-re-util.ts +758 -0
  475. package/src/prover/smt/solver/seq-regex-bisim.ts +144 -0
  476. package/src/prover/smt/solver/seq-regex-live.ts +200 -0
  477. package/src/prover/smt/solver/seq-rewriter.ts +2404 -0
  478. package/src/prover/smt/solver/seq-skolem.ts +294 -0
  479. package/src/prover/smt/solver/seq-subset.ts +165 -0
  480. package/src/prover/smt/solver/seq-view-witness.ts +353 -0
  481. package/src/prover/smt/solver/smt-consequences.ts +297 -0
  482. package/src/prover/smt/solver/smt-kernel.ts +124 -0
  483. package/src/prover/smt/solver/smt-logics.ts +66 -0
  484. package/src/prover/smt/solver/smt-setup.ts +589 -0
  485. package/src/prover/smt/solver/smt2-printer.ts +765 -0
  486. package/src/prover/smt/solver/smtlib-parser.ts +3546 -406
  487. package/src/prover/smt/solver/smtlib-script.ts +2134 -0
  488. package/src/prover/smt/solver/solve-eqs.ts +928 -0
  489. package/src/prover/smt/solver/solver.ts +135 -40
  490. package/src/prover/smt/solver/sort.ts +1 -5
  491. package/src/prover/smt/solver/static-features.ts +314 -0
  492. package/src/prover/smt/solver/sticky-generations.ts +0 -6
  493. package/src/prover/smt/solver/tactic.ts +2141 -0
  494. package/src/prover/smt/solver/term-enumeration.ts +205 -0
  495. package/src/prover/smt/solver/theory-array.ts +1240 -0
  496. package/src/prover/smt/solver/theory-bv.ts +1210 -0
  497. package/src/prover/smt/solver/theory-char.ts +355 -0
  498. package/src/prover/smt/solver/theory-datatype.ts +598 -0
  499. package/src/prover/smt/solver/theory-finite-set.ts +30 -0
  500. package/src/prover/smt/solver/theory-fpa.ts +389 -0
  501. package/src/prover/smt/solver/theory-lra-axioms.ts +55 -25
  502. package/src/prover/smt/solver/theory-lra-bounds.ts +31 -11
  503. package/src/prover/smt/solver/theory-lra-final-check.ts +60 -91
  504. package/src/prover/smt/solver/theory-lra-internalize.ts +96 -53
  505. package/src/prover/smt/solver/theory-lra-model.ts +23 -53
  506. package/src/prover/smt/solver/theory-lra-propagate.ts +34 -42
  507. package/src/prover/smt/solver/theory-lra-state.ts +7 -28
  508. package/src/prover/smt/solver/theory-lra.ts +189 -9
  509. package/src/prover/smt/solver/theory-pb.ts +951 -0
  510. package/src/prover/smt/solver/theory-polymorphism.ts +58 -0
  511. package/src/prover/smt/solver/theory-recfun.ts +307 -0
  512. package/src/prover/smt/solver/theory-seq-regex.ts +867 -0
  513. package/src/prover/smt/solver/theory-seq-solve.ts +1373 -0
  514. package/src/prover/smt/solver/theory-seq-state.ts +852 -0
  515. package/src/prover/smt/solver/theory-seq.ts +961 -0
  516. package/src/prover/smt/solver/theory-without-terms.ts +24 -0
  517. package/src/prover/smt/solver/theory.ts +189 -0
  518. package/src/prover/smt/solver/tseitin-cnf.ts +486 -0
  519. package/src/prover/smt/solver/var-subst.ts +37 -39
  520. package/src/prover/smt/table.ts +3 -10
  521. package/src/prover/smt/types.ts +146 -0
  522. package/src/prover/tlapm/cache.ts +74 -48
  523. package/src/prover/tlapm/ocaml-marshal.ts +19 -21
  524. package/src/prover/tlapm/tlapm.ts +21 -20
  525. package/src/prover/tlapm-library.ts +3208 -0
  526. package/src/prover/verdict.ts +9 -2
  527. package/src/prover/zenon/check/check.ts +1 -11
  528. package/src/prover/zenon/check/definitions.ts +5 -15
  529. package/src/prover/zenon/check/equality.ts +0 -8
  530. package/src/prover/zenon/check/functions.ts +0 -4
  531. package/src/prover/zenon/check/keys.ts +0 -7
  532. package/src/prover/zenon/check/propositional.ts +0 -3
  533. package/src/prover/zenon/check/records.ts +1 -6
  534. package/src/prover/zenon/check/relations.ts +2 -14
  535. package/src/prover/zenon/check/rewrites.ts +2 -21
  536. package/src/prover/zenon/check/sets.ts +40 -61
  537. package/src/prover/zenon/check/terms.ts +1 -19
  538. package/src/prover/zenon/check/tla.ts +0 -6
  539. package/src/prover/zenon/decide.ts +10 -19
  540. package/src/prover/zenon/encode.ts +0 -9
  541. package/src/prover/zenon/eqrel.ts +2 -15
  542. package/src/prover/zenon/equality-rules.ts +24 -6
  543. package/src/prover/zenon/expr.ts +29 -28
  544. package/src/prover/zenon/index-table.ts +33 -61
  545. package/src/prover/zenon/isar-case.ts +9 -21
  546. package/src/prover/zenon/isar.ts +37 -67
  547. package/src/prover/zenon/limits.ts +0 -4
  548. package/src/prover/zenon/llproof.ts +2 -22
  549. package/src/prover/zenon/mltoll.ts +66 -106
  550. package/src/prover/zenon/node.ts +20 -15
  551. package/src/prover/zenon/ocaml.ts +1 -17
  552. package/src/prover/zenon/parse.ts +9 -13
  553. package/src/prover/zenon/phrase.ts +2 -14
  554. package/src/prover/zenon/proof.ts +0 -11
  555. package/src/prover/zenon/propositional-rules.ts +0 -7
  556. package/src/prover/zenon/rules.ts +3 -8
  557. package/src/prover/zenon/search.ts +11 -35
  558. package/src/prover/zenon/tla/functions.ts +59 -33
  559. package/src/prover/zenon/tla/llproof.ts +67 -78
  560. package/src/prover/zenon/tla/records.ts +57 -35
  561. package/src/prover/zenon/tla/rewrites.ts +12 -21
  562. package/src/prover/zenon/tla/sets.ts +88 -59
  563. package/src/prover/zenon/tla/terms.ts +0 -8
  564. package/src/prover/zenon/tla/tla.ts +66 -66
  565. package/src/randomization.ts +81 -35
  566. package/src/resolve.ts +1132 -430
  567. package/src/runtime.ts +33 -23
  568. package/src/sany/builtins.ts +11 -14
  569. package/src/sany/generation.ts +383 -0
  570. package/src/sany/generator-def-entries.ts +210 -0
  571. package/src/sany/generator-definitions.ts +688 -0
  572. package/src/sany/generator-expressions.ts +1108 -0
  573. package/src/sany/generator-proofs.ts +665 -0
  574. package/src/sany/generator.ts +192 -2764
  575. package/src/sany/levels.ts +5 -35
  576. package/src/sany/lexer.ts +61 -80
  577. package/src/sany/linter.ts +0 -10
  578. package/src/sany/modules.ts +5 -7
  579. package/src/sany/nodes.ts +6 -44
  580. package/src/sany/parse-error.ts +39 -117
  581. package/src/sany/report.ts +32 -69
  582. package/src/sany/selectors.ts +60 -82
  583. package/src/sany/source.ts +1 -17
  584. package/src/sany/xml.ts +37 -120
  585. package/src/search.ts +913 -227
  586. package/src/simulate.ts +765 -0
  587. package/src/spec-description.ts +198 -104
  588. package/src/standard-definitions.ts +4 -4
  589. package/src/standard-modules.ts +302 -99
  590. package/src/state-graph.ts +52 -33
  591. package/src/subexpressions.ts +578 -166
  592. package/src/substitution-levels.ts +7 -7
  593. package/src/successors.ts +299 -108
  594. package/src/symmetry.ts +37 -28
  595. package/src/tableau.ts +29 -26
  596. package/src/tlc/fingerprint.ts +267 -79
  597. package/src/tlc/jar-data.ts +122 -6
  598. package/src/tlc/messages.ts +127 -56
  599. package/src/tlc/order.ts +53 -72
  600. package/src/tlc/random.ts +38 -49
  601. package/src/tlc/replay.ts +579 -230
  602. package/src/tlc/summary.ts +64 -60
  603. package/src/tlc/tlc-operators.ts +83 -47
  604. package/src/tlc/tlcext-operators.ts +205 -127
  605. package/src/tlc/trace-spec.ts +235 -0
  606. package/src/tlc/value-stream.ts +139 -0
  607. package/src/tlc/version.ts +1 -4
  608. package/src/trace-liveness.ts +529 -0
  609. package/src/transfer.ts +22 -25
  610. package/src/typed-tier.ts +6556 -0
  611. package/src/typescript/actions.ts +479 -0
  612. package/src/typescript/collections.ts +614 -0
  613. package/src/typescript/compile.ts +63 -0
  614. package/src/typescript/context.ts +94 -0
  615. package/src/typescript/emit.ts +121 -0
  616. package/src/typescript/expressions.ts +496 -0
  617. package/src/typescript/formula.ts +154 -0
  618. package/src/typescript/functions.ts +284 -0
  619. package/src/typescript/model.ts +162 -0
  620. package/src/typescript/names.ts +114 -0
  621. package/src/typescript/program.ts +48 -0
  622. package/src/typescript/properties.ts +139 -0
  623. package/src/typescript/scope.ts +112 -0
  624. package/src/typescript/steps.ts +167 -0
  625. package/src/typescript/types.ts +171 -0
  626. package/src/values.ts +945 -526
  627. package/src/worker.ts +7 -8
  628. package/src/prover/isabelle/isar/statement.ts +0 -57
  629. package/src/prover/smt/solver/z3-license.txt +0 -10
  630. package/src/prover/tlaps-module.ts +0 -510
  631. package/src/prover/zenon/LICENSE +0 -32
@@ -1,13 +1,35 @@
1
- // Ported from Z3 (src/smt/smt_context.cpp), MIT license, see z3-license.txt. The SMT kernel's
2
- // search: a CDCL loop over Boolean variables combined with an E-graph for congruence closure,
3
- // relevancy propagation, the arithmetic theory and quantifier instantiation, with Z3's default
4
- // parameters for UFNIA.
1
+ import { SmtCanceledError, SmtInvariantError } from "../../../errors";
5
2
  import type { AssertedFormulas } from "./asserted-formulas";
6
- import { AstManager, FAMILY_ARITH, KIND_APP, KIND_QUANTIFIER, KIND_VAR } from "./ast";
3
+ import {
4
+ AstManager,
5
+ FAMILY_ARITH,
6
+ FAMILY_ARRAY,
7
+ FAMILY_BASIC,
8
+ FAMILY_BV,
9
+ FAMILY_CHAR,
10
+ FAMILY_DATALOG_RELATION,
11
+ FAMILY_DATATYPE,
12
+ FAMILY_FF,
13
+ FAMILY_FINITE_SET,
14
+ FAMILY_FPA,
15
+ FAMILY_PB,
16
+ FAMILY_POLY,
17
+ FAMILY_RECFUN,
18
+ FAMILY_SEQ,
19
+ FAMILY_SPECIAL_RELATIONS,
20
+ KIND_APP,
21
+ KIND_QUANTIFIER,
22
+ KIND_VAR,
23
+ OP_IMPLIES,
24
+ OP_ITE,
25
+ OP_NOT,
26
+ SORT_BOOL,
27
+ } from "./ast";
7
28
  import { getCongruenceJustification, isCongruent } from "./cg-table";
8
29
  import { BJustification, type Clause, CLS_LEARNED, CLS_TH_LEMMA, HEADER_SIZE } from "./clause";
9
30
  import { ConflictResolution } from "./conflict-resolution";
10
31
  import { DynAckManager } from "./dyn-ack";
32
+ import { FingerprintSet } from "./fingerprints";
11
33
  import {
12
34
  Enode,
13
35
  EqConflictJustification,
@@ -29,119 +51,241 @@ import {
29
51
  UNDO_TH_VAR,
30
52
  } from "./internalizer";
31
53
  import { L_FALSE, L_TRUE, L_UNDEF } from "./lbool";
32
- import { BoolVar, getVar, isNegated, Literal, mkLiteral, negate } from "./literal";
54
+ import { MaxCliques } from "./max-cliques";
55
+ import { BoolVar, getVar, isNegated, Literal, mkLiteral, negate, toBoolVar } from "./literal";
56
+ import type { MacroManager } from "./macro-finder";
33
57
  import { mkModel } from "./model-generator";
58
+ import { TheoryRecfun } from "./theory-recfun";
34
59
  import type { GeneratedModel } from "./model-generator";
35
60
  import type { ProtoModel } from "./proto-model";
36
61
  import { DefaultQuantifierManager } from "./quantifier-manager";
62
+ import { FC_CONTINUE, FC_DONE, FC_GIVEUP, Theory } from "./theory";
63
+ import { TheoryArray } from "./theory-array";
64
+ import { TheoryBv } from "./theory-bv";
65
+ import { TheoryFpa } from "./theory-fpa";
66
+ import { TheoryChar } from "./theory-char";
67
+ import { TheorySeq } from "./theory-seq";
68
+ import { TheoryDatatype } from "./theory-datatype";
69
+ import { TheoryFiniteSet } from "./theory-finite-set";
70
+ import { TheoryPb } from "./theory-pb";
71
+ import { TheoryPolymorphism } from "./theory-polymorphism";
72
+ import { TheoryWithoutTerms } from "./theory-without-terms";
37
73
  import { TheoryLra } from "./theory-lra";
38
74
  import { shrink } from "./array";
39
-
40
- export const FC_DONE = 0;
41
- export const FC_CONTINUE = 1;
42
- export const FC_GIVEUP = 2;
75
+ import {
76
+ DEFAULT_CONFIG,
77
+ getSmtConfig,
78
+ PS_ALWAYS_FALSE,
79
+ PS_CACHING_CONSERVATIVE,
80
+ PS_CACHING_CONSERVATIVE2,
81
+ PS_THEORY,
82
+ RS_GEOMETRIC,
83
+ RS_LUBY,
84
+ type SmtSetup,
85
+ } from "./smt-setup";
86
+ import type { KernelParams } from "./solver";
43
87
 
44
88
  const ACTIVITY_LIMIT = 1e100;
45
89
  const INV_ACTIVITY_LIMIT = 1e-100;
46
90
  const INV_DECAY = 1.052;
47
91
  const RESTART_INITIAL = 100;
48
- const RESTART_FACTOR = 1.1;
49
- // phase_caching_on and phase_caching_off: the numbers of conflicts while phase caching is on and off.
50
92
  const PHASE_CACHING_ON = 400;
51
93
  const PHASE_CACHING_OFF = 100;
52
94
  const AGILITY_FACTOR = 0.9999;
53
- // The LGC_FIXED lemma garbage collection: lemma_gc_initial conflicts between collections, and the
54
- // activity and unassigned literal thresholds of del_inactive_lemmas2.
55
95
  const LEMMA_GC_INITIAL = 5000;
56
- // theory_lra::num_final_check_levels: level 2 also runs nlsat's full check.
57
- const NUM_ARITH_FINAL_CHECK_LEVELS = 2;
58
96
  const NEW_OLD_RATIO = 16;
59
97
  const OLD_CLAUSE_ACTIVITY = 500;
60
98
  const NEW_CLAUSE_RELEVANCY = 45;
61
99
  const OLD_CLAUSE_RELEVANCY = 6;
62
100
  const RESTART_AGILITY_THRESHOLD = 0.18;
63
101
 
102
+ export const MBQI_MAX_ITERATIONS = 1000;
103
+
64
104
  export const CHECK_MODEL_SAT = 0;
65
105
  export const CHECK_MODEL_UNKNOWN = 1;
66
106
  export const CHECK_MODEL_RESTART = 2;
67
107
 
68
- // The reasons a search may stop without an answer that MBQI cares about.
69
108
  const FAILURE_OK = 0;
70
109
  const FAILURE_THEORY = 1;
71
110
  const FAILURE_QUANTIFIERS = 2;
72
111
  const FAILURE_CANCELED = 3;
112
+ const FAILURE_NUM_CONFLICTS = 4;
73
113
 
74
114
  type SearchFailure =
75
115
  | typeof FAILURE_OK
76
116
  | typeof FAILURE_THEORY
77
117
  | typeof FAILURE_QUANTIFIERS
78
- | typeof FAILURE_CANCELED;
79
-
80
- // smt_params: the kernel runs model-based quantifier instantiation with relevancy level 2 and the
81
- // CS_ACTIVITY_DELAY_NEW case split queue. The model checker's auxiliary context runs neither, as Z3
82
- // sets its relevancy level to 0 and its case split strategy to CS_ACTIVITY.
83
- // m_model_generator's model, m_proto_model and m_model. The model generator holds the last model it
84
- // made. From mk_proto_model to reset_model the context holds that model too as its proto model, and
85
- // get_model adds the model the proto model makes.
118
+ | typeof FAILURE_CANCELED
119
+ | typeof FAILURE_NUM_CONFLICTS;
120
+
86
121
  type ModelState =
87
122
  | { kind: "none" }
88
123
  | { kind: "generated"; generated: GeneratedModel }
89
124
  | { kind: "proto"; generated: GeneratedModel }
90
125
  | { kind: "final"; generated: GeneratedModel; model: ProtoModel };
91
126
 
92
- interface SmtParams {
127
+ const THEORY_MAKERS = new Map<number, (context: Context) => Theory>([
128
+ [FAMILY_ARITH, (context) => new TheoryLra(context)],
129
+ [FAMILY_ARRAY, (context) => new TheoryArray(context)],
130
+ [FAMILY_BV, (context) => new TheoryBv(context)],
131
+ [FAMILY_DATATYPE, (context) => new TheoryDatatype(context)],
132
+ [FAMILY_RECFUN, (context) => new TheoryRecfun(context)],
133
+ [FAMILY_SEQ, (context) => new TheorySeq(context)],
134
+ [FAMILY_CHAR, (context) => new TheoryChar(context)],
135
+ [FAMILY_FPA, (context) => new TheoryFpa(context)],
136
+ [FAMILY_FINITE_SET, (context) => new TheoryFiniteSet(context)],
137
+ [FAMILY_POLY, (context) => new TheoryPolymorphism(context)],
138
+ [FAMILY_PB, (context) => new TheoryPb(context)],
139
+ [
140
+ FAMILY_DATALOG_RELATION,
141
+ (context) => new TheoryWithoutTerms(context, FAMILY_DATALOG_RELATION, "datalog"),
142
+ ],
143
+ [FAMILY_FF, (context) => new TheoryWithoutTerms(context, FAMILY_FF, "finite-field")],
144
+ [
145
+ FAMILY_SPECIAL_RELATIONS,
146
+ (context) => new TheoryWithoutTerms(context, FAMILY_SPECIAL_RELATIONS, "unknown"),
147
+ ],
148
+ ]);
149
+
150
+ // get_luby
151
+ const getLuby = (index: number): number => {
152
+ if (index === 1) return 1;
153
+ const exponent = Math.log(index + 1) / Math.log(2);
154
+ if (exponent === Math.floor(exponent + 0.5)) return 2 ** (exponent - 1);
155
+ return getLuby(index - 2 ** Math.floor(exponent) + 1);
156
+ };
157
+
158
+ const isValidAssumption = (manager: AstManager, expr: number) => {
159
+ if (manager.sorts[expr] !== SORT_BOOL) return false;
160
+ if (manager.isUninterpretedConst(expr)) return true;
161
+ if (manager.isNot(expr) && manager.isUninterpretedConst(manager.getArg(expr, 0))) return true;
162
+ if (manager.kinds[expr] !== KIND_APP || expr === manager.falseExpr) return false;
163
+ if (expr === manager.trueExpr) return true;
164
+ return manager.getFamily(expr) !== FAMILY_BASIC && manager.getNumArgs(expr) === 0;
165
+ };
166
+
167
+ export interface SmtParams {
93
168
  isMbqi: boolean;
169
+ mbqiMaxIterations: number;
94
170
  relevancyLevel: 0 | 2;
171
+ randomSeed?: number;
172
+ // The model checker's auxiliary context pretends every array operation is supported.
173
+ isArrayFakeSupport?: boolean;
95
174
  }
96
175
 
97
176
  export class Context extends Internalizer {
98
- // setup_context makes the theories after the first formulas are asserted, so the field starts
99
- // unassigned.
100
- theory!: TheoryLra;
177
+ arith: TheoryLra | undefined;
178
+ setup: SmtSetup | undefined;
179
+ readonly theories: Theory[] = [];
180
+ private theoryByFamily: (Theory | undefined)[] = [];
101
181
  readonly qmanager: DefaultQuantifierManager;
182
+ readonly fingerprints = new FingerprintSet(this.manager);
102
183
  readonly conflictResolution: ConflictResolution = new ConflictResolution(this);
103
184
  private readonly dynAck = new DynAckManager(this);
104
185
  private qhead = 0;
105
186
  private scopeAssignedLimits: number[] = [];
106
187
  private scopeAuxClauseLimits: number[] = [];
107
188
  private scopeTrailLimits: number[] = [];
108
- // The number of lemmas when each user scope began.
109
189
  private baseScopeLemmaLimits: number[] = [];
190
+ private isBaseScopeInconsistent: boolean[] = [];
110
191
  private atomPropagationQueue: Literal[] = [];
111
192
  private thEqQueue: number[] = [];
112
193
  private thDiseqQueue: number[] = [];
113
194
  private bvarInc = 1;
114
195
  private agility = 0;
115
196
  private numConflicts = 0;
197
+ maxConflicts = Infinity;
116
198
  private numConflictsSinceRestart = 0;
117
199
  private numConflictsSinceLemmaGc = 0;
118
200
  private restartThreshold = RESTART_INITIAL;
119
201
  private restartOuterThreshold = RESTART_INITIAL;
120
202
  private isPhaseCacheOn = true;
121
203
  private phaseCounter = 0;
204
+ private phaseDefault = false;
205
+ private lubyIndex = 1;
122
206
  private finalCheckIndex = 0;
207
+ private literalAssumptions = new Map<Literal, number>();
208
+ unsatCore: number[] = [];
123
209
  private r1ParentGenerations = new Map<Enode, number>();
124
210
  private erasedGenerations = new Map<Enode, number>();
125
211
  private lastSearchFailure: SearchFailure = FAILURE_OK;
212
+ // As in Z3, a new search doesn't reset it.
213
+ reasonUnknown = "unknown";
214
+ private hasCaseSplit = true;
215
+ private incompleteTheories: Theory[] = [];
126
216
  private modelState: ModelState = { kind: "none" };
217
+ private asserted: AssertedFormulas | undefined;
218
+ macros: MacroManager | undefined;
219
+ hasQuantifiers = false;
127
220
 
128
- constructor(manager: AstManager, params: SmtParams) {
129
- super(manager, params.relevancyLevel > 0, params.relevancyLevel > 0);
130
- this.qmanager = new DefaultQuantifierManager(this, params.isMbqi);
221
+ constructor(
222
+ manager: AstManager,
223
+ readonly params: SmtParams,
224
+ ) {
225
+ super(manager, params.relevancyLevel > 0);
226
+ this.qmanager = new DefaultQuantifierManager(this);
227
+ }
228
+
229
+ // As in Z3, rereading the parameters drops the setup's tuning but for eliminate_term_ite, eliminate_bounds and relevancy.
230
+ updateParams(params: KernelParams) {
231
+ this.params.isMbqi = params.isMbqi;
232
+ this.params.mbqiMaxIterations = params.mbqiMaxIterations;
233
+ this.params.randomSeed = params.randomSeed;
234
+ this.config = {
235
+ ...DEFAULT_CONFIG,
236
+ theories: this.config.theories,
237
+ isFindingMacros: params.isFindingMacros,
238
+ isEliminatingTermIte: this.config.isEliminatingTermIte,
239
+ isEliminatingBounds: this.config.isEliminatingBounds,
240
+ };
241
+ this.qmanager.updateParams();
242
+ }
243
+
244
+ // setup_context and setup_components. The setup's theories come in its order, then setup_card's.
245
+ setupContext(
246
+ setup: SmtSetup | undefined,
247
+ isUsingStaticFeatures: boolean,
248
+ asserted: AssertedFormulas,
249
+ ) {
250
+ if (this.isInconsistent() || asserted.isInconsistent) return false;
251
+ const config = getSmtConfig(
252
+ this.manager,
253
+ setup,
254
+ isUsingStaticFeatures,
255
+ asserted.getFormulas(),
256
+ this.config,
257
+ );
258
+ this.setup = setup;
259
+ this.config = config;
260
+ this.randomSeed = this.params.randomSeed ?? 0;
261
+ if (config.relevancyLevel !== undefined) this.relevancy.isEnabled = config.relevancyLevel > 0;
262
+ for (const family of config.theories)
263
+ if (family !== FAMILY_POLY || this.manager.hasTypeVars) this.registerFamily(family);
264
+ this.registerFamily(FAMILY_PB);
265
+ asserted.setup(config);
266
+ return true;
131
267
  }
132
268
 
133
- // register_plugin initializes each theory it registers.
134
- setupContext() {
135
- this.theory = new TheoryLra(this);
136
- this.theory.init();
269
+ // register_plugin keeps the theory a family already has.
270
+ registerFamily(family: number) {
271
+ if (this.getTheory(family) !== undefined) return;
272
+ const theory = THEORY_MAKERS.get(family)!(this);
273
+ if (theory instanceof TheoryLra) this.arith = theory;
274
+ this.theories.push(theory);
275
+ this.theoryByFamily[theory.id] = theory;
276
+ theory.init();
277
+ for (let level = 0; level < this.scopeLevel; level++) theory.pushScopeEh();
137
278
  }
138
279
 
139
- // The search stops with unknown when the manager's resource limit cancels it.
140
- checkCanceled() {
141
- return !this.manager.limit.inc();
280
+ getTheory(family: number) {
281
+ return family < 0 ? undefined : this.theoryByFamily[family];
142
282
  }
143
283
 
144
- // Assignment and propagation.
284
+ checkCanceled(cost = 1) {
285
+ if (this.manager.limit.inc(cost)) return false;
286
+ this.lastSearchFailure = FAILURE_CANCELED;
287
+ return true;
288
+ }
145
289
 
146
290
  assign(literal: Literal, justification: BJustification, isDecision = false) {
147
291
  const value = this.assignment[literal];
@@ -157,7 +301,7 @@ export class Context extends Internalizer {
157
301
  this.justifications[boolVar] = justification;
158
302
  this.setLevel(boolVar, this.scopeLevel);
159
303
  const isNegative = isNegated(literal);
160
- if (this.hasBoolVarFlag(boolVar, BV_PHASE_AVAILABLE)) {
304
+ if (this.config.isRestartAdaptive && this.hasBoolVarFlag(boolVar, BV_PHASE_AVAILABLE)) {
161
305
  this.agility *= AGILITY_FACTOR;
162
306
  if (!isDecision && this.hasBoolVarFlag(boolVar, BV_PHASE) === isNegative)
163
307
  this.agility += 1 - AGILITY_FACTOR;
@@ -189,7 +333,6 @@ export class Context extends Internalizer {
189
333
  }
190
334
  const list = this.watches[literal];
191
335
  if (list === undefined) continue;
192
- // Nothing below makes a clause, so the clause data stays in place.
193
336
  const data = this.clauses.data;
194
337
  let kept = 0;
195
338
  let index = 0;
@@ -260,13 +403,13 @@ export class Context extends Internalizer {
260
403
  const lhs = this.exprToEnode[this.manager.getArg(eq, 0)];
261
404
  const rhs = this.exprToEnode[this.manager.getArg(eq, 1)];
262
405
  if (lhs !== undefined && rhs !== undefined) {
263
- if (value === L_TRUE) this.addEq(lhs, rhs, { kind: "equation", literal: literal });
406
+ if (value === L_TRUE) this.addEq(lhs, rhs, { kind: "equation", literal });
264
407
  else if (!this.addDiseq(lhs, rhs) && !this.isInconsistent())
265
408
  this.setConflict(new EqPropagationJustification(lhs, rhs), mkLiteral(boolVar, true));
266
409
  }
267
410
  }
268
411
  } else if (this.hasBoolVarFlag(boolVar, BV_THEORY))
269
- this.theory.assignEh(boolVar, value === L_TRUE);
412
+ this.getTheory(this.getBoolVarTheory(boolVar))?.assignEh(boolVar, value === L_TRUE);
270
413
  else if (this.hasBoolVarFlag(boolVar, BV_QUANTIFIER) && value === L_TRUE)
271
414
  this.qmanager.assignEh(this.boolVar2Expr[boolVar]);
272
415
  if (this.isInconsistent()) return false;
@@ -316,8 +459,14 @@ export class Context extends Internalizer {
316
459
  if (this.manager.kinds[expr] !== KIND_APP) return;
317
460
  const node = this.exprToEnode[expr];
318
461
  if (node !== undefined) this.qmanager.relevantEh(node);
319
- if (this.manager.getFamily(expr) === FAMILY_ARITH || (node !== undefined && node.thVar >= 0))
320
- this.theory.relevantEh(expr);
462
+ const propagated = this.getTheory(this.manager.getFamily(expr));
463
+ propagated?.relevantEh(expr);
464
+ if (node === undefined || node.thVar < 0) return;
465
+ if (this.theoryByFamily[node.thId] !== propagated)
466
+ this.theoryByFamily[node.thId]?.relevantEh(expr);
467
+ for (let cell = node.thNext; cell !== null; cell = cell.next)
468
+ if (this.theoryByFamily[cell.thId] !== propagated)
469
+ this.theoryByFamily[cell.thId]?.relevantEh(expr);
321
470
  }
322
471
 
323
472
  private propagateRelevancy(qhead: number) {
@@ -330,25 +479,38 @@ export class Context extends Internalizer {
330
479
 
331
480
  private propagateThEqs() {
332
481
  const queue = this.thEqQueue;
333
- for (let index = 0; index < queue.length && !this.isInconsistent(); index += 2)
334
- this.theory.newEqEh(queue[index], queue[index + 1]);
482
+ for (let index = 0; index < queue.length && !this.isInconsistent(); index += 3)
483
+ this.theoryByFamily[queue[index]]?.newEqEh(queue[index + 1], queue[index + 2]);
335
484
  this.thEqQueue = [];
336
485
  }
337
486
 
338
487
  private propagateThDiseqs() {
339
488
  const queue = this.thDiseqQueue;
340
- for (let index = 0; index < queue.length && !this.isInconsistent(); index += 2)
341
- this.theory.newDiseqEh(queue[index], queue[index + 1]);
489
+ for (let index = 0; index < queue.length && !this.isInconsistent(); index += 3)
490
+ this.theoryByFamily[queue[index]]?.newDiseqEh(queue[index + 1], queue[index + 2]);
342
491
  this.thDiseqQueue = [];
343
492
  }
344
493
 
494
+ private canTheoriesPropagate() {
495
+ for (const theory of this.theories) if (theory.canPropagate()) return true;
496
+ return false;
497
+ }
498
+
499
+ private propagateTheories() {
500
+ for (const theory of this.theories) {
501
+ theory.propagate();
502
+ if (this.isInconsistent()) return false;
503
+ }
504
+ return true;
505
+ }
506
+
345
507
  canPropagate() {
346
508
  return (
347
509
  this.qhead !== this.assignedLiterals.length ||
348
510
  this.relevancy.canPropagate() ||
349
511
  this.atomPropagationQueue.length > 0 ||
350
512
  this.qmanager.canPropagate() ||
351
- this.theory.canPropagate() ||
513
+ this.canTheoriesPropagate() ||
352
514
  this.eqPropagationQueue.length > 0 ||
353
515
  this.thEqQueue.length > 0 ||
354
516
  this.thDiseqQueue.length > 0
@@ -367,8 +529,7 @@ export class Context extends Internalizer {
367
529
  this.propagateThEqs();
368
530
  this.propagateThDiseqs();
369
531
  if (this.isInconsistent()) return false;
370
- this.theory.propagate();
371
- if (this.isInconsistent()) return false;
532
+ if (!this.propagateTheories()) return false;
372
533
  if (!this.checkCanceled()) this.qmanager.propagate();
373
534
  if (this.isInconsistent()) return false;
374
535
  if (this.isResourceLimitExceeded()) {
@@ -379,11 +540,12 @@ export class Context extends Internalizer {
379
540
  }
380
541
  }
381
542
 
382
- // Equalities.
383
-
384
- private getClosestVar(start: Enode) {
385
- for (let node: Enode | null = start; node !== null; node = node.transTarget)
386
- if (node.thVar >= 0) return node.thVar;
543
+ private getClosestVar(start: Enode, thId: number) {
544
+ if (thId < 0) return -1;
545
+ for (let node: Enode | null = start; node !== null; node = node.transTarget) {
546
+ const thVar = node.getThVar(thId);
547
+ if (thVar >= 0) return thVar;
548
+ }
387
549
  return -1;
388
550
  }
389
551
 
@@ -403,17 +565,19 @@ export class Context extends Internalizer {
403
565
  }
404
566
  }
405
567
 
406
- private pushNewThEq(first: number, second: number) {
407
- this.thEqQueue.push(first, second);
568
+ private pushNewThEq(thId: number, first: number, second: number) {
569
+ this.thEqQueue.push(thId, first, second);
408
570
  }
409
571
 
410
- private pushNewThDiseq(first: number, second: number) {
411
- const theory = this.theory;
572
+ private pushNewThDiseq(thId: number, first: number, second: number) {
573
+ const theory = this.theoryByFamily[thId];
574
+ if (theory === undefined) return;
412
575
  if (theory.getEnode(first).isInterpreted && theory.getEnode(second).isInterpreted) return;
413
- this.thDiseqQueue.push(first, second);
576
+ this.thDiseqQueue.push(thId, first, second);
414
577
  }
415
578
 
416
- private pushNewThDiseqs(root: Enode, thVar: number) {
579
+ private pushNewThDiseqs(root: Enode, thVar: number, thId: number) {
580
+ if (!this.theoryByFamily[thId]?.useDiseqs()) return;
417
581
  for (const parent of root.parents) {
418
582
  if (!parent.isEq) continue;
419
583
  if (this.assignment[mkLiteral(this.getBoolVar(parent.owner))] !== L_FALSE) continue;
@@ -424,10 +588,10 @@ export class Context extends Internalizer {
424
588
  lhs = rhs;
425
589
  rhs = saved;
426
590
  }
427
- const rhsVar = this.getClosestVar(rhs);
428
- const lhsVar = this.getClosestVar(lhs);
591
+ const rhsVar = this.getClosestVar(rhs, thId);
592
+ const lhsVar = this.getClosestVar(lhs, thId);
429
593
  const finalVar = lhsVar >= 0 ? lhsVar : thVar;
430
- if (rhsVar >= 0 && finalVar !== rhsVar) this.pushNewThDiseq(finalVar, rhsVar);
594
+ if (rhsVar >= 0 && finalVar !== rhsVar) this.pushNewThDiseq(thId, finalVar, rhsVar);
431
595
  }
432
596
  }
433
597
 
@@ -435,39 +599,65 @@ export class Context extends Internalizer {
435
599
  const r2 = n2.root;
436
600
  const r1 = n1.root;
437
601
  if (r1.thVar < 0 && r2.thVar < 0) return;
438
- const isFromTheory = justification.kind === "justification";
439
- const v2 = this.getClosestVar(n2);
440
- const v1 = this.getClosestVar(n1);
441
- if (v2 >= 0 && v1 >= 0) {
442
- if (!isFromTheory) this.pushNewThEq(v2, v1);
443
- } else if (v1 < 0 && v2 >= 0) this.pushNewThDiseqs(r1, v2);
444
- else if (v1 >= 0 && v2 < 0) {
445
- r2.thVar = v1;
446
- this.pushNewThDiseqs(r2, v1);
602
+ const fromTheory =
603
+ justification.kind === "justification" ? justification.justification.fromTheory : -1;
604
+ if (r2.thNext === null && r1.thNext === null) {
605
+ const t2 = r2.thId;
606
+ const t1 = r1.thId;
607
+ const v2 = this.getClosestVar(n2, t2);
608
+ const v1 = this.getClosestVar(n1, t1);
609
+ if (v2 >= 0 && v1 >= 0) {
610
+ if (t1 === t2) {
611
+ if (t1 !== fromTheory) this.pushNewThEq(t1, v2, v1);
612
+ return;
613
+ }
614
+ r2.addThVar(v1, t1);
615
+ this.pushNewThDiseqs(r2, v1, t1);
616
+ this.pushNewThDiseqs(r1, v2, t2);
617
+ } else if (v1 < 0 && v2 >= 0) this.pushNewThDiseqs(r1, v2, t2);
618
+ else if (v1 >= 0 && v2 < 0) {
619
+ r2.thVar = v1;
620
+ r2.thId = t1;
621
+ this.pushNewThDiseqs(r2, v1, t1);
622
+ }
623
+ return;
447
624
  }
448
- }
449
-
450
- attachThVar(node: Enode, thVar: number) {
451
- const oldVar = node.thVar;
452
- // A variable that an equality moved to the node's list, which the node's own replaces.
625
+ r2.forEachThVar((t2) => {
626
+ const v2 = this.getClosestVar(n2, t2);
627
+ const v1 = this.getClosestVar(n1, t2);
628
+ if (v1 >= 0) {
629
+ if (t2 !== fromTheory) this.pushNewThEq(t2, v2, v1);
630
+ } else this.pushNewThDiseqs(r1, v2, t2);
631
+ });
632
+ r1.forEachThVar((t1) => {
633
+ const v1 = this.getClosestVar(n1, t1);
634
+ if (r2.getThVar(t1) >= 0) return;
635
+ r2.addThVar(v1, t1);
636
+ this.pushNewThDiseqs(r2, v1, t1);
637
+ });
638
+ }
639
+
640
+ attachThVar(node: Enode, theory: Theory, thVar: number) {
641
+ const thId = theory.id;
642
+ const oldVar = node.getThVar(thId);
453
643
  if (oldVar >= 0) {
454
- node.thVar = thVar;
644
+ node.replaceThVar(thVar, thId);
455
645
  this.pushTrail(() => {
456
- node.thVar = oldVar;
646
+ node.replaceThVar(oldVar, thId);
457
647
  });
458
- this.pushNewThEq(thVar, oldVar);
648
+ this.pushNewThEq(thId, thVar, oldVar);
459
649
  return;
460
650
  }
461
651
  const root = node.root;
462
- const rootVar = root.thVar;
463
- node.thVar = thVar;
464
- this.trailInts.push(thVar);
652
+ const rootVar = root.getThVar(thId);
653
+ node.addThVar(thVar, thId);
654
+ this.trailInts.push(thId);
465
655
  this.trailNodes.push(node);
466
656
  this.trailKinds.push(UNDO_TH_VAR);
467
657
  if (rootVar < 0) {
468
- if (root !== node) root.thVar = thVar;
469
- this.pushNewThDiseqs(root, thVar);
470
- } else if (root !== node) this.pushNewThEq(rootVar, thVar);
658
+ if (root !== node) root.addThVar(thVar, thId);
659
+ this.pushNewThDiseqs(root, thVar, thId);
660
+ } else if (root !== node) this.pushNewThEq(thId, rootVar, thVar);
471
661
  }
472
662
 
473
663
  addEq(inputN1: Enode, inputN2: Enode, justification: EqJustification) {
@@ -524,8 +714,6 @@ export class Context extends Internalizer {
524
714
  }
525
715
  }
526
716
 
527
- // n1 = n2, justified by the justification, implied r1 = r2. A congruence that makes a false
528
- // equality true is the root of a conflict, which dynamic Ackermannization counts.
529
717
  private reinsertParentsIntoCgTable(
530
718
  r1: Enode,
531
719
  r2: Enode,
@@ -582,9 +770,10 @@ export class Context extends Internalizer {
582
770
  }
583
771
  case UNDO_TH_VAR: {
584
772
  const node = this.popTrailNode();
585
- const thVar = this.popTrailInt();
586
- node.thVar = -1;
587
- if (node.root !== node && node.root.thVar === thVar) node.root.thVar = -1;
773
+ const thId = this.popTrailInt();
774
+ const thVar = node.getThVar(thId);
775
+ node.delThVar(thId);
776
+ if (node.root !== node && node.root.getThVar(thId) === thVar) node.root.delThVar(thId);
588
777
  return;
589
778
  }
590
779
  default:
@@ -628,7 +817,12 @@ export class Context extends Internalizer {
628
817
  parent.cg = congruent;
629
818
  if (congruent === parent) parent.generation = generation;
630
819
  }
631
- if (r2.thVar >= 0 && this.theory.getEnode(r2.thVar).root !== r2) r2.thVar = -1;
820
+ if (r2.thNext === null) {
821
+ if (r2.thVar >= 0 && this.theoryByFamily[r2.thId]?.getEnode(r2.thVar).root !== r2) {
822
+ r2.thVar = -1;
823
+ r2.thId = -1;
824
+ }
825
+ } else r2.restoreThVars((thId, thVar) => this.theoryByFamily[thId]?.getEnode(thVar) ?? r2);
632
826
  n1.transTarget = null;
633
827
  this.invertTrans(r1);
634
828
  }
@@ -670,14 +864,38 @@ export class Context extends Internalizer {
670
864
  private addDiseq(n1: Enode, n2: Enode) {
671
865
  const r1 = n1.root;
672
866
  const r2 = n2.root;
673
- if (r1 === r2) return r1.thVar >= 0;
674
- const v1 = this.getClosestVar(n1);
675
- const v2 = this.getClosestVar(n2);
676
- if (v1 >= 0 && v2 >= 0) this.pushNewThDiseq(v1, v2);
867
+ if (r1 === r2) return this.theoryByFamily[r1.thId]?.useDiseqs() ?? false;
868
+ if (r1.thNext === null && r2.thNext === null) {
869
+ const t1 = r1.thId;
870
+ const v1 = this.getClosestVar(n1, t1);
871
+ const v2 = this.getClosestVar(n2, t1);
872
+ if (v1 >= 0 && v2 >= 0 && t1 === r2.thId && this.theoryByFamily[t1]?.useDiseqs())
873
+ this.pushNewThDiseq(t1, v1, v2);
874
+ return true;
875
+ }
876
+ r1.forEachThVar((t1) => {
877
+ if (!this.theoryByFamily[t1]?.useDiseqs()) return;
878
+ const v1 = this.getClosestVar(n1, t1);
879
+ const v2 = this.getClosestVar(n2, t1);
880
+ if (v2 >= 0) this.pushNewThDiseq(t1, v1, v2);
881
+ });
677
882
  return true;
678
883
  }
679
884
 
680
- // Theory combination: assume that two shared terms are equal.
885
+ isShared(node: Enode) {
886
+ const root = node.root;
887
+ if (this.manager.getOp(root.owner) === OP_ITE) return true;
888
+ if (root.thVar < 0) return false;
889
+ if (root.thNext !== null) return true;
890
+ if (this.qmanager.isShared(root)) return true;
891
+ for (const parent of root.parents) {
892
+ const family = this.manager.getFamily(parent.owner);
893
+ if (family === root.thId || family === FAMILY_BASIC) continue;
894
+ if (!this.getTheory(family)?.isBetaRedex(parent, root)) return true;
895
+ }
896
+ return this.getTheory(root.thId)?.isShared(root.thVar) ?? false;
897
+ }
898
+
681
899
  assumeEq(lhs: Enode, rhs: Enode) {
682
900
  if (lhs.root === rhs.root) return false;
683
901
  const eq = this.mkEqAtom(lhs.owner, rhs.owner);
@@ -687,7 +905,10 @@ export class Context extends Internalizer {
687
905
  const boolVar = this.getBoolVar(eq);
688
906
  this.setBoolVarFlag(boolVar, BV_EQ, true);
689
907
  this.setTrueFirstFlag(boolVar);
690
- this.theory.internalizeEqEh(eq);
908
+ this.getTheory(this.manager.getSortFamily(this.manager.sorts[lhs.owner]))?.internalizeEqEh(
909
+ eq,
910
+ boolVar,
911
+ );
691
912
  isNew = true;
692
913
  }
693
914
  const boolVar = this.getBoolVar(eq);
@@ -703,8 +924,6 @@ export class Context extends Internalizer {
703
924
  return isNew;
704
925
  }
705
926
 
706
- // Search.
707
-
708
927
  incBvarActivity(boolVar: BoolVar) {
709
928
  this.activity[boolVar] += this.bvarInc;
710
929
  if (this.activity[boolVar] > ACTIVITY_LIMIT) {
@@ -715,14 +934,15 @@ export class Context extends Internalizer {
715
934
  this.caseSplitQueue.activityIncreased(boolVar);
716
935
  }
717
936
 
718
- private pushScope() {
937
+ pushScope() {
719
938
  this.scopeLevel++;
720
939
  this.scopeAssignedLimits.push(this.assignedLiterals.length);
721
940
  this.scopeAuxClauseLimits.push(this.auxClauses.length);
722
941
  this.scopeTrailLimits.push(this.trailKinds.length);
723
942
  this.relevancy.push();
724
943
  this.qmanager.push();
725
- this.theory.pushScopeEh();
944
+ this.fingerprints.push();
945
+ for (const theory of this.theories) theory.pushScopeEh();
726
946
  }
727
947
 
728
948
  private cacheGenerationOfExpr(expr: number, newLevel: number, visited: Set<number>) {
@@ -780,16 +1000,18 @@ export class Context extends Internalizer {
780
1000
  const newLevel = this.scopeLevel - numScopes;
781
1001
  this.cacheGeneration(newLevel, visited);
782
1002
  this.qmanager.pop(numScopes);
1003
+ this.fingerprints.pop(numScopes);
1004
+ if (newLevel >= this.baseLevel || !this.isBaseScopeInconsistent[newLevel]) this.conflict = null;
783
1005
  if (newLevel < this.baseLevel) {
784
1006
  this.deleteClauses(this.lemmas, this.baseScopeLemmaLimits[newLevel]);
785
1007
  shrink(this.baseScopeLemmaLimits, newLevel);
1008
+ shrink(this.isBaseScopeInconsistent, newLevel);
786
1009
  }
787
- this.conflict = null;
788
1010
  this.deleteClauses(this.auxClauses, this.scopeAuxClauseLimits[newLevel]);
789
1011
  this.relevancy.pop(numScopes);
790
1012
  this.unassignVars(this.scopeAssignedLimits[newLevel]);
791
1013
  this.popTrail(this.scopeTrailLimits[newLevel]);
792
- this.theory.popScopeEh(numScopes);
1014
+ for (const theory of this.theories) theory.popScopeEh(numScopes);
793
1015
  this.eqPropagationQueue = [];
794
1016
  this.thEqQueue = [];
795
1017
  this.thDiseqQueue = [];
@@ -807,7 +1029,7 @@ export class Context extends Internalizer {
807
1029
  return numBoolVars;
808
1030
  }
809
1031
 
810
- private popScope(numScopes: number) {
1032
+ popScope(numScopes: number) {
811
1033
  this.popScopeCore(numScopes, new Set());
812
1034
  this.cachedGeneration.clear();
813
1035
  }
@@ -888,7 +1110,6 @@ export class Context extends Internalizer {
888
1110
  return true;
889
1111
  }
890
1112
 
891
- // is_unit_clause: exactly one literal is unassigned and the rest are false.
892
1113
  private isUnitClause(clause: Clause) {
893
1114
  const store = this.clauses;
894
1115
  let isFound = false;
@@ -903,15 +1124,20 @@ export class Context extends Internalizer {
903
1124
  return isFound;
904
1125
  }
905
1126
 
906
- // guess with PS_CACHING_CONSERVATIVE: the cached phase while phase caching is on, else false.
907
1127
  private guess(boolVar: BoolVar) {
908
1128
  if (this.manager.kinds[this.boolVar2Expr[boolVar]] === KIND_QUANTIFIER) return false;
909
1129
  if (this.hasBoolVarFlag(boolVar, BV_TRUE_FIRST)) return true;
910
- return (
911
- this.isPhaseCacheOn &&
912
- this.hasBoolVarFlag(boolVar, BV_PHASE_AVAILABLE) &&
913
- this.hasBoolVarFlag(boolVar, BV_PHASE)
914
- );
1130
+ const phaseSelection = this.config.phaseSelection;
1131
+ if (phaseSelection === PS_ALWAYS_FALSE) return false;
1132
+ const isPhaseAvailable = this.hasBoolVarFlag(boolVar, BV_PHASE_AVAILABLE);
1133
+ if (phaseSelection === PS_THEORY) {
1134
+ const phase = this.getTheory(this.getBoolVarTheory(boolVar))?.getPhase(boolVar) ?? L_UNDEF;
1135
+ if (phase !== L_UNDEF) return phase === L_TRUE;
1136
+ return isPhaseAvailable ? this.hasBoolVarFlag(boolVar, BV_PHASE) : this.phaseDefault;
1137
+ }
1138
+ return this.isPhaseCacheOn && isPhaseAvailable
1139
+ ? this.hasBoolVarFlag(boolVar, BV_PHASE)
1140
+ : this.phaseDefault;
915
1141
  }
916
1142
 
917
1143
  private updatePhaseCacheCounter() {
@@ -919,18 +1145,27 @@ export class Context extends Internalizer {
919
1145
  if (this.phaseCounter < (this.isPhaseCacheOn ? PHASE_CACHING_ON : PHASE_CACHING_OFF)) return;
920
1146
  this.phaseCounter = 0;
921
1147
  this.isPhaseCacheOn = !this.isPhaseCacheOn;
1148
+ if (this.config.phaseSelection === PS_CACHING_CONSERVATIVE2)
1149
+ this.phaseDefault = !this.phaseDefault;
922
1150
  }
923
1151
 
924
1152
  private decide() {
925
1153
  const boolVar = this.caseSplitQueue.nextCaseSplit();
926
- if (boolVar === undefined) return false;
1154
+ if (boolVar === undefined) {
1155
+ const hadCaseSplit = this.hasCaseSplit;
1156
+ this.pushTrail(() => {
1157
+ this.hasCaseSplit = hadCaseSplit;
1158
+ });
1159
+ this.hasCaseSplit = false;
1160
+ return false;
1161
+ }
927
1162
  const isPositive = this.guess(boolVar);
928
1163
  this.pushScope();
929
1164
  this.assign(mkLiteral(boolVar, !isPositive), "axiom", true);
930
1165
  return true;
931
1166
  }
932
1167
 
933
- private resolveConflict() {
1168
+ resolveConflict() {
934
1169
  this.numConflicts++;
935
1170
  this.numConflictsSinceRestart++;
936
1171
  this.numConflictsSinceLemmaGc++;
@@ -938,9 +1173,15 @@ export class Context extends Internalizer {
938
1173
  this.eqPropagationQueue = [];
939
1174
  this.thEqQueue = [];
940
1175
  this.thDiseqQueue = [];
1176
+ const phaseSelection = this.config.phaseSelection;
941
1177
  const head = this.scopeLevel === 0 ? 0 : this.scopeAssignedLimits[this.scopeLevel - 1];
942
- for (let index = head; index < this.assignedLiterals.length; index++)
943
- this.setBoolVarFlag(getVar(this.assignedLiterals[index]), BV_PHASE_AVAILABLE, false);
1178
+ if (
1179
+ phaseSelection === PS_THEORY ||
1180
+ phaseSelection === PS_CACHING_CONSERVATIVE ||
1181
+ phaseSelection === PS_CACHING_CONSERVATIVE2
1182
+ )
1183
+ for (let index = head; index < this.assignedLiterals.length; index++)
1184
+ this.setBoolVarFlag(getVar(this.assignedLiterals[index]), BV_PHASE_AVAILABLE, false);
944
1185
  const resolution = this.conflictResolution;
945
1186
  if (
946
1187
  this.conflict === null ||
@@ -966,7 +1207,6 @@ export class Context extends Internalizer {
966
1207
  ? negate(this.getLiteral(atoms[index]))
967
1208
  : this.getLiteral(atoms[index]);
968
1209
  }
969
- // restore_relevancy: marking propagates, so it only marks the literals that lost relevancy.
970
1210
  for (let index = 0; index < literals.length; index++)
971
1211
  if (wasRelevant[index] && !this.isRelevant(this.boolVar2Expr[getVar(literals[index])]))
972
1212
  this.markLiteralAsRelevant(literals[index]);
@@ -987,37 +1227,33 @@ export class Context extends Internalizer {
987
1227
  let failure: SearchFailure = FAILURE_OK;
988
1228
  let level = 1;
989
1229
  let maxLevel = 1;
1230
+ this.incompleteTheories = [];
990
1231
  for (;;) {
991
- const isTheory = this.finalCheckIndex === 0;
992
- // Z3 registers every theory for UFNIA, and only arithmetic acts on tlapm's obligations. Of
993
- // the theories between arithmetic and the quantifiers, theory_finite_set makes a set.range
994
- // declaration, and its assume_eqs draws a random value.
995
- if (!isTheory) {
996
- this.manager.initFiniteSetPlugin();
997
- this.getRandomValue();
998
- }
999
- const check = isTheory ? this.theory.finalCheckEh(level) : qmanager.finalCheckEh(true);
1000
- if (isTheory) maxLevel = Math.max(maxLevel, NUM_ARITH_FINAL_CHECK_LEVELS);
1001
- // Z3 reads the cancel flag after each theory's final check, and a canceled check gives up.
1002
- const isCanceled = isTheory && this.checkCanceled();
1232
+ const theory = this.theories[this.finalCheckIndex];
1233
+ const check = theory === undefined ? qmanager.finalCheckEh(true) : theory.finalCheckEh(level);
1234
+ if (theory !== undefined) maxLevel = Math.max(maxLevel, theory.numFinalCheckLevels());
1235
+ const isCanceled = theory !== undefined && this.checkCanceled();
1003
1236
  if (isCanceled) failure = FAILURE_CANCELED;
1004
- else if (isTheory && check === FC_GIVEUP) failure = FAILURE_THEORY;
1005
- this.finalCheckIndex = (this.finalCheckIndex + 1) % 2;
1237
+ else if (theory !== undefined && check === FC_GIVEUP) {
1238
+ failure = FAILURE_THEORY;
1239
+ if (!this.incompleteTheories.includes(theory)) this.incompleteTheories.push(theory);
1240
+ }
1241
+ this.finalCheckIndex = (this.finalCheckIndex + 1) % (this.theories.length + 1);
1006
1242
  if (check === FC_CONTINUE) return FC_CONTINUE;
1007
1243
  if (check === FC_GIVEUP || isCanceled) result = FC_GIVEUP;
1008
1244
  if (this.finalCheckIndex !== oldIndex) continue;
1009
1245
  if (level >= maxLevel || result === FC_DONE || this.canPropagate()) break;
1010
- // A higher level reruns every check with the give-up state of the lower one cleared.
1011
1246
  level++;
1012
1247
  result = FC_DONE;
1013
1248
  failure = FAILURE_OK;
1249
+ this.incompleteTheories = [];
1014
1250
  }
1015
1251
  if (this.canPropagate()) return FC_CONTINUE;
1016
1252
  if (result === FC_GIVEUP && failure !== FAILURE_OK) this.lastSearchFailure = failure;
1017
1253
  return result;
1018
1254
  }
1019
1255
 
1020
- private boundedSearch() {
1256
+ boundedSearch() {
1021
1257
  for (;;) {
1022
1258
  while (!this.propagate()) {
1023
1259
  if (!this.resolveConflict()) return L_FALSE;
@@ -1028,6 +1264,10 @@ export class Context extends Internalizer {
1028
1264
  this.scopeLevel - this.baseLevel > 2
1029
1265
  )
1030
1266
  return L_UNDEF;
1267
+ if (this.numConflicts > this.maxConflicts) {
1268
+ this.lastSearchFailure = FAILURE_NUM_CONFLICTS;
1269
+ return L_UNDEF;
1270
+ }
1031
1271
  }
1032
1272
  if (this.numConflictsSinceLemmaGc > LEMMA_GC_INITIAL) this.delInactiveLemmas();
1033
1273
  this.dynAck.propagateEh();
@@ -1044,15 +1284,13 @@ export class Context extends Internalizer {
1044
1284
  }
1045
1285
  }
1046
1286
 
1047
- // resource_limits_exceeded: while searching, a failure stops the search, and the cancel flag is
1048
- // read twice.
1287
+ // Z3's resource_limits_exceeded reads the cancel flag twice while searching.
1049
1288
  private isResourceLimitExceeded() {
1050
1289
  if (this.isSearching && (this.lastSearchFailure !== FAILURE_OK || this.checkCanceled()))
1051
1290
  return true;
1052
1291
  return this.checkCanceled();
1053
1292
  }
1054
1293
 
1055
- // reset_model: the model generator still holds the proto model.
1056
1294
  private resetModel() {
1057
1295
  const state = this.modelState;
1058
1296
  if (state.kind === "none" || state.kind === "generated") return;
@@ -1061,9 +1299,10 @@ export class Context extends Internalizer {
1061
1299
  this.modelState = { kind: "generated", generated: state.generated };
1062
1300
  }
1063
1301
 
1064
- // mk_proto_model: the model of the current assignment, which the quantifier manager adjusts. The
1065
- // model generator releases the last model first.
1066
1302
  private mkProtoModel() {
1303
+ const failure = this.lastSearchFailure;
1304
+ if (this.hasCaseSplits() || failure === FAILURE_CANCELED || failure === FAILURE_NUM_CONFLICTS)
1305
+ return undefined;
1067
1306
  if (this.modelState.kind !== "none") this.modelState.generated.model.decRef();
1068
1307
  const generated = mkModel(this);
1069
1308
  generated.model.incRef();
@@ -1076,27 +1315,61 @@ export class Context extends Internalizer {
1076
1315
  return generated;
1077
1316
  }
1078
1317
 
1079
- // get_model: the model that the proto model makes, which the caller holds too. add_rec_funs gives
1080
- // each named expression without an interpretation its expression.
1318
+ getLastFailureMessage() {
1319
+ if (this.lastSearchFailure === FAILURE_CANCELED) return "canceled";
1320
+ if (this.lastSearchFailure === FAILURE_NUM_CONFLICTS) return "max-conflicts-reached";
1321
+ if (this.lastSearchFailure === FAILURE_QUANTIFIERS) return "(incomplete quantifiers)";
1322
+ if (this.lastSearchFailure === FAILURE_THEORY)
1323
+ return `(incomplete (theory${this.incompleteTheories.map((theory) => ` ${theory.name}`).join("")}))`;
1324
+ return this.reasonUnknown;
1325
+ }
1326
+
1327
+ private hasCaseSplits() {
1328
+ if (!this.hasCaseSplit) return false;
1329
+ for (let index = this.numBoolVars; index-- > 0;)
1330
+ if (
1331
+ this.isRelevant(this.boolVar2Expr[index]) &&
1332
+ this.assignment[mkLiteral(toBoolVar(index))] === L_UNDEF
1333
+ )
1334
+ return true;
1335
+ return false;
1336
+ }
1337
+
1338
+ isQuantifierIncomplete() {
1339
+ return this.lastSearchFailure === FAILURE_QUANTIFIERS;
1340
+ }
1341
+
1342
+ // Z3's update_model always answers false, after it recomputes a final state for the next model.
1343
+ updateModel() {
1344
+ if (!this.hasCaseSplits() && this.finalCheck() === FC_DONE) this.resetModel();
1345
+ }
1346
+
1081
1347
  getModel() {
1348
+ if (this.isInconsistent()) return undefined;
1082
1349
  if (this.modelState.kind === "final") return this.modelState.model;
1350
+ if (!this.manager.limit.inc()) return undefined;
1083
1351
  const generated =
1084
1352
  this.modelState.kind === "proto" ? this.modelState.generated : this.mkProtoModel();
1353
+ if (generated === undefined) return undefined;
1085
1354
  const model = generated.model.mkModel();
1086
- for (const entry of this.manager.macros)
1087
- if (!model.constInterps.has(entry[0])) model.registerConst(entry[0], entry[1]);
1355
+ model.addRecFuns();
1088
1356
  model.incRef();
1089
1357
  this.modelState = { kind: "final", generated, model };
1090
1358
  return model;
1091
1359
  }
1092
1360
 
1093
- // validate_model: every relevant ground literal of the assignment holds in the model.
1361
+ getSatModel() {
1362
+ const model = this.getModel();
1363
+ if (model !== undefined) return model;
1364
+ if (this.manager.limit.isExhausted()) throw new SmtCanceledError();
1365
+ throw new SmtInvariantError("a sat answer without a model");
1366
+ }
1367
+
1094
1368
  validateModel(model: ProtoModel) {
1095
1369
  const manager = this.manager;
1096
1370
  for (const literal of this.assignedLiterals) {
1097
1371
  const atom = this.boolVar2Expr[getVar(literal)];
1098
1372
  if (!this.isRelevant(atom)) continue;
1099
- // n and res of Z3's loop hold the literal and its value.
1100
1373
  const expr = isNegated(literal) ? manager.mkNot(atom) : atom;
1101
1374
  manager.incRef(expr);
1102
1375
  const value = manager.isGround(expr) ? model.eval(expr, false) : -1;
@@ -1107,9 +1380,6 @@ export class Context extends Internalizer {
1107
1380
  return true;
1108
1381
  }
1109
1382
 
1110
- // restart: decides whether the search goes on after a bounded search. A candidate model of a
1111
- // problem with quantifiers goes to model-based quantifier instantiation, which may add instances
1112
- // and force a restart.
1113
1383
  private restart(status: number, currentLevel: number): number | undefined {
1114
1384
  const qmanager = this.qmanager;
1115
1385
  this.resetModel();
@@ -1119,42 +1389,43 @@ export class Context extends Internalizer {
1119
1389
  this.lastSearchFailure !== FAILURE_THEORY ||
1120
1390
  status === L_FALSE ||
1121
1391
  this.isInconsistent() ||
1122
- !qmanager.hasQuantifiers() ||
1392
+ qmanager.quantifiers.length === 0 ||
1123
1393
  !qmanager.isModelBased()
1124
1394
  )
1125
1395
  return status;
1126
1396
  const generated = this.mkProtoModel();
1127
- if (qmanager.checkModel(generated.model, generated.root2value) !== CHECK_MODEL_RESTART)
1397
+ if (
1398
+ generated === undefined ||
1399
+ qmanager.checkModel(generated.model, generated.root2value) !== CHECK_MODEL_RESTART
1400
+ )
1128
1401
  return status;
1129
1402
  this.lastSearchFailure = FAILURE_OK;
1130
1403
  status = L_UNDEF;
1131
1404
  isForcedRestart = true;
1132
1405
  }
1133
1406
  if (status === L_FALSE) return L_FALSE;
1134
- if (status === L_TRUE && !qmanager.hasQuantifiers()) return L_TRUE;
1407
+ if (status === L_TRUE && qmanager.quantifiers.length === 0) return L_TRUE;
1135
1408
  if (status === L_TRUE) {
1136
1409
  const generated = this.mkProtoModel();
1137
- const result = qmanager.isModelBased()
1138
- ? qmanager.checkModel(generated.model, generated.root2value)
1139
- : CHECK_MODEL_UNKNOWN;
1410
+ const result =
1411
+ generated !== undefined && qmanager.isModelBased()
1412
+ ? qmanager.checkModel(generated.model, generated.root2value)
1413
+ : CHECK_MODEL_UNKNOWN;
1140
1414
  if (result === CHECK_MODEL_SAT) return L_TRUE;
1141
1415
  if (result === CHECK_MODEL_UNKNOWN) {
1142
1416
  this.lastSearchFailure = FAILURE_QUANTIFIERS;
1143
1417
  return L_UNDEF;
1144
1418
  }
1145
1419
  }
1146
- // inc_limits with RS_IN_OUT_GEOMETRIC.
1147
- if (this.numConflictsSinceRestart >= this.restartThreshold) {
1148
- this.restartThreshold = Math.trunc(this.restartThreshold * RESTART_FACTOR);
1149
- if (this.restartThreshold > this.restartOuterThreshold) {
1150
- this.restartThreshold = RESTART_INITIAL;
1151
- this.restartOuterThreshold = Math.trunc(this.restartOuterThreshold * RESTART_FACTOR);
1152
- }
1153
- }
1154
- this.numConflictsSinceRestart = 0;
1155
- if (isForcedRestart || status === L_TRUE || this.agility < RESTART_AGILITY_THRESHOLD) {
1420
+ this.incLimits();
1421
+ if (
1422
+ isForcedRestart ||
1423
+ status === L_TRUE ||
1424
+ !this.config.isRestartAdaptive ||
1425
+ this.agility < RESTART_AGILITY_THRESHOLD
1426
+ ) {
1156
1427
  if (this.scopeLevel > currentLevel) this.popScope(this.scopeLevel - currentLevel);
1157
- if (!this.isInconsistent()) this.theory.restartEh();
1428
+ for (const theory of this.theories) if (!this.isInconsistent()) theory.restartEh();
1158
1429
  if (!this.isInconsistent()) qmanager.restartEh();
1159
1430
  if (this.isInconsistent()) {
1160
1431
  this.resolveConflict();
@@ -1164,7 +1435,28 @@ export class Context extends Internalizer {
1164
1435
  return undefined;
1165
1436
  }
1166
1437
 
1167
- // can_delete: a lemma that justifies neither of its watched literals.
1438
+ incLimits() {
1439
+ const config = this.config;
1440
+ if (this.numConflictsSinceRestart >= this.restartThreshold) {
1441
+ if (config.restartStrategy === RS_LUBY) {
1442
+ this.lubyIndex++;
1443
+ this.restartThreshold = getLuby(this.lubyIndex) * RESTART_INITIAL;
1444
+ } else {
1445
+ this.restartThreshold = Math.trunc(this.restartThreshold * config.restartFactor);
1446
+ if (
1447
+ config.restartStrategy !== RS_GEOMETRIC &&
1448
+ this.restartThreshold > this.restartOuterThreshold
1449
+ ) {
1450
+ this.restartThreshold = RESTART_INITIAL;
1451
+ this.restartOuterThreshold = Math.trunc(
1452
+ this.restartOuterThreshold * config.restartFactor,
1453
+ );
1454
+ }
1455
+ }
1456
+ }
1457
+ this.numConflictsSinceRestart = 0;
1458
+ }
1459
+
1168
1460
  private isDeletable(clause: Clause) {
1169
1461
  const store = this.clauses;
1170
1462
  if (store.isReinit(clause)) return false;
@@ -1183,8 +1475,6 @@ export class Context extends Internalizer {
1183
1475
  return false;
1184
1476
  }
1185
1477
 
1186
- // del_inactive_lemmas2: deletes the lemmas of the current user scope with low activity and many
1187
- // unassigned literals. The newest sixteenth of them tolerates more unassigned literals.
1188
1478
  private delInactiveLemmas() {
1189
1479
  const lemmas = this.lemmas;
1190
1480
  const startAt = this.baseLevel === 0 ? 0 : this.baseScopeLemmaLimits[this.baseLevel - 1];
@@ -1212,11 +1502,11 @@ export class Context extends Internalizer {
1212
1502
  this.numConflictsSinceLemmaGc = 0;
1213
1503
  }
1214
1504
 
1215
- // push: a user scope, which pop removes with everything asserted in it.
1216
1505
  push() {
1217
1506
  this.popToBaseLevel();
1218
1507
  this.pushScope();
1219
1508
  this.baseScopeLemmaLimits.push(this.lemmas.length);
1509
+ this.isBaseScopeInconsistent.push(this.isInconsistent());
1220
1510
  this.baseLevel++;
1221
1511
  this.searchLevel++;
1222
1512
  }
@@ -1226,54 +1516,177 @@ export class Context extends Internalizer {
1226
1516
  this.popScope(numScopes);
1227
1517
  }
1228
1518
 
1229
- // pop_to_base_lvl: undoes the decisions of the last search, before new assertions.
1230
1519
  popToBaseLevel() {
1231
1520
  if (this.scopeLevel > this.baseLevel) this.popScope(this.scopeLevel - this.baseLevel);
1232
1521
  }
1233
1522
 
1234
- // internalize_assertions: the formulas of the asserted formulas, after preprocessing. When they
1235
- // are inconsistent, none is internalized and the context has an axiom conflict.
1523
+ popToSearchLevel() {
1524
+ if (this.scopeLevel > this.searchLevel) this.popScope(this.scopeLevel - this.searchLevel);
1525
+ }
1526
+
1527
+ hasSearchFailure() {
1528
+ return this.lastSearchFailure !== FAILURE_OK;
1529
+ }
1530
+
1531
+ resetConflict() {
1532
+ this.conflict = null;
1533
+ }
1534
+
1535
+ getNumAssertedFormulas() {
1536
+ return this.asserted?.getNumFormulas() ?? 0;
1537
+ }
1538
+
1236
1539
  internalizeAssertions(asserted: AssertedFormulas) {
1237
- const formulas = asserted.reduce();
1540
+ this.asserted = asserted;
1541
+ this.macros = asserted.macros;
1542
+ this.hasQuantifiers = asserted.hasQuantifiers;
1543
+ if (this.checkCanceled()) return;
1544
+ asserted.reduce();
1545
+ if (this.checkCanceled()) return;
1238
1546
  if (asserted.isInconsistent) {
1239
1547
  this.setConflict("axiom", null);
1240
1548
  return;
1241
1549
  }
1242
- for (const formula of formulas) {
1243
- if (this.isInconsistent()) break;
1244
- this.internalizeAssertion(formula, 0);
1550
+ const formulas = asserted.getFormulas();
1551
+ const size = asserted.getNumFormulas();
1552
+ for (let qhead = asserted.getQhead(); qhead < size && !this.isInconsistent(); qhead++) {
1553
+ if (this.checkCanceled()) {
1554
+ asserted.commit(qhead);
1555
+ return;
1556
+ }
1557
+ this.internalizeAssertion(formulas[qhead], 0);
1245
1558
  }
1559
+ asserted.commit();
1246
1560
  }
1247
1561
 
1248
- // init_assumptions: the search runs above a scope where the assumptions hold.
1249
- initAssumptions(assumptions: number[]) {
1562
+ initAssumptions(assumptions: number[], asserted: AssertedFormulas) {
1563
+ this.literalAssumptions.clear();
1564
+ for (const assumption of this.unsatCore) this.manager.decRef(assumption);
1565
+ this.unsatCore = [];
1250
1566
  if (assumptions.length > 0) {
1251
1567
  this.propagate();
1252
- if (this.isInconsistent()) return;
1568
+ if (this.isInconsistent() || this.checkCanceled()) return;
1253
1569
  this.delInactiveLemmas();
1254
1570
  this.pushScope();
1255
- for (const assumption of assumptions) {
1571
+ const manager = this.manager;
1572
+ const proxies = assumptions.map((assumption) => {
1573
+ if (isValidAssumption(manager, assumption)) return assumption;
1574
+ const proxy = manager.mkFreshConst(null, SORT_BOOL);
1575
+ asserted.assertExpr(manager.mkApp(OP_IMPLIES, [proxy, assumption], SORT_BOOL));
1576
+ return proxy;
1577
+ });
1578
+ this.internalizeAssertions(asserted);
1579
+ for (const [index, proxy] of proxies.entries()) {
1256
1580
  if (this.isInconsistent()) break;
1257
- this.internalizeAssertion(assumption, 0);
1581
+ if (proxy === manager.trueExpr) continue;
1582
+ this.internalizeAssertion(proxy, 0);
1583
+ const literal = this.getLiteral(proxy);
1584
+ if (literal === this.trueLiteral || literal === this.falseLiteral) continue;
1585
+ this.literalAssumptions.set(literal, assumptions[index]);
1258
1586
  }
1259
1587
  }
1260
1588
  this.searchLevel = this.scopeLevel;
1261
1589
  }
1262
1590
 
1591
+ addTheoryAssumptions(assumptions: number[]) {
1592
+ for (const theory of this.theories) theory.addTheoryAssumptions(assumptions);
1593
+ }
1594
+
1595
+ checkResearching(asserted: AssertedFormulas, assumptions: readonly number[]) {
1596
+ let result: number;
1597
+ for (;;) {
1598
+ this.popToBaseLevel();
1599
+ this.internalizeAssertions(asserted);
1600
+ const all = [...assumptions];
1601
+ this.addTheoryAssumptions(all);
1602
+ this.initAssumptions(all, asserted);
1603
+ result = this.mkUnsatCore(this.search());
1604
+ if (result !== L_FALSE || this.unsatCore.length === 0) return result;
1605
+ if (!this.theories.some((theory) => theory.shouldResearch(this.unsatCore))) return result;
1606
+ }
1607
+ }
1608
+
1609
+ findMutexes(vars: readonly number[]) {
1610
+ const manager = this.manager;
1611
+ const cliques = new MaxCliques((index) => index ^ 1);
1612
+ const literals: number[] = [];
1613
+ for (const variable of vars) {
1614
+ const isNot = manager.getOp(variable) === OP_NOT;
1615
+ const atom = isNot ? manager.getArg(variable, 0) : variable;
1616
+ const boolVar = this.findBoolVar(atom);
1617
+ if (boolVar !== undefined) literals.push(mkLiteral(boolVar, isNot));
1618
+ }
1619
+ for (let index = 0; index < this.binaryWatches.length; index++)
1620
+ for (const other of this.binaryWatches[index] ?? []) {
1621
+ const source = index ^ 1;
1622
+ if (source < other) cliques.addEdge(source, other);
1623
+ }
1624
+ return cliques.cliques2(literals).map((mutex) =>
1625
+ mutex.map((index) => {
1626
+ const literal = index as Literal;
1627
+ if (literal === this.trueLiteral) return manager.trueExpr;
1628
+ if (literal === this.falseLiteral) return manager.falseExpr;
1629
+ const atom = this.boolVar2Expr[getVar(literal)];
1630
+ return isNegated(literal) ? manager.mkApp(OP_NOT, [atom], SORT_BOOL) : atom;
1631
+ }),
1632
+ );
1633
+ }
1634
+
1635
+ isAssumption(boolVar: BoolVar) {
1636
+ return (
1637
+ this.literalAssumptions.has(mkLiteral(boolVar)) ||
1638
+ this.literalAssumptions.has(mkLiteral(boolVar, true))
1639
+ );
1640
+ }
1641
+
1642
+ isTrackingAssumptions() {
1643
+ return this.literalAssumptions.size > 0 && this.searchLevel > this.baseLevel;
1644
+ }
1645
+
1646
+ mkUnsatCore(result: number) {
1647
+ if (result !== L_FALSE || !this.isTrackingAssumptions()) return result;
1648
+ const literalAssumptions = this.literalAssumptions;
1649
+ const found = new Set<Literal>();
1650
+ const core: number[] = [];
1651
+ for (const literal of this.conflictResolution.unsatCore) {
1652
+ const assumed = literalAssumptions.has(literal) ? literal : negate(literal);
1653
+ const assumption = literalAssumptions.get(assumed);
1654
+ if (assumption === undefined || found.has(assumed)) continue;
1655
+ found.add(assumed);
1656
+ this.manager.incRef(assumption);
1657
+ core.push(assumption);
1658
+ }
1659
+ literalAssumptions.clear();
1660
+ this.popToBaseLevel();
1661
+ this.searchLevel = this.baseLevel;
1662
+ const ids = this.manager.ids;
1663
+ this.unsatCore = core.sort((left, right) => ids[left] - ids[right]);
1664
+ return L_FALSE;
1665
+ }
1666
+
1263
1667
  search() {
1264
- if (this.isInconsistent()) return L_FALSE;
1668
+ if (this.asserted?.isInconsistent && !this.isInconsistent()) this.setConflict("axiom", null);
1669
+ if (this.isInconsistent()) {
1670
+ this.resolveConflict();
1671
+ return L_FALSE;
1672
+ }
1673
+ if (this.checkCanceled()) return L_UNDEF;
1265
1674
  this.resetModel();
1266
- this.theory.initSearchEh();
1675
+ for (const theory of this.theories) theory.initSearchEh();
1267
1676
  this.qmanager.initSearchEh();
1268
1677
  this.dynAck.initSearchEh();
1678
+ this.incompleteTheories = [];
1269
1679
  this.numConflicts = 0;
1270
1680
  this.numConflictsSinceRestart = 0;
1271
1681
  this.numConflictsSinceLemmaGc = 0;
1272
1682
  this.restartThreshold = RESTART_INITIAL;
1273
1683
  this.restartOuterThreshold = RESTART_INITIAL;
1274
1684
  this.agility = 0;
1685
+ this.lubyIndex = 1;
1275
1686
  this.finalCheckIndex = 0;
1276
1687
  this.lastSearchFailure = FAILURE_OK;
1688
+ this.phaseDefault = false;
1689
+ if (this.manager.hasTypeVars) this.registerFamily(FAMILY_POLY);
1277
1690
  this.isSearching = true;
1278
1691
  const currentLevel = this.scopeLevel;
1279
1692
  let result: number | undefined;