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,15 +1,11 @@
1
- // Ported from Z3 (src/math/lp/monic.h, src/math/lp/emonics.h, src/math/lp/emonics.cpp), MIT
2
- // license, see z3-license.txt. The monomials v := v1 * ... * vn of nla, canonized over the
3
- // variable equivalences, with the cyclic use lists of their variables and the congruence classes
4
- // of monomials equal up to sign.
5
- import { getSignedVarVar, isSignedVarNegated, negateSignedVar, VarEqs } from "./nla-var-eqs";
1
+ // Ported from Z3 (src/math/lp/monic.h, src/math/lp/emonics.h, src/math/lp/emonics.cpp), MIT license, see z3-license.txt.
2
+ import { getSignedVarVar, isSignedVarNegated, negateSignedVar, type VarEqs } from "./nla-var-eqs";
6
3
  import { TrailStack, UnionFind } from "./union-find";
7
4
 
8
5
  const compareNumbers = (first: number, second: number) => first - second;
9
6
 
10
7
  export class Monic {
11
8
  readonly vars: number[];
12
- // The roots of the variables, sorted, and the parity of their signs.
13
9
  rvars: number[] = [];
14
10
  rsign = false;
15
11
  visited = 0;
@@ -32,7 +28,6 @@ export class Monic {
32
28
  }
33
29
  }
34
30
 
35
- // A cell of a cyclic use list: the index of a monic, and the next cell.
36
31
  class Cell {
37
32
  next: Cell = this;
38
33
 
@@ -53,15 +48,13 @@ export class Emonics {
53
48
  private var2index: number[] = [];
54
49
  private visitedStamp = 0;
55
50
  private useLists: HeadTail[] = [];
56
- // The congruence table: the monics of each rooted variable list, the first its representative.
57
51
  private cgTable = new Map<string, number[]>();
58
52
 
59
53
  constructor(private varEqs: VarEqs) {
60
54
  varEqs.setMergeHandler(this.varEqsHandler);
61
55
  }
62
56
 
63
- // The handlers of var_eqs' union-find, over signed variables.
64
- readonly varEqsHandler = {
57
+ private readonly varEqsHandler = {
65
58
  afterMergeEh: (r2: number, r1: number) => {
66
59
  if (
67
60
  getSignedVarVar(r1) !== getSignedVarVar(r2) &&
@@ -230,7 +223,6 @@ export class Emonics {
230
223
  return this.useLists[root].head;
231
224
  }
232
225
 
233
- // The monics in the use list of a variable's root, around the cycle from its head.
234
226
  *getUseList(lpVar: number) {
235
227
  const head = this.getHead(lpVar);
236
228
  if (head === null) return;
@@ -246,11 +238,6 @@ export class Emonics {
246
238
  return table === undefined || table.length === 0 ? undefined : this.get(table[0]);
247
239
  }
248
240
 
249
- isCanonicalMonic(lpVar: number) {
250
- const index = this.var2index[lpVar];
251
- return index >= this.unionFind.numVars || this.unionFind.find(index) === index;
252
- }
253
-
254
241
  private removeCg(lpVar: number) {
255
242
  const first = this.useLists[lpVar].head;
256
243
  if (first === null) return;
@@ -328,8 +315,7 @@ export class Emonics {
328
315
  for (const monic of this.monics) this.doCanonize(monic);
329
316
  }
330
317
 
331
- // canonize_divides: whether the rooted variables of the first are a sub-multiset of the second's.
332
- canonizeDivides(divisor: Monic, product: Monic) {
318
+ private canonizeDivides(divisor: Monic, product: Monic) {
333
319
  if (divisor.size > product.size) return false;
334
320
  let divisorIndex = 0;
335
321
  let productIndex = 0;
@@ -346,8 +332,6 @@ export class Emonics {
346
332
  }
347
333
  }
348
334
 
349
- // get_products_of: the monics, other than the given one, that it divides, or every monic using
350
- // the variable, each once.
351
335
  *getProductsOf(factor: Monic | number) {
352
336
  this.incVisited();
353
337
  const isMonic = factor instanceof Monic;
@@ -360,7 +344,6 @@ export class Emonics {
360
344
  }
361
345
  }
362
346
 
363
- // enum_sign_equiv_monics: the monics equal to this one up to sign, around its class's cycle.
364
347
  *getSignEquivMonics(monic: Monic) {
365
348
  const start = this.var2index[monic.variable];
366
349
  let index = start;
@@ -1,6 +1,4 @@
1
- // Ported from Z3 (src/math/lp/factorization.h), MIT license, see z3-license.txt. A factor of a
2
- // monic is a variable or a monic, with a sign. The core makes the factorizations, see
3
- // getFactorizations in nla-core.ts.
1
+ // Ported from Z3 (src/math/lp/factorization.h), MIT license, see z3-license.txt.
4
2
  import type { Monic } from "./nla-emonics";
5
3
  import { signToRat } from "./nla-types";
6
4
 
@@ -18,7 +16,6 @@ export const mkFactor = (variable: number, isMon: boolean): Factor => ({
18
16
 
19
17
  export const getFactorSign = (factor: Factor) => signToRat(factor.isNegated);
20
18
 
21
- // A factorization: the factors of a monic, which is set for the factorization into its variables.
22
19
  export interface Factorization {
23
20
  readonly factors: Factor[];
24
21
  mon: Monic | null;
@@ -1,8 +1,5 @@
1
- // Ported from Z3 (src/math/lp/nla_grobner.h, src/math/lp/nla_grobner.cpp), MIT license, see
2
- // z3-license.txt. nla's Grobner pass: the rows around the monomials to refine become polynomial
3
- // equations, which dd::solver saturates, and the equations then yield lemmas: interval conflicts,
4
- // quotient and residue bounds, failed gcd tests, fixed variables, factorizations, and new linear
5
- // rows. Z3's nlsat conflict check (is_nla_conflict) is not ported, nor are the statistics.
1
+ // Ported from Z3 (src/math/lp/nla_grobner.h, src/math/lp/nla_grobner.cpp), MIT license, see z3-license.txt.
2
+ // Deviation from Z3: its nlsat conflict check (is_nla_conflict) is not ported.
6
3
  import { PddMemoryOutError } from "../../../../errors";
7
4
  import { getEuclideanMod, getGcd, getLcm, Rational } from "../rational";
8
5
  import { KIND_EQ, KIND_GE, KIND_LE, KIND_LT, KIND_NE } from "./constraints";
@@ -40,7 +37,6 @@ const ADAPTIVE_MAX = 4 * 16;
40
37
  const ADAPTIVE_BUMP_AFTER = 2;
41
38
  const DELAY_CAP = 1000000;
42
39
 
43
- // A dependency that pdd_expr and val_of_fixed_var_with_deps extend, where Z3 passes a reference.
44
40
  interface DepRef {
45
41
  dep: Dependency;
46
42
  }
@@ -63,11 +59,9 @@ const getRationalLcm = (first: Rational, second: Rational) =>
63
59
 
64
60
  const getDenominator = (value: Rational) => Rational.of(value.den);
65
61
 
66
- // divides: whether the integer a divides the integer b, where 0 divides only 0.
67
62
  const divides = (divisor: Rational, value: Rational) =>
68
63
  divisor.isZero() ? value.isZero() : value.num % divisor.num === 0n;
69
64
 
70
- // ps_root: the root a of a^2 * M^2, a perfect square with every variable of even multiplicity.
71
65
  const getPerfectSquareRoot = (coeff: Rational, vars: number[]) => {
72
66
  if (vars.length % 2 === 1) return undefined;
73
67
  const root = coeff.root(2);
@@ -80,8 +74,6 @@ const getPerfectSquareRoot = (coeff: Rational, vars: number[]) => {
80
74
  return root;
81
75
  };
82
76
 
83
- // ps_cross: whether (c12, v12) is the cross term -2ab*M1*M2 of the perfect squares a^2*M1^2 and
84
- // b^2*M2^2.
85
77
  const isPerfectSquareCross = (
86
78
  first: Rational,
87
79
  firstVars: number[],
@@ -112,12 +104,11 @@ export class Grobner {
112
104
  private readonly solver: PddSolver;
113
105
  private readonly nexCreator = new NexCreator();
114
106
  private readonly rows = new IndexedUintSet();
115
- private quota: number = NLA_PARAMS.grQ;
107
+ private quota = NLA_PARAMS.grQ;
116
108
  private delayBase = 0;
117
109
  private delay = 0;
118
110
  private growthBoost = ADAPTIVE_UNIT;
119
111
  private hitStreak = 0;
120
- private readonly isAddingAllEqs = false;
121
112
  private mon2var = new Map<string, number>();
122
113
 
123
114
  constructor(private core: NlaCore) {
@@ -125,7 +116,6 @@ export class Grobner {
125
116
  this.solver = new PddSolver(this.manager, () => core.isCanceled());
126
117
  }
127
118
 
128
- // operator(): runs the pass, unless the quota of misses delays it.
129
119
  run() {
130
120
  if (this.core.lra.getColumnCount() > 5000) return;
131
121
  if (this.quota === 0) this.quota = NLA_PARAMS.grQ;
@@ -166,7 +156,6 @@ export class Grobner {
166
156
  if (this.quota > 0) this.quota--;
167
157
  }
168
158
 
169
- // Z3 catches every exception here, of which a failed pdd allocation is the one that can occur.
170
159
  private catchMemoryOut(propagate: () => boolean) {
171
160
  try {
172
161
  return propagate();
@@ -176,8 +165,6 @@ export class Grobner {
176
165
  }
177
166
  }
178
167
 
179
- // update_growth_boost: two productive runs in a row raise the boost by half, up to the cap, and a
180
- // miss takes back a quarter of the excess over the unit.
181
168
  private updateGrowthBoost(isProductive: boolean) {
182
169
  if (isProductive) {
183
170
  if (++this.hitStreak < ADAPTIVE_BUMP_AFTER) return;
@@ -222,7 +209,6 @@ export class Grobner {
222
209
  return this.countPropagations((equation) => this.propagateQuotientsOf(equation));
223
210
  }
224
211
 
225
- // propagate_fixed: k*x = 0 gives x = 0, and x + b = 0 gives x = -b.
226
212
  private propagateFixed(equation: Equation) {
227
213
  const poly = equation.poly;
228
214
  if (poly.isUnary()) {
@@ -246,7 +232,6 @@ export class Grobner {
246
232
  return true;
247
233
  }
248
234
 
249
- // propagate_factorization: x*q = 0 gives x = 0 or q = 0, for a linear q.
250
235
  private propagateFactorizationOf(equation: Equation) {
251
236
  const factors = equation.poly.varFactors();
252
237
  if (factors.vars.length === 0 || !factors.poly.isLinear()) return false;
@@ -259,8 +244,6 @@ export class Grobner {
259
244
  return true;
260
245
  }
261
246
 
262
- // linear_to_term: the linear polynomial times the lcm of its denominators, as a term and an
263
- // offset.
264
247
  private linearToTerm(poly: Pdd): LinearTerm {
265
248
  let lcm = Rational.one;
266
249
  let current = poly;
@@ -289,8 +272,6 @@ export class Grobner {
289
272
  );
290
273
  }
291
274
 
292
- // propagate_gcd_test: x^k - y = 0 limits y modulo k^2. For each residue r of x modulo k, the
293
- // gcd of the coefficients of p with k*x + r for x must divide its constant term.
294
275
  private propagateGcdTestOf(equation: Equation) {
295
276
  let poly = equation.poly;
296
277
  if (poly.isLinear() || poly.isVal() || !this.isIntPoly(poly)) return false;
@@ -330,8 +311,6 @@ export class Grobner {
330
311
  return false;
331
312
  }
332
313
 
333
- // propagate_quotients: for x*y + z = 0 over the integers, the residue of a linear variable and
334
- // bounds that relate a factor to the rest.
335
314
  private propagateQuotientsOf(equation: Equation) {
336
315
  const poly = equation.poly;
337
316
  if (poly.isLinear() || poly.isVal() || !this.isIntPoly(poly)) return false;
@@ -355,8 +334,6 @@ export class Grobner {
355
334
  return isLemmaFound;
356
335
  }
357
336
 
358
- // mod_residue: when every monomial but c_v*v is a multiple of M*c_v and the constant term is
359
- // K*c_v, then v = -K modulo M, so 0 <= v < M forces v to the residue.
360
337
  private propagateModResidue(equation: Equation) {
361
338
  const poly = equation.poly;
362
339
  for (const linear of poly) {
@@ -399,14 +376,12 @@ export class Grobner {
399
376
  return false;
400
377
  }
401
378
 
402
- // The lemmas of p = v*lc + r for a linear r, by the values of v, lc and r.
403
379
  private addQuotientLemma(equation: Equation, variable: number, lc: Pdd, rest: Pdd) {
404
380
  const variableValue = this.core.val(variable);
405
381
  const restValue = this.getValue(rest);
406
382
  const lcValue = this.getValue(lc);
407
383
  if (restValue.isZero()) {
408
384
  if (variableValue.isZero() || lcValue.isZero() || !lc.isLinear()) return false;
409
- // v = 0 or lc = 0 or r != 0
410
385
  const lcTerm = this.linearToTerm(lc);
411
386
  const restTerm = this.linearToTerm(rest);
412
387
  this.addDependencies(new LemmaBuilder(this.core), equation)
@@ -416,7 +391,6 @@ export class Grobner {
416
391
  return true;
417
392
  }
418
393
  if (variableValue.isZero()) {
419
- // v = 0 => r = 0
420
394
  const lemma = this.addDependencies(new LemmaBuilder(this.core), equation);
421
395
  const restTerm = this.linearToTerm(rest);
422
396
  lemma
@@ -426,7 +400,6 @@ export class Grobner {
426
400
  }
427
401
  if (lcValue.isZero()) {
428
402
  if (!lc.isLinear()) return false;
429
- // lc = 0 => r = 0
430
403
  const lemma = this.addDependencies(new LemmaBuilder(this.core), equation);
431
404
  const lcTerm = this.linearToTerm(lc);
432
405
  const restTerm = this.linearToTerm(rest);
@@ -439,7 +412,6 @@ export class Grobner {
439
412
  const isVariablePositive = variableValue.isPositive();
440
413
  const isRestPositive = restValue.isPositive();
441
414
  if (variableValue.abs().compare(restValue.abs()) > 0) {
442
- // v*c + t = 0 with |v| > |t| != 0: v changes sign, t changes sign, or |v| <= |t|
443
415
  const lemma = new LemmaBuilder(this.core);
444
416
  const restTerm = this.linearToTerm(rest);
445
417
  this.addDependencies(lemma, equation);
@@ -460,7 +432,6 @@ export class Grobner {
460
432
  variableValue.abs().compare(one) > 0 &&
461
433
  variableValue.abs().compare(restValue.abs()) >= 0
462
434
  ) {
463
- // v*c + t = 0 & |c| > 1, |v| > 1 => |v| < |t|
464
435
  const lemma = new LemmaBuilder(this.core);
465
436
  const restTerm = this.linearToTerm(rest);
466
437
  const lcTerm = this.linearToTerm(lc);
@@ -497,7 +468,7 @@ export class Grobner {
497
468
 
498
469
  private configure() {
499
470
  this.solver.reset();
500
- try {
471
+ const isLoaded = this.catchMemoryOut(() => {
501
472
  this.setLevel2var();
502
473
  for (const lpVar of this.core.activeVarSet.elems) {
503
474
  if (this.core.lra.isBase(lpVar)) {
@@ -505,10 +476,9 @@ export class Grobner {
505
476
  }
506
477
  if (this.core.isMonicVar(lpVar) && this.core.varIsFixed(lpVar)) this.addFixedMonic(lpVar);
507
478
  }
508
- } catch (error) {
509
- if (!(error instanceof PddMemoryOutError)) throw error;
510
- return false;
511
- }
479
+ return true;
480
+ });
481
+ if (!isLoaded) return false;
512
482
  const config = getDefaultPddSolverConfig();
513
483
  config.maxSteps = this.solver.equations().length;
514
484
  config.maxSimplified = NLA_PARAMS.grobnerMaxSimplified;
@@ -530,7 +500,6 @@ export class Grobner {
530
500
  return true;
531
501
  }
532
502
 
533
- // equation_is_true: the equation holds at the values, or a free column can make it hold.
534
503
  private isEquationTrue(equation: Equation) {
535
504
  if (equation.poly.freeVars().some((variable) => this.core.lra.isFree(variable))) return true;
536
505
  return this.getValue(equation.poly).isZero();
@@ -542,8 +511,6 @@ export class Grobner {
542
511
  return interval;
543
512
  };
544
513
 
545
- // is_conflicting: the interval of the polynomial excludes 0, or a cross-nested form or a
546
- // perfect square shows that it does.
547
514
  private isEquationConflicting(equation: Equation) {
548
515
  if (this.isEquationTrue(equation)) return false;
549
516
  const interval = getPddInterval(equation.poly, "without-deps", this.getVarInterval);
@@ -563,7 +530,6 @@ export class Grobner {
563
530
  new LemmaBuilder(this.core).addExplanation(explanation);
564
531
  }
565
532
 
566
- // monomial_interval: coeff times the product of the variables' intervals.
567
533
  private getMonomialInterval(coeff: Rational, vars: number[], mode: DepsMode) {
568
534
  const result = mkDepInterval();
569
535
  setValue(result, coeff);
@@ -580,8 +546,6 @@ export class Grobner {
580
546
  return result;
581
547
  }
582
548
 
583
- // add_perfect_square_conflict: a triple of monomials a^2*M1^2, b^2*M2^2 and -2ab*M1*M2 is
584
- // (a*M1 - b*M2)^2, at least 0, which replaces their interval when its lower bound is negative.
585
549
  private addPerfectSquareConflict(equation: Equation) {
586
550
  const monomials: SortedMonomial[] = [...equation.poly].map((monomial) => ({
587
551
  coeff: monomial.coeff,
@@ -632,7 +596,6 @@ export class Grobner {
632
596
  }
633
597
  }
634
598
  if (!isFound) return false;
635
- // [0, oo) for the perfect squares is an unconditional bound, without a dependency.
636
599
  const sum = mkDepInterval();
637
600
  sum.isLowerInf = false;
638
601
  sum.lower = Rational.zero;
@@ -658,7 +621,6 @@ export class Grobner {
658
621
  return this.getMonomialInterval(monomial.coeff, monomial.vars, "without-deps");
659
622
  }
660
623
 
661
- // add_horner_conflict: the cross-nested forms of the polynomial, whose intervals may exclude 0.
662
624
  private addHornerConflict(equation: Equation) {
663
625
  const nexCreator = this.nexCreator;
664
626
  const freeVars = equation.poly.freeVars();
@@ -688,8 +650,6 @@ export class Grobner {
688
650
  return crossNested.done();
689
651
  }
690
652
 
691
- // propagate_linear_equations: an equation whose monomials all have columns and that the values
692
- // violate becomes a new row fixed to its constant.
693
653
  private propagateLinearEquations() {
694
654
  this.mon2var.clear();
695
655
  for (const monic of this.core.emons.monics)
@@ -701,8 +661,7 @@ export class Grobner {
701
661
  return changed > 0;
702
662
  }
703
663
 
704
- // The monomial's column: Z3 looks up the variables in the pdd's order in the sorted variables of
705
- // the monics.
664
+ // Like Z3, the variables are looked up in the pdd's order among the monics' sorted variables.
706
665
  private getMonomialColumn(vars: number[]) {
707
666
  return this.mon2var.get(vars.join(","));
708
667
  }
@@ -739,7 +698,6 @@ export class Grobner {
739
698
  return true;
740
699
  }
741
700
 
742
- // find_nl_cluster: the variables and rows reachable from the monomials to refine.
743
701
  private findNlCluster() {
744
702
  this.rows.clear();
745
703
  this.core.activeVarSet.clear();
@@ -749,7 +707,6 @@ export class Grobner {
749
707
  }
750
708
  }
751
709
 
752
- // add_var_and_its_factors_to_q_and_collect_new_rows.
753
710
  private addVarAndItsFactorsToQueue(lpVar: number, queue: number[]) {
754
711
  const core = this.core;
755
712
  const lra = core.lra;
@@ -769,17 +726,12 @@ export class Grobner {
769
726
  if (this.rows.has(row)) continue;
770
727
  this.rows.add(row);
771
728
  const basic = lra.core.basis[row];
772
- // A free column over the reals can be assigned.
773
729
  if (lra.isFree(basic) && basic !== lpVar) {
774
730
  if (!lra.isInt(basic)) continue;
775
- // Free integer columns count only for the gcd test, the quotients, or all equations.
776
- if (!this.isAddingAllEqs && !this.hasGcdTest && !this.propagatesQuotients) continue;
777
- // A free integer column with integer coefficients can be assigned.
778
- if (!this.isAddingAllEqs && lra.getRow(row).every((rowCell) => rowCell.coeff.isInt()))
779
- continue;
731
+ if (!this.hasGcdTest && !this.propagatesQuotients) continue;
732
+ if (lra.getRow(row).every((rowCell) => rowCell.coeff.isInt())) continue;
780
733
  }
781
- if (!this.isAddingAllEqs && lra.getRow(row).length > NLA_PARAMS.hornerRowLengthLimit)
782
- continue;
734
+ if (lra.getRow(row).length > NLA_PARAMS.hornerRowLengthLimit) continue;
783
735
  for (const rowCell of lra.getRow(row)) this.addVarAndItsFactorsToQueue(rowCell.column, queue);
784
736
  }
785
737
  }
@@ -792,13 +744,11 @@ export class Grobner {
792
744
 
793
745
  private getTermPdd(term: LarTerm, ref: DepRef) {
794
746
  let result = this.manager.mkVal(Rational.zero);
795
- for (const entry of term.coeffs) result = result.add(this.getPdd(entry[1], entry[0], ref));
747
+ for (const entry of term.coeffs) result = result.add(this.getPddExpr(entry[1], entry[0], ref));
796
748
  return result;
797
749
  }
798
750
 
799
- // pdd_expr: coeff times the column, with fixed columns as values, terms expanded, and monics as
800
- // the products of their variables.
801
- private getPdd(coeff: Rational, lpVar: number, ref: DepRef) {
751
+ private getPddExpr(coeff: Rational, lpVar: number, ref: DepRef) {
802
752
  const core = this.core;
803
753
  let result = this.manager.mkVal(coeff);
804
754
  const vars = [lpVar];
@@ -822,8 +772,6 @@ export class Grobner {
822
772
  return result;
823
773
  }
824
774
 
825
- // is_solved: p = 0 as v = r, for a linear p where v is the only variable bounded on one side
826
- // while several are bounded on the other, so that r has no bound on that side.
827
775
  private getSolvedForm(poly: Pdd) {
828
776
  if (!poly.isLinear()) return null;
829
777
  let numLo = 0;
@@ -862,7 +810,6 @@ export class Grobner {
862
810
  };
863
811
  }
864
812
 
865
- // add_eq: adds the equation in solved form when it has one.
866
813
  private addEq(poly: Pdd, dep: Dependency) {
867
814
  const simplified = this.solver.simplify(poly, dep);
868
815
  const solved = this.getSolvedForm(simplified.poly);
@@ -874,7 +821,7 @@ export class Grobner {
874
821
  const ref: DepRef = { dep: null };
875
822
  let product = this.manager.mkVal(Rational.one);
876
823
  for (const factor of this.core.emons.get(lpVar).vars) {
877
- product = product.mul(this.getPdd(Rational.one, factor, ref));
824
+ product = product.mul(this.getPddExpr(Rational.one, factor, ref));
878
825
  }
879
826
  product = product.sub(this.getValOfFixedVarWithDeps(lpVar, ref));
880
827
  this.addEq(product, ref.dep);
@@ -883,11 +830,10 @@ export class Grobner {
883
830
  private addRow(row: RowCell[]) {
884
831
  const ref: DepRef = { dep: null };
885
832
  let sum = this.manager.mkVal(Rational.zero);
886
- for (const cell of row) sum = sum.add(this.getPdd(cell.coeff, cell.column, ref));
833
+ for (const cell of row) sum = sum.add(this.getPddExpr(cell.coeff, cell.column, ref));
887
834
  this.addEq(sum, ref.dep);
888
835
  }
889
836
 
890
- // set_level2var: the columns by weight, then index, from the lowest level.
891
837
  private setLevel2var() {
892
838
  const core = this.core;
893
839
  const count = core.lra.getColumnCount();
@@ -1,7 +1,5 @@
1
1
  // Ported from Z3 (src/math/lp/horner.h, src/math/lp/horner.cpp, and nexvar, create_sum_from_row,
2
- // and add_deps_of_fixed from src/math/lp/nla_common.cpp), MIT license, see z3-license.txt. Horner
3
- // lemmas: a tableau row is a sum that equals zero. Each cross-nested form of the row that
4
- // intervals proves nonzero yields a conflict.
2
+ // and add_deps_of_fixed from src/math/lp/nla_common.cpp), MIT license, see z3-license.txt.
5
3
  import { Rational } from "../rational";
6
4
  import { CrossNested } from "./cross-nested";
7
5
  import { type Dependency, mkJoin } from "./dependency";
@@ -12,7 +10,6 @@ import type { RowCell } from "./static-matrix";
12
10
 
13
11
  export class Horner {
14
12
  private readonly nexCreator = new NexCreator();
15
- // The joined bounds of the fixed variables that the row's sum replaced by their values.
16
13
  private fixedDep: Dependency = null;
17
14
 
18
15
  constructor(private readonly core: NlaCore) {}
@@ -38,7 +35,6 @@ export class Horner {
38
35
  return false;
39
36
  }
40
37
 
41
- // row_is_interesting: whether two monomials of the row share a variable.
42
38
  private rowIsInteresting(row: RowCell[]) {
43
39
  if (row.length > NLA_PARAMS.hornerRowLengthLimit) return false;
44
40
  const core = this.core;
@@ -60,7 +56,7 @@ export class Horner {
60
56
  const core = this.core;
61
57
  core.activeVarSet.clear();
62
58
  this.fixedDep = null;
63
- const summands = row.map((cell) => this.nexvar(cell.coeff, cell.column));
59
+ const summands = row.map((cell) => this.mkNexVar(cell.coeff, cell.column));
64
60
  const fixedDep = this.fixedDep;
65
61
  this.setActiveVarsWeights();
66
62
  const expr = this.nexCreator.simplify(this.nexCreator.mkSum(summands));
@@ -76,21 +72,17 @@ export class Horner {
76
72
  return crossNested.done();
77
73
  }
78
74
 
79
- // set_active_vars_weights: without the weights the comparisons of nex_creator are wrong.
80
75
  private setActiveVarsWeights() {
81
76
  this.nexCreator.setNumberOfVars(this.core.lra.getColumnCount());
82
77
  for (const lpVar of this.core.activeVarSet.elems)
83
78
  this.nexCreator.setVarWeight(lpVar, this.core.getVarWeight(lpVar));
84
79
  }
85
80
 
86
- // add_deps_of_fixed.
87
81
  private addDepsOfFixed(lpVar: number) {
88
82
  this.fixedDep = mkJoin(this.fixedDep, this.core.lra.getBoundWitnesses(lpVar));
89
83
  }
90
84
 
91
- // nexvar: coeff times the column, a product for a monic, where hornerSubsFixed replaces fixed
92
- // variables by their values (1) or only those fixed to zero (2).
93
- private nexvar(coeff: Rational, lpVar: number): Nex {
85
+ private mkNexVar(coeff: Rational, lpVar: number): Nex {
94
86
  const core = this.core;
95
87
  const creator = this.nexCreator;
96
88
  const subsFixed: number = NLA_PARAMS.hornerSubsFixed;
@@ -1,7 +1,4 @@
1
- // Ported from Z3 (src/math/lp/nla_intervals.h, src/math/lp/nla_intervals.cpp), MIT license, see
2
- // z3-license.txt. Evaluates a nex expression over the bounds of its variables. When the interval
3
- // excludes zero, the expression cannot vanish, so the bounds behind the interval and the
4
- // dependencies of the row conflict with the row's equation, and the conflict becomes a lemma.
1
+ // Ported from Z3 (src/math/lp/nla_intervals.h, src/math/lp/nla_intervals.cpp), MIT license, see z3-license.txt.
5
2
  import { Rational } from "../rational";
6
3
  import {
7
4
  type DepInterval,
@@ -38,7 +35,6 @@ const mkExplanation = (constraints: number[]) => {
38
35
  export class Intervals {
39
36
  constructor(private readonly core: NlaCore) {}
40
37
 
41
- // check_nex: whether the expression's interval excludes zero, in which case a lemma explains it.
42
38
  checkNex(expr: Nex, initialDeps: Dependency) {
43
39
  const report: ReportConflict = (explanation) =>
44
40
  new LemmaBuilder(this.core).addExplanation(explanation);
@@ -74,8 +70,6 @@ export class Intervals {
74
70
  return hasInf;
75
71
  }
76
72
 
77
- // expression_to_normalized_term: the sum a*t + b, where t is the linear part divided by the
78
- // coefficient of its smallest variable, which is a.
79
73
  private expressionToNormalizedTerm(sum: NexSum) {
80
74
  const pairs: [Rational, number][] = [];
81
75
  let constant = Rational.zero;
@@ -134,8 +128,6 @@ export class Intervals {
134
128
  if (mode === "with-deps") interval.upperDep = upperDep;
135
129
  }
136
130
 
137
- // interval_from_term: the interval of a linear sum from the bounds of the term column that
138
- // equals it, or from an equivalence that fixes it.
139
131
  private intervalFromTerm(sum: NexSum, interval: DepInterval, mode: DepsMode) {
140
132
  const normalized = this.expressionToNormalizedTerm(sum);
141
133
  const explanation = new Explanation();
@@ -176,12 +168,11 @@ export class Intervals {
176
168
  return true;
177
169
  }
178
170
 
179
- // conflict_u_l: whether first's upper bound is below second's lower bound. Like Z3, equal
180
- // bounds conflict when either upper bound is open.
181
171
  private conflictUpperLower(first: DepInterval, second: DepInterval) {
182
172
  if (first.isUpperInf || second.isLowerInf) return false;
183
173
  const comparison = first.upper.compare(second.lower);
184
174
  if (comparison !== 0) return comparison < 0;
175
+ // Like Z3, equal bounds conflict when either upper bound is open.
185
176
  return first.isUpperOpen || second.isUpperOpen;
186
177
  }
187
178
 
@@ -242,7 +233,6 @@ export class Intervals {
242
233
  set(interval, result, mode);
243
234
  }
244
235
 
245
- // interval_of_expr: false when a sum met a conflict, which report received.
246
236
  private intervalOfExpr(
247
237
  expr: Nex,
248
238
  exponent: number,