tla-ts 0.0.9-dev.8298a52 → 0.0.10-dev.28c823e4b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (390) hide show
  1. package/README.md +7 -0
  2. package/dist/compile.cjs +3 -3
  3. package/dist/compile.js +3 -3
  4. package/dist/deciders.cjs +28 -28
  5. package/dist/deciders.js +52 -52
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +105 -10
  8. package/dist/index.d.ts +105 -10
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +116 -36
  15. package/dist/prove.js +116 -36
  16. package/dist/run.cjs +143 -31
  17. package/dist/run.js +143 -31
  18. package/dist/tlapm.cjs +1 -1
  19. package/dist/tlapm.js +2 -2
  20. package/dist/transfer.cjs +129 -104
  21. package/dist/transfer.js +129 -104
  22. package/dist/worker.cjs +7 -7
  23. package/dist/worker.js +7 -7
  24. package/package.json +1 -1
  25. package/src/ast.ts +4 -23
  26. package/src/bags.ts +99 -102
  27. package/src/builtins.ts +40 -78
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check.ts +564 -366
  30. package/src/cli/options.ts +10 -5
  31. package/src/cli/run.ts +0 -2
  32. package/src/cli/runtime-invariants.ts +136 -0
  33. package/src/cli/shared.ts +18 -11
  34. package/src/cli/tlapm.ts +0 -12
  35. package/src/cli/tlc-arguments.ts +640 -0
  36. package/src/cli/tlc-usage.ts +361 -0
  37. package/src/cli/tlc.ts +525 -216
  38. package/src/cli/typescript.ts +0 -3
  39. package/src/cli/xml-exporter.ts +4 -16
  40. package/src/cli.ts +0 -1
  41. package/src/codegen.ts +191 -64
  42. package/src/config.ts +140 -109
  43. package/src/coverage.ts +837 -0
  44. package/src/dependencies.ts +6 -40
  45. package/src/dfid.ts +618 -0
  46. package/src/environment.ts +237 -119
  47. package/src/errors.ts +56 -56
  48. package/src/evaluate.ts +543 -341
  49. package/src/exit-codes.ts +37 -3
  50. package/src/fingerprints.ts +10 -10
  51. package/src/index.ts +3 -0
  52. package/src/instances.ts +38 -31
  53. package/src/java-overrides.ts +4 -19
  54. package/src/json-reader.ts +455 -0
  55. package/src/json.ts +255 -139
  56. package/src/levels.ts +8 -17
  57. package/src/lexer.ts +80 -100
  58. package/src/liveness-checker.ts +77 -117
  59. package/src/liveness.ts +106 -62
  60. package/src/obligations/action.ts +4 -28
  61. package/src/obligations/anonymize.ts +84 -80
  62. package/src/obligations/equality.ts +1 -1
  63. package/src/obligations/expression.ts +2 -19
  64. package/src/obligations/format.ts +1 -9
  65. package/src/obligations/generate.ts +1 -11
  66. package/src/obligations/index.ts +0 -11
  67. package/src/obligations/levels.ts +4 -8
  68. package/src/obligations/module.ts +1 -15
  69. package/src/obligations/normalize.ts +5 -24
  70. package/src/obligations/operators.ts +1 -2
  71. package/src/obligations/pragma.ts +1 -10
  72. package/src/obligations/printer.ts +47 -46
  73. package/src/obligations/proof.ts +1 -5
  74. package/src/obligations/regroup.ts +1 -4
  75. package/src/obligations/simplify.ts +3 -14
  76. package/src/obligations/source.ts +1 -21
  77. package/src/obligations/subexpression.ts +5 -11
  78. package/src/obligations/substitution.ts +1 -3
  79. package/src/obligations/temporal.ts +8 -14
  80. package/src/obligations/tuples.ts +3 -9
  81. package/src/parallel-worker.ts +24 -33
  82. package/src/parallel.ts +48 -40
  83. package/src/parser.ts +565 -282
  84. package/src/pcal/ast.ts +53 -86
  85. package/src/pcal/parse.ts +144 -219
  86. package/src/pcal/tokenize.ts +91 -131
  87. package/src/pcal/translate.ts +83 -130
  88. package/src/pcal/validate.ts +48 -68
  89. package/src/pretty-print.ts +7 -8
  90. package/src/prover/decide-pool.ts +5 -10
  91. package/src/prover/deciders.ts +0 -4
  92. package/src/prover/first-order.ts +0 -11
  93. package/src/prover/isabelle/decide.ts +0 -6
  94. package/src/prover/isabelle/encode.ts +11 -23
  95. package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
  96. package/src/prover/isabelle/isar/method.ts +25 -38
  97. package/src/prover/isabelle/isar/proof.ts +1 -10
  98. package/src/prover/isabelle/isar/statement.ts +1 -6
  99. package/src/prover/isabelle/isar/theory.ts +15 -26
  100. package/src/prover/isabelle/isar/type-check.ts +11 -25
  101. package/src/prover/isabelle/provers/blast/blast.ts +10 -41
  102. package/src/prover/isabelle/provers/blast/branch.ts +1 -32
  103. package/src/prover/isabelle/provers/blast/prove.ts +1 -35
  104. package/src/prover/isabelle/provers/blast/rules.ts +6 -44
  105. package/src/prover/isabelle/provers/blast/state.ts +2 -28
  106. package/src/prover/isabelle/provers/blast/term.ts +9 -36
  107. package/src/prover/isabelle/provers/clasimp.ts +1 -13
  108. package/src/prover/isabelle/provers/classical.ts +14 -42
  109. package/src/prover/isabelle/provers/hypsubst.ts +11 -25
  110. package/src/prover/isabelle/pure/bicompose.ts +16 -13
  111. package/src/prover/isabelle/pure/consts.ts +1 -7
  112. package/src/prover/isabelle/pure/conv.ts +1 -9
  113. package/src/prover/isabelle/pure/drule.ts +24 -40
  114. package/src/prover/isabelle/pure/envir.ts +3 -52
  115. package/src/prover/isabelle/pure/goal.ts +1 -7
  116. package/src/prover/isabelle/pure/interrupt.ts +0 -5
  117. package/src/prover/isabelle/pure/list.ts +0 -3
  118. package/src/prover/isabelle/pure/logic.ts +1 -14
  119. package/src/prover/isabelle/pure/name.ts +2 -9
  120. package/src/prover/isabelle/pure/net.ts +3 -59
  121. package/src/prover/isabelle/pure/object-logic.ts +3 -10
  122. package/src/prover/isabelle/pure/pattern.ts +2 -19
  123. package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
  124. package/src/prover/isabelle/pure/rewriter.ts +26 -58
  125. package/src/prover/isabelle/pure/search.ts +3 -10
  126. package/src/prover/isabelle/pure/seq.ts +1 -10
  127. package/src/prover/isabelle/pure/simplifier.ts +4 -12
  128. package/src/prover/isabelle/pure/table.ts +1 -31
  129. package/src/prover/isabelle/pure/tactic.ts +12 -22
  130. package/src/prover/isabelle/pure/tactical.ts +6 -12
  131. package/src/prover/isabelle/pure/term-ord.ts +2 -6
  132. package/src/prover/isabelle/pure/term.ts +2 -43
  133. package/src/prover/isabelle/pure/thm.ts +13 -36
  134. package/src/prover/isabelle/pure/type.ts +2 -15
  135. package/src/prover/isabelle/pure/unify.ts +20 -30
  136. package/src/prover/isabelle/pure/variable.ts +3 -7
  137. package/src/prover/isabelle/tla/classical-setup.ts +9 -19
  138. package/src/prover/isabelle/tla/context.ts +8 -16
  139. package/src/prover/isabelle/tla/logic.ts +4 -11
  140. package/src/prover/isabelle/tla/simpdata.ts +46 -34
  141. package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
  142. package/src/prover/ocaml.ts +0 -6
  143. package/src/prover/prep/action.ts +4 -36
  144. package/src/prover/prep/enabled-axioms.ts +12 -19
  145. package/src/prover/prep/fingerprint.ts +0 -16
  146. package/src/prover/prep/level-comparison.ts +8 -12
  147. package/src/prover/prep/md5.ts +0 -2
  148. package/src/prover/prep/methods.ts +9 -36
  149. package/src/prover/prep/normalize.ts +4 -28
  150. package/src/prover/prove-worker.ts +0 -2
  151. package/src/prover/prove.ts +0 -36
  152. package/src/prover/ptl/decide.ts +7 -12
  153. package/src/prover/ptl/encode.ts +14 -36
  154. package/src/prover/ptl/sat.ts +24 -32
  155. package/src/prover/ptl/tableau.ts +12 -26
  156. package/src/prover/smt/axioms.ts +0 -7
  157. package/src/prover/smt/context.ts +19 -26
  158. package/src/prover/smt/data.ts +51 -54
  159. package/src/prover/smt/encode.ts +14 -35
  160. package/src/prover/smt/extensionality.ts +0 -10
  161. package/src/prover/smt/flatten.ts +3 -22
  162. package/src/prover/smt/format.ts +5 -10
  163. package/src/prover/smt/instances.ts +0 -10
  164. package/src/prover/smt/rewrite.ts +66 -101
  165. package/src/prover/smt/solver/act-cache.ts +0 -15
  166. package/src/prover/smt/solver/arith-rewriter.ts +3 -48
  167. package/src/prover/smt/solver/array.ts +1 -3
  168. package/src/prover/smt/solver/asserted-formulas.ts +1 -43
  169. package/src/prover/smt/solver/ast-lt.ts +1 -11
  170. package/src/prover/smt/solver/ast-util.ts +1 -6
  171. package/src/prover/smt/solver/ast.ts +1 -143
  172. package/src/prover/smt/solver/auf-solver.ts +6 -39
  173. package/src/prover/smt/solver/case-split-queue.ts +1 -9
  174. package/src/prover/smt/solver/cg-table.ts +1 -18
  175. package/src/prover/smt/solver/clause.ts +1 -27
  176. package/src/prover/smt/solver/conflict-resolution.ts +0 -9
  177. package/src/prover/smt/solver/context.ts +4 -61
  178. package/src/prover/smt/solver/ctx-simplify.ts +14 -41
  179. package/src/prover/smt/solver/der.ts +2 -21
  180. package/src/prover/smt/solver/dyn-ack.ts +1 -11
  181. package/src/prover/smt/solver/e-matching.ts +3 -34
  182. package/src/prover/smt/solver/enode.ts +1 -21
  183. package/src/prover/smt/solver/expr-ref.ts +1 -5
  184. package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
  185. package/src/prover/smt/solver/fingerprints.ts +1 -12
  186. package/src/prover/smt/solver/flat-literals.ts +1 -9
  187. package/src/prover/smt/solver/goal.ts +2 -14
  188. package/src/prover/smt/solver/hash.ts +0 -8
  189. package/src/prover/smt/solver/hashtable.ts +1 -12
  190. package/src/prover/smt/solver/internalizer.ts +6 -98
  191. package/src/prover/smt/solver/lbool.ts +1 -2
  192. package/src/prover/smt/solver/literal.ts +0 -3
  193. package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
  194. package/src/prover/smt/solver/lp/constraints.ts +2 -8
  195. package/src/prover/smt/solver/lp/containers.ts +12 -30
  196. package/src/prover/smt/solver/lp/core-solver.ts +10 -31
  197. package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
  198. package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
  199. package/src/prover/smt/solver/lp/dependency.ts +1 -4
  200. package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
  201. package/src/prover/smt/solver/lp/explanation.ts +1 -6
  202. package/src/prover/smt/solver/lp/gomory.ts +9 -22
  203. package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
  204. package/src/prover/smt/solver/lp/hnf.ts +11 -26
  205. package/src/prover/smt/solver/lp/int-cube.ts +15 -36
  206. package/src/prover/smt/solver/lp/int-solver.ts +4 -34
  207. package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
  208. package/src/prover/smt/solver/lp/lar-term.ts +1 -5
  209. package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
  210. package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
  211. package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
  212. package/src/prover/smt/solver/lp/nex.ts +1 -6
  213. package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
  214. package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
  215. package/src/prover/smt/solver/lp/nla-core.ts +35 -130
  216. package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
  217. package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
  218. package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
  219. package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
  220. package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
  221. package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
  222. package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
  223. package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
  224. package/src/prover/smt/solver/lp/nla-order.ts +2 -13
  225. package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
  226. package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
  227. package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
  228. package/src/prover/smt/solver/lp/nla-types.ts +1 -11
  229. package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
  230. package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
  231. package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
  232. package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
  233. package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
  234. package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
  235. package/src/prover/smt/solver/lp/pdd.ts +7 -70
  236. package/src/prover/smt/solver/lp/random-updater.ts +1 -8
  237. package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
  238. package/src/prover/smt/solver/lp/union-find.ts +1 -6
  239. package/src/prover/smt/solver/mam-compiler.ts +14 -56
  240. package/src/prover/smt/solver/mam-interpreter.ts +1 -21
  241. package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
  242. package/src/prover/smt/solver/model-checker.ts +2 -36
  243. package/src/prover/smt/solver/model-evaluator.ts +3 -29
  244. package/src/prover/smt/solver/model-finder.ts +3 -15
  245. package/src/prover/smt/solver/model-generator.ts +1 -12
  246. package/src/prover/smt/solver/model-macro-solver.ts +12 -69
  247. package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
  248. package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
  249. package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
  250. package/src/prover/smt/solver/nlsat/explain.ts +3 -47
  251. package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
  252. package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
  253. package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
  254. package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
  255. package/src/prover/smt/solver/nlsat/solver.ts +7 -67
  256. package/src/prover/smt/solver/nlsat/types.ts +1 -8
  257. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
  258. package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
  259. package/src/prover/smt/solver/nnf.ts +3 -38
  260. package/src/prover/smt/solver/pattern-inference.ts +2 -15
  261. package/src/prover/smt/solver/poly-rewriter.ts +3 -23
  262. package/src/prover/smt/solver/propagate-values.ts +1 -10
  263. package/src/prover/smt/solver/proto-model.ts +3 -48
  264. package/src/prover/smt/solver/pull-quant.ts +1 -12
  265. package/src/prover/smt/solver/qe-lite-der.ts +1 -29
  266. package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
  267. package/src/prover/smt/solver/qe-lite.ts +3 -33
  268. package/src/prover/smt/solver/qi-queue.ts +1 -16
  269. package/src/prover/smt/solver/quant-tactics.ts +5 -22
  270. package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
  271. package/src/prover/smt/solver/quantifier-manager.ts +1 -8
  272. package/src/prover/smt/solver/random-gen.ts +1 -2
  273. package/src/prover/smt/solver/rational.ts +1 -8
  274. package/src/prover/smt/solver/ref-vector.ts +1 -6
  275. package/src/prover/smt/solver/relevancy.ts +2 -15
  276. package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
  277. package/src/prover/smt/solver/rewriter.ts +3 -85
  278. package/src/prover/smt/solver/rlimit.ts +2 -20
  279. package/src/prover/smt/solver/smtlib-parser.ts +2 -37
  280. package/src/prover/smt/solver/solver.ts +1 -16
  281. package/src/prover/smt/solver/sort.ts +1 -5
  282. package/src/prover/smt/solver/sticky-generations.ts +0 -5
  283. package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
  284. package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
  285. package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
  286. package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
  287. package/src/prover/smt/solver/theory-lra-model.ts +4 -19
  288. package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
  289. package/src/prover/smt/solver/theory-lra-state.ts +3 -8
  290. package/src/prover/smt/solver/theory-lra.ts +1 -8
  291. package/src/prover/smt/solver/var-subst.ts +2 -26
  292. package/src/prover/smt/table.ts +0 -8
  293. package/src/prover/tlapm/cache.ts +20 -25
  294. package/src/prover/tlapm/ocaml-marshal.ts +19 -21
  295. package/src/prover/tlapm/tlapm.ts +12 -17
  296. package/src/prover/verdict.ts +0 -2
  297. package/src/prover/zenon/check/check.ts +0 -9
  298. package/src/prover/zenon/check/definitions.ts +5 -15
  299. package/src/prover/zenon/check/equality.ts +0 -8
  300. package/src/prover/zenon/check/functions.ts +0 -4
  301. package/src/prover/zenon/check/keys.ts +0 -7
  302. package/src/prover/zenon/check/propositional.ts +0 -3
  303. package/src/prover/zenon/check/records.ts +0 -5
  304. package/src/prover/zenon/check/relations.ts +0 -13
  305. package/src/prover/zenon/check/rewrites.ts +0 -6
  306. package/src/prover/zenon/check/sets.ts +0 -3
  307. package/src/prover/zenon/check/terms.ts +0 -17
  308. package/src/prover/zenon/check/tla.ts +0 -6
  309. package/src/prover/zenon/decide.ts +0 -12
  310. package/src/prover/zenon/encode.ts +1 -8
  311. package/src/prover/zenon/eqrel.ts +0 -13
  312. package/src/prover/zenon/equality-rules.ts +0 -4
  313. package/src/prover/zenon/expr.ts +1 -26
  314. package/src/prover/zenon/index-table.ts +17 -38
  315. package/src/prover/zenon/isar-case.ts +9 -19
  316. package/src/prover/zenon/isar.ts +1 -29
  317. package/src/prover/zenon/limits.ts +0 -4
  318. package/src/prover/zenon/llproof.ts +0 -9
  319. package/src/prover/zenon/mltoll.ts +54 -76
  320. package/src/prover/zenon/node.ts +1 -11
  321. package/src/prover/zenon/ocaml.ts +1 -17
  322. package/src/prover/zenon/parse.ts +2 -7
  323. package/src/prover/zenon/phrase.ts +1 -11
  324. package/src/prover/zenon/proof.ts +0 -9
  325. package/src/prover/zenon/propositional-rules.ts +0 -5
  326. package/src/prover/zenon/rules.ts +2 -6
  327. package/src/prover/zenon/search.ts +1 -17
  328. package/src/prover/zenon/tla/functions.ts +57 -29
  329. package/src/prover/zenon/tla/llproof.ts +63 -70
  330. package/src/prover/zenon/tla/records.ts +56 -27
  331. package/src/prover/zenon/tla/rewrites.ts +12 -19
  332. package/src/prover/zenon/tla/sets.ts +68 -39
  333. package/src/prover/zenon/tla/terms.ts +0 -6
  334. package/src/prover/zenon/tla/tla.ts +59 -58
  335. package/src/randomization.ts +81 -35
  336. package/src/resolve.ts +12 -112
  337. package/src/runtime.ts +22 -22
  338. package/src/sany/builtins.ts +2 -5
  339. package/src/sany/generator.ts +149 -252
  340. package/src/sany/levels.ts +6 -34
  341. package/src/sany/lexer.ts +41 -61
  342. package/src/sany/linter.ts +1 -9
  343. package/src/sany/modules.ts +1 -5
  344. package/src/sany/nodes.ts +0 -31
  345. package/src/sany/parse-error.ts +39 -117
  346. package/src/sany/report.ts +29 -63
  347. package/src/sany/selectors.ts +15 -39
  348. package/src/sany/source.ts +1 -17
  349. package/src/sany/xml.ts +13 -63
  350. package/src/search.ts +495 -155
  351. package/src/simulate.ts +685 -0
  352. package/src/spec-description.ts +176 -69
  353. package/src/standard-definitions.ts +0 -4
  354. package/src/standard-modules.ts +254 -69
  355. package/src/state-graph.ts +50 -24
  356. package/src/subexpressions.ts +69 -52
  357. package/src/substitution-levels.ts +2 -3
  358. package/src/successors.ts +260 -91
  359. package/src/symmetry.ts +33 -25
  360. package/src/tableau.ts +27 -24
  361. package/src/tlc/fingerprint.ts +183 -67
  362. package/src/tlc/jar-data.ts +112 -6
  363. package/src/tlc/messages.ts +110 -44
  364. package/src/tlc/order.ts +37 -60
  365. package/src/tlc/random.ts +33 -45
  366. package/src/tlc/replay.ts +549 -217
  367. package/src/tlc/summary.ts +36 -47
  368. package/src/tlc/tlc-operators.ts +76 -41
  369. package/src/tlc/tlcext-operators.ts +139 -122
  370. package/src/tlc/trace-spec.ts +269 -0
  371. package/src/tlc/value-stream.ts +139 -0
  372. package/src/tlc/version.ts +1 -4
  373. package/src/transfer.ts +22 -25
  374. package/src/typescript/actions.ts +8 -21
  375. package/src/typescript/collections.ts +0 -15
  376. package/src/typescript/compile.ts +0 -5
  377. package/src/typescript/context.ts +0 -12
  378. package/src/typescript/emit.ts +0 -1
  379. package/src/typescript/expressions.ts +0 -12
  380. package/src/typescript/formula.ts +4 -12
  381. package/src/typescript/functions.ts +6 -17
  382. package/src/typescript/model.ts +10 -11
  383. package/src/typescript/names.ts +0 -2
  384. package/src/typescript/program.ts +0 -3
  385. package/src/typescript/properties.ts +6 -8
  386. package/src/typescript/scope.ts +0 -5
  387. package/src/typescript/steps.ts +0 -10
  388. package/src/typescript/types.ts +1 -8
  389. package/src/values.ts +749 -330
  390. package/src/worker.ts +7 -8
@@ -1,6 +1,4 @@
1
- // Ported from Z3 (src/smt/smt_context.h, src/smt/smt_internalizer.cpp), MIT license, see
2
- // z3-license.txt. The state of the SMT kernel and the translation of formulas into it: Boolean
3
- // variables, enodes, clauses and relevancy watches. The search lives in context.ts.
1
+ // Ported from Z3 (src/smt/smt_context.h, src/smt/smt_internalizer.cpp), MIT license, see z3-license.txt.
4
2
  import { SmtInvariantError } from "../../../errors";
5
3
  import {
6
4
  AstManager,
@@ -61,15 +59,11 @@ import type { TheoryLra } from "./theory-lra";
61
59
  import { setAt, shrink } from "./array";
62
60
  import { StickyGenerations } from "./sticky-generations";
63
61
 
64
- // DEEP_EXPR_THRESHOLD: the depth above which internalize_deep sorts an expression's subterms.
65
62
  const DEEP_EXPR_THRESHOLD = 1024;
66
63
  const WHITE = 0;
67
64
  const GREY = 1;
68
65
  const BLACK = 2;
69
66
 
70
- // The kinds of undo trail entries. Z3 allocates its trail objects in a region. Here an entry is its
71
- // kind on trailKinds, with its operands on trailNodes and trailInts, so recording one allocates
72
- // nothing. pushTrail's closures are one more kind.
73
67
  const UNDO_CLOSURE = 0;
74
68
  const UNDO_MK_BOOL_VAR = 1;
75
69
  const UNDO_MK_ENODE = 2;
@@ -79,9 +73,6 @@ const UNDO_CGC_GENERATIONS = 5;
79
73
  const UNDO_MERGE_TF = 6;
80
74
  const UNDO_ENODE_FLAG = 7;
81
75
 
82
- // The first word of bool_var_data: the level of the assignment in the low 24 bits, then m_mark,
83
- // m_phase_available, m_phase, m_eq, m_true_first, m_enode, m_quantifier and whether a theory is
84
- // notified.
85
76
  const LEVEL_MASK = 0xffffff;
86
77
  const BV_MARK = 1 << 24;
87
78
  export const BV_PHASE_AVAILABLE = 1 << 25;
@@ -100,7 +91,6 @@ interface NewEq {
100
91
  justification: EqJustification;
101
92
  }
102
93
 
103
- // m_conflict and m_not_l: the justification of the conflict, and the literal it falsifies, if any.
104
94
  interface Conflict {
105
95
  justification: BJustification;
106
96
  notLiteral: Literal | null;
@@ -117,39 +107,20 @@ export abstract class Internalizer {
117
107
  abstract readonly theory: TheoryLra;
118
108
  abstract readonly qmanager: DefaultQuantifierManager;
119
109
 
120
- // Per Boolean variable. Like Z3's vectors, the arrays keep their size when a variable is deleted,
121
- // since V8 shrinks an array's storage when it pops and copies it again when it grows. Only the
122
- // first numBoolVars entries are live.
123
110
  numBoolVars = 0;
124
111
  boolVar2Expr: number[] = [];
125
- // bool_var_data: two words per variable. The first holds the level of its assignment and the BV_
126
- // flags, the second the level of its internalization.
127
112
  private boolVarData = new Int32Array(2048);
128
113
  justifications: BJustification[] = [];
129
114
  activity: number[] = [];
130
- // Per literal.
131
115
  protected assignment: number[] = [];
132
116
  readonly clauses = new ClauseStore();
133
- // Like Z3's watch lists, a literal's lists are created when the first clause is added.
134
117
  protected watches: (Clause[] | undefined)[] = [];
135
- // del_clauses' uint_set of the watch lists to filter, by literal, all 0 between calls.
136
118
  private watchMarks = new Uint8Array(1024);
137
- // The false literals that simplify_aux_clause_literals removes from the clause mkClause makes.
138
119
  private removedLiterals: Literal[] = [];
139
- // The literal_buffer of mk_and_cnstr and mk_or_cnstr, and the array that mk_gate_clause keeps on
140
- // the stack. mkClause neither keeps them nor makes a gate, so the gates reuse them.
141
120
  private gateBuffer: Literal[] = [];
142
121
  private gateLiterals: Literal[] = [];
143
- // The binary clauses of the binary clause optimization: the literals each literal propagates when it
144
- // becomes true, which Z3 visits newest first and before the clauses.
145
122
  protected binaryWatches: (Literal[] | undefined)[] = [];
146
- // A binary justification holds only its literal, so undoMkBoolVar keeps it for the next variable
147
- // with that literal. Clearing it would write past the end of this sparse array, which V8 then
148
- // turns into a dictionary.
149
123
  private binJustifications: (BinJustification | undefined)[] = [];
150
- // Per expression.
151
- // The Boolean variable of each expression, or -1. A typed array keeps the element loads of every
152
- // context monomorphic, where the holes of a growing array give each its own elements kind.
153
124
  private exprToBoolVar = new Int32Array(1024).fill(-1);
154
125
  protected exprToEnode: (Enode | undefined)[] = [];
155
126
 
@@ -225,7 +196,6 @@ export abstract class Internalizer {
225
196
  this.eqPropagationQueue.push({ lhs, rhs, justification });
226
197
  }
227
198
 
228
- // random_gen from Z3's util/util.h with the default seed 0.
229
199
  getRandomValue() {
230
200
  this.randomSeed = (Math.imul(this.randomSeed, 214013) + 2531011) >>> 0;
231
201
  return (this.randomSeed >>> 16) & 0x7fff;
@@ -289,8 +259,6 @@ export abstract class Internalizer {
289
259
  }
290
260
  }
291
261
 
292
- // Assignment queries.
293
-
294
262
  getAssignment(literal: Literal) {
295
263
  return this.assignment[literal];
296
264
  }
@@ -341,9 +309,6 @@ export abstract class Internalizer {
341
309
  return this.cgTable.findFor(decl, args, decl === OP_EQ);
342
310
  }
343
311
 
344
- // is_diseq_core: the roots are distinct values, or an equality between the two classes is false.
345
- // The congruence table is searched with m_is_diseq_tmp, an equality of the sort, which holds a
346
- // reference until an equality of another sort replaces it.
347
312
  isDiseq(first: Enode, second: Enode) {
348
313
  const manager = this.manager;
349
314
  if (manager.areDistinct(first.root.owner, second.root.owner)) return true;
@@ -401,7 +366,6 @@ export abstract class Internalizer {
401
366
  return this.relevancy.isRelevant(expr);
402
367
  }
403
368
 
404
- // context::mark_as_relevant, which propagates the relevancy at once.
405
369
  markAsRelevant(expr: number) {
406
370
  this.relevancy.markAsRelevant(expr);
407
371
  this.relevancy.propagate();
@@ -415,13 +379,10 @@ export abstract class Internalizer {
415
379
  return this.conflict !== null;
416
380
  }
417
381
 
418
- // get_generation: the generation of the congruence root. Equalities have generation 0, since
419
- // patterns have no equalities.
420
382
  getGeneration(node: Enode) {
421
383
  return node.isEq ? 0 : this.getCgRoot(node).generation;
422
384
  }
423
385
 
424
- // get_cg_root: a node's cg can be stale, so a node that is not a congruence root looks the root up.
425
386
  private getCgRoot(node: Enode) {
426
387
  if (!node.usesCgTable() || node.isCgr()) return node;
427
388
  return this.cgTable.findCongruent(node) ?? node;
@@ -439,9 +400,6 @@ export abstract class Internalizer {
439
400
  ) {
440
401
  this.setGeneration(first, firstGeneration);
441
402
  this.setGeneration(second, secondGeneration);
442
- // apply_sticky_updates: a lowered generation outlives the merge that it was made under. Only the
443
- // updates of the two nodes' declarations can be congruent to them, and a node with an update
444
- // uses the congruence table, so it has arguments and is no equality.
445
403
  this.applyStickyUpdates(first, firstGeneration, second, secondGeneration);
446
404
  if (second.decl !== first.decl) this.applyStickyUpdates(second, secondGeneration, null, 0);
447
405
  }
@@ -473,10 +431,6 @@ export abstract class Internalizer {
473
431
  }
474
432
  }
475
433
 
476
- // Boolean variables and enodes.
477
-
478
- // mk_bool_var: m_b_internalized_stack holds a reference to the expression until the variable is
479
- // deleted.
480
434
  mkBoolVar(expr: number) {
481
435
  const boolVar = toBoolVar(this.numBoolVars++);
482
436
  const literal = mkLiteral(boolVar);
@@ -501,8 +455,6 @@ export abstract class Internalizer {
501
455
  return boolVar;
502
456
  }
503
457
 
504
- // The arrays keep the deleted variable's entries, which mkBoolVar overwrites. Those that hold
505
- // objects are cleared, so the objects can be collected.
506
458
  private undoMkBoolVar() {
507
459
  const boolVar = toBoolVar(--this.numBoolVars);
508
460
  const expr = this.boolVar2Expr[boolVar];
@@ -513,7 +465,6 @@ export abstract class Internalizer {
513
465
  this.manager.decRef(expr);
514
466
  }
515
467
 
516
- // The level of the variable's assignment.
517
468
  getLevel(boolVar: number) {
518
469
  return this.boolVarData[2 * boolVar] & LEVEL_MASK;
519
470
  }
@@ -523,7 +474,6 @@ export abstract class Internalizer {
523
474
  this.boolVarData[index] = (this.boolVarData[index] & ~LEVEL_MASK) | level;
524
475
  }
525
476
 
526
- // The scope level at which the variable was internalized.
527
477
  getInternLevel(boolVar: number) {
528
478
  return this.boolVarData[2 * boolVar + 1];
529
479
  }
@@ -547,10 +497,9 @@ export abstract class Internalizer {
547
497
  this.setBoolVarFlag(boolVar, BV_MARK, value);
548
498
  }
549
499
 
550
- // watch_list::reset: a new variable's lists keep the room of a deleted one's. Assigning undefined to
551
- // a literal past the end keeps the arrays without holes.
552
500
  private resetWatches(literal: number) {
553
501
  const list = this.watches[literal];
502
+ // HACK: assigning undefined to a literal past the end keeps V8's arrays without holes.
554
503
  if (list === undefined) this.watches[literal] = undefined;
555
504
  else shrink(list, 0);
556
505
  const binary = this.binaryWatches[literal];
@@ -604,7 +553,6 @@ export abstract class Internalizer {
604
553
  for (let index = 0; index < numArgs; index++) node.getArg(index).root.addParent(node);
605
554
  if (manager.isUniqueValue(expr)) node.isInterpreted = true;
606
555
  setAt(this.exprToEnode, expr, node);
607
- // m_e_internalized_stack holds a reference to the expression until the enode is deleted.
608
556
  manager.incRef(expr);
609
557
  this.trailKinds.push(UNDO_MK_ENODE);
610
558
  this.enodes.push(node);
@@ -632,7 +580,6 @@ export abstract class Internalizer {
632
580
  return node;
633
581
  }
634
582
 
635
- // The enode of an argument of expr, which is internalized before expr.
636
583
  private getArgEnode(expr: number, index: number) {
637
584
  const node = this.exprToEnode[this.manager.getArg(expr, index)];
638
585
  if (node === undefined) throw new SmtInvariantError("an argument was not internalized");
@@ -680,8 +627,6 @@ export abstract class Internalizer {
680
627
  this.setBoolVarFlag(boolVar, BV_ENODE, true);
681
628
  }
682
629
 
683
- // update_generation: a node of a congruence class records its lower generation as sticky, so
684
- // undoing a merge of the class keeps it.
685
630
  private updateGeneration(node: Enode) {
686
631
  if (node.isEq) return;
687
632
  if (this.generation > 0 && this.generation < this.getGeneration(node)) {
@@ -690,16 +635,12 @@ export abstract class Internalizer {
690
635
  }
691
636
  }
692
637
 
693
- // Internalization.
694
-
695
638
  private isGate(expr: number) {
696
639
  const op = this.manager.getOp(expr);
697
640
  if (op === OP_AND || op === OP_OR || op === OP_ITE) return true;
698
641
  return op === OP_EQ && this.manager.isBool(this.manager.getArg(expr, 0));
699
642
  }
700
643
 
701
- // should_internalize_rec: a term, or a Boolean application of the basic family or an
702
- // uninterpreted declaration.
703
644
  private shouldInternalizeRec(expr: number) {
704
645
  const manager = this.manager;
705
646
  if (manager.kinds[expr] !== KIND_APP || manager.sorts[expr] !== SORT_BOOL) return true;
@@ -707,8 +648,6 @@ export abstract class Internalizer {
707
648
  return family === FAMILY_BASIC || family === FAMILY_USER;
708
649
  }
709
650
 
710
- // internalize_deep: internalizes the subterms of a deep expression bottom up, in the order of a
711
- // topological sort, so the recursion of internalizeRec stays shallow.
712
651
  private internalizeDeep(expr: number) {
713
652
  if (
714
653
  this.isEInternalized(expr) ||
@@ -717,8 +656,6 @@ export abstract class Internalizer {
717
656
  )
718
657
  return;
719
658
  const manager = this.manager;
720
- // The color of each expression in a gate context and outside one: white while unvisited, grey
721
- // while its children are visited, and black once it is sorted.
722
659
  const colors = new Map<number, number>();
723
660
  const getColor = (current: number, isGate: boolean) =>
724
661
  colors.get(current * 2 + (isGate ? 1 : 0)) ?? WHITE;
@@ -727,7 +664,6 @@ export abstract class Internalizer {
727
664
  const visitChild = (child: number, isGate: boolean) => {
728
665
  if (getColor(child, isGate) === WHITE) todo.push([child, isGate]);
729
666
  };
730
- // ts_visit_children, which Z3 calls again on grey expressions only in its assertions.
731
667
  const visitChildren = (current: number) => {
732
668
  if (manager.kinds[current] === KIND_QUANTIFIER || !this.shouldInternalizeRec(current)) return;
733
669
  const node = this.exprToEnode[current];
@@ -873,12 +809,8 @@ export abstract class Internalizer {
873
809
  this.internalizeFormulaCore(expr, isGateContext);
874
810
  const boolVar = this.getBoolVar(expr);
875
811
  this.setBoolVarFlag(boolVar, BV_EQ, true);
876
- if (this.manager.sorts[this.manager.getArg(expr, 0)] !== SORT_BOOL && this.isArithSort(expr))
877
- this.theory.internalizeEqEh(expr);
878
- }
879
-
880
- private isArithSort(eq: number) {
881
- return isArithSort(this.manager.sorts[this.manager.getArg(eq, 0)]);
812
+ const sort = this.manager.sorts[this.manager.getArg(expr, 0)];
813
+ if (sort !== SORT_BOOL && isArithSort(sort)) this.theory.internalizeEqEh(expr);
882
814
  }
883
815
 
884
816
  private internalizeTheoryAtom(expr: number, isGateContext: boolean) {
@@ -995,7 +927,6 @@ export abstract class Internalizer {
995
927
  }
996
928
  }
997
929
 
998
- // mk_gate_clause with two or three literals.
999
930
  private mkGateClause(first: Literal, second: Literal, third?: Literal) {
1000
931
  const literals = this.gateLiterals;
1001
932
  shrink(literals, 0);
@@ -1009,11 +940,8 @@ export abstract class Internalizer {
1009
940
  const existing = this.exprToEnode[expr];
1010
941
  if (existing !== undefined) {
1011
942
  this.updateGeneration(existing);
1012
- // The theory may have made a nested term, such as the 2 of (* 2 x), without a variable, which
1013
- // it needs once the term occurs elsewhere.
1014
- if (manager.getFamily(expr) === FAMILY_ARITH && !this.theory.isAttachedToVar(existing)) {
943
+ if (manager.getFamily(expr) === FAMILY_ARITH && !this.theory.isAttachedToVar(existing))
1015
944
  this.theory.internalizeTerm(expr);
1016
- }
1017
945
  return;
1018
946
  }
1019
947
  if (manager.getOp(expr) === OP_ITE) {
@@ -1029,7 +957,6 @@ export abstract class Internalizer {
1029
957
  this.mkEnode(expr, false, false, true);
1030
958
  }
1031
959
 
1032
- // mk_eq_atom: the side with the smaller id goes first.
1033
960
  mkEqAtom(lhs: number, rhs: number) {
1034
961
  const ids = this.manager.ids;
1035
962
  return ids[lhs] < ids[rhs] ? this.manager.mkEq(lhs, rhs) : this.manager.mkEq(rhs, lhs);
@@ -1047,7 +974,6 @@ export abstract class Internalizer {
1047
974
  const condition = this.getLiteral(this.manager.getArg(expr, 0));
1048
975
  this.mkClause([negate(condition), this.getLiteral(thenEq)], null, CLS_AUX);
1049
976
  this.mkClause([condition, this.getLiteral(elseEq)], null, CLS_AUX);
1050
- // ite_term_relevancy_eh: it marks the terms for the propagator, which propagates them later.
1051
977
  const handler = () => {
1052
978
  if (!this.isRelevant(expr)) return;
1053
979
  this.relevancy.markAsRelevant(this.manager.getArg(expr, 0));
@@ -1096,8 +1022,6 @@ export abstract class Internalizer {
1096
1022
  this.addRelWatch(negate(literal), handler);
1097
1023
  }
1098
1024
 
1099
- // Clauses.
1100
-
1101
1025
  mkThAxiom(literals: Literal[]) {
1102
1026
  this.mkClause(literals, null, CLS_TH_AXIOM);
1103
1027
  }
@@ -1125,8 +1049,6 @@ export abstract class Internalizer {
1125
1049
  return true;
1126
1050
  }
1127
1051
 
1128
- // simplify_aux_lemma_literals: unlike an aux clause, a theory lemma keeps its false literals, so it
1129
- // needs no unit resolution justification.
1130
1052
  private simplifyAuxLemmaLiterals(literals: Literal[]) {
1131
1053
  sortNumbers(literals);
1132
1054
  let previous: Literal | null = null;
@@ -1191,8 +1113,6 @@ export abstract class Internalizer {
1191
1113
  this.addWatch(negate(this.clauses.getLiteral(clause, index)), clause);
1192
1114
  }
1193
1115
 
1194
- // A literal's first watch gets a list of its own size, since growing an empty list allocates room
1195
- // for many.
1196
1116
  protected addWatch(literal: Literal, clause: Clause) {
1197
1117
  const list = this.watches[literal];
1198
1118
  if (list === undefined) this.watches[literal] = [clause];
@@ -1202,7 +1122,6 @@ export abstract class Internalizer {
1202
1122
  protected removeWatchLiteral(clause: Clause, index: number) {
1203
1123
  const list = this.watches[negate(this.clauses.getLiteral(clause, index))];
1204
1124
  if (list === undefined) return;
1205
- // A clause is deleted when its scope is popped, so it is most often near the end.
1206
1125
  const position = list.lastIndexOf(clause);
1207
1126
  if (position === -1) return;
1208
1127
  list.copyWithin(position, position + 1);
@@ -1217,9 +1136,6 @@ export abstract class Internalizer {
1217
1136
  return created;
1218
1137
  }
1219
1138
 
1220
- // use_binary_clause_opt: a clause of two literals at the base level of the first scope, over
1221
- // variables created there, becomes a pair of binary watches. With relevancy, lemmas stay clauses so
1222
- // their propagations can mark literals as relevant.
1223
1139
  private isUsingBinaryClauseOpt(first: Literal, second: Literal, isLemma: boolean) {
1224
1140
  if (isLemma && this.relevancy.isEnabled) return false;
1225
1141
  if (this.baseLevel > 0) return false;
@@ -1240,14 +1156,12 @@ export abstract class Internalizer {
1240
1156
  this.clausesToReinit[level].push(clause);
1241
1157
  }
1242
1158
 
1243
- // mk_clause: like Z3's, it simplifies the literals in the array it is given.
1244
1159
  mkClause(
1245
- input: Literal[],
1160
+ literals: Literal[],
1246
1161
  inputJustification: Justification | null,
1247
1162
  kind: number,
1248
1163
  delEh: (() => void) | null = null,
1249
1164
  ) {
1250
- const literals = input;
1251
1165
  let justification = inputJustification;
1252
1166
  if (kind === CLS_TH_LEMMA) {
1253
1167
  if (!this.simplifyAuxLemmaLiterals(literals)) return null;
@@ -1298,8 +1212,6 @@ export abstract class Internalizer {
1298
1212
  this.addWatchLiteral(clause, 1);
1299
1213
  const first = clauses.getLiteral(clause, 0);
1300
1214
  const second = clauses.getLiteral(clause, 1);
1301
- // A theory lemma that conflicts or propagates above the base level is checked again when the
1302
- // level is backtracked.
1303
1215
  const isPropagating =
1304
1216
  this.assignment[first] === L_FALSE || this.assignment[second] === L_FALSE;
1305
1217
  if (this.assignment[first] === L_FALSE) this.setConflict(clause, null);
@@ -1317,7 +1229,6 @@ export abstract class Internalizer {
1317
1229
  return clause;
1318
1230
  }
1319
1231
 
1320
- // del_clause. A clause in the reinit stack is only marked deleted, and reinitClauses frees it.
1321
1232
  protected deleteClause(clause: Clause) {
1322
1233
  const clauses = this.clauses;
1323
1234
  if (clauses.isDeleted(clause)) return;
@@ -1329,14 +1240,11 @@ export abstract class Internalizer {
1329
1240
  if (!clauses.isReinit(clause)) clauses.free(clause);
1330
1241
  }
1331
1242
 
1332
- // release_atoms: the clause no longer holds its atoms.
1333
1243
  protected releaseAtoms(clause: Clause) {
1334
1244
  for (const atom of this.clauses.getAtoms(clause)) this.manager.decRef(atom);
1335
1245
  this.clauses.clearAtoms(clause);
1336
1246
  }
1337
1247
 
1338
- // del_clauses: past 1,000 clauses, mark each deleted, filter each of their watch lists once, then
1339
- // release their atoms, instead of searching a watch list per clause.
1340
1248
  protected deleteClauses(clauses: Clause[], oldSize: number) {
1341
1249
  if (clauses.length - oldSize <= 1000) {
1342
1250
  for (let index = clauses.length - 1; index >= oldSize; index--)
@@ -1,5 +1,4 @@
1
- // Ported from Z3 (src/util/lbool.h), MIT license, see z3-license.txt. The three truth values of a
2
- // literal, an assignment or a search.
1
+ // Ported from Z3 (src/util/lbool.h), MIT license, see z3-license.txt.
3
2
  export const L_TRUE = 1;
4
3
  export const L_FALSE = -1;
5
4
  export const L_UNDEF = 0;
@@ -1,13 +1,10 @@
1
1
  // Ported from Z3 (src/smt/smt_literal.h, src/smt/smt_types.h), MIT license, see z3-license.txt.
2
- // A Boolean variable numbers an atom. A literal is a variable or its negation, encoded as twice the
3
- // variable plus one when negated, so a literal indexes per-literal arrays directly.
4
2
  declare const boolVarBrand: unique symbol;
5
3
  declare const literalBrand: unique symbol;
6
4
 
7
5
  export type BoolVar = number & { readonly [boolVarBrand]: true };
8
6
  export type Literal = number & { readonly [literalBrand]: true };
9
7
 
10
- // The variable of true. Its positive literal is true and its negative literal false.
11
8
  export const TRUE_BOOL_VAR = 0 as BoolVar;
12
9
  export const TRUE_LITERAL = 0 as Literal;
13
10
  export const FALSE_LITERAL = 1 as Literal;
@@ -1,16 +1,12 @@
1
- // Ported from Z3 (src/math/lp/bound_analyzer_on_row.h, src/math/lp/lp_bound_propagator.h,
2
- // src/math/lp/implied_bound.h, and propagate_bounds_for_touched_rows in src/math/lp/lar_solver.h),
3
- // MIT license, see z3-license.txt. Bounds that a row implies on its columns from the bounds of the
4
- // others, and equalities between columns that rows with fixed columns imply.
1
+ // Ported from Z3 (src/math/lp/bound_analyzer_on_row.h, src/math/lp/lp_bound_propagator.h, src/math/lp/implied_bound.h, and propagate_bounds_for_touched_rows in src/math/lp/lar_solver.h), MIT license, see z3-license.txt.
5
2
  import { Rational } from "../rational";
6
3
  import { COLUMN_FIXED, COLUMN_FREE, COLUMN_LOWER, COLUMN_UPPER } from "./core-solver";
7
4
  import { type ConstraintKind, KIND_GE, KIND_GT, KIND_LE, KIND_LT } from "./constraints";
8
- import { Dependency, linearize } from "./dependency";
5
+ import { type Dependency, linearize } from "./dependency";
9
6
  import { Explanation } from "./explanation";
10
7
  import type { LarSolver } from "./lar-solver";
11
8
  import type { RowCell } from "./static-matrix";
12
9
 
13
- // The theory side of lp_bound_propagator.
14
10
  interface BoundPropagatorHost {
15
11
  columnIsInteresting(column: number): boolean;
16
12
  boundIsInteresting(column: number, kind: ConstraintKind, value: Rational): boolean;
@@ -18,7 +14,6 @@ interface BoundPropagatorHost {
18
14
  addEq(first: number, second: number, explanation: Explanation, isFixed: boolean): boolean;
19
15
  }
20
16
 
21
- // implied_bound: the explanation is a weighted list of the witnesses of the other columns.
22
17
  const getBoundKind = (isLower: boolean, isStrict: boolean) => {
23
18
  if (isLower) return isStrict ? KIND_GT : KIND_GE;
24
19
  return isStrict ? KIND_LT : KIND_LE;
@@ -32,7 +27,6 @@ export interface ImpliedBound {
32
27
  explain: () => [Rational, Dependency][];
33
28
  }
34
29
 
35
- // bound_kind: the kind of a lower or upper bound, strict or not.
36
30
  export const getImpliedKind = (bound: ImpliedBound) => getBoundKind(bound.isLower, bound.isStrict);
37
31
 
38
32
  export class BoundPropagator {
@@ -55,7 +49,6 @@ export class BoundPropagator {
55
49
  this.ibounds = [];
56
50
  }
57
51
 
58
- // propagate_bounds_for_touched_rows.
59
52
  propagateBoundsForTouchedRows() {
60
53
  const solver = this.solver;
61
54
  const settings = solver.settings;
@@ -80,8 +73,6 @@ export class BoundPropagator {
80
73
  solver.touchedRows.clear();
81
74
  }
82
75
 
83
- // Bound analysis of a row whose sum is zero.
84
-
85
76
  private analyzeRow(row: RowCell[]) {
86
77
  const core = this.solver.core;
87
78
  let columnOfU = -1;
@@ -123,7 +114,6 @@ export class BoundPropagator {
123
114
  } else if (columnOfL === -1 && isSomeInteresting()) this.limitAllMonoids(row, false);
124
115
  }
125
116
 
126
- // The bound of a monoid a * x at its maximum, or its minimum, and whether it is strict.
127
117
  private getMonoidBound(coeff: Rational, column: number, isMax: boolean) {
128
118
  const solver = this.solver;
129
119
  const isUpper = coeff.isPositive() === isMax;
@@ -131,7 +121,6 @@ export class BoundPropagator {
131
121
  return { value: bound.x, isStrict: !bound.y.isZero() };
132
122
  }
133
123
 
134
- // limit_all_monoids_from_below (isFromBelow) and limit_all_monoids_from_above.
135
124
  private limitAllMonoids(row: RowCell[], isFromBelow: boolean) {
136
125
  let numStrict = 0;
137
126
  let total = Rational.zero;
@@ -150,7 +139,6 @@ export class BoundPropagator {
150
139
  }
151
140
  }
152
141
 
153
- // limit_monoid_u_from_below (isFromBelow) and limit_monoid_l_from_above.
154
142
  private limitMonoidFromOne(row: RowCell[], target: number, isFromBelow: boolean) {
155
143
  let bound = Rational.zero;
156
144
  let targetCoeff = Rational.zero;
@@ -221,10 +209,7 @@ export class BoundPropagator {
221
209
  }
222
210
  }
223
211
 
224
- // Equalities from rows.
225
-
226
- // column_is_fixed: fixed, without an infinitesimal.
227
- private isFixed(column: number) {
212
+ private columnIsFixed(column: number) {
228
213
  const solver = this.solver;
229
214
  return (
230
215
  solver.core.getColumnType(column) === COLUMN_FIXED && solver.getLowerBound(column).y.isZero()
@@ -257,8 +242,7 @@ export class BoundPropagator {
257
242
  second: number,
258
243
  isFixed: boolean,
259
244
  ) {
260
- const isAdded = this.host.addEq(first, second, explanation, isFixed);
261
- if (!isAdded) return;
245
+ if (!this.host.addEq(first, second, explanation, isFixed)) return;
262
246
  const stats = this.solver.settings.stats;
263
247
  if (isFixed) stats.fixedEqs++;
264
248
  else stats.offsetEqs++;
@@ -267,7 +251,7 @@ export class BoundPropagator {
267
251
  private getOnlyOneNonFixed(rowIndex: number) {
268
252
  let result = -1;
269
253
  for (const cell of this.solver.getRow(rowIndex)) {
270
- if (this.isFixed(cell.column)) continue;
254
+ if (this.columnIsFixed(cell.column)) continue;
271
255
  if (result !== -1) return -1;
272
256
  result = cell.column;
273
257
  }
@@ -302,7 +286,7 @@ export class BoundPropagator {
302
286
 
303
287
  private tryAddEquationWithLpFixedTables(rowIndex: number, column: number) {
304
288
  const solver = this.solver;
305
- if (this.isFixed(column)) return;
289
+ if (this.columnIsFixed(column)) return;
306
290
  const value = solver.getValue(column);
307
291
  const other = value.y.isZero()
308
292
  ? solver.findInFixedTables(value.x, solver.isInt(column))
@@ -322,17 +306,15 @@ export class BoundPropagator {
322
306
  this.addEqOnColumns(explanation, other, column, true);
323
307
  }
324
308
 
325
- // extract_non_fixed: the basic column, the other non-fixed column and the sign of its unit
326
- // coefficient, when the row has at most two non-fixed columns.
327
309
  private extractNonFixed(rowIndex: number) {
328
310
  const solver = this.solver;
329
311
  const x = solver.core.basis[rowIndex];
330
- if (this.isFixed(x)) return { count: 0, x, y: -1, ySign: 0 };
312
+ if (this.columnIsFixed(x)) return { count: 0, x, y: -1, ySign: 0 };
331
313
  let count = 1;
332
314
  let y = -1;
333
315
  let ySign = 0;
334
316
  for (const cell of solver.getRow(rowIndex)) {
335
- if (cell.column === x || this.isFixed(cell.column)) continue;
317
+ if (cell.column === x || this.columnIsFixed(cell.column)) continue;
336
318
  if (++count > 2) return { count, x, y, ySign };
337
319
  y = cell.column;
338
320
  ySign = cell.coeff.equals(Rational.one) ? 1 : cell.coeff.equals(Rational.minusOne) ? -1 : 0;
@@ -1,17 +1,13 @@
1
- // Ported from Z3 (src/math/lp/lar_constraints.h), MIT license, see z3-license.txt. The bounds
2
- // that the theory asserts on columns, each with a leaf dependency on its own index, and the set of
3
- // active ones, both undone by pop.
4
- import { Dependency, mkLeaf } from "./dependency";
1
+ // Ported from Z3 (src/math/lp/lar_constraints.h), MIT license, see z3-license.txt.
2
+ import { type Dependency, mkLeaf } from "./dependency";
5
3
  import { Impq } from "./numeric-pair";
6
4
  import { shrink } from "../array";
7
5
 
8
- // lconstraint_kind: flipping negates the kind, and halving a non-strict kind gives the strict one.
9
6
  export const KIND_LE = -2;
10
7
  export const KIND_LT = -1;
11
8
  export const KIND_EQ = 0;
12
9
  export const KIND_GT = 1;
13
10
  export const KIND_GE = 2;
14
- // NE: a kind of nla's inequalities, never of a bound the theory asserts.
15
11
  export const KIND_NE = 3;
16
12
 
17
13
  export type ConstraintKind =
@@ -27,7 +23,6 @@ export interface LarConstraint {
27
23
  readonly rhs: Impq;
28
24
  readonly dep: Dependency;
29
25
  isActive: boolean;
30
- // Made for the atom of an nla lemma.
31
26
  readonly isAuxiliary: boolean;
32
27
  }
33
28
 
@@ -40,7 +35,6 @@ export class ConstraintSet {
40
35
  readonly constraints: LarConstraint[] = [];
41
36
  private active: number[] = [];
42
37
  private scopes: ConstraintScope[] = [];
43
- // m_is_auxiliary_mode: whether new constraints are auxiliary.
44
38
  isAuxiliaryMode = false;
45
39
 
46
40
  add(column: number, kind: ConstraintKind, rhs: Impq) {