tla-ts 0.0.10-dev.99796fe03 → 0.0.10-dev.a17d6d9fa

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 (226) 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 +3 -2
  7. package/dist/index.d.ts +3 -2
  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 +60 -60
  14. package/dist/prove.js +78 -78
  15. package/dist/run.cjs +42 -44
  16. package/dist/run.js +44 -46
  17. package/dist/tlapm.cjs +1 -1
  18. package/dist/tlapm.js +2 -2
  19. package/dist/transfer.cjs +43 -43
  20. package/dist/transfer.js +39 -39
  21. package/dist/worker.cjs +6 -6
  22. package/dist/worker.js +6 -6
  23. package/package.json +1 -1
  24. package/src/ast.ts +1 -0
  25. package/src/bags.ts +50 -29
  26. package/src/builtins.ts +4 -3
  27. package/src/check-failure.ts +1 -1
  28. package/src/check-trace.ts +90 -51
  29. package/src/check.ts +367 -178
  30. package/src/cli/runtime-invariants.ts +20 -56
  31. package/src/cli/tlc-arguments.ts +2 -2
  32. package/src/cli/tlc-output.ts +1 -2
  33. package/src/cli/tlc.ts +16 -10
  34. package/src/cli/xml-exporter.ts +1 -1
  35. package/src/codegen.ts +26 -9
  36. package/src/dependencies.ts +49 -9
  37. package/src/dfid.ts +22 -10
  38. package/src/environment.ts +58 -33
  39. package/src/errors.ts +7 -0
  40. package/src/evaluate.ts +117 -41
  41. package/src/exit-codes.ts +4 -2
  42. package/src/instances.ts +5 -5
  43. package/src/java-hash.ts +14 -0
  44. package/src/java-overrides.ts +2 -2
  45. package/src/levels.ts +138 -90
  46. package/src/liveness-checker.ts +81 -33
  47. package/src/liveness.ts +49 -11
  48. package/src/obligations/index.ts +1 -1
  49. package/src/obligations/normalize.ts +1 -4
  50. package/src/obligations/printer.ts +5 -5
  51. package/src/parallel-worker.ts +8 -2
  52. package/src/parallel.ts +5 -0
  53. package/src/parser.ts +112 -145
  54. package/src/prover/isabelle/isar/attrib.ts +4 -4
  55. package/src/prover/isabelle/isar/rule-cases.ts +8 -6
  56. package/src/prover/isabelle/provers/clasimp.ts +1 -1
  57. package/src/prover/isabelle/provers/hypsubst.ts +2 -2
  58. package/src/prover/isabelle/pure/rewriter.ts +3 -3
  59. package/src/prover/isabelle/pure/term.ts +3 -3
  60. package/src/prover/prep/md5.ts +26 -29
  61. package/src/prover/smt/rewrite.ts +2 -7
  62. package/src/prover/smt/simplify.ts +1 -1
  63. package/src/prover/smt/solver/arith-rewriter.ts +11 -3
  64. package/src/prover/smt/solver/array-rewriter.ts +12 -2
  65. package/src/prover/smt/solver/asserted-formulas.ts +169 -58
  66. package/src/prover/smt/solver/ast-lt.ts +1 -1
  67. package/src/prover/smt/solver/ast.ts +63 -14
  68. package/src/prover/smt/solver/auf-solver.ts +23 -12
  69. package/src/prover/smt/solver/bit-blast-tactic.ts +26 -0
  70. package/src/prover/smt/solver/blast-term-ite.ts +47 -0
  71. package/src/prover/smt/solver/bound-simplifier.ts +11 -13
  72. package/src/prover/smt/solver/bv-decl-plugin.ts +13 -10
  73. package/src/prover/smt/solver/bv-rewriter.ts +1 -1
  74. package/src/prover/smt/solver/card2bv.ts +32 -18
  75. package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -24
  76. package/src/prover/smt/solver/context.ts +47 -9
  77. package/src/prover/smt/solver/ctx-simplify.ts +1 -2
  78. package/src/prover/smt/solver/datatype-decl-plugin.ts +15 -7
  79. package/src/prover/smt/solver/dependent-expr-state.ts +9 -4
  80. package/src/prover/smt/solver/diff-neq.ts +1 -2
  81. package/src/prover/smt/solver/elim-bounds.ts +89 -0
  82. package/src/prover/smt/solver/elim-term-ite-tactic.ts +48 -0
  83. package/src/prover/smt/solver/elim-uncnstr.ts +5 -8
  84. package/src/prover/smt/solver/euf/arith-internalize.ts +1 -1
  85. package/src/prover/smt/solver/euf/array-internalize.ts +1 -1
  86. package/src/prover/smt/solver/euf/bv-internalize.ts +1 -1
  87. package/src/prover/smt/solver/euf/egraph.ts +4 -11
  88. package/src/prover/smt/solver/euf/euf-solver.ts +1 -2
  89. package/src/prover/smt/solver/euf/mam.ts +1 -5
  90. package/src/prover/smt/solver/euf/q-ematch.ts +1 -2
  91. package/src/prover/smt/solver/euf/th-solver.ts +0 -7
  92. package/src/prover/smt/solver/expr2polynomial.ts +204 -79
  93. package/src/prover/smt/solver/factor.ts +36 -14
  94. package/src/prover/smt/solver/fd-solver.ts +2 -0
  95. package/src/prover/smt/solver/fix-dl-var.ts +1 -2
  96. package/src/prover/smt/solver/fpa-rewriter.ts +1 -2
  97. package/src/prover/smt/solver/fpa2bv-converter.ts +3 -1
  98. package/src/prover/smt/solver/fpa2bv-rewriter.ts +1 -0
  99. package/src/prover/smt/solver/goal.ts +6 -3
  100. package/src/prover/smt/solver/goal2nlsat.ts +57 -30
  101. package/src/prover/smt/solver/hashtable.ts +4 -0
  102. package/src/prover/smt/solver/internalizer.ts +1 -1
  103. package/src/prover/smt/solver/logic-tactics.ts +9 -2
  104. package/src/prover/smt/solver/lp/lp-settings.ts +5 -1
  105. package/src/prover/smt/solver/lp/nla-core.ts +1 -1
  106. package/src/prover/smt/solver/lp/nla-grobner.ts +2 -2
  107. package/src/prover/smt/solver/lp/nra-solver.ts +45 -39
  108. package/src/prover/smt/solver/lp/pdd.ts +2 -3
  109. package/src/prover/smt/solver/lp/union-find.ts +1 -1
  110. package/src/prover/smt/solver/mam-compiler.ts +1 -1
  111. package/src/prover/smt/solver/model-based-opt.ts +1 -1
  112. package/src/prover/smt/solver/model-evaluator.ts +2 -0
  113. package/src/prover/smt/solver/model-generator.ts +85 -43
  114. package/src/prover/smt/solver/mpf.ts +2 -4
  115. package/src/prover/smt/solver/mus.ts +2 -3
  116. package/src/prover/smt/solver/muz/dl-context.ts +10 -4
  117. package/src/prover/smt/solver/muz/dl-mk-slice.ts +3 -3
  118. package/src/prover/smt/solver/muz/dl-rule.ts +2 -2
  119. package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +1 -1
  120. package/src/prover/smt/solver/muz/horn-tactic.ts +1 -1
  121. package/src/prover/smt/solver/muz/spacer-context.ts +2 -4
  122. package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -0
  123. package/src/prover/smt/solver/nlqsat.ts +1 -1
  124. package/src/prover/smt/solver/nlsat/algebraic.ts +196 -92
  125. package/src/prover/smt/solver/nlsat/atoms.ts +52 -33
  126. package/src/prover/smt/solver/nlsat/explain.ts +375 -217
  127. package/src/prover/smt/solver/nlsat/levelwise.ts +460 -240
  128. package/src/prover/smt/solver/nlsat/polynomial.ts +2366 -681
  129. package/src/prover/smt/solver/nlsat/solver.ts +74 -64
  130. package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -17
  131. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -4
  132. package/src/prover/smt/solver/nlsat/upolynomial.ts +41 -18
  133. package/src/prover/smt/solver/nlsat-tactic.ts +1 -1
  134. package/src/prover/smt/solver/nnf.ts +6 -2
  135. package/src/prover/smt/solver/opt-context.ts +20 -7
  136. package/src/prover/smt/solver/opt-nlsat.ts +29 -18
  137. package/src/prover/smt/solver/opt-pareto.ts +19 -0
  138. package/src/prover/smt/solver/opt-preprocess.ts +1 -1
  139. package/src/prover/smt/solver/opt-solver.ts +9 -5
  140. package/src/prover/smt/solver/optsmt.ts +1 -1
  141. package/src/prover/smt/solver/pb-rewriter.ts +1 -4
  142. package/src/prover/smt/solver/poly-rewriter.ts +75 -18
  143. package/src/prover/smt/solver/probes.ts +88 -23
  144. package/src/prover/smt/solver/proto-model.ts +8 -8
  145. package/src/prover/smt/solver/push-app-ite.ts +37 -0
  146. package/src/prover/smt/solver/qe-arith-plugin.ts +2 -4
  147. package/src/prover/smt/solver/qe-lite.ts +2 -2
  148. package/src/prover/smt/solver/qe.ts +3 -2
  149. package/src/prover/smt/solver/qsat.ts +16 -6
  150. package/src/prover/smt/solver/quantifier-manager.ts +14 -9
  151. package/src/prover/smt/solver/recfun-decl-plugin.ts +2 -1
  152. package/src/prover/smt/solver/rewriter.ts +31 -25
  153. package/src/prover/smt/solver/rlimit.ts +4 -0
  154. package/src/prover/smt/solver/sat/config.ts +1 -1
  155. package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
  156. package/src/prover/smt/solver/sat/inc-sat-solver.ts +39 -5
  157. package/src/prover/smt/solver/sat/model-converter.ts +1 -1
  158. package/src/prover/smt/solver/sat/pb-solver.ts +1 -1
  159. package/src/prover/smt/solver/sat/sat-tactic.ts +13 -5
  160. package/src/prover/smt/solver/sat/simplifier.ts +1 -1
  161. package/src/prover/smt/solver/sat/solver.ts +25 -47
  162. package/src/prover/smt/solver/seq-axioms.ts +20 -35
  163. package/src/prover/smt/solver/seq-decl-plugin.ts +1 -1
  164. package/src/prover/smt/solver/seq-derive.ts +2 -2
  165. package/src/prover/smt/solver/seq-eq-solver.ts +2 -2
  166. package/src/prover/smt/solver/seq-monadic.ts +7 -5
  167. package/src/prover/smt/solver/seq-re-rewriter.ts +2 -1
  168. package/src/prover/smt/solver/seq-re-util.ts +1 -1
  169. package/src/prover/smt/solver/seq-regex-bisim.ts +1 -1
  170. package/src/prover/smt/solver/seq-regex-live.ts +2 -2
  171. package/src/prover/smt/solver/seq-rewriter.ts +31 -29
  172. package/src/prover/smt/solver/seq-skolem.ts +0 -23
  173. package/src/prover/smt/solver/seq-view-witness.ts +4 -4
  174. package/src/prover/smt/solver/smt-kernel.ts +39 -5
  175. package/src/prover/smt/solver/smt-setup.ts +96 -10
  176. package/src/prover/smt/solver/smtlib-parser.ts +584 -223
  177. package/src/prover/smt/solver/smtlib-script.ts +509 -154
  178. package/src/prover/smt/solver/solve-eqs.ts +36 -37
  179. package/src/prover/smt/solver/solver.ts +18 -3
  180. package/src/prover/smt/solver/tactic.ts +284 -168
  181. package/src/prover/smt/solver/theory-bv.ts +13 -3
  182. package/src/prover/smt/solver/theory-fpa.ts +1 -1
  183. package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
  184. package/src/prover/smt/solver/theory-lra-internalize.ts +2 -0
  185. package/src/prover/smt/solver/theory-lra-propagate.ts +11 -3
  186. package/src/prover/smt/solver/theory-lra.ts +1 -1
  187. package/src/prover/smt/solver/theory-pb.ts +24 -7
  188. package/src/prover/smt/solver/theory-seq-solve.ts +1 -1
  189. package/src/prover/smt/solver/theory-seq-state.ts +2 -21
  190. package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
  191. package/src/prover/tlapm/cache.ts +8 -8
  192. package/src/prover/zenon/index-table.ts +5 -2
  193. package/src/prover/zenon/isar-case.ts +1 -1
  194. package/src/prover/zenon/isar.ts +2 -2
  195. package/src/prover/zenon/phrase.ts +1 -1
  196. package/src/resolve.ts +959 -243
  197. package/src/runtime.ts +7 -1
  198. package/src/sany/builtins.ts +10 -10
  199. package/src/sany/generation.ts +2 -13
  200. package/src/sany/generator-definitions.ts +3 -1
  201. package/src/sany/generator-expressions.ts +36 -30
  202. package/src/sany/generator-proofs.ts +5 -3
  203. package/src/sany/generator.ts +2 -1
  204. package/src/sany/lexer.ts +3 -3
  205. package/src/sany/modules.ts +4 -2
  206. package/src/sany/nodes.ts +1 -1
  207. package/src/sany/selectors.ts +11 -6
  208. package/src/sany/xml.ts +2 -3
  209. package/src/search.ts +166 -101
  210. package/src/simulate.ts +110 -50
  211. package/src/spec-description.ts +5 -6
  212. package/src/standard-modules.ts +15 -6
  213. package/src/subexpressions.ts +398 -108
  214. package/src/successors.ts +4 -2
  215. package/src/symmetry.ts +1 -1
  216. package/src/tlc/jar-data.ts +10 -0
  217. package/src/tlc/messages.ts +3 -3
  218. package/src/tlc/order.ts +14 -3
  219. package/src/tlc/random.ts +2 -1
  220. package/src/tlc/replay.ts +3 -2
  221. package/src/tlc/tlc-operators.ts +10 -8
  222. package/src/tlc/tlcext-operators.ts +44 -15
  223. package/src/tlc/trace-spec.ts +9 -22
  224. package/src/typed-tier.ts +32 -25
  225. package/src/typescript/types.ts +2 -2
  226. package/src/values.ts +135 -78
@@ -1,24 +1,16 @@
1
1
  import {
2
2
  SmtCanceledError,
3
3
  SmtParseError,
4
+ SmtDefaultError,
4
5
  SmtTacticError,
5
6
  SmtUnsupportedError,
6
7
  } from "../../../errors";
7
- import {
8
- type AstManager,
9
- KIND_APP,
10
- OP_DIV0,
11
- OP_IDIV0,
12
- OP_ITE,
13
- OP_MOD0,
14
- OP_POWER0,
15
- SORT_BOOL,
16
- } from "./ast";
8
+ import { type AstManager, OP_DIV0, OP_IDIV0, OP_MOD0, OP_OR, OP_POWER0, SORT_BOOL } from "./ast";
17
9
  import { createQfufbvAckrTactic, runAckermannizeBv } from "./ackermannize-bv-tactic";
18
- import { AssertedFormulas } from "./asserted-formulas";
19
10
  import { createAigTactic } from "./aig-tactic";
11
+ import { blastTermIte } from "./blast-term-ite";
20
12
  import { card2bv } from "./card2bv";
21
- import { Context, MBQI_MAX_ITERATIONS } from "./context";
13
+ import { type Context, MBQI_MAX_ITERATIONS } from "./context";
22
14
  import { ctxSimplify } from "./ctx-simplify";
23
15
  import { createCtxSolverSimplify } from "./ctx-solver-simplify";
24
16
  import {
@@ -32,6 +24,7 @@ import {
32
24
  import type { AckrSolver } from "./lackr";
33
25
  import { L_FALSE, L_TRUE, L_UNDEF } from "./lbool";
34
26
  import { DerRewriter } from "./der";
27
+ import { finishSimplifier, runSimplifier } from "./dependent-expr-state";
35
28
  import { fixDlVar } from "./fix-dl-var";
36
29
  import { runFpa2Bv } from "./fpa2bv-tactic";
37
30
  import { type BitBlasterRewriter, runBitBlast } from "./bit-blast-tactic";
@@ -44,6 +37,7 @@ import { createSatTactic } from "./sat/sat-tactic";
44
37
  import { mkThSolver } from "./euf/th-solvers";
45
38
  import { createFdTactic } from "./fd-solver";
46
39
  import { elimUncnstr } from "./elim-uncnstr";
40
+ import { runElimTermIte } from "./elim-term-ite-tactic";
47
41
  import { rewriteUfbv } from "./demodulator";
48
42
  import { distributeForall } from "./distribute-forall";
49
43
  import { createDt2BvTactic } from "./dt2bv-tactic";
@@ -72,6 +66,7 @@ import { propagateValues } from "./propagate-values";
72
66
  import { purifyArith } from "./purify-arith";
73
67
  import { ModelEvaluator } from "./model-evaluator";
74
68
  import { FuncInterp, ProtoModel } from "./proto-model";
69
+ import { SmtKernel } from "./smt-kernel";
75
70
  import { isMbqiByFeatures, type SmtSetup } from "./smt-setup";
76
71
  import { compileProbe, formatProbeValue, isQfufbv, type Probe } from "./probes";
77
72
  import { runHorn } from "./muz/horn-tactic";
@@ -87,6 +82,7 @@ import { LOGIC_TACTICS, QFAUFBV, QFUFBV_ACKR_PREAMBLE } from "./logic-tactics";
87
82
  import {
88
83
  createCommandReader,
89
84
  isSymbol,
85
+ isUnsigned,
90
86
  type SExpr,
91
87
  type SmtList,
92
88
  type SmtToken,
@@ -145,9 +141,9 @@ interface NamedTactic {
145
141
 
146
142
  const getDescrs = (module: string, entries: [string, number, TacticParam, boolean?][]) =>
147
143
  new Map(
148
- entries.map(([name, kind, defaultValue, isPorted]) => [
149
- name,
150
- { kind, module, defaultValue, isPorted: isPorted ?? false },
144
+ entries.map((entry) => [
145
+ entry[0],
146
+ { kind: entry[1], module, defaultValue: entry[2], isPorted: entry[3] ?? false },
151
147
  ]),
152
148
  );
153
149
 
@@ -176,7 +172,7 @@ const REWRITER_DESCRS = getDescrs("rewriter", [
176
172
  ["sort_sums", PARAM_BOOL, false, true],
177
173
  ["gcd_rounding", PARAM_BOOL, false, true],
178
174
  ["arith_lhs", PARAM_BOOL, false, true],
179
- ["arith_ineq_lhs", PARAM_BOOL, false],
175
+ ["arith_ineq_lhs", PARAM_BOOL, false, true],
180
176
  ["elim_to_real", PARAM_BOOL, false],
181
177
  ["push_to_real", PARAM_BOOL, true],
182
178
  ["eq2ineq", PARAM_BOOL, false],
@@ -255,7 +251,8 @@ export const getRewriterOptions = (manager: AstManager, params: TacticParams): R
255
251
  arith: {
256
252
  isSom: getBool(params, "flat", true) && getBool(params, "som", false),
257
253
  isSortSums: getBool(params, "sort_sums", false),
258
- isArithIneqLhs: getBool(params, "arith_lhs", false),
254
+ isArithLhs: getBool(params, "arith_lhs", false),
255
+ isArithIneqLhs: getBool(params, "arith_ineq_lhs", false),
259
256
  isGcdRounding: getBool(params, "gcd_rounding", false),
260
257
  isAnumSimp: getBool(params, "algebraic_number_evaluator", true),
261
258
  isExpandPower: getBool(params, "expand_power", false),
@@ -280,6 +277,7 @@ const SMT_DESCRS = getDescrs("smt", [
280
277
  ["mbqi", PARAM_BOOL, true, true],
281
278
  ["mbqi.max_iterations", PARAM_UINT, MBQI_MAX_ITERATIONS, true],
282
279
  ["arith.nl.rounds", PARAM_UINT, 1024, true],
280
+ ["random_seed", PARAM_UINT, 0, true],
283
281
  ]);
284
282
 
285
283
  // The dependencies are assertion names, which are Boolean constants, so each one is its own
@@ -294,6 +292,11 @@ const getKernelParams = (environment: TacticEnvironment, params: TacticParams, g
294
292
  mbqiMaxIterations: getUint(params, "mbqi.max_iterations", environment.mbqiMaxIterations),
295
293
  isFindingMacros: environment.isFindingMacros,
296
294
  setup: environment.setup,
295
+ randomSeed: getUint(
296
+ params,
297
+ "random_seed",
298
+ Number(getParameter(environment, "smt.random_seed", "0")),
299
+ ),
297
300
  };
298
301
  };
299
302
 
@@ -339,6 +342,11 @@ export const getSatParams = (parameters: ReadonlyMap<string, string>) =>
339
342
  }),
340
343
  );
341
344
 
345
+ export const getSmtTacticFailure = (context: Context) =>
346
+ context.checkCanceled()
347
+ ? "canceled"
348
+ : `smt tactic failed to show goal to be sat/unsat ${context.getLastFailureMessage()}`;
349
+
342
350
  // sat_params reads what using-params leaves unset from the sat module's global parameters.
343
351
  const getSatTacticParams = (environment: TacticEnvironment, params: TacticParams) =>
344
352
  new Map([...getSatParams(environment.parameters), ...params]);
@@ -355,7 +363,8 @@ const runSmt = (environment: TacticEnvironment, params: TacticParams) => (goal:
355
363
  ? solveGoal(manager, goal.forms.items, kernelParams)
356
364
  : solveAssuming(manager, extracted.clauses.items, extracted.assumptions, kernelParams);
357
365
  extracted.clauses.reset();
358
- if (solved.result === L_UNDEF) throw new SmtTacticError(solved.context.getLastFailureMessage());
366
+ if (solved.result === L_UNDEF)
367
+ throw new SmtTacticError(solved.reasonUnknown ?? getSmtTacticFailure(solved.context));
359
368
  goal.reset();
360
369
  if (solved.result === L_FALSE)
361
370
  goal.assert(environment.manager.falseExpr, mkCoreDependency(solved.context.unsatCore));
@@ -423,30 +432,42 @@ const createTacticSolver = (manager: AstManager, getTactic: () => Tactic): AckrS
423
432
  // Each clause gets a fresh context, where Z3 pushes a scope on one context.
424
433
  const runUnitSubsume = (environment: TacticEnvironment) => (goal: Goal) => {
425
434
  const manager = environment.manager;
435
+ const kernel = new SmtKernel(manager, {
436
+ isMbqi: environment.isMbqi,
437
+ mbqiMaxIterations: environment.mbqiMaxIterations,
438
+ isFindingMacros: false,
439
+ });
440
+ const trail = new RefVector(manager);
426
441
  const clauses = goal.forms.items.map(() => manager.mkFreshConst("#clause", SORT_BOOL));
427
- const definitions = goal.forms.items.map((form, index) => manager.mkEq(clauses[index], form));
428
- for (const expr of [...clauses, ...definitions]) manager.incRef(expr);
442
+ for (const clause of clauses) trail.push(clause);
443
+ kernel.push();
444
+ for (const [index, form] of goal.forms.items.entries()) {
445
+ const definition = manager.mkEq(clauses[index], form);
446
+ trail.push(definition);
447
+ kernel.assertExpr(definition);
448
+ }
449
+ kernel.push();
450
+ const isDeleted = clauses.map(() => false);
429
451
  const deleted: number[] = [];
430
452
  for (const [index, clause] of clauses.entries()) {
431
- const asserted = new AssertedFormulas(manager);
432
- const context = new Context(manager, {
433
- isMbqi: environment.isMbqi,
434
- mbqiMaxIterations: environment.mbqiMaxIterations,
435
- relevancyLevel: 2,
436
- });
437
- for (const definition of definitions) asserted.assertExpr(definition);
453
+ kernel.push();
438
454
  for (const [other, otherClause] of clauses.entries())
439
- if (other === index) asserted.assertExpr(manager.mkNot(clause));
440
- else if (!deleted.includes(other)) asserted.assertExpr(otherClause);
441
- // The context has no logic, so setup_default picks setup_unknown.
442
- context.setupContext(undefined, false, asserted);
443
- context.internalizeAssertions(asserted);
444
- if (!context.isInconsistent()) context.propagate();
445
- if (context.isInconsistent()) deleted.push(index);
455
+ if (other === index) {
456
+ const negated = manager.mkNot(clause);
457
+ trail.push(negated);
458
+ kernel.assertExpr(negated);
459
+ } else if (!isDeleted[other]) kernel.assertExpr(otherClause);
460
+ kernel.push();
461
+ const isUnsat = kernel.context.isInconsistent();
462
+ kernel.pop(2);
463
+ if (!isUnsat) continue;
464
+ isDeleted[index] = true;
465
+ deleted.push(index);
446
466
  }
447
467
  for (const index of deleted) goal.update(index, manager.trueExpr);
448
468
  goal.elimTrue();
449
- for (const expr of [...clauses, ...definitions]) manager.decRef(expr);
469
+ kernel.pop(2);
470
+ trail.reset();
450
471
  return [goal];
451
472
  };
452
473
 
@@ -455,19 +476,50 @@ const inPlace = (run: (goal: Goal) => void) => (goal: Goal) => {
455
476
  return [goal];
456
477
  };
457
478
 
458
- const runDer = (manager: AstManager) => (goal: Goal) => {
459
- const rewriter = new DerRewriter(manager);
460
- const size = goal.forms.size;
461
- for (let index = 0; !goal.isInconsistent && index < size; index++) {
462
- const result = rewriter.rewrite(goal.forms.items[index]);
463
- goal.update(index, result);
464
- manager.decRef(result);
479
+ const selectClause = (goal: Goal, isLargest: boolean) => {
480
+ const manager = goal.manager;
481
+ let position = -1;
482
+ let length = 0;
483
+ for (let index = 0; index < goal.forms.size; index++) {
484
+ const form = goal.forms.items[index];
485
+ if (manager.getOp(form) !== OP_OR) continue;
486
+ const currentLength = manager.getNumArgs(form);
487
+ if (currentLength < 2) continue;
488
+ if (!isLargest) return index;
489
+ if (currentLength > length) {
490
+ position = index;
491
+ length = currentLength;
492
+ }
465
493
  }
466
- goal.elimTrue();
467
- goal.elimRedundancies();
468
- goal.depth++;
469
- rewriter.der.release();
470
- rewriter.release();
494
+ return position;
495
+ };
496
+
497
+ const runSplitClause = (isLargest: boolean) => (goal: Goal) => {
498
+ const manager = goal.manager;
499
+ const position = selectClause(goal, isLargest);
500
+ if (position === -1)
501
+ throw new SmtTacticError("split-clause tactic failed, goal does not contain any clause");
502
+ if (goal.isProofsEnabled) throw new SmtUnsupportedError("the proofs of split-clause");
503
+ const dependency = goal.dependencies[position];
504
+ return manager.getArgs(goal.forms.items[position]).map((literal) => {
505
+ const subgoal = goal.copy();
506
+ subgoal.update(position, literal, dependency);
507
+ subgoal.depth++;
508
+ return subgoal;
509
+ });
510
+ };
511
+
512
+ const runDer = (manager: AstManager) => (goal: Goal) => {
513
+ runSimplifier(goal, true, (state) => {
514
+ const rewriter = new DerRewriter(manager);
515
+ return {
516
+ reduce: () => state.rewriteEach((form) => rewriter.rewrite(form)),
517
+ release: () => {
518
+ rewriter.der.release();
519
+ rewriter.release();
520
+ },
521
+ };
522
+ });
471
523
  return [goal];
472
524
  };
473
525
 
@@ -507,10 +559,16 @@ const runNnf = (manager: AstManager, params: TacticParams) => (goal: Goal) => {
507
559
  const nnf = new Nnf(manager, names, mode, getBool(params, "ignore_labels", false));
508
560
  const definitions = new RefVector(manager);
509
561
  const size = goal.forms.size;
510
- for (let index = 0; !goal.isInconsistent && index < size; index++) {
511
- const result = nnf.apply(goal.forms.items[index], definitions);
512
- goal.update(index, result);
513
- manager.decRef(result);
562
+ try {
563
+ for (let index = 0; !goal.isInconsistent && index < size; index++) {
564
+ const result = nnf.apply(goal.forms.items[index], definitions);
565
+ goal.update(index, result);
566
+ manager.decRef(result);
567
+ }
568
+ } catch (error) {
569
+ // Z3's nnf stops at the limit with a default_exception, which or-else lets pass.
570
+ if (!(error instanceof SmtCanceledError)) throw error;
571
+ throw new SmtDefaultError(manager.limit.getCancelMessage());
514
572
  }
515
573
  for (const definition of definitions.items) {
516
574
  if (goal.isInconsistent) break;
@@ -691,40 +749,30 @@ const NAMED_TACTICS = new Map<string, NamedTactic>([
691
749
  ]),
692
750
  build: (environment, params) => {
693
751
  const manager = environment.manager;
694
- const snf = runNnf(manager, new Map());
695
752
  const elimRemParams = new Map([...params, ["elim_rem", true]]);
696
- return (goal) => {
697
- snf(goal);
698
- simplifyGoal(manager, goal, getRewriterOptions(manager, elimRemParams));
699
- purifyArith(manager, goal, {
700
- isComplete: getBool(params, "complete", true),
701
- isElimRootObjects: getBool(params, "elim_root_objects", true),
702
- isElimInverses: getBool(params, "elim_inverses", true),
703
- });
704
- simplifyGoal(manager, goal, getRewriterOptions(manager, params));
705
- return [goal];
706
- };
753
+ return [
754
+ runNnf(manager, new Map()),
755
+ inPlace((goal) =>
756
+ simplifyGoal(manager, goal, getRewriterOptions(manager, elimRemParams)),
757
+ ),
758
+ inPlace((goal) =>
759
+ purifyArith(manager, goal, {
760
+ isComplete: getBool(params, "complete", true),
761
+ isElimRootObjects: getBool(params, "elim_root_objects", true),
762
+ isElimInverses: getBool(params, "elim_inverses", true),
763
+ }),
764
+ ),
765
+ inPlace((goal) => simplifyGoal(manager, goal, getRewriterOptions(manager, params))),
766
+ ].reduceRight((second, first) => runAndThen(first, second));
707
767
  },
708
768
  },
709
769
  ],
710
770
  [
711
771
  "elim-term-ite",
712
772
  {
773
+ isTrackingDependencies: true,
713
774
  descrs: getDescrs("", [["max_memory", PARAM_UINT, UINT_MAX, true]]),
714
- build: (environment) =>
715
- inPlace((goal) => {
716
- const manager = environment.manager;
717
- const seen = new Set<number>();
718
- const todo = [...goal.forms.items];
719
- for (let expr = todo.pop(); expr !== undefined; expr = todo.pop()) {
720
- if (seen.has(expr) || manager.kinds[expr] !== KIND_APP) continue;
721
- seen.add(expr);
722
- if (manager.getOp(expr) === OP_ITE && manager.sorts[expr] !== SORT_BOOL)
723
- throw new SmtUnsupportedError("elim-term-ite on a goal it changes");
724
- manager.pushArgs(expr, todo);
725
- }
726
- goal.depth++;
727
- }),
775
+ build: (environment) => runElimTermIte(environment.manager),
728
776
  },
729
777
  ],
730
778
  [
@@ -752,7 +800,7 @@ const NAMED_TACTICS = new Map<string, NamedTactic>([
752
800
  isEliminatingAnd: true,
753
801
  isKeepingDistinct: false,
754
802
  });
755
- tseitinCnf(manager, goal);
803
+ if (!goal.isDecided()) tseitinCnf(manager, goal);
756
804
  } finally {
757
805
  original.reset();
758
806
  }
@@ -764,14 +812,9 @@ const NAMED_TACTICS = new Map<string, NamedTactic>([
764
812
  {
765
813
  descrs: new Map(),
766
814
  build: (environment) =>
767
- inPlace((goal) => {
768
- if (!goal.isProofsEnabled) applyQeLite(environment.manager, goal);
769
- else {
770
- goal.elimTrue();
771
- goal.elimRedundancies();
772
- }
773
- goal.depth++;
774
- }),
815
+ inPlace((goal) =>
816
+ goal.isProofsEnabled ? finishSimplifier(goal) : applyQeLite(environment.manager, goal),
817
+ ),
775
818
  },
776
819
  ],
777
820
  [
@@ -803,6 +846,7 @@ const NAMED_TACTICS = new Map<string, NamedTactic>([
803
846
  [
804
847
  "elim-uncnstr",
805
848
  {
849
+ isTrackingDependencies: true,
806
850
  descrs: getDescrs("", [
807
851
  ["max_memory", PARAM_UINT, UINT_MAX, true],
808
852
  ["max_steps", PARAM_UINT, UINT_MAX],
@@ -898,7 +942,7 @@ const NAMED_TACTICS = new Map<string, NamedTactic>([
898
942
  "pb2bv",
899
943
  {
900
944
  descrs: new Map([
901
- ...[...REWRITER_DESCRS].filter(([name]) => BOOL_REWRITER_PARAMS.includes(name)),
945
+ ...[...REWRITER_DESCRS].filter((entry) => BOOL_REWRITER_PARAMS.includes(entry[0])),
902
946
  ...getDescrs("", [
903
947
  ["max_memory", PARAM_UINT, UINT_MAX, true],
904
948
  ["pb2bv_all_clauses_limit", PARAM_UINT, 8, true],
@@ -1043,6 +1087,14 @@ const NAMED_TACTICS = new Map<string, NamedTactic>([
1043
1087
  },
1044
1088
  ],
1045
1089
  ["der", { descrs: new Map(), build: (environment) => runDer(environment.manager) }],
1090
+ [
1091
+ "blast-term-ite",
1092
+ {
1093
+ isTrackingDependencies: true,
1094
+ descrs: new Map(),
1095
+ build: (environment) => inPlace((goal) => blastTermIte(environment.manager, goal)),
1096
+ },
1097
+ ],
1046
1098
  [
1047
1099
  "distribute-forall",
1048
1100
  {
@@ -1104,6 +1156,15 @@ const NAMED_TACTICS = new Map<string, NamedTactic>([
1104
1156
  build: (environment) => inPlace((goal) => domSimplify(environment.manager, goal)),
1105
1157
  },
1106
1158
  ],
1159
+ [
1160
+ "split-clause",
1161
+ {
1162
+ descrs: getDescrs("", [["split_largest_clause", PARAM_BOOL, false, true]]),
1163
+ isTrackingDependencies: true,
1164
+ build: (_environment, params) =>
1165
+ runSplitClause(getBool(params, "split_largest_clause", false)),
1166
+ },
1167
+ ],
1107
1168
  [
1108
1169
  "occf",
1109
1170
  {
@@ -1208,7 +1269,7 @@ const NAMED_TACTICS = new Map<string, NamedTactic>([
1208
1269
  const manager = environment.manager;
1209
1270
  const preamble = createCommandReader(QFUFBV_ACKR_PREAMBLE).read() as SmtList;
1210
1271
  return runAndThen(
1211
- compile(environment, preamble, preamble.end, true).build(params),
1272
+ compile(environment, preamble, true).build(params),
1212
1273
  runCond(
1213
1274
  isQfufbv,
1214
1275
  createQfufbvAckrTactic(manager, getRewriterOptions(manager, new Map()), true, () =>
@@ -1289,7 +1350,7 @@ const NAMED_TACTICS = new Map<string, NamedTactic>([
1289
1350
  {
1290
1351
  descrs: new Map(),
1291
1352
  isRejectingUnknown: false,
1292
- build: (environment) => runQsat(environment.manager, QSAT_SAT),
1353
+ build: (environment) => runQsat(environment, QSAT_SAT),
1293
1354
  },
1294
1355
  ],
1295
1356
  [
@@ -1297,7 +1358,7 @@ const NAMED_TACTICS = new Map<string, NamedTactic>([
1297
1358
  {
1298
1359
  descrs: new Map(),
1299
1360
  isRejectingUnknown: false,
1300
- build: (environment) => runQsat(environment.manager, QSAT_QE),
1361
+ build: (environment) => runQsat(environment, QSAT_QE),
1301
1362
  },
1302
1363
  ],
1303
1364
  [
@@ -1305,7 +1366,7 @@ const NAMED_TACTICS = new Map<string, NamedTactic>([
1305
1366
  {
1306
1367
  descrs: new Map(),
1307
1368
  isRejectingUnknown: false,
1308
- build: (environment) => runQsat(environment.manager, QSAT_QE_REC),
1369
+ build: (environment) => runQsat(environment, QSAT_QE_REC),
1309
1370
  },
1310
1371
  ],
1311
1372
  [
@@ -1381,20 +1442,19 @@ const NAMED_TACTICS = new Map<string, NamedTactic>([
1381
1442
 
1382
1443
  const UNPORTED_TACTICS = new Set(
1383
1444
  (
1384
- "blast-term-ite " +
1385
1445
  "bv-slice bvarray2uf collect-statistics " +
1386
1446
  "degree-shift demodulator " +
1387
1447
  "elim-predicates elim-uncnstr2 " +
1388
1448
  "euf-completion ff-sat ff-simplify ff-solve ff-unique ff2bv fold-unfold fpa2bv " +
1389
1449
  "horn-simplify injectivity pb-preprocess pqffd propagate-bv-bounds " +
1390
- "propagate-bv-bounds2 propagate-values2 qfbv-sls qfufbv recover-01 reduce-args2 " +
1450
+ "propagate-bv-bounds2 propagate-values2 qfbv-sls recover-01 reduce-args2 " +
1391
1451
  "sat-preprocess sls-smt smtfd solver-subsumption special-relations " +
1392
- "split-clause subpaving symmetry-reduce"
1452
+ "subpaving symmetry-reduce"
1393
1453
  ).split(" "),
1394
1454
  );
1395
1455
 
1396
- const isUnsigned = (sexpr: SExpr | undefined): sexpr is SmtToken =>
1397
- sexpr?.kind === "numeral" && BigInt(sexpr.text) <= BigInt(UINT_MAX);
1456
+ const isUnsignedNumeral = (sexpr: SExpr | undefined): sexpr is SmtToken =>
1457
+ sexpr?.kind === "numeral" && isUnsigned(sexpr.text);
1398
1458
 
1399
1459
  const getParamName = (keyword: string) =>
1400
1460
  keyword.replace(/^:/, "").toLowerCase().replaceAll("-", "_");
@@ -1415,7 +1475,7 @@ const parseParamValue = (kind: number, value: SExpr) =>
1415
1475
  kind === PARAM_BOOL
1416
1476
  ? isSymbol(value, "true") || (isSymbol(value, "false") ? false : undefined)
1417
1477
  : kind === PARAM_UINT
1418
- ? isUnsigned(value)
1478
+ ? isUnsignedNumeral(value)
1419
1479
  ? Number(value.text)
1420
1480
  : undefined
1421
1481
  : kind === PARAM_NUMERAL
@@ -1444,27 +1504,33 @@ const checkParams = (descrs: ParamDescrs, params: TacticParams) => {
1444
1504
  }
1445
1505
  };
1446
1506
 
1507
+ // sexpr2tactic reports an error at the s-expression: a list at its closing parenthesis.
1508
+ const getSexprPosition = (sexpr: SExpr) => (sexpr.kind === "list" ? sexpr.end : sexpr);
1509
+
1447
1510
  const getParams = (
1448
1511
  builder: TacticBuilder,
1449
1512
  items: SExpr[],
1450
- end: SmtToken,
1451
1513
  isInternal: boolean,
1452
1514
  ): Map<string, TacticParam> => {
1453
1515
  const params = new Map<string, TacticParam>();
1454
1516
  for (let index = 2; index < items.length; index += 2) {
1455
1517
  const keyword = items[index];
1456
1518
  if (keyword.kind !== "keyword")
1457
- throw new SmtParseError("invalid using-params combinator, keyword expected", end);
1519
+ throw new SmtParseError(
1520
+ "invalid using-params combinator, keyword expected",
1521
+ getSexprPosition(keyword),
1522
+ );
1458
1523
  const value = items[index + 1];
1459
1524
  if (value === undefined)
1460
- throw new SmtParseError("invalid using-params combinator, parameter value expected", end);
1525
+ throw new SmtParseError("invalid using-params combinator, parameter value expected", keyword);
1461
1526
  const found = findParam(builder.descrs, getParamName(keyword.text));
1462
1527
  if (isInternal) {
1463
1528
  const parsed =
1464
1529
  found === undefined
1465
1530
  ? getUntypedParamValue(value)
1466
1531
  : parseParamValue(found.descr.kind, value);
1467
- if (parsed === undefined) throw new SmtParseError("invalid parameter value", end);
1532
+ if (parsed === undefined)
1533
+ throw new SmtParseError("invalid parameter value", getSexprPosition(value));
1468
1534
  params.set(found?.name ?? getParamName(keyword.text), parsed);
1469
1535
  continue;
1470
1536
  }
@@ -1473,7 +1539,7 @@ const getParams = (
1473
1539
  throw new SmtUnsupportedError(`the parameter ${keyword.text} of the tactic`);
1474
1540
  throw new SmtParseError(
1475
1541
  `invalid using-params combinator, unknown parameter ${getParamName(keyword.text)}`,
1476
- end,
1542
+ getSexprPosition(value),
1477
1543
  );
1478
1544
  }
1479
1545
  const parsed = parseParamValue(found.descr.kind, value);
@@ -1486,7 +1552,7 @@ const getParams = (
1486
1552
  : found.descr.kind === PARAM_NUMERAL
1487
1553
  ? "invalid parameter value, numeral expected"
1488
1554
  : "invalid parameter value, symbol expected",
1489
- end,
1555
+ getSexprPosition(value),
1490
1556
  );
1491
1557
  if (isUnportedParam(found.descr, parsed))
1492
1558
  throw new SmtUnsupportedError(`the parameter ${found.name} of the tactic`);
@@ -1505,19 +1571,30 @@ const isDecidedSat = (goals: Goal[]) => goals.length === 1 && goals[0].isDecided
1505
1571
 
1506
1572
  const isDecidedUnsat = (goals: Goal[]) => goals.length === 1 && goals[0].isDecidedUnsat();
1507
1573
 
1574
+ // Deviation from Z3: and_then and repeat join the subgoals' cores, where Z3 answers an empty core.
1575
+ const assertUnsat = (goal: Goal, unsatGoals: Goal[]) => {
1576
+ goal.resetAll();
1577
+ goal.assert(
1578
+ goal.manager.falseExpr,
1579
+ unsatGoals.reduce<Dependency | undefined>(
1580
+ (core, unsatGoal) => joinDependencies(unsatGoal.getDependency(0), core),
1581
+ undefined,
1582
+ ),
1583
+ );
1584
+ return [goal];
1585
+ };
1586
+
1508
1587
  const runAndThen = (first: Tactic, second: Tactic) => (goal: Goal) => {
1509
1588
  const goals = first(goal);
1510
1589
  if (goals.length === 1) return goals[0].isDecided() ? goals : second(goals[0]);
1511
1590
  const results: Goal[] = [];
1591
+ const unsatGoals: Goal[] = [];
1512
1592
  for (const subgoal of goals) {
1513
1593
  const subresults = second(subgoal);
1514
1594
  if (isDecidedSat(subresults)) return subresults;
1515
- if (!isDecidedUnsat(subresults)) results.push(...subresults);
1595
+ (isDecidedUnsat(subresults) ? unsatGoals : results).push(...subresults);
1516
1596
  }
1517
- if (results.length > 0) return results;
1518
- goal.resetAll();
1519
- goal.assert(goal.manager.falseExpr);
1520
- return [goal];
1597
+ return results.length > 0 ? results : assertUnsat(goal, unsatGoals);
1521
1598
  };
1522
1599
 
1523
1600
  const runOrElse = (tactics: Tactic[]) => (goal: Goal) => {
@@ -1526,12 +1603,12 @@ const runOrElse = (tactics: Tactic[]) => (goal: Goal) => {
1526
1603
  try {
1527
1604
  return tactic(goal);
1528
1605
  } catch (error) {
1529
- if (!(error instanceof SmtTacticError)) throw error;
1606
+ if (!(error instanceof SmtTacticError || error instanceof SmtCanceledError)) throw error;
1530
1607
  }
1531
1608
  goal.resetAll();
1532
1609
  goal.copyFrom(original);
1533
1610
  }
1534
- return (tactics.at(-1) as Tactic)(goal);
1611
+ return tactics[tactics.length - 1](goal);
1535
1612
  };
1536
1613
 
1537
1614
  const isEqualGoal = (first: Goal, second: Goal) => {
@@ -1551,15 +1628,13 @@ const runRepeat = (tactic: Tactic, maxDepth: number) => {
1551
1628
  if (goals.length === 1 && isEqualGoal(original, goals[0])) return goals;
1552
1629
  if (goals.length === 1) return goals[0].isDecided() ? goals : run(depth + 1, goals[0]);
1553
1630
  const results: Goal[] = [];
1631
+ const unsatGoals: Goal[] = [];
1554
1632
  for (const subgoal of goals) {
1555
1633
  const subresults = run(depth + 1, subgoal);
1556
1634
  if (isDecidedSat(subresults)) return subresults;
1557
- if (!isDecidedUnsat(subresults)) results.push(...subresults);
1635
+ (isDecidedUnsat(subresults) ? unsatGoals : results).push(...subresults);
1558
1636
  }
1559
- if (results.length > 0) return results;
1560
- goal.resetAll();
1561
- goal.assert(goal.manager.falseExpr);
1562
- return [goal];
1637
+ return results.length > 0 ? results : assertUnsat(goal, unsatGoals);
1563
1638
  };
1564
1639
  return (goal: Goal) => run(0, goal);
1565
1640
  };
@@ -1567,22 +1642,21 @@ const runRepeat = (tactic: Tactic, maxDepth: number) => {
1567
1642
  const runCond = (probe: Probe, onTrue: Tactic, onFalse: Tactic) => (goal: Goal) =>
1568
1643
  probe(goal) === 0 ? onFalse(goal) : onTrue(goal);
1569
1644
 
1570
- const checkHasArgument = (list: SmtList, combinator: string, end: SmtToken) => {
1645
+ const checkHasArgument = (list: SmtList, combinator: string) => {
1571
1646
  if (list.items.length < 2)
1572
1647
  throw new SmtParseError(
1573
1648
  `invalid ${combinator} combinator, at least one argument expected`,
1574
- end,
1649
+ list.end,
1575
1650
  );
1576
1651
  };
1577
1652
 
1578
1653
  const compile = (
1579
1654
  environment: TacticEnvironment,
1580
1655
  sexpr: SExpr,
1581
- end: SmtToken,
1582
1656
  isInternal: boolean,
1583
1657
  ): TacticBuilder => {
1584
1658
  if (sexpr.kind !== "list") {
1585
- if (!isSymbol(sexpr)) throw new SmtParseError("invalid tactic, unexpected input", end);
1659
+ if (!isSymbol(sexpr)) throw new SmtParseError("invalid tactic, unexpected input", sexpr);
1586
1660
  const named = NAMED_TACTICS.get(sexpr.text);
1587
1661
  if (named !== undefined)
1588
1662
  return {
@@ -1600,7 +1674,7 @@ const compile = (
1600
1674
  };
1601
1675
  const strategy = LOGIC_TACTICS.get(sexpr.text);
1602
1676
  if (strategy !== undefined)
1603
- return compile(environment, createCommandReader(strategy).read() as SmtList, end, true);
1677
+ return compile(environment, createCommandReader(strategy).read() as SmtList, true);
1604
1678
  if (UNPORTED_TACTICS.has(sexpr.text)) {
1605
1679
  const error = new SmtUnsupportedError(`the tactic ${sexpr.text}`);
1606
1680
  if (!isInternal) throw error;
@@ -1613,14 +1687,14 @@ const compile = (
1613
1687
  },
1614
1688
  };
1615
1689
  }
1616
- throw new SmtParseError(`invalid tactic, unknown tactic ${sexpr.text}`, end);
1690
+ throw new SmtParseError(`invalid tactic, unknown tactic ${sexpr.text}`, sexpr);
1617
1691
  }
1618
1692
  const head = sexpr.items[0];
1619
- if (head === undefined) throw new SmtParseError("invalid tactic, arguments expected", end);
1620
- if (!isSymbol(head)) throw new SmtParseError("invalid tactic, symbol expected", end);
1693
+ if (head === undefined) throw new SmtParseError("invalid tactic, arguments expected", sexpr.end);
1694
+ if (!isSymbol(head)) throw new SmtParseError("invalid tactic, symbol expected", sexpr.end);
1621
1695
  const compileChildren = (combinator: string) => {
1622
- checkHasArgument(sexpr, combinator, end);
1623
- return sexpr.items.slice(1).map((child) => compile(environment, child, end, isInternal));
1696
+ checkHasArgument(sexpr, combinator);
1697
+ return sexpr.items.slice(1).map((child) => compile(environment, child, isInternal));
1624
1698
  };
1625
1699
  switch (head.text) {
1626
1700
  case "then":
@@ -1670,27 +1744,43 @@ const compile = (
1670
1744
  // The timeout is not ported, so the child runs to the end.
1671
1745
  case "try-for": {
1672
1746
  if (sexpr.items.length !== 3)
1673
- throw new SmtParseError("invalid try-for combinator, two arguments expected", end);
1674
- if (!isUnsigned(sexpr.items[2]))
1747
+ throw new SmtParseError("invalid try-for combinator, two arguments expected", sexpr.end);
1748
+ if (!isUnsignedNumeral(sexpr.items[2]))
1675
1749
  throw new SmtParseError(
1676
1750
  "invalid try-for combinator, second argument must be an unsigned integer",
1677
- end,
1751
+ sexpr.end,
1678
1752
  );
1679
- return compile(environment, sexpr.items[1], end, isInternal);
1753
+ const child = compile(environment, sexpr.items[1], isInternal);
1754
+ return {
1755
+ ...child,
1756
+ build: (params) => {
1757
+ const tactic = child.build(params);
1758
+ return (goal) => {
1759
+ try {
1760
+ return tactic(goal);
1761
+ } catch (error) {
1762
+ if (error instanceof SmtDefaultError) throw new SmtTacticError(error.message);
1763
+ if (error instanceof SmtCanceledError)
1764
+ throw new SmtTacticError(goal.manager.limit.getCancelMessage());
1765
+ throw error;
1766
+ }
1767
+ };
1768
+ },
1769
+ };
1680
1770
  }
1681
1771
  case "fail-if-branching": {
1682
1772
  if (sexpr.items.length !== 3 && sexpr.items.length !== 2)
1683
1773
  throw new SmtParseError(
1684
1774
  "invalid fail-if-branching combinator, one or two arguments expected",
1685
- end,
1775
+ sexpr.end,
1686
1776
  );
1687
1777
  const bound = sexpr.items[2];
1688
- if (bound !== undefined && !isUnsigned(bound))
1778
+ if (bound !== undefined && !isUnsignedNumeral(bound))
1689
1779
  throw new SmtParseError(
1690
1780
  "invalid fail-if-branching combinator, second argument must be an unsigned integer",
1691
- end,
1781
+ sexpr.end,
1692
1782
  );
1693
- const child = compile(environment, sexpr.items[1], end, isInternal);
1783
+ const child = compile(environment, sexpr.items[1], isInternal);
1694
1784
  const threshold = bound === undefined ? 1 : Number(bound.text);
1695
1785
  return {
1696
1786
  ...mergeDescrs([child]),
@@ -1708,11 +1798,17 @@ const compile = (
1708
1798
  case "if-no-unsat-cores":
1709
1799
  case "if-no-models": {
1710
1800
  if (sexpr.items.length !== 2)
1711
- throw new SmtParseError(`invalid ${head.text} combinator, one argument expected`, end);
1712
- const child = compile(environment, sexpr.items[1], end, isInternal);
1801
+ throw new SmtParseError(
1802
+ `invalid ${head.text} combinator, one argument expected`,
1803
+ sexpr.end,
1804
+ );
1805
+ const child = compile(environment, sexpr.items[1], isInternal);
1713
1806
  const isSkipping = (goal: Goal) =>
1714
- head.text === "if-no-models" ||
1715
- (head.text === "if-no-proofs" ? goal.isProofsEnabled : goal.isCoresEnabled);
1807
+ head.text === "if-no-models"
1808
+ ? goal.isModelsEnabled
1809
+ : head.text === "if-no-proofs"
1810
+ ? goal.isProofsEnabled
1811
+ : goal.isCoresEnabled;
1716
1812
  return {
1717
1813
  ...mergeDescrs([child]),
1718
1814
  build: (params) => {
@@ -1723,14 +1819,17 @@ const compile = (
1723
1819
  }
1724
1820
  case "repeat": {
1725
1821
  if (sexpr.items.length !== 3 && sexpr.items.length !== 2)
1726
- throw new SmtParseError("invalid repeat combinator, one or two arguments expected", end);
1822
+ throw new SmtParseError(
1823
+ "invalid repeat combinator, one or two arguments expected",
1824
+ sexpr.end,
1825
+ );
1727
1826
  const bound = sexpr.items[2];
1728
- if (bound !== undefined && !isUnsigned(bound))
1827
+ if (bound !== undefined && !isUnsignedNumeral(bound))
1729
1828
  throw new SmtParseError(
1730
1829
  "invalid repeat combinator, second argument must be an unsigned integer",
1731
- end,
1830
+ sexpr.end,
1732
1831
  );
1733
- const child = compile(environment, sexpr.items[1], end, isInternal);
1832
+ const child = compile(environment, sexpr.items[1], isInternal);
1734
1833
  const maxDepth = bound === undefined ? UINT_MAX : Number(bound.text);
1735
1834
  return {
1736
1835
  ...mergeDescrs([child]),
@@ -1740,10 +1839,10 @@ const compile = (
1740
1839
  case "!":
1741
1840
  case "using-params":
1742
1841
  case "with": {
1743
- checkHasArgument(sexpr, "using-params", end);
1744
- const child = compile(environment, sexpr.items[1], end, isInternal);
1842
+ checkHasArgument(sexpr, "using-params");
1843
+ const child = compile(environment, sexpr.items[1], isInternal);
1745
1844
  if (sexpr.items.length === 2) return child;
1746
- const own = getParams(child, sexpr.items, end, isInternal);
1845
+ const own = getParams(child, sexpr.items, isInternal);
1747
1846
  return {
1748
1847
  ...mergeDescrs([child]),
1749
1848
  build: (params) => child.build(new Map([...params, ...own])),
@@ -1751,8 +1850,11 @@ const compile = (
1751
1850
  }
1752
1851
  case "skip-if-failed": {
1753
1852
  if (sexpr.items.length !== 2)
1754
- throw new SmtParseError("invalid skip-if-failed combinator, one argument expected", end);
1755
- const child = compile(environment, sexpr.items[1], end, isInternal);
1853
+ throw new SmtParseError(
1854
+ "invalid skip-if-failed combinator, one argument expected",
1855
+ sexpr.end,
1856
+ );
1857
+ const child = compile(environment, sexpr.items[1], isInternal);
1756
1858
  return {
1757
1859
  ...mergeDescrs([child]),
1758
1860
  build: (params) => runOrElse([child.build(params), (goal) => [goal]]),
@@ -1762,11 +1864,12 @@ const compile = (
1762
1864
  case "ite":
1763
1865
  case "cond": {
1764
1866
  if (sexpr.items.length !== 4)
1765
- throw new SmtParseError("invalid if/conditional combinator, three arguments expected", end);
1766
- const probe = compileProbe(sexpr.items[1], end, isInternal);
1767
- const children = sexpr.items
1768
- .slice(2)
1769
- .map((child) => compile(environment, child, end, isInternal));
1867
+ throw new SmtParseError(
1868
+ "invalid if/conditional combinator, three arguments expected",
1869
+ sexpr.end,
1870
+ );
1871
+ const probe = compileProbe(sexpr.items[1], isInternal);
1872
+ const children = sexpr.items.slice(2).map((child) => compile(environment, child, isInternal));
1770
1873
  return {
1771
1874
  ...mergeDescrs(children),
1772
1875
  build: (params) => runCond(probe, children[0].build(params), children[1].build(params)),
@@ -1774,9 +1877,9 @@ const compile = (
1774
1877
  }
1775
1878
  case "when": {
1776
1879
  if (sexpr.items.length !== 3)
1777
- throw new SmtParseError("invalid when combinator, two arguments expected", end);
1778
- const probe = compileProbe(sexpr.items[1], end, isInternal);
1779
- const child = compile(environment, sexpr.items[2], end, isInternal);
1880
+ throw new SmtParseError("invalid when combinator, two arguments expected", sexpr.end);
1881
+ const probe = compileProbe(sexpr.items[1], isInternal);
1882
+ const child = compile(environment, sexpr.items[2], isInternal);
1780
1883
  return {
1781
1884
  ...mergeDescrs([child]),
1782
1885
  build: (params) => runCond(probe, child.build(params), (goal) => [goal]),
@@ -1784,8 +1887,8 @@ const compile = (
1784
1887
  }
1785
1888
  case "fail-if": {
1786
1889
  if (sexpr.items.length !== 2)
1787
- throw new SmtParseError("invalid fail-if tactic, one argument expected", end);
1788
- const probe = compileProbe(sexpr.items[1], end, isInternal);
1890
+ throw new SmtParseError("invalid fail-if tactic, one argument expected", sexpr.end);
1891
+ const probe = compileProbe(sexpr.items[1], isInternal);
1789
1892
  return {
1790
1893
  descrs: new Map(),
1791
1894
  isRejectingUnknown: true,
@@ -1798,7 +1901,7 @@ const compile = (
1798
1901
  }
1799
1902
  case "echo": {
1800
1903
  if (sexpr.items.length < 2)
1801
- throw new SmtParseError("invalid echo tactic, must have at least one argument", end);
1904
+ throw new SmtParseError("invalid echo tactic, must have at least one argument", sexpr.end);
1802
1905
  const pieces = sexpr.items.slice(1).map((piece, index, all): Tactic => {
1803
1906
  const newline = index === all.length - 1 ? "\n" : "";
1804
1907
  if (piece.kind === "string")
@@ -1806,7 +1909,7 @@ const compile = (
1806
1909
  environment.write(piece.text + newline, false);
1807
1910
  return [goal];
1808
1911
  };
1809
- const probe = compileProbe(piece, end, isInternal);
1912
+ const probe = compileProbe(piece, isInternal);
1810
1913
  return (goal) => {
1811
1914
  environment.write(formatProbeValue(probe(goal)) + newline, true);
1812
1915
  return [goal];
@@ -1820,7 +1923,7 @@ const compile = (
1820
1923
  };
1821
1924
  }
1822
1925
  default:
1823
- throw new SmtParseError(`invalid tactic, unknown tactic combinator ${head.text}`, end);
1926
+ throw new SmtParseError(`invalid tactic, unknown tactic combinator ${head.text}`, sexpr.end);
1824
1927
  }
1825
1928
  };
1826
1929
 
@@ -1868,19 +1971,18 @@ export const mkIncSatPreprocess = (manager: AstManager, bitBlaster: BitBlasterRe
1868
1971
  ),
1869
1972
  ].reduceRight((second, first) => runAndThen(first, second));
1870
1973
 
1871
- export const compileTactic = (environment: TacticEnvironment, sexpr: SExpr, end: SmtToken) =>
1872
- compile(environment, sexpr, end, false);
1974
+ export const compileTactic = (environment: TacticEnvironment, sexpr: SExpr) =>
1975
+ compile(environment, sexpr, false);
1873
1976
 
1874
1977
  export const compileInternalTactic = (environment: TacticEnvironment, text: string) => {
1875
1978
  const list = createCommandReader(`(${text})`).read() as SmtList;
1876
- return compile(environment, list.items[0], list.end, true).build(new Map());
1979
+ return compile(environment, list.items[0], true).build(new Map());
1877
1980
  };
1878
1981
 
1879
1982
  interface TacticCheck {
1880
1983
  status: number;
1881
1984
  model: ProtoModel | undefined;
1882
1985
  core: Dependency | undefined;
1883
- // What check_sat leaves in reason_unknown, or undefined where the port does not track it.
1884
1986
  reasonUnknown: string | undefined;
1885
1987
  }
1886
1988
 
@@ -1948,32 +2050,46 @@ export const convertModel = (goal: Goal, model: ProtoModel) =>
1948
2050
  return converted;
1949
2051
  }, model);
1950
2052
 
2053
+ const getConvertedModel = (goal: Goal) =>
2054
+ convertModel(goal, goal.model?.copy() ?? new ProtoModel(goal.manager).mkModel());
2055
+
1951
2056
  export const checkSatUsing = (tactic: Tactic, goal: Goal): TacticCheck => {
1952
2057
  const undecided = { status: L_UNDEF, model: undefined, core: undefined };
1953
2058
  const goals = (() => {
1954
2059
  try {
1955
2060
  return tactic(goal);
1956
2061
  } catch (error) {
1957
- if (error instanceof SmtTacticError) return error.message;
2062
+ if (error instanceof SmtTacticError || error instanceof SmtDefaultError) return error.message;
1958
2063
  if (error instanceof SmtCanceledError) return undefined;
1959
2064
  throw error;
1960
2065
  }
1961
2066
  })();
2067
+ if (goals === undefined) return { ...undecided, reasonUnknown: undefined };
1962
2068
  if (typeof goals === "string") return { ...undecided, reasonUnknown: goals };
1963
- if (goals !== undefined && isDecidedSat(goals)) {
1964
- const model = convertModel(goals[0], goals[0].model ?? new ProtoModel(goal.manager));
2069
+ if (isDecidedSat(goals)) {
2070
+ const model = getConvertedModel(goals[0]);
1965
2071
  return goal.manager.limit.inc()
1966
2072
  ? { status: L_TRUE, model, core: undefined, reasonUnknown: "" }
1967
2073
  : { ...undecided, model, reasonUnknown: "canceled" };
1968
2074
  }
1969
- if (goals !== undefined && isDecidedUnsat(goals))
2075
+ if (isDecidedUnsat(goals))
1970
2076
  return {
1971
2077
  status: L_FALSE,
1972
2078
  model: undefined,
1973
2079
  core: goals[0].getDependency(0),
1974
2080
  reasonUnknown: "",
1975
2081
  };
1976
- return { ...undecided, reasonUnknown: undefined };
2082
+ return {
2083
+ ...undecided,
2084
+ model:
2085
+ goal.isModelsEnabled &&
2086
+ goals.length > 0 &&
2087
+ (goals[0].model !== undefined || goals[0].converters.length > 0)
2088
+ ? getConvertedModel(goals[0])
2089
+ : undefined,
2090
+ reasonUnknown:
2091
+ goals.length === 1 && goals[0].reasonUnknown !== "" ? goals[0].reasonUnknown : "unknown",
2092
+ };
1977
2093
  };
1978
2094
 
1979
2095
  export const applyTactic = (tactic: Tactic, goal: Goal) => {