tla-ts 0.0.10-dev.c92e6a4ea → 0.0.10-dev.d166e0ae9

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 (235) hide show
  1. package/dist/compile.cjs +3 -3
  2. package/dist/compile.js +1 -1
  3. package/dist/deciders.cjs +36 -36
  4. package/dist/deciders.js +54 -54
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.d.cts +13 -3
  7. package/dist/index.d.ts +13 -3
  8. package/dist/index.js +1 -1
  9. package/dist/parallel-worker.cjs +1 -1
  10. package/dist/parallel-worker.js +1 -1
  11. package/dist/prove-worker.cjs +1 -1
  12. package/dist/prove-worker.js +1 -1
  13. package/dist/prove.cjs +68 -68
  14. package/dist/prove.js +78 -78
  15. package/dist/run.cjs +42 -42
  16. package/dist/run.js +44 -44
  17. package/dist/tlapm.cjs +1 -1
  18. package/dist/tlapm.js +2 -2
  19. package/dist/transfer.cjs +45 -43
  20. package/dist/transfer.js +45 -43
  21. package/dist/worker.cjs +7 -7
  22. package/dist/worker.js +7 -7
  23. package/package.json +1 -1
  24. package/src/ast.ts +11 -1
  25. package/src/bags.ts +50 -29
  26. package/src/builtins.ts +4 -3
  27. package/src/check-failure.ts +9 -6
  28. package/src/check-trace.ts +116 -64
  29. package/src/check.ts +356 -173
  30. package/src/cli/tlc-output.ts +1 -0
  31. package/src/cli/tlc.ts +4 -3
  32. package/src/cli/xml-exporter.ts +1 -1
  33. package/src/codegen.ts +34 -13
  34. package/src/coverage.ts +3 -0
  35. package/src/dependencies.ts +61 -13
  36. package/src/dfid.ts +22 -10
  37. package/src/environment.ts +71 -35
  38. package/src/errors.ts +7 -0
  39. package/src/evaluate.ts +149 -54
  40. package/src/exit-codes.ts +29 -15
  41. package/src/instances.ts +16 -6
  42. package/src/java-hash.ts +14 -0
  43. package/src/java-overrides.ts +2 -2
  44. package/src/levels.ts +186 -97
  45. package/src/liveness-checker.ts +131 -83
  46. package/src/liveness.ts +52 -11
  47. package/src/obligations/index.ts +1 -1
  48. package/src/obligations/normalize.ts +1 -4
  49. package/src/obligations/printer.ts +5 -5
  50. package/src/obligations/source.ts +2 -0
  51. package/src/parser.ts +115 -145
  52. package/src/prover/isabelle/isar/attrib.ts +4 -4
  53. package/src/prover/isabelle/isar/rule-cases.ts +8 -6
  54. package/src/prover/isabelle/provers/clasimp.ts +1 -1
  55. package/src/prover/isabelle/provers/hypsubst.ts +2 -2
  56. package/src/prover/isabelle/pure/rewriter.ts +3 -3
  57. package/src/prover/isabelle/pure/term.ts +3 -3
  58. package/src/prover/prep/md5.ts +26 -29
  59. package/src/prover/smt/rewrite.ts +2 -7
  60. package/src/prover/smt/simplify.ts +1 -1
  61. package/src/prover/smt/solver/arith-rewriter.ts +11 -3
  62. package/src/prover/smt/solver/array-rewriter.ts +12 -2
  63. package/src/prover/smt/solver/asserted-formulas.ts +169 -58
  64. package/src/prover/smt/solver/ast-lt.ts +1 -1
  65. package/src/prover/smt/solver/ast.ts +63 -14
  66. package/src/prover/smt/solver/auf-solver.ts +23 -12
  67. package/src/prover/smt/solver/bit-blast-tactic.ts +26 -0
  68. package/src/prover/smt/solver/blast-term-ite.ts +47 -0
  69. package/src/prover/smt/solver/bound-simplifier.ts +11 -13
  70. package/src/prover/smt/solver/bv-decl-plugin.ts +13 -10
  71. package/src/prover/smt/solver/bv-rewriter.ts +1 -1
  72. package/src/prover/smt/solver/card2bv.ts +35 -18
  73. package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -24
  74. package/src/prover/smt/solver/context.ts +67 -13
  75. package/src/prover/smt/solver/ctx-simplify.ts +1 -2
  76. package/src/prover/smt/solver/datatype-decl-plugin.ts +15 -7
  77. package/src/prover/smt/solver/dependent-expr-state.ts +26 -15
  78. package/src/prover/smt/solver/diff-neq.ts +1 -2
  79. package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
  80. package/src/prover/smt/solver/elim-bounds.ts +89 -0
  81. package/src/prover/smt/solver/elim-term-ite-tactic.ts +48 -0
  82. package/src/prover/smt/solver/elim-uncnstr.ts +5 -8
  83. package/src/prover/smt/solver/euf/arith-internalize.ts +1 -1
  84. package/src/prover/smt/solver/euf/array-internalize.ts +1 -1
  85. package/src/prover/smt/solver/euf/bv-internalize.ts +1 -1
  86. package/src/prover/smt/solver/euf/egraph.ts +4 -11
  87. package/src/prover/smt/solver/euf/euf-solver.ts +1 -2
  88. package/src/prover/smt/solver/euf/mam.ts +1 -5
  89. package/src/prover/smt/solver/euf/q-ematch.ts +1 -2
  90. package/src/prover/smt/solver/euf/th-solver.ts +0 -7
  91. package/src/prover/smt/solver/expr2polynomial.ts +204 -79
  92. package/src/prover/smt/solver/factor.ts +36 -14
  93. package/src/prover/smt/solver/fd-solver.ts +148 -39
  94. package/src/prover/smt/solver/fix-dl-var.ts +1 -2
  95. package/src/prover/smt/solver/fpa-rewriter.ts +1 -2
  96. package/src/prover/smt/solver/fpa2bv-converter.ts +3 -1
  97. package/src/prover/smt/solver/fpa2bv-rewriter.ts +1 -0
  98. package/src/prover/smt/solver/goal.ts +6 -3
  99. package/src/prover/smt/solver/goal2nlsat.ts +57 -30
  100. package/src/prover/smt/solver/hashtable.ts +4 -0
  101. package/src/prover/smt/solver/internalizer.ts +1 -1
  102. package/src/prover/smt/solver/logic-tactics.ts +9 -2
  103. package/src/prover/smt/solver/lp/lp-settings.ts +5 -1
  104. package/src/prover/smt/solver/lp/nla-core.ts +1 -1
  105. package/src/prover/smt/solver/lp/nla-grobner.ts +2 -2
  106. package/src/prover/smt/solver/lp/nra-solver.ts +45 -39
  107. package/src/prover/smt/solver/lp/pdd.ts +2 -3
  108. package/src/prover/smt/solver/lp/union-find.ts +1 -1
  109. package/src/prover/smt/solver/mam-compiler.ts +1 -1
  110. package/src/prover/smt/solver/maxcore.ts +2 -1
  111. package/src/prover/smt/solver/maxsmt-base.ts +1 -0
  112. package/src/prover/smt/solver/model-based-opt.ts +1 -1
  113. package/src/prover/smt/solver/model-checker.ts +1 -1
  114. package/src/prover/smt/solver/model-evaluator.ts +2 -0
  115. package/src/prover/smt/solver/model-generator.ts +85 -43
  116. package/src/prover/smt/solver/mpf.ts +2 -4
  117. package/src/prover/smt/solver/mus.ts +2 -3
  118. package/src/prover/smt/solver/muz/dl-context.ts +22 -44
  119. package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
  120. package/src/prover/smt/solver/muz/dl-mk-slice.ts +3 -3
  121. package/src/prover/smt/solver/muz/dl-rule.ts +8 -9
  122. package/src/prover/smt/solver/muz/hnf.ts +2 -2
  123. package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +1 -1
  124. package/src/prover/smt/solver/muz/horn-tactic.ts +15 -2
  125. package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
  126. package/src/prover/smt/solver/muz/spacer-context.ts +2 -4
  127. package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -0
  128. package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
  129. package/src/prover/smt/solver/nlqsat.ts +1 -1
  130. package/src/prover/smt/solver/nlsat/algebraic.ts +196 -92
  131. package/src/prover/smt/solver/nlsat/atoms.ts +52 -33
  132. package/src/prover/smt/solver/nlsat/explain.ts +375 -217
  133. package/src/prover/smt/solver/nlsat/levelwise.ts +460 -240
  134. package/src/prover/smt/solver/nlsat/polynomial.ts +2366 -681
  135. package/src/prover/smt/solver/nlsat/solver.ts +74 -64
  136. package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -17
  137. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -4
  138. package/src/prover/smt/solver/nlsat/upolynomial.ts +41 -18
  139. package/src/prover/smt/solver/nlsat-tactic.ts +1 -1
  140. package/src/prover/smt/solver/nnf.ts +6 -2
  141. package/src/prover/smt/solver/opt-context.ts +21 -7
  142. package/src/prover/smt/solver/opt-nlsat.ts +29 -18
  143. package/src/prover/smt/solver/opt-pareto.ts +19 -0
  144. package/src/prover/smt/solver/opt-preprocess.ts +1 -1
  145. package/src/prover/smt/solver/opt-solver.ts +10 -6
  146. package/src/prover/smt/solver/optsmt.ts +1 -1
  147. package/src/prover/smt/solver/parallel-tactic.ts +1 -1
  148. package/src/prover/smt/solver/pb-rewriter.ts +1 -4
  149. package/src/prover/smt/solver/poly-rewriter.ts +75 -18
  150. package/src/prover/smt/solver/probes.ts +88 -23
  151. package/src/prover/smt/solver/proto-model.ts +8 -8
  152. package/src/prover/smt/solver/push-app-ite.ts +37 -0
  153. package/src/prover/smt/solver/qe-arith-plugin.ts +2 -4
  154. package/src/prover/smt/solver/qe-lite.ts +2 -2
  155. package/src/prover/smt/solver/qe.ts +3 -2
  156. package/src/prover/smt/solver/qsat.ts +23 -8
  157. package/src/prover/smt/solver/quantifier-manager.ts +14 -9
  158. package/src/prover/smt/solver/recfun-decl-plugin.ts +2 -1
  159. package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
  160. package/src/prover/smt/solver/rewriter.ts +31 -25
  161. package/src/prover/smt/solver/rlimit.ts +4 -0
  162. package/src/prover/smt/solver/sat/config.ts +1 -1
  163. package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
  164. package/src/prover/smt/solver/sat/inc-sat-solver.ts +81 -28
  165. package/src/prover/smt/solver/sat/model-converter.ts +1 -1
  166. package/src/prover/smt/solver/sat/pb-solver.ts +1 -1
  167. package/src/prover/smt/solver/sat/sat-tactic.ts +17 -7
  168. package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
  169. package/src/prover/smt/solver/sat/simplifier.ts +1 -1
  170. package/src/prover/smt/solver/sat/solver.ts +25 -47
  171. package/src/prover/smt/solver/seq-axioms.ts +20 -35
  172. package/src/prover/smt/solver/seq-decl-plugin.ts +1 -1
  173. package/src/prover/smt/solver/seq-derive.ts +2 -2
  174. package/src/prover/smt/solver/seq-eq-solver.ts +2 -2
  175. package/src/prover/smt/solver/seq-monadic.ts +7 -5
  176. package/src/prover/smt/solver/seq-re-rewriter.ts +2 -1
  177. package/src/prover/smt/solver/seq-re-util.ts +1 -1
  178. package/src/prover/smt/solver/seq-regex-bisim.ts +1 -1
  179. package/src/prover/smt/solver/seq-regex-live.ts +2 -2
  180. package/src/prover/smt/solver/seq-rewriter.ts +31 -29
  181. package/src/prover/smt/solver/seq-skolem.ts +0 -23
  182. package/src/prover/smt/solver/seq-view-witness.ts +4 -4
  183. package/src/prover/smt/solver/smt-consequences.ts +1 -1
  184. package/src/prover/smt/solver/smt-kernel.ts +48 -7
  185. package/src/prover/smt/solver/smt-setup.ts +96 -10
  186. package/src/prover/smt/solver/smtlib-parser.ts +589 -224
  187. package/src/prover/smt/solver/smtlib-script.ts +674 -195
  188. package/src/prover/smt/solver/solve-eqs.ts +36 -37
  189. package/src/prover/smt/solver/solver.ts +18 -3
  190. package/src/prover/smt/solver/tactic.ts +332 -189
  191. package/src/prover/smt/solver/theory-bv.ts +13 -3
  192. package/src/prover/smt/solver/theory-fpa.ts +1 -1
  193. package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
  194. package/src/prover/smt/solver/theory-lra-internalize.ts +2 -0
  195. package/src/prover/smt/solver/theory-lra-propagate.ts +11 -3
  196. package/src/prover/smt/solver/theory-lra.ts +1 -1
  197. package/src/prover/smt/solver/theory-pb.ts +24 -7
  198. package/src/prover/smt/solver/theory-seq-solve.ts +1 -1
  199. package/src/prover/smt/solver/theory-seq-state.ts +2 -21
  200. package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
  201. package/src/prover/tlapm/cache.ts +8 -8
  202. package/src/prover/zenon/index-table.ts +5 -2
  203. package/src/prover/zenon/isar-case.ts +1 -1
  204. package/src/prover/zenon/isar.ts +2 -2
  205. package/src/prover/zenon/phrase.ts +1 -1
  206. package/src/resolve.ts +1071 -251
  207. package/src/runtime.ts +5 -1
  208. package/src/sany/builtins.ts +10 -10
  209. package/src/sany/generation.ts +2 -13
  210. package/src/sany/generator-definitions.ts +3 -1
  211. package/src/sany/generator-expressions.ts +38 -30
  212. package/src/sany/generator-proofs.ts +6 -3
  213. package/src/sany/generator.ts +2 -1
  214. package/src/sany/lexer.ts +3 -3
  215. package/src/sany/modules.ts +4 -2
  216. package/src/sany/nodes.ts +1 -1
  217. package/src/sany/selectors.ts +11 -6
  218. package/src/sany/xml.ts +2 -3
  219. package/src/search.ts +197 -117
  220. package/src/simulate.ts +165 -102
  221. package/src/spec-description.ts +8 -6
  222. package/src/standard-modules.ts +56 -22
  223. package/src/subexpressions.ts +518 -123
  224. package/src/successors.ts +10 -3
  225. package/src/symmetry.ts +2 -1
  226. package/src/tlc/jar-data.ts +10 -0
  227. package/src/tlc/messages.ts +3 -3
  228. package/src/tlc/random.ts +2 -1
  229. package/src/tlc/replay.ts +27 -14
  230. package/src/tlc/tlc-operators.ts +10 -8
  231. package/src/tlc/tlcext-operators.ts +26 -10
  232. package/src/tlc/trace-spec.ts +9 -22
  233. package/src/typed-tier.ts +44 -27
  234. package/src/typescript/types.ts +2 -2
  235. package/src/values.ts +135 -78
@@ -1,16 +1,22 @@
1
- import { SmtTacticError, SmtUnsupportedError } from "../../../../errors";
1
+ import { SmtCanceledError, SmtTacticError, SmtUnsupportedError } from "../../../../errors";
2
2
  import { type AstManager, OP_AND, OP_EQ, OP_IMPLIES, OP_NOT, OP_OR, SORT_BOOL } from "../ast";
3
+ import { mkNot } from "../ast-util";
3
4
  import { BitBlasterRewriter } from "../bit-blast-tactic";
4
5
  import { Goal } from "../goal";
5
6
  import { L_FALSE, L_TRUE, L_UNDEF } from "../lbool";
6
7
  import { ProtoModel } from "../proto-model";
7
8
  import { RefVector } from "../ref-vector";
8
9
  import type { ThSolverFactory } from "../euf/euf-solver";
9
- import { convertModel, mkIncSatEufPreprocess, mkIncSatPreprocess } from "../tactic";
10
+ import {
11
+ applyDefinitions,
12
+ convertModel,
13
+ mkIncSatEufPreprocess,
14
+ mkIncSatPreprocess,
15
+ } from "../tactic";
10
16
  import type { SatParams } from "./config";
11
17
  import { Goal2Sat } from "./goal2sat";
12
18
  import { getConsequences } from "./consequences";
13
- import { isLiteral, sat2goal } from "./sat2goal";
19
+ import { isLiteral, Sat2GoalConverter, sat2goal } from "./sat2goal";
14
20
  import { Solver } from "./solver";
15
21
 
16
22
  const BIT_BLAST_PARAMS = {
@@ -24,6 +30,8 @@ interface Scope {
24
30
  readonly converters: Goal["converters"];
25
31
  readonly fmlsSize: number;
26
32
  readonly fmlsHead: number;
33
+ readonly namesSize: number;
34
+ readonly hasUninterpreted: boolean;
27
35
  }
28
36
 
29
37
  export class IncSatSolver {
@@ -31,6 +39,7 @@ export class IncSatSolver {
31
39
  private readonly goal2sat: Goal2Sat;
32
40
  private readonly fmls: RefVector;
33
41
  private fmlsHead = 0;
42
+ private readonly names: RefVector;
34
43
  private isCnf = true;
35
44
  private readonly core: RefVector;
36
45
  private dep2asm = new Map<number, number>();
@@ -38,6 +47,7 @@ export class IncSatSolver {
38
47
  private bitBlaster: BitBlasterRewriter | undefined;
39
48
  // m_mcs.back(), the model converters of the preprocessed goals.
40
49
  private readonly converters: Goal;
50
+ private readonly satConverter: Sat2GoalConverter;
41
51
  private isInternalizedConverted = false;
42
52
  private readonly internalized: RefVector;
43
53
  private hasUninterpreted = false;
@@ -62,8 +72,10 @@ export class IncSatSolver {
62
72
  );
63
73
  if (mkThSolver !== null) this.goal2sat.ensureEuf();
64
74
  this.fmls = new RefVector(manager);
75
+ this.names = new RefVector(manager);
65
76
  this.core = new RefVector(manager);
66
77
  this.converters = new Goal(manager);
78
+ this.satConverter = new Sat2GoalConverter(manager);
67
79
  this.internalized = new RefVector(manager);
68
80
  }
69
81
 
@@ -87,21 +99,44 @@ export class IncSatSolver {
87
99
  this.fmls.push(expr);
88
100
  }
89
101
 
90
- // Outside sat.euf, a scope would also need the scopes of the bit-blaster.
102
+ assertNamed(expr: number, name: number) {
103
+ const manager = this.manager;
104
+ this.names.push(name);
105
+ if (this.isCnf && isLiteral(manager, expr) && isLiteral(manager, name))
106
+ return this.assertExpr(manager.mkApp(OP_OR, [mkNot(manager, name), expr], SORT_BOOL));
107
+ if (
108
+ this.isCnf &&
109
+ manager.getOp(expr) === OP_OR &&
110
+ this.isClause(expr) &&
111
+ isLiteral(manager, name)
112
+ )
113
+ return this.assertExpr(
114
+ manager.mkApp(OP_OR, [mkNot(manager, name), ...manager.getArgs(expr)], SORT_BOOL),
115
+ );
116
+ this.isCnf = false;
117
+ this.assertExpr(manager.mkApp(OP_IMPLIES, [name, expr], SORT_BOOL));
118
+ }
119
+
91
120
  push() {
92
- if (this.goal2sat.euf === null) throw new SmtUnsupportedError("push on the SAT solver");
93
- this.internalizeFormulas();
94
- this.goal2sat.push();
95
- this.solver.userPush();
96
- this.scopes.push({
97
- converters: this.converters.converters,
98
- fmlsSize: this.fmls.size,
99
- fmlsHead: this.fmlsHead,
100
- });
121
+ try {
122
+ this.internalizeFormulas();
123
+ } finally {
124
+ this.goal2sat.push();
125
+ this.solver.userPush();
126
+ this.bitBlaster?.push();
127
+ this.scopes.push({
128
+ converters: this.converters.converters,
129
+ fmlsSize: this.fmls.size,
130
+ fmlsHead: this.fmlsHead,
131
+ namesSize: this.names.size,
132
+ hasUninterpreted: this.hasUninterpreted,
133
+ });
134
+ }
101
135
  }
102
136
 
103
137
  pop(numScopes: number) {
104
138
  const count = Math.min(numScopes, this.scopes.length);
139
+ this.bitBlaster?.pop(count);
105
140
  this.goal2sat.pop(count);
106
141
  this.solver.userPop(count);
107
142
  for (let index = 0; index < count; index++) {
@@ -109,9 +144,17 @@ export class IncSatSolver {
109
144
  this.converters.converters = scope.converters;
110
145
  this.fmlsHead = scope.fmlsHead;
111
146
  this.fmls.shrink(scope.fmlsSize);
147
+ this.names.shrink(scope.namesSize);
148
+ this.hasUninterpreted = scope.hasUninterpreted;
112
149
  }
113
150
  }
114
151
 
152
+ private getBitBlaster() {
153
+ const bitBlaster = (this.bitBlaster ??= new BitBlasterRewriter(this.manager, BIT_BLAST_PARAMS));
154
+ while (bitBlaster.getNumScopes() < this.scopes.length) bitBlaster.push();
155
+ return bitBlaster;
156
+ }
157
+
115
158
  private checkUninterpreted() {
116
159
  if (this.goal2sat.unhandledFuns.length === 0) return L_TRUE;
117
160
  this.hasUninterpreted = true;
@@ -131,7 +174,7 @@ export class IncSatSolver {
131
174
  private internalizeGoal(goal: Goal) {
132
175
  this.solver.popToBaseLevel();
133
176
  if (this.solver.isInconsistent) return L_FALSE;
134
- const bitBlaster = (this.bitBlaster ??= new BitBlasterRewriter(this.manager, BIT_BLAST_PARAMS));
177
+ const bitBlaster = this.getBitBlaster();
135
178
  const subgoals = (() => {
136
179
  if (this.isCnf) return [goal];
137
180
  try {
@@ -144,8 +187,10 @@ export class IncSatSolver {
144
187
  return goals;
145
188
  } catch (error) {
146
189
  this.releaseBitBlaster();
147
- if (!(error instanceof SmtTacticError)) throw error;
148
- this.reasonUnknown = error.message;
190
+ if (!(error instanceof SmtTacticError || error instanceof SmtCanceledError)) throw error;
191
+ // The tactics of the preprocessing report a limit that stops their rewriters as a tactic_exception.
192
+ this.reasonUnknown =
193
+ error instanceof SmtCanceledError ? this.manager.limit.getCancelMessage() : error.message;
149
194
  return undefined;
150
195
  }
151
196
  })();
@@ -203,10 +248,19 @@ export class IncSatSolver {
203
248
  this.dep2asm = new Map();
204
249
  const internalized = this.internalizeFormulas();
205
250
  if (internalized !== L_TRUE) return internalized;
206
- this.internalizeAssumptions(literals);
251
+ this.internalizeAssumptions([...literals, ...this.names.items]);
207
252
  this.reasonUnknown = "no reason given";
208
253
  this.isInternalizedConverted = false;
209
- const result = this.solver.check(this.asms);
254
+ const result = (() => {
255
+ try {
256
+ return this.solver.check(this.asms);
257
+ } catch (error) {
258
+ if (!(error instanceof SmtCanceledError)) throw error;
259
+ // check_sat_core counts a step to see whether the limit stopped the search.
260
+ manager.limit.inc();
261
+ return L_UNDEF;
262
+ }
263
+ })();
210
264
  if (result === L_TRUE && this.hasUninterpreted) {
211
265
  this.reasonUnknown = "(sat.giveup has-uninterpreted)";
212
266
  return L_UNDEF;
@@ -239,7 +293,7 @@ export class IncSatSolver {
239
293
 
240
294
  getConsequences(assumptions: readonly number[], vars: readonly number[]) {
241
295
  const manager = this.manager;
242
- this.bitBlaster ??= new BitBlasterRewriter(manager, BIT_BLAST_PARAMS);
296
+ this.getBitBlaster();
243
297
  this.dep2asm = new Map();
244
298
  this.solver.popToBaseLevel();
245
299
  const consequences: number[] = [];
@@ -304,18 +358,15 @@ export class IncSatSolver {
304
358
  const manager = this.manager;
305
359
  if (!this.solver.isModelCurrent || this.fmls.size > this.fmlsHead) return null;
306
360
  const euf = this.goal2sat.euf;
307
- // The euf solver fills a model rather than a proto_model, so its declarations keep their order.
308
- const model = euf === null ? new ProtoModel(manager) : new ProtoModel(manager).mkModel();
361
+ const model = new ProtoModel(manager).mkModel();
309
362
  for (const [expr, boolVar] of this.goal2sat.atoms) {
310
363
  if (!manager.isUninterpretedConst(expr)) continue;
311
364
  const value = this.solver.model[boolVar];
312
365
  if (value === L_TRUE) model.registerConst(manager.decls[expr], manager.trueExpr);
313
366
  else if (value === L_FALSE) model.registerConst(manager.decls[expr], manager.falseExpr);
314
367
  }
315
- const converted = convertModel(
316
- this.converters,
317
- euf === null ? model.mkModel() : euf.updateModel(model),
318
- );
368
+ if (this.satConverter.entries.length > 0) applyDefinitions(this.satConverter.entries, model);
369
+ const converted = convertModel(this.converters, euf === null ? model : euf.updateModel(model));
319
370
  converted.incRef();
320
371
  this.models.push(converted);
321
372
  return converted;
@@ -346,10 +397,9 @@ export class IncSatSolver {
346
397
  if (this.fmlsHead !== this.fmls.size) return this.fmls.items;
347
398
  if (this.isInternalizedConverted) return this.internalized.items;
348
399
  const goal = new Goal(this.manager);
349
- sat2goal(this.manager, this.solver, this.goal2sat.atoms, goal);
400
+ sat2goal(this.manager, this.solver, this.goal2sat.atoms, goal, this.satConverter);
350
401
  this.internalized.reset();
351
402
  for (const form of goal.forms.items) this.internalized.push(form);
352
- this.converters.converters = [...this.converters.converters, ...goal.converters];
353
403
  this.isInternalizedConverted = true;
354
404
  return this.internalized.items;
355
405
  }
@@ -358,13 +408,16 @@ export class IncSatSolver {
358
408
  // asserted formulas are internalized.
359
409
  getConverters(): Goal["converters"] {
360
410
  this.getAssertions();
361
- return this.isInternalizedConverted ? this.converters.converters : [];
411
+ return this.isInternalizedConverted
412
+ ? [...this.converters.converters, { definitions: this.satConverter.entries }]
413
+ : [];
362
414
  }
363
415
 
364
416
  release() {
365
417
  for (const model of this.models) model.decRef();
366
418
  this.models = [];
367
419
  this.fmls.reset();
420
+ this.names.reset();
368
421
  this.core.reset();
369
422
  this.internalized.reset();
370
423
  this.releaseBitBlaster();
@@ -6,7 +6,7 @@ export const MC_BCE = 1;
6
6
  export const MC_CCE = 2;
7
7
  export const MC_ACCE = 3;
8
8
  export const MC_ABCE = 4;
9
- export const MC_ATE = 5;
9
+ const MC_ATE = 5;
10
10
 
11
11
  export interface McEntry {
12
12
  boolVar: number;
@@ -1443,7 +1443,7 @@ export class PbSolver implements SatExtension, ConstraintHost {
1443
1443
  private convertPbWlits(expr: number): WLits {
1444
1444
  const manager = this.manager;
1445
1445
  const lits = this.convertPbArgs(expr);
1446
- const coeffs = lits.map((_, index) =>
1446
+ const coeffs = lits.map((_value, index) =>
1447
1447
  this.checkUnsigned(getPbCoeff(manager, manager.decls[expr], index)),
1448
1448
  );
1449
1449
  return { coeffs, lits };
@@ -1,12 +1,12 @@
1
- import { SmtTacticError } from "../../../../errors";
1
+ import { SmtCanceledError, SmtTacticError } from "../../../../errors";
2
2
  import type { AstManager } from "../ast";
3
3
  import type { ThSolverFactory } from "../euf/euf-solver";
4
4
  import { OVER, type Goal } from "../goal";
5
- import { L_FALSE, L_TRUE } from "../lbool";
5
+ import { L_FALSE, L_TRUE, L_UNDEF } from "../lbool";
6
6
  import { ProtoModel } from "../proto-model";
7
7
  import type { SatParams } from "./config";
8
8
  import { Goal2Sat } from "./goal2sat";
9
- import { sat2goal } from "./sat2goal";
9
+ import { Sat2GoalConverter, sat2goal } from "./sat2goal";
10
10
  import { Solver } from "./solver";
11
11
 
12
12
  // With a theory factory, the sat solver runs the euf solver of sat.euf as its extension.
@@ -19,11 +19,19 @@ export const createSatTactic =
19
19
  const goal2sat = new Goal2Sat(manager, solver, params.get("ite_extra") !== false, mkThSolver);
20
20
  goal2sat.run(goal.forms.items);
21
21
  goal.reset();
22
- const result = solver.check();
22
+ const result = (() => {
23
+ try {
24
+ return solver.check();
25
+ } catch (error) {
26
+ if (error instanceof SmtCanceledError) throw new SmtTacticError("canceled");
27
+ throw error;
28
+ }
29
+ })();
30
+ if (result === L_UNDEF) goal.reasonUnknown = solver.reasonUnknown;
23
31
  const unhandledFuns = goal2sat.euf?.unhandledFunctions ?? goal2sat.unhandledFuns;
24
32
  if (result === L_FALSE) goal.assert(manager.falseExpr);
25
33
  else if (result === L_TRUE && unhandledFuns.length === 0) {
26
- const model = new ProtoModel(manager);
34
+ const model = new ProtoModel(manager).mkModel();
27
35
  for (const [expr, boolVar] of goal2sat.atoms) {
28
36
  if (!manager.isUninterpretedConst(expr)) continue;
29
37
  const value = solver.model[boolVar];
@@ -31,11 +39,13 @@ export const createSatTactic =
31
39
  else if (value === L_FALSE) model.registerConst(manager.decls[expr], manager.falseExpr);
32
40
  }
33
41
  const euf = goal2sat.euf;
34
- goal.model = (euf?.updateModel(model) ?? model).mkModel();
42
+ goal.model = euf?.updateModel(model) ?? model;
35
43
  euf?.validateModel(goal.model);
36
44
  } else {
37
45
  solver.popToBaseLevel();
38
- sat2goal(manager, solver, goal2sat.atoms, goal);
46
+ const converter = new Sat2GoalConverter(manager);
47
+ sat2goal(manager, solver, goal2sat.atoms, goal, converter);
48
+ goal.addDefinitions(converter.entries);
39
49
  if (unhandledFuns.length > 0) goal.updatePrecision(OVER);
40
50
  }
41
51
  goal.depth++;
@@ -12,9 +12,9 @@ export const isLiteral = (manager: AstManager, expr: number) =>
12
12
  manager.isUninterpretedConst(expr) ||
13
13
  (manager.isNot(expr) && manager.isUninterpretedConst(manager.getArg(expr, 0)));
14
14
 
15
- class Sat2GoalConverter {
15
+ export class Sat2GoalConverter {
16
16
  readonly smc = new ModelConverter();
17
- var2expr: number[] = [];
17
+ readonly var2expr: number[] = [];
18
18
  readonly entries: Definition[] = [];
19
19
 
20
20
  constructor(private manager: AstManager) {}
@@ -22,17 +22,21 @@ class Sat2GoalConverter {
22
22
  private add(expr: number, def: number) {
23
23
  const manager = this.manager;
24
24
  manager.incRef(def);
25
+ manager.incDeclRef(manager.decls[expr]);
25
26
  this.entries.push({ decl: manager.decls[expr], def });
26
27
  }
27
28
 
28
29
  hide(expr: number) {
29
- this.entries.push({ decl: this.manager.decls[expr], def: -1 });
30
+ const manager = this.manager;
31
+ manager.incDeclRef(manager.decls[expr]);
32
+ this.entries.push({ decl: manager.decls[expr], def: -1 });
30
33
  }
31
34
 
32
35
  flushSmc(solver: Solver, atoms: Map<number, number>) {
33
36
  this.smc.flush(solver.mc);
34
- this.var2expr.length = solver.numVars();
35
- this.var2expr.fill(-1);
37
+ const numVars = solver.numVars();
38
+ while (this.var2expr.length < numVars) this.var2expr.push(-1);
39
+ this.var2expr.length = numVars;
36
40
  for (const [expr, boolVar] of atoms) this.var2expr[boolVar] = expr;
37
41
  this.flushGmc();
38
42
  }
@@ -106,12 +110,12 @@ export const sat2goal = (
106
110
  solver: Solver,
107
111
  atoms: Map<number, number>,
108
112
  goal: Goal,
113
+ converter: Sat2GoalConverter,
109
114
  ) => {
110
115
  if (solver.atBaseLvl() && solver.isInconsistent) {
111
116
  goal.assert(manager.falseExpr);
112
117
  return;
113
118
  }
114
- const converter = new Sat2GoalConverter(manager);
115
119
  converter.flushSmc(solver, atoms);
116
120
  const lit2expr = new Int32Array(2 * solver.numVars()).fill(-1);
117
121
  for (const [expr, boolVar] of atoms) {
@@ -161,5 +165,4 @@ export const sat2goal = (
161
165
  const formulas: number[] = [];
162
166
  solver.ext?.toFormulas(getExpr, formulas);
163
167
  for (const formula of formulas) goal.assert(formula);
164
- goal.addDefinitions(converter.entries);
165
168
  };
@@ -1270,7 +1270,7 @@ export class Simplifier {
1270
1270
  for (const wlist of solver.watches) {
1271
1271
  solver.checkpoint();
1272
1272
  const size = wlist.size;
1273
- const order = Array.from({ length: size }, (_, index) => index);
1273
+ const order = Array.from({ length: size }, (_value, index) => index);
1274
1274
  const getRank = (index: number) =>
1275
1275
  wlist.isBinary(index)
1276
1276
  ? 2 * wlist.getLiteral(index) + (wlist.isLearned(index) ? 1 : 0)
@@ -74,7 +74,7 @@ const RANDOM_MAX_VALUE = 0x7fff;
74
74
  const S_SAT = 0;
75
75
  const S_UNSAT = 1;
76
76
 
77
- export class Ema {
77
+ class Ema {
78
78
  private beta = 1;
79
79
  value = 0;
80
80
  private period = 0;
@@ -139,7 +139,6 @@ export class Solver {
139
139
  model = new Int8Array(0);
140
140
  isModelCurrent = false;
141
141
  isInconsistent = false;
142
- isSearching = false;
143
142
  conflictJustLevel = 0;
144
143
  conflictLevel = 0;
145
144
  conflictVal = 0;
@@ -147,7 +146,6 @@ export class Solver {
147
146
  notL = NULL_LITERAL;
148
147
  clauses: number[] = [];
149
148
  learned: number[] = [];
150
- numFrozen = 0;
151
149
  watches: WatchList[] = [];
152
150
  assignment = new Int8Array(16);
153
151
  justLevel = new Uint32Array(8);
@@ -196,7 +194,6 @@ export class Solver {
196
194
  scopes: Scope[] = [];
197
195
  core: number[] = [];
198
196
  conflicts = 0;
199
- decisions = 0;
200
197
  conflictsSinceInit = 0;
201
198
  restarts = 0;
202
199
  conflictsSinceRestart = 0;
@@ -392,7 +389,6 @@ export class Solver {
392
389
  }
393
390
 
394
391
  delClause(clause: number) {
395
- if (this.arena.isFrozen(clause)) this.numFrozen--;
396
392
  this.arena.delClause(clause);
397
393
  }
398
394
 
@@ -879,38 +875,33 @@ export class Solver {
879
875
  check(assumptions: readonly number[] = []) {
880
876
  this.reasonUnknown = "no reason given";
881
877
  this.popToBaseLevel();
882
- this.isSearching = true;
883
878
  this.isGivenUp = false;
884
- try {
885
- this.initSearch();
886
- if (this.checkInconsistent()) return L_FALSE;
887
- this.propagate(false);
888
- if (this.checkInconsistent()) return L_FALSE;
889
- this.initAssumptions(assumptions);
890
- this.propagate(false);
879
+ this.initSearch();
880
+ if (this.checkInconsistent()) return L_FALSE;
881
+ this.propagate(false);
882
+ if (this.checkInconsistent()) return L_FALSE;
883
+ this.initAssumptions(assumptions);
884
+ this.propagate(false);
885
+ if (this.checkInconsistent()) return L_FALSE;
886
+ if (this.config.isForcingCleanup) this.doCleanup(true);
887
+ if (this.config.isGcBurst) {
888
+ this.conflictsSinceGc = this.gcThreshold + 1;
889
+ this.doGc();
890
+ }
891
+ if (this.config.isEnablingPreSimplify) {
892
+ this.doSimplify();
891
893
  if (this.checkInconsistent()) return L_FALSE;
892
- if (this.config.isForcingCleanup) this.doCleanup(true);
893
- if (this.config.isGcBurst) {
894
- this.conflictsSinceGc = this.gcThreshold + 1;
895
- this.doGc();
896
- }
897
- if (this.config.isEnablingPreSimplify) {
898
- this.doSimplify();
899
- if (this.checkInconsistent()) return L_FALSE;
900
- }
901
- if (this.config.maxConflicts === 0) return L_UNDEF;
902
- if (this.config.maxConflicts > 0 && this.config.burstSearch > 0) {
903
- this.restartThreshold = this.config.burstSearch;
904
- const result = this.boundedSearch();
905
- if (result !== L_UNDEF || this.isGivenUp) return result;
906
- this.popReinit(this.scopeLvl);
907
- this.conflictsSinceRestart = 0;
908
- this.restartThreshold = this.config.restartInitial;
909
- }
910
- return this.basicSearch();
911
- } finally {
912
- this.isSearching = false;
913
894
  }
895
+ if (this.config.maxConflicts === 0) return L_UNDEF;
896
+ if (this.config.maxConflicts > 0 && this.config.burstSearch > 0) {
897
+ this.restartThreshold = this.config.burstSearch;
898
+ const result = this.boundedSearch();
899
+ if (result !== L_UNDEF || this.isGivenUp) return result;
900
+ this.popReinit(this.scopeLvl);
901
+ this.conflictsSinceRestart = 0;
902
+ this.restartThreshold = this.config.restartInitial;
903
+ }
904
+ return this.basicSearch();
914
905
  }
915
906
 
916
907
  checkInconsistent() {
@@ -1126,7 +1117,6 @@ export class Solver {
1126
1117
  const next = this.nextVar();
1127
1118
  if (next === -1) return false;
1128
1119
  this.push();
1129
- this.decisions++;
1130
1120
  this.assignScoped(2 * next + (this.guess(next) ? 0 : 1));
1131
1121
  return true;
1132
1122
  }
@@ -1932,16 +1922,6 @@ export class Solver {
1932
1922
  this.activityInc >>>= 14;
1933
1923
  }
1934
1924
 
1935
- numClauses() {
1936
- let numClauses = this.trail.length;
1937
- for (let lit = 0; lit < this.watches.length; lit++) {
1938
- const wlist = this.watches[lit];
1939
- for (let index = 0; index < wlist.size; index++)
1940
- if (wlist.isBinary(index) && (lit ^ 1) < wlist.getLiteral(index)) numClauses++;
1941
- }
1942
- return numClauses + this.clauses.length + this.learned.length;
1943
- }
1944
-
1945
1925
  doCleanup(isForced: boolean) {
1946
1926
  if (this.conflictsSinceInit === 0 && !isForced) return false;
1947
1927
  return this.atBaseLvl() && !this.isInconsistent && this.cleaner.run(isForced);
@@ -2063,12 +2043,10 @@ export class Solver {
2063
2043
  this.detachClause(clause);
2064
2044
  arena.inactRounds[clause] = 0;
2065
2045
  arena.setFrozen(clause, true);
2066
- this.numFrozen++;
2067
2046
  }
2068
2047
  }
2069
2048
  } else if (this.psm(clause) <= Math.trunc(arena.size[clause] * this.minDTk)) {
2070
2049
  arena.setFrozen(clause, false);
2071
- this.numFrozen--;
2072
2050
  if (!this.activateFrozenClause(clause)) {
2073
2051
  this.delClause(clause);
2074
2052
  continue;
@@ -1,4 +1,3 @@
1
- import { SmtUnsupportedError } from "../../../errors";
2
1
  import {
3
2
  type AstManager,
4
3
  FAMILY_ARITH,
@@ -24,7 +23,6 @@ import {
24
23
  OP_SEQ_PREFIX,
25
24
  OP_SEQ_UNIT,
26
25
  OP_STRING_FROM_CODE,
27
- OP_STRING_ITOS,
28
26
  OP_STRING_LT,
29
27
  OP_STRING_STOI,
30
28
  OP_STRING_TO_CODE,
@@ -36,7 +34,7 @@ import { FALSE_LITERAL, type Literal, TRUE_LITERAL, negate } from "./literal";
36
34
  import { isBinaryApp, isEmptySeq, mkConcatOf, mkEmptySeq, mkSeqApp } from "./seq-decl-plugin";
37
35
  import { SeqSkolem } from "./seq-skolem";
38
36
 
39
- export interface SeqAxiomsHost {
37
+ interface SeqAxiomsHost {
40
38
  rewrite(expr: number): number;
41
39
  mkEqLiteral(first: number, second: number): Literal;
42
40
  ensureEnode(expr: number): void;
@@ -62,7 +60,7 @@ export const getMinLengthOf = (manager: AstManager, seq: number): number => {
62
60
 
63
61
  const UINT_MAX = 0xffffffff;
64
62
 
65
- export const getMaxLengthOf = (manager: AstManager, seq: number): number => {
63
+ const getMaxLengthOf = (manager: AstManager, seq: number): number => {
66
64
  const getLength = (expr: number) => {
67
65
  if (isEmptySeq(manager, expr)) return 0;
68
66
  const op = manager.getOp(expr);
@@ -180,13 +178,8 @@ export class SeqAxioms {
180
178
  return result;
181
179
  }
182
180
 
183
- mkLen(seq: number) {
184
- return this.host.rewrite(this.mkSeq(OP_SEQ_LENGTH, [seq]));
185
- }
186
-
187
- private purify(expr: number | undefined) {
181
+ private purify(expr: number) {
188
182
  const manager = this.manager;
189
- if (expr === undefined) return undefined;
190
183
  if (manager.depths[expr] === 1 || manager.isValue(expr)) return expr;
191
184
  if (this.host.rewrite(expr) === expr) return expr;
192
185
  let result = this.purified.get(expr);
@@ -256,9 +249,9 @@ export class SeqAxioms {
256
249
  extractAxiom(expr: number) {
257
250
  const manager = this.manager;
258
251
  const [seqArg, indexArg, lengthArg] = manager.getArgs(expr);
259
- const seq = this.purify(seqArg)!;
260
- const index = this.purify(indexArg)!;
261
- const length = this.purify(lengthArg)!;
252
+ const seq = this.purify(seqArg);
253
+ const index = this.purify(indexArg);
254
+ const length = this.purify(lengthArg);
262
255
  if (this.smallSegmentAxiom(expr, seqArg, indexArg, lengthArg)) return;
263
256
  if (this.isTail(seq, indexArg, lengthArg)) {
264
257
  this.tailAxiom(expr, seq);
@@ -436,9 +429,9 @@ export class SeqAxioms {
436
429
  const args = manager.getArgs(index);
437
430
  const minusOne = this.mkInt(-1);
438
431
  const zero = this.mkInt(0);
439
- const offset = this.purify(args[2]);
440
- const pattern = this.purify(args[1])!;
441
- const text = this.purify(args[0])!;
432
+ const offset = args.length > 2 ? this.purify(args[2]) : undefined;
433
+ const pattern = this.purify(args[1]);
434
+ const text = this.purify(args[0]);
442
435
  const contains = this.mkSeq(OP_SEQ_CONTAINS, [text, pattern]);
443
436
  const isMinusOne = this.mkEq(index, minusOne);
444
437
  const isZero = this.mkEq(index, zero);
@@ -511,8 +504,8 @@ export class SeqAxioms {
511
504
  lastIndexofAxiom(index: number) {
512
505
  const manager = this.manager;
513
506
  const [textArg, patternArg] = manager.getArgs(index);
514
- const text = this.purify(textArg)!;
515
- const pattern = this.purify(patternArg)!;
507
+ const text = this.purify(textArg);
508
+ const pattern = this.purify(patternArg);
516
509
  const minusOne = this.mkInt(-1);
517
510
  const zero = this.mkInt(0);
518
511
  const skolem = this.skolem;
@@ -539,9 +532,9 @@ export class SeqAxioms {
539
532
  replaceAxiom(replace: number) {
540
533
  const manager = this.manager;
541
534
  const [source, patternArg, targetArg] = manager.getArgs(replace);
542
- const text = this.purify(source)!;
543
- const pattern = this.purify(patternArg)!;
544
- const target = this.purify(targetArg)!;
535
+ const text = this.purify(source);
536
+ const pattern = this.purify(patternArg);
537
+ const target = this.purify(targetArg);
545
538
  const skolem = this.skolem;
546
539
  const left = skolem.mkIndexofLeft(text, pattern);
547
540
  const right = skolem.mkIndexofRight(text, pattern);
@@ -565,8 +558,8 @@ export class SeqAxioms {
565
558
  atAxiom(expr: number) {
566
559
  const manager = this.manager;
567
560
  const [seqArg, indexArg] = manager.getArgs(expr);
568
- const seq = this.purify(seqArg)!;
569
- const index = this.purify(indexArg)!;
561
+ const seq = this.purify(seqArg);
562
+ const index = this.purify(indexArg);
570
563
  this.mkInt(0);
571
564
  const one = this.mkInt(1);
572
565
  const empty = this.mkEmpty(manager.sorts[expr]);
@@ -747,8 +740,8 @@ export class SeqAxioms {
747
740
  ltAxiom(expr: number) {
748
741
  const manager = this.manager;
749
742
  const [firstArg, secondArg] = manager.getArgs(expr);
750
- const first = this.purify(firstArg)!;
751
- const second = this.purify(secondArg)!;
743
+ const first = this.purify(firstArg);
744
+ const second = this.purify(secondArg);
752
745
  const charSort = manager.getSeqElementSort(manager.sorts[first]);
753
746
  const lt = expr;
754
747
  const gt = this.mkSeq(OP_STRING_LT, [second, first]);
@@ -895,8 +888,8 @@ export class SeqAxioms {
895
888
  private affixAxiom(expr: number, name: string, isPrefix: boolean) {
896
889
  const manager = this.manager;
897
890
  const [firstArg, secondArg] = manager.getArgs(expr);
898
- const first = this.purify(firstArg)!;
899
- const second = this.purify(secondArg)!;
891
+ const first = this.purify(firstArg);
892
+ const second = this.purify(secondArg);
900
893
  const firstLength = this.mkLenAxiom(first);
901
894
  const secondLength = this.mkLenAxiom(second);
902
895
  const isLonger = this.mkGe(this.mkSub(firstLength, secondLength), 1);
@@ -999,12 +992,4 @@ export class SeqAxioms {
999
992
  this.addClause([this.mkNot(tracker), this.mkLe(this.mkLenAxiom(target), limit)]);
1000
993
  return tracker;
1001
994
  }
1002
-
1003
- ubvAxiom(): never {
1004
- throw new SmtUnsupportedError("str.from_ubv in the theory of sequences");
1005
- }
1006
-
1007
- isItos(expr: number) {
1008
- return this.manager.getOp(expr) === OP_STRING_ITOS;
1009
- }
1010
995
  }
@@ -271,7 +271,7 @@ const SEQ_VARIANTS = new Map([
271
271
  [OP_INTERNAL_STRING_SUBSTR, OP_SEQ_EXTRACT],
272
272
  ]);
273
273
 
274
- const STRING_VARIANTS = new Map([...SEQ_VARIANTS].map(([variant, op]) => [op, variant]));
274
+ const STRING_VARIANTS = new Map([...SEQ_VARIANTS].map((entry) => [entry[1], entry[0]]));
275
275
 
276
276
  const getPsig = (op: number) => {
277
277
  const sig = SIGS.get(op);