tla-ts 0.0.9 → 0.0.10-dev.63a6693bd

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 (400) hide show
  1. package/README.md +29 -1
  2. package/dist/compile.cjs +23 -0
  3. package/dist/compile.js +23 -0
  4. package/dist/deciders.cjs +29 -29
  5. package/dist/deciders.js +42 -42
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +106 -10
  8. package/dist/index.d.ts +106 -10
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +117 -37
  15. package/dist/prove.js +116 -36
  16. package/dist/run.cjs +143 -31
  17. package/dist/run.js +143 -31
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +2 -2
  20. package/dist/transfer.cjs +129 -104
  21. package/dist/transfer.js +129 -104
  22. package/dist/worker.cjs +7 -7
  23. package/dist/worker.js +7 -7
  24. package/package.json +3 -1
  25. package/src/ast.ts +48 -62
  26. package/src/bags.ts +99 -102
  27. package/src/builtins.ts +28 -75
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check-failure.ts +116 -0
  30. package/src/check-trace.ts +282 -0
  31. package/src/check.ts +599 -754
  32. package/src/cli/options.ts +12 -32
  33. package/src/cli/run.ts +0 -2
  34. package/src/cli/runtime-invariants.ts +136 -0
  35. package/src/cli/shared.ts +19 -12
  36. package/src/cli/tlapm.ts +14 -25
  37. package/src/cli/tlc-arguments.ts +652 -0
  38. package/src/cli/tlc-output.ts +687 -0
  39. package/src/cli/tlc-usage.ts +361 -0
  40. package/src/cli/tlc.ts +309 -658
  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 +196 -74
  45. package/src/config.ts +140 -109
  46. package/src/coverage.ts +830 -0
  47. package/src/dependencies.ts +14 -53
  48. package/src/dfid.ts +618 -0
  49. package/src/environment-config.ts +315 -0
  50. package/src/environment.ts +169 -335
  51. package/src/errors.ts +71 -55
  52. package/src/evaluate.ts +598 -340
  53. package/src/exit-codes.ts +37 -3
  54. package/src/fingerprints.ts +75 -11
  55. package/src/index.ts +3 -0
  56. package/src/instances.ts +126 -21
  57. package/src/java-hash.ts +7 -0
  58. package/src/java-overrides.ts +4 -19
  59. package/src/json-reader.ts +455 -0
  60. package/src/json.ts +252 -139
  61. package/src/levels.ts +46 -58
  62. package/src/lexer.ts +80 -100
  63. package/src/liveness-checker.ts +103 -153
  64. package/src/liveness.ts +150 -109
  65. package/src/obligations/action.ts +8 -39
  66. package/src/obligations/anonymize.ts +88 -82
  67. package/src/obligations/equality.ts +1 -1
  68. package/src/obligations/expression.ts +20 -21
  69. package/src/obligations/format.ts +1 -9
  70. package/src/obligations/generate.ts +46 -49
  71. package/src/obligations/index.ts +2 -13
  72. package/src/obligations/levels.ts +4 -8
  73. package/src/obligations/module.ts +28 -53
  74. package/src/obligations/normalize.ts +7 -25
  75. package/src/obligations/operators.ts +1 -2
  76. package/src/obligations/pragma.ts +1 -10
  77. package/src/obligations/printer.ts +47 -46
  78. package/src/obligations/proof.ts +1 -5
  79. package/src/obligations/regroup.ts +1 -4
  80. package/src/obligations/simplify.ts +42 -58
  81. package/src/obligations/source.ts +48 -78
  82. package/src/obligations/subexpression.ts +5 -11
  83. package/src/obligations/substitution.ts +1 -3
  84. package/src/obligations/temporal.ts +13 -19
  85. package/src/obligations/tuples.ts +3 -9
  86. package/src/parallel-worker.ts +30 -60
  87. package/src/parallel.ts +57 -71
  88. package/src/parser.ts +584 -316
  89. package/src/pcal/ast.ts +53 -86
  90. package/src/pcal/parse.ts +144 -219
  91. package/src/pcal/tokenize.ts +91 -131
  92. package/src/pcal/translate.ts +83 -130
  93. package/src/pcal/validate.ts +48 -68
  94. package/src/pretty-print.ts +7 -8
  95. package/src/prover/decide-pool.ts +8 -13
  96. package/src/prover/deciders.ts +3 -7
  97. package/src/prover/first-order.ts +0 -11
  98. package/src/prover/isabelle/decide.ts +0 -6
  99. package/src/prover/isabelle/encode.ts +11 -23
  100. package/src/prover/isabelle/isar/inner-syntax.ts +114 -115
  101. package/src/prover/isabelle/isar/method.ts +29 -53
  102. package/src/prover/isabelle/isar/proof.ts +1 -10
  103. package/src/prover/isabelle/isar/statement.ts +1 -6
  104. package/src/prover/isabelle/isar/theory.ts +26 -36
  105. package/src/prover/isabelle/isar/type-check.ts +17 -31
  106. package/src/prover/isabelle/provers/blast/blast.ts +17 -104
  107. package/src/prover/isabelle/provers/blast/branch.ts +1 -32
  108. package/src/prover/isabelle/provers/blast/prove.ts +1 -35
  109. package/src/prover/isabelle/provers/blast/rules.ts +6 -44
  110. package/src/prover/isabelle/provers/blast/state.ts +2 -28
  111. package/src/prover/isabelle/provers/blast/term.ts +9 -36
  112. package/src/prover/isabelle/provers/clasimp.ts +1 -13
  113. package/src/prover/isabelle/provers/classical.ts +14 -42
  114. package/src/prover/isabelle/provers/hypsubst.ts +28 -51
  115. package/src/prover/isabelle/pure/bicompose.ts +25 -38
  116. package/src/prover/isabelle/pure/consts.ts +1 -7
  117. package/src/prover/isabelle/pure/conv.ts +3 -17
  118. package/src/prover/isabelle/pure/drule.ts +33 -42
  119. package/src/prover/isabelle/pure/envir.ts +3 -52
  120. package/src/prover/isabelle/pure/goal.ts +1 -7
  121. package/src/prover/isabelle/pure/interrupt.ts +0 -5
  122. package/src/prover/isabelle/pure/list.ts +0 -3
  123. package/src/prover/isabelle/pure/logic.ts +2 -15
  124. package/src/prover/isabelle/pure/name.ts +2 -9
  125. package/src/prover/isabelle/pure/net.ts +3 -59
  126. package/src/prover/isabelle/pure/object-logic.ts +3 -10
  127. package/src/prover/isabelle/pure/pattern.ts +2 -19
  128. package/src/prover/isabelle/pure/raw-simplifier.ts +17 -62
  129. package/src/prover/isabelle/pure/rewriter.ts +31 -67
  130. package/src/prover/isabelle/pure/search.ts +3 -10
  131. package/src/prover/isabelle/pure/seq.ts +1 -10
  132. package/src/prover/isabelle/pure/simplifier.ts +4 -12
  133. package/src/prover/isabelle/pure/table.ts +3 -32
  134. package/src/prover/isabelle/pure/tactic.ts +12 -22
  135. package/src/prover/isabelle/pure/tactical.ts +48 -47
  136. package/src/prover/isabelle/pure/term-ord.ts +2 -6
  137. package/src/prover/isabelle/pure/term.ts +2 -43
  138. package/src/prover/isabelle/pure/thm.ts +27 -47
  139. package/src/prover/isabelle/pure/type.ts +2 -15
  140. package/src/prover/isabelle/pure/unify.ts +20 -30
  141. package/src/prover/isabelle/pure/variable.ts +3 -7
  142. package/src/prover/isabelle/tla/classical-setup.ts +17 -24
  143. package/src/prover/isabelle/tla/context.ts +15 -18
  144. package/src/prover/isabelle/tla/logic.ts +14 -32
  145. package/src/prover/isabelle/tla/simpdata.ts +46 -43
  146. package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
  147. package/src/prover/ocaml.ts +0 -6
  148. package/src/prover/prep/action.ts +14 -54
  149. package/src/prover/prep/enabled-axioms.ts +12 -19
  150. package/src/prover/prep/fingerprint.ts +2 -21
  151. package/src/prover/prep/level-comparison.ts +8 -12
  152. package/src/prover/prep/md5.ts +0 -2
  153. package/src/prover/prep/methods.ts +33 -39
  154. package/src/prover/prep/normalize.ts +4 -28
  155. package/src/prover/prove-worker.ts +0 -2
  156. package/src/prover/prove.ts +87 -100
  157. package/src/prover/ptl/decide.ts +7 -12
  158. package/src/prover/ptl/encode.ts +14 -36
  159. package/src/prover/ptl/sat.ts +24 -32
  160. package/src/prover/ptl/tableau.ts +12 -26
  161. package/src/prover/smt/axioms.ts +0 -7
  162. package/src/prover/smt/context.ts +20 -28
  163. package/src/prover/smt/data.ts +433 -424
  164. package/src/prover/smt/encode.ts +43 -52
  165. package/src/prover/smt/extensionality.ts +0 -10
  166. package/src/prover/smt/flatten.ts +3 -22
  167. package/src/prover/smt/format.ts +5 -10
  168. package/src/prover/smt/instances.ts +0 -10
  169. package/src/prover/smt/rewrite.ts +663 -667
  170. package/src/prover/smt/solver/act-cache.ts +0 -15
  171. package/src/prover/smt/solver/arith-rewriter.ts +3 -48
  172. package/src/prover/smt/solver/array.ts +1 -3
  173. package/src/prover/smt/solver/asserted-formulas.ts +1 -43
  174. package/src/prover/smt/solver/ast-lt.ts +1 -11
  175. package/src/prover/smt/solver/ast-util.ts +1 -6
  176. package/src/prover/smt/solver/ast.ts +1 -165
  177. package/src/prover/smt/solver/auf-solver.ts +8 -44
  178. package/src/prover/smt/solver/case-split-queue.ts +1 -9
  179. package/src/prover/smt/solver/cg-table.ts +1 -18
  180. package/src/prover/smt/solver/clause.ts +1 -27
  181. package/src/prover/smt/solver/conflict-resolution.ts +0 -9
  182. package/src/prover/smt/solver/context.ts +7 -64
  183. package/src/prover/smt/solver/ctx-simplify.ts +14 -41
  184. package/src/prover/smt/solver/der.ts +2 -21
  185. package/src/prover/smt/solver/dyn-ack.ts +1 -11
  186. package/src/prover/smt/solver/e-matching.ts +4 -35
  187. package/src/prover/smt/solver/enode.ts +1 -21
  188. package/src/prover/smt/solver/expr-ref.ts +1 -5
  189. package/src/prover/smt/solver/expr-safe-replace.ts +1 -6
  190. package/src/prover/smt/solver/fingerprints.ts +1 -12
  191. package/src/prover/smt/solver/flat-literals.ts +1 -9
  192. package/src/prover/smt/solver/goal.ts +2 -14
  193. package/src/prover/smt/solver/hash.ts +0 -8
  194. package/src/prover/smt/solver/hashtable.ts +1 -12
  195. package/src/prover/smt/solver/internalizer.ts +7 -100
  196. package/src/prover/smt/solver/lbool.ts +1 -2
  197. package/src/prover/smt/solver/literal.ts +0 -3
  198. package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
  199. package/src/prover/smt/solver/lp/constraints.ts +2 -8
  200. package/src/prover/smt/solver/lp/containers.ts +12 -30
  201. package/src/prover/smt/solver/lp/core-solver.ts +10 -31
  202. package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
  203. package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
  204. package/src/prover/smt/solver/lp/dependency.ts +1 -4
  205. package/src/prover/smt/solver/lp/dioph-eq.ts +9 -102
  206. package/src/prover/smt/solver/lp/explanation.ts +1 -6
  207. package/src/prover/smt/solver/lp/gomory.ts +9 -22
  208. package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
  209. package/src/prover/smt/solver/lp/hnf.ts +11 -26
  210. package/src/prover/smt/solver/lp/int-cube.ts +15 -36
  211. package/src/prover/smt/solver/lp/int-solver.ts +4 -34
  212. package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
  213. package/src/prover/smt/solver/lp/lar-term.ts +1 -5
  214. package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
  215. package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
  216. package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
  217. package/src/prover/smt/solver/lp/nex.ts +1 -6
  218. package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
  219. package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
  220. package/src/prover/smt/solver/lp/nla-core.ts +36 -135
  221. package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
  222. package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
  223. package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
  224. package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
  225. package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
  226. package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
  227. package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
  228. package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
  229. package/src/prover/smt/solver/lp/nla-order.ts +2 -13
  230. package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
  231. package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
  232. package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
  233. package/src/prover/smt/solver/lp/nla-types.ts +1 -11
  234. package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
  235. package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
  236. package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
  237. package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
  238. package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
  239. package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
  240. package/src/prover/smt/solver/lp/pdd.ts +7 -70
  241. package/src/prover/smt/solver/lp/random-updater.ts +1 -8
  242. package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
  243. package/src/prover/smt/solver/lp/union-find.ts +1 -6
  244. package/src/prover/smt/solver/mam-compiler.ts +18 -58
  245. package/src/prover/smt/solver/mam-interpreter.ts +1 -21
  246. package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
  247. package/src/prover/smt/solver/model-checker.ts +3 -37
  248. package/src/prover/smt/solver/model-evaluator.ts +3 -29
  249. package/src/prover/smt/solver/model-finder.ts +15 -32
  250. package/src/prover/smt/solver/model-generator.ts +1 -12
  251. package/src/prover/smt/solver/model-macro-solver.ts +23 -88
  252. package/src/prover/smt/solver/nlsat/algebraic.ts +63 -159
  253. package/src/prover/smt/solver/nlsat/atoms.ts +25 -23
  254. package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
  255. package/src/prover/smt/solver/nlsat/explain.ts +10 -69
  256. package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
  257. package/src/prover/smt/solver/nlsat/levelwise.ts +49 -135
  258. package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
  259. package/src/prover/smt/solver/nlsat/polynomial.ts +29 -159
  260. package/src/prover/smt/solver/nlsat/solver.ts +18 -90
  261. package/src/prover/smt/solver/nlsat/types.ts +1 -8
  262. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +2 -45
  263. package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
  264. package/src/prover/smt/solver/nnf.ts +3 -38
  265. package/src/prover/smt/solver/pattern-inference.ts +2 -15
  266. package/src/prover/smt/solver/poly-rewriter.ts +3 -23
  267. package/src/prover/smt/solver/propagate-values.ts +1 -10
  268. package/src/prover/smt/solver/proto-model.ts +3 -52
  269. package/src/prover/smt/solver/pull-quant.ts +1 -12
  270. package/src/prover/smt/solver/qe-lite-der.ts +1 -29
  271. package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
  272. package/src/prover/smt/solver/qe-lite.ts +3 -33
  273. package/src/prover/smt/solver/qi-queue.ts +1 -16
  274. package/src/prover/smt/solver/quant-tactics.ts +5 -22
  275. package/src/prover/smt/solver/quantifier-analyzer.ts +27 -47
  276. package/src/prover/smt/solver/quantifier-manager.ts +2 -13
  277. package/src/prover/smt/solver/random-gen.ts +1 -2
  278. package/src/prover/smt/solver/rational.ts +1 -8
  279. package/src/prover/smt/solver/ref-vector.ts +1 -6
  280. package/src/prover/smt/solver/relevancy.ts +2 -15
  281. package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
  282. package/src/prover/smt/solver/rewriter.ts +3 -85
  283. package/src/prover/smt/solver/rlimit.ts +2 -20
  284. package/src/prover/smt/solver/smtlib-parser.ts +80 -131
  285. package/src/prover/smt/solver/solver.ts +23 -34
  286. package/src/prover/smt/solver/sort.ts +1 -5
  287. package/src/prover/smt/solver/sticky-generations.ts +0 -5
  288. package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
  289. package/src/prover/smt/solver/theory-lra-bounds.ts +1 -7
  290. package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
  291. package/src/prover/smt/solver/theory-lra-internalize.ts +6 -43
  292. package/src/prover/smt/solver/theory-lra-model.ts +4 -19
  293. package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
  294. package/src/prover/smt/solver/theory-lra-state.ts +3 -8
  295. package/src/prover/smt/solver/theory-lra.ts +1 -8
  296. package/src/prover/smt/solver/var-subst.ts +2 -26
  297. package/src/prover/smt/table.ts +0 -8
  298. package/src/prover/tlapm/cache.ts +45 -40
  299. package/src/prover/tlapm/ocaml-marshal.ts +19 -21
  300. package/src/prover/tlapm/tlapm.ts +21 -20
  301. package/src/prover/verdict.ts +7 -2
  302. package/src/prover/zenon/check/check.ts +1 -11
  303. package/src/prover/zenon/check/definitions.ts +5 -15
  304. package/src/prover/zenon/check/equality.ts +0 -8
  305. package/src/prover/zenon/check/functions.ts +0 -4
  306. package/src/prover/zenon/check/keys.ts +0 -7
  307. package/src/prover/zenon/check/propositional.ts +0 -3
  308. package/src/prover/zenon/check/records.ts +1 -6
  309. package/src/prover/zenon/check/relations.ts +2 -14
  310. package/src/prover/zenon/check/rewrites.ts +2 -21
  311. package/src/prover/zenon/check/sets.ts +40 -61
  312. package/src/prover/zenon/check/terms.ts +1 -19
  313. package/src/prover/zenon/check/tla.ts +0 -6
  314. package/src/prover/zenon/decide.ts +0 -12
  315. package/src/prover/zenon/encode.ts +1 -8
  316. package/src/prover/zenon/eqrel.ts +2 -13
  317. package/src/prover/zenon/equality-rules.ts +0 -4
  318. package/src/prover/zenon/expr.ts +8 -26
  319. package/src/prover/zenon/index-table.ts +26 -57
  320. package/src/prover/zenon/isar-case.ts +9 -19
  321. package/src/prover/zenon/isar.ts +36 -64
  322. package/src/prover/zenon/limits.ts +0 -4
  323. package/src/prover/zenon/llproof.ts +2 -20
  324. package/src/prover/zenon/mltoll.ts +66 -104
  325. package/src/prover/zenon/node.ts +1 -11
  326. package/src/prover/zenon/ocaml.ts +1 -17
  327. package/src/prover/zenon/parse.ts +4 -12
  328. package/src/prover/zenon/phrase.ts +1 -11
  329. package/src/prover/zenon/proof.ts +0 -9
  330. package/src/prover/zenon/propositional-rules.ts +0 -5
  331. package/src/prover/zenon/rules.ts +2 -6
  332. package/src/prover/zenon/search.ts +5 -31
  333. package/src/prover/zenon/tla/functions.ts +59 -31
  334. package/src/prover/zenon/tla/llproof.ts +67 -76
  335. package/src/prover/zenon/tla/records.ts +57 -33
  336. package/src/prover/zenon/tla/rewrites.ts +12 -19
  337. package/src/prover/zenon/tla/sets.ts +83 -53
  338. package/src/prover/zenon/tla/terms.ts +0 -6
  339. package/src/prover/zenon/tla/tla.ts +66 -64
  340. package/src/randomization.ts +81 -35
  341. package/src/resolve.ts +67 -184
  342. package/src/runtime.ts +22 -22
  343. package/src/sany/builtins.ts +2 -5
  344. package/src/sany/generation.ts +394 -0
  345. package/src/sany/generator-def-entries.ts +210 -0
  346. package/src/sany/generator-definitions.ts +686 -0
  347. package/src/sany/generator-expressions.ts +1100 -0
  348. package/src/sany/generator-proofs.ts +662 -0
  349. package/src/sany/generator.ts +191 -2764
  350. package/src/sany/levels.ts +6 -34
  351. package/src/sany/lexer.ts +58 -77
  352. package/src/sany/linter.ts +1 -9
  353. package/src/sany/modules.ts +1 -5
  354. package/src/sany/nodes.ts +5 -43
  355. package/src/sany/parse-error.ts +39 -117
  356. package/src/sany/report.ts +32 -69
  357. package/src/sany/selectors.ts +49 -76
  358. package/src/sany/source.ts +1 -17
  359. package/src/sany/xml.ts +35 -117
  360. package/src/search.ts +541 -163
  361. package/src/simulate.ts +709 -0
  362. package/src/spec-description.ts +192 -100
  363. package/src/standard-definitions.ts +0 -4
  364. package/src/standard-modules.ts +264 -95
  365. package/src/state-graph.ts +52 -31
  366. package/src/subexpressions.ts +69 -52
  367. package/src/substitution-levels.ts +7 -7
  368. package/src/successors.ts +266 -99
  369. package/src/symmetry.ts +33 -25
  370. package/src/tableau.ts +27 -24
  371. package/src/tlc/fingerprint.ts +183 -67
  372. package/src/tlc/jar-data.ts +112 -6
  373. package/src/tlc/messages.ts +125 -54
  374. package/src/tlc/order.ts +39 -69
  375. package/src/tlc/random.ts +37 -49
  376. package/src/tlc/replay.ts +553 -228
  377. package/src/tlc/summary.ts +36 -47
  378. package/src/tlc/tlc-operators.ts +78 -44
  379. package/src/tlc/tlcext-operators.ts +139 -122
  380. package/src/tlc/trace-spec.ts +249 -0
  381. package/src/tlc/value-stream.ts +139 -0
  382. package/src/tlc/version.ts +1 -4
  383. package/src/transfer.ts +22 -25
  384. package/src/typescript/actions.ts +479 -0
  385. package/src/typescript/collections.ts +614 -0
  386. package/src/typescript/compile.ts +63 -0
  387. package/src/typescript/context.ts +94 -0
  388. package/src/typescript/emit.ts +121 -0
  389. package/src/typescript/expressions.ts +496 -0
  390. package/src/typescript/formula.ts +154 -0
  391. package/src/typescript/functions.ts +284 -0
  392. package/src/typescript/model.ts +162 -0
  393. package/src/typescript/names.ts +114 -0
  394. package/src/typescript/program.ts +48 -0
  395. package/src/typescript/properties.ts +139 -0
  396. package/src/typescript/scope.ts +112 -0
  397. package/src/typescript/steps.ts +167 -0
  398. package/src/typescript/types.ts +171 -0
  399. package/src/values.ts +832 -484
  400. 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
 
@@ -179,7 +150,6 @@ export abstract class Internalizer {
179
150
  constructor(
180
151
  readonly manager: AstManager,
181
152
  isRelevancyEnabled: boolean,
182
- isDelayingNewCaseSplits: boolean,
183
153
  ) {
184
154
  this.rewriter = new Rewriter(manager, KERNEL_REWRITER_OPTIONS);
185
155
  this.relevancy = new RelevancyPropagator(
@@ -199,7 +169,7 @@ export abstract class Internalizer {
199
169
  getNumBoolVars: () => this.numBoolVars,
200
170
  isUnassigned: (boolVar) => this.assignment[mkLiteral(boolVar)] === L_UNDEF,
201
171
  },
202
- isDelayingNewCaseSplits,
172
+ isRelevancyEnabled,
203
173
  );
204
174
  this.mkBoolVar(manager.trueExpr);
205
175
  this.assignment[0] = L_TRUE;
@@ -225,7 +195,6 @@ export abstract class Internalizer {
225
195
  this.eqPropagationQueue.push({ lhs, rhs, justification });
226
196
  }
227
197
 
228
- // random_gen from Z3's util/util.h with the default seed 0.
229
198
  getRandomValue() {
230
199
  this.randomSeed = (Math.imul(this.randomSeed, 214013) + 2531011) >>> 0;
231
200
  return (this.randomSeed >>> 16) & 0x7fff;
@@ -289,8 +258,6 @@ export abstract class Internalizer {
289
258
  }
290
259
  }
291
260
 
292
- // Assignment queries.
293
-
294
261
  getAssignment(literal: Literal) {
295
262
  return this.assignment[literal];
296
263
  }
@@ -341,9 +308,6 @@ export abstract class Internalizer {
341
308
  return this.cgTable.findFor(decl, args, decl === OP_EQ);
342
309
  }
343
310
 
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
311
  isDiseq(first: Enode, second: Enode) {
348
312
  const manager = this.manager;
349
313
  if (manager.areDistinct(first.root.owner, second.root.owner)) return true;
@@ -401,7 +365,6 @@ export abstract class Internalizer {
401
365
  return this.relevancy.isRelevant(expr);
402
366
  }
403
367
 
404
- // context::mark_as_relevant, which propagates the relevancy at once.
405
368
  markAsRelevant(expr: number) {
406
369
  this.relevancy.markAsRelevant(expr);
407
370
  this.relevancy.propagate();
@@ -415,13 +378,10 @@ export abstract class Internalizer {
415
378
  return this.conflict !== null;
416
379
  }
417
380
 
418
- // get_generation: the generation of the congruence root. Equalities have generation 0, since
419
- // patterns have no equalities.
420
381
  getGeneration(node: Enode) {
421
382
  return node.isEq ? 0 : this.getCgRoot(node).generation;
422
383
  }
423
384
 
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
385
  private getCgRoot(node: Enode) {
426
386
  if (!node.usesCgTable() || node.isCgr()) return node;
427
387
  return this.cgTable.findCongruent(node) ?? node;
@@ -439,9 +399,6 @@ export abstract class Internalizer {
439
399
  ) {
440
400
  this.setGeneration(first, firstGeneration);
441
401
  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
402
  this.applyStickyUpdates(first, firstGeneration, second, secondGeneration);
446
403
  if (second.decl !== first.decl) this.applyStickyUpdates(second, secondGeneration, null, 0);
447
404
  }
@@ -473,10 +430,6 @@ export abstract class Internalizer {
473
430
  }
474
431
  }
475
432
 
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
433
  mkBoolVar(expr: number) {
481
434
  const boolVar = toBoolVar(this.numBoolVars++);
482
435
  const literal = mkLiteral(boolVar);
@@ -501,8 +454,6 @@ export abstract class Internalizer {
501
454
  return boolVar;
502
455
  }
503
456
 
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
457
  private undoMkBoolVar() {
507
458
  const boolVar = toBoolVar(--this.numBoolVars);
508
459
  const expr = this.boolVar2Expr[boolVar];
@@ -513,7 +464,6 @@ export abstract class Internalizer {
513
464
  this.manager.decRef(expr);
514
465
  }
515
466
 
516
- // The level of the variable's assignment.
517
467
  getLevel(boolVar: number) {
518
468
  return this.boolVarData[2 * boolVar] & LEVEL_MASK;
519
469
  }
@@ -523,7 +473,6 @@ export abstract class Internalizer {
523
473
  this.boolVarData[index] = (this.boolVarData[index] & ~LEVEL_MASK) | level;
524
474
  }
525
475
 
526
- // The scope level at which the variable was internalized.
527
476
  getInternLevel(boolVar: number) {
528
477
  return this.boolVarData[2 * boolVar + 1];
529
478
  }
@@ -547,10 +496,9 @@ export abstract class Internalizer {
547
496
  this.setBoolVarFlag(boolVar, BV_MARK, value);
548
497
  }
549
498
 
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
499
  private resetWatches(literal: number) {
553
500
  const list = this.watches[literal];
501
+ // HACK: assigning undefined to a literal past the end keeps V8's arrays without holes.
554
502
  if (list === undefined) this.watches[literal] = undefined;
555
503
  else shrink(list, 0);
556
504
  const binary = this.binaryWatches[literal];
@@ -604,7 +552,6 @@ export abstract class Internalizer {
604
552
  for (let index = 0; index < numArgs; index++) node.getArg(index).root.addParent(node);
605
553
  if (manager.isUniqueValue(expr)) node.isInterpreted = true;
606
554
  setAt(this.exprToEnode, expr, node);
607
- // m_e_internalized_stack holds a reference to the expression until the enode is deleted.
608
555
  manager.incRef(expr);
609
556
  this.trailKinds.push(UNDO_MK_ENODE);
610
557
  this.enodes.push(node);
@@ -632,7 +579,6 @@ export abstract class Internalizer {
632
579
  return node;
633
580
  }
634
581
 
635
- // The enode of an argument of expr, which is internalized before expr.
636
582
  private getArgEnode(expr: number, index: number) {
637
583
  const node = this.exprToEnode[this.manager.getArg(expr, index)];
638
584
  if (node === undefined) throw new SmtInvariantError("an argument was not internalized");
@@ -680,8 +626,6 @@ export abstract class Internalizer {
680
626
  this.setBoolVarFlag(boolVar, BV_ENODE, true);
681
627
  }
682
628
 
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
629
  private updateGeneration(node: Enode) {
686
630
  if (node.isEq) return;
687
631
  if (this.generation > 0 && this.generation < this.getGeneration(node)) {
@@ -690,16 +634,12 @@ export abstract class Internalizer {
690
634
  }
691
635
  }
692
636
 
693
- // Internalization.
694
-
695
637
  private isGate(expr: number) {
696
638
  const op = this.manager.getOp(expr);
697
639
  if (op === OP_AND || op === OP_OR || op === OP_ITE) return true;
698
640
  return op === OP_EQ && this.manager.isBool(this.manager.getArg(expr, 0));
699
641
  }
700
642
 
701
- // should_internalize_rec: a term, or a Boolean application of the basic family or an
702
- // uninterpreted declaration.
703
643
  private shouldInternalizeRec(expr: number) {
704
644
  const manager = this.manager;
705
645
  if (manager.kinds[expr] !== KIND_APP || manager.sorts[expr] !== SORT_BOOL) return true;
@@ -707,8 +647,6 @@ export abstract class Internalizer {
707
647
  return family === FAMILY_BASIC || family === FAMILY_USER;
708
648
  }
709
649
 
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
650
  private internalizeDeep(expr: number) {
713
651
  if (
714
652
  this.isEInternalized(expr) ||
@@ -717,8 +655,6 @@ export abstract class Internalizer {
717
655
  )
718
656
  return;
719
657
  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
658
  const colors = new Map<number, number>();
723
659
  const getColor = (current: number, isGate: boolean) =>
724
660
  colors.get(current * 2 + (isGate ? 1 : 0)) ?? WHITE;
@@ -727,7 +663,6 @@ export abstract class Internalizer {
727
663
  const visitChild = (child: number, isGate: boolean) => {
728
664
  if (getColor(child, isGate) === WHITE) todo.push([child, isGate]);
729
665
  };
730
- // ts_visit_children, which Z3 calls again on grey expressions only in its assertions.
731
666
  const visitChildren = (current: number) => {
732
667
  if (manager.kinds[current] === KIND_QUANTIFIER || !this.shouldInternalizeRec(current)) return;
733
668
  const node = this.exprToEnode[current];
@@ -873,12 +808,8 @@ export abstract class Internalizer {
873
808
  this.internalizeFormulaCore(expr, isGateContext);
874
809
  const boolVar = this.getBoolVar(expr);
875
810
  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)]);
811
+ const sort = this.manager.sorts[this.manager.getArg(expr, 0)];
812
+ if (sort !== SORT_BOOL && isArithSort(sort)) this.theory.internalizeEqEh(expr);
882
813
  }
883
814
 
884
815
  private internalizeTheoryAtom(expr: number, isGateContext: boolean) {
@@ -995,7 +926,6 @@ export abstract class Internalizer {
995
926
  }
996
927
  }
997
928
 
998
- // mk_gate_clause with two or three literals.
999
929
  private mkGateClause(first: Literal, second: Literal, third?: Literal) {
1000
930
  const literals = this.gateLiterals;
1001
931
  shrink(literals, 0);
@@ -1009,11 +939,8 @@ export abstract class Internalizer {
1009
939
  const existing = this.exprToEnode[expr];
1010
940
  if (existing !== undefined) {
1011
941
  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)) {
942
+ if (manager.getFamily(expr) === FAMILY_ARITH && !this.theory.isAttachedToVar(existing))
1015
943
  this.theory.internalizeTerm(expr);
1016
- }
1017
944
  return;
1018
945
  }
1019
946
  if (manager.getOp(expr) === OP_ITE) {
@@ -1029,7 +956,6 @@ export abstract class Internalizer {
1029
956
  this.mkEnode(expr, false, false, true);
1030
957
  }
1031
958
 
1032
- // mk_eq_atom: the side with the smaller id goes first.
1033
959
  mkEqAtom(lhs: number, rhs: number) {
1034
960
  const ids = this.manager.ids;
1035
961
  return ids[lhs] < ids[rhs] ? this.manager.mkEq(lhs, rhs) : this.manager.mkEq(rhs, lhs);
@@ -1047,7 +973,6 @@ export abstract class Internalizer {
1047
973
  const condition = this.getLiteral(this.manager.getArg(expr, 0));
1048
974
  this.mkClause([negate(condition), this.getLiteral(thenEq)], null, CLS_AUX);
1049
975
  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
976
  const handler = () => {
1052
977
  if (!this.isRelevant(expr)) return;
1053
978
  this.relevancy.markAsRelevant(this.manager.getArg(expr, 0));
@@ -1096,8 +1021,6 @@ export abstract class Internalizer {
1096
1021
  this.addRelWatch(negate(literal), handler);
1097
1022
  }
1098
1023
 
1099
- // Clauses.
1100
-
1101
1024
  mkThAxiom(literals: Literal[]) {
1102
1025
  this.mkClause(literals, null, CLS_TH_AXIOM);
1103
1026
  }
@@ -1125,8 +1048,6 @@ export abstract class Internalizer {
1125
1048
  return true;
1126
1049
  }
1127
1050
 
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
1051
  private simplifyAuxLemmaLiterals(literals: Literal[]) {
1131
1052
  sortNumbers(literals);
1132
1053
  let previous: Literal | null = null;
@@ -1191,8 +1112,6 @@ export abstract class Internalizer {
1191
1112
  this.addWatch(negate(this.clauses.getLiteral(clause, index)), clause);
1192
1113
  }
1193
1114
 
1194
- // A literal's first watch gets a list of its own size, since growing an empty list allocates room
1195
- // for many.
1196
1115
  protected addWatch(literal: Literal, clause: Clause) {
1197
1116
  const list = this.watches[literal];
1198
1117
  if (list === undefined) this.watches[literal] = [clause];
@@ -1202,7 +1121,6 @@ export abstract class Internalizer {
1202
1121
  protected removeWatchLiteral(clause: Clause, index: number) {
1203
1122
  const list = this.watches[negate(this.clauses.getLiteral(clause, index))];
1204
1123
  if (list === undefined) return;
1205
- // A clause is deleted when its scope is popped, so it is most often near the end.
1206
1124
  const position = list.lastIndexOf(clause);
1207
1125
  if (position === -1) return;
1208
1126
  list.copyWithin(position, position + 1);
@@ -1217,9 +1135,6 @@ export abstract class Internalizer {
1217
1135
  return created;
1218
1136
  }
1219
1137
 
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
1138
  private isUsingBinaryClauseOpt(first: Literal, second: Literal, isLemma: boolean) {
1224
1139
  if (isLemma && this.relevancy.isEnabled) return false;
1225
1140
  if (this.baseLevel > 0) return false;
@@ -1240,14 +1155,12 @@ export abstract class Internalizer {
1240
1155
  this.clausesToReinit[level].push(clause);
1241
1156
  }
1242
1157
 
1243
- // mk_clause: like Z3's, it simplifies the literals in the array it is given.
1244
1158
  mkClause(
1245
- input: Literal[],
1159
+ literals: Literal[],
1246
1160
  inputJustification: Justification | null,
1247
1161
  kind: number,
1248
1162
  delEh: (() => void) | null = null,
1249
1163
  ) {
1250
- const literals = input;
1251
1164
  let justification = inputJustification;
1252
1165
  if (kind === CLS_TH_LEMMA) {
1253
1166
  if (!this.simplifyAuxLemmaLiterals(literals)) return null;
@@ -1298,8 +1211,6 @@ export abstract class Internalizer {
1298
1211
  this.addWatchLiteral(clause, 1);
1299
1212
  const first = clauses.getLiteral(clause, 0);
1300
1213
  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
1214
  const isPropagating =
1304
1215
  this.assignment[first] === L_FALSE || this.assignment[second] === L_FALSE;
1305
1216
  if (this.assignment[first] === L_FALSE) this.setConflict(clause, null);
@@ -1317,7 +1228,6 @@ export abstract class Internalizer {
1317
1228
  return clause;
1318
1229
  }
1319
1230
 
1320
- // del_clause. A clause in the reinit stack is only marked deleted, and reinitClauses frees it.
1321
1231
  protected deleteClause(clause: Clause) {
1322
1232
  const clauses = this.clauses;
1323
1233
  if (clauses.isDeleted(clause)) return;
@@ -1329,14 +1239,11 @@ export abstract class Internalizer {
1329
1239
  if (!clauses.isReinit(clause)) clauses.free(clause);
1330
1240
  }
1331
1241
 
1332
- // release_atoms: the clause no longer holds its atoms.
1333
1242
  protected releaseAtoms(clause: Clause) {
1334
1243
  for (const atom of this.clauses.getAtoms(clause)) this.manager.decRef(atom);
1335
1244
  this.clauses.clearAtoms(clause);
1336
1245
  }
1337
1246
 
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
1247
  protected deleteClauses(clauses: Clause[], oldSize: number) {
1341
1248
  if (clauses.length - oldSize <= 1000) {
1342
1249
  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) {