tla-ts 0.0.10-dev.1ebc153bd → 0.0.10-dev.22f7435d3

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 (108) hide show
  1. package/dist/deciders.cjs +31 -31
  2. package/dist/deciders.js +30 -30
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.d.cts +6 -2
  5. package/dist/index.d.ts +6 -2
  6. package/dist/index.js +1 -1
  7. package/dist/parallel-worker.cjs +1 -1
  8. package/dist/parallel-worker.js +1 -1
  9. package/dist/prove.cjs +68 -68
  10. package/dist/prove.js +61 -61
  11. package/dist/run.cjs +42 -42
  12. package/dist/run.js +44 -44
  13. package/dist/transfer.cjs +38 -38
  14. package/dist/transfer.js +29 -29
  15. package/dist/worker.cjs +7 -7
  16. package/dist/worker.js +7 -7
  17. package/package.json +1 -1
  18. package/src/bags.ts +5 -2
  19. package/src/builtins.ts +4 -3
  20. package/src/check-failure.ts +9 -6
  21. package/src/check-trace.ts +116 -64
  22. package/src/check.ts +343 -166
  23. package/src/cli/tlc-output.ts +1 -0
  24. package/src/cli/tlc.ts +3 -2
  25. package/src/codegen.ts +23 -8
  26. package/src/dependencies.ts +5 -4
  27. package/src/dfid.ts +13 -8
  28. package/src/environment.ts +1 -0
  29. package/src/evaluate.ts +58 -23
  30. package/src/exit-codes.ts +27 -13
  31. package/src/java-hash.ts +14 -0
  32. package/src/liveness-checker.ts +131 -81
  33. package/src/liveness.ts +48 -10
  34. package/src/parser.ts +6 -1
  35. package/src/prover/smt/solver/arith-rewriter.ts +11 -3
  36. package/src/prover/smt/solver/array-rewriter.ts +12 -2
  37. package/src/prover/smt/solver/asserted-formulas.ts +109 -63
  38. package/src/prover/smt/solver/ast.ts +5 -3
  39. package/src/prover/smt/solver/auf-solver.ts +23 -12
  40. package/src/prover/smt/solver/bit-blast-tactic.ts +26 -0
  41. package/src/prover/smt/solver/bound-simplifier.ts +10 -11
  42. package/src/prover/smt/solver/card2bv.ts +34 -15
  43. package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -23
  44. package/src/prover/smt/solver/context.ts +44 -11
  45. package/src/prover/smt/solver/dependent-expr-state.ts +19 -13
  46. package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
  47. package/src/prover/smt/solver/elim-bounds.ts +89 -0
  48. package/src/prover/smt/solver/elim-uncnstr.ts +1 -1
  49. package/src/prover/smt/solver/fd-solver.ts +146 -39
  50. package/src/prover/smt/solver/internalizer.ts +1 -1
  51. package/src/prover/smt/solver/lp/lp-settings.ts +4 -0
  52. package/src/prover/smt/solver/maxcore.ts +2 -1
  53. package/src/prover/smt/solver/maxsmt-base.ts +1 -0
  54. package/src/prover/smt/solver/model-checker.ts +1 -1
  55. package/src/prover/smt/solver/model-evaluator.ts +2 -0
  56. package/src/prover/smt/solver/model-generator.ts +82 -42
  57. package/src/prover/smt/solver/muz/dl-context.ts +12 -40
  58. package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
  59. package/src/prover/smt/solver/muz/dl-rule.ts +6 -7
  60. package/src/prover/smt/solver/muz/hnf.ts +2 -2
  61. package/src/prover/smt/solver/muz/horn-tactic.ts +14 -1
  62. package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
  63. package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
  64. package/src/prover/smt/solver/opt-context.ts +12 -4
  65. package/src/prover/smt/solver/opt-pareto.ts +19 -0
  66. package/src/prover/smt/solver/opt-solver.ts +4 -3
  67. package/src/prover/smt/solver/parallel-tactic.ts +1 -1
  68. package/src/prover/smt/solver/poly-rewriter.ts +1 -0
  69. package/src/prover/smt/solver/proto-model.ts +4 -2
  70. package/src/prover/smt/solver/push-app-ite.ts +37 -0
  71. package/src/prover/smt/solver/qsat.ts +23 -8
  72. package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
  73. package/src/prover/smt/solver/rewriter.ts +31 -25
  74. package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
  75. package/src/prover/smt/solver/sat/inc-sat-solver.ts +56 -28
  76. package/src/prover/smt/solver/sat/sat-tactic.ts +13 -4
  77. package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
  78. package/src/prover/smt/solver/smt-consequences.ts +1 -1
  79. package/src/prover/smt/solver/smt-kernel.ts +39 -4
  80. package/src/prover/smt/solver/smt-setup.ts +28 -4
  81. package/src/prover/smt/solver/smtlib-parser.ts +31 -4
  82. package/src/prover/smt/solver/smtlib-script.ts +219 -82
  83. package/src/prover/smt/solver/solve-eqs.ts +24 -17
  84. package/src/prover/smt/solver/solver.ts +18 -3
  85. package/src/prover/smt/solver/tactic.ts +132 -78
  86. package/src/prover/smt/solver/theory-bv.ts +11 -1
  87. package/src/prover/smt/solver/theory-fpa.ts +1 -1
  88. package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
  89. package/src/prover/smt/solver/theory-lra-internalize.ts +1 -0
  90. package/src/prover/smt/solver/theory-lra-propagate.ts +7 -1
  91. package/src/prover/smt/solver/theory-lra.ts +1 -0
  92. package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
  93. package/src/resolve.ts +446 -167
  94. package/src/runtime.ts +4 -0
  95. package/src/search.ts +161 -92
  96. package/src/simulate.ts +165 -102
  97. package/src/spec-description.ts +3 -4
  98. package/src/standard-modules.ts +56 -22
  99. package/src/subexpressions.ts +168 -49
  100. package/src/successors.ts +6 -3
  101. package/src/symmetry.ts +1 -0
  102. package/src/tlc/random.ts +2 -1
  103. package/src/tlc/replay.ts +22 -14
  104. package/src/tlc/tlc-operators.ts +7 -7
  105. package/src/tlc/tlcext-operators.ts +26 -10
  106. package/src/tlc/trace-spec.ts +6 -20
  107. package/src/typed-tier.ts +9 -4
  108. package/src/values.ts +95 -57
@@ -9,7 +9,7 @@ import type { DecideOptions, Verdict } from "../../verdict";
9
9
  import { AssertedFormulas } from "./asserted-formulas";
10
10
  import { AstManager } from "./ast";
11
11
  import { Context, MBQI_MAX_ITERATIONS } from "./context";
12
- import { L_FALSE, L_TRUE } from "./lbool";
12
+ import { L_FALSE, L_TRUE, L_UNDEF } from "./lbool";
13
13
  import { applyUfniaTactic } from "./quant-tactics";
14
14
  import { ResourceLimit } from "./rlimit";
15
15
  import { parseSmtlib } from "./smtlib-parser";
@@ -20,6 +20,8 @@ export interface KernelParams {
20
20
  mbqiMaxIterations: number;
21
21
  isFindingMacros: boolean;
22
22
  relevancyLevel?: 0 | 2;
23
+ isCoreMinimizing?: boolean;
24
+ randomSeed?: number;
23
25
  // A kernel without a setup runs as with auto_config false.
24
26
  setup?: SmtSetup;
25
27
  }
@@ -30,6 +32,11 @@ const DEFAULT_KERNEL_PARAMS: KernelParams = {
30
32
  isFindingMacros: false,
31
33
  };
32
34
 
35
+ const assertForms = (context: Context, asserted: AssertedFormulas, forms: number[]) => {
36
+ for (const form of forms) if (!context.checkCanceled()) asserted.assertExpr(form);
37
+ return !context.checkCanceled();
38
+ };
39
+
33
40
  interface SmtCheck {
34
41
  verdict: Verdict;
35
42
  numInstances: number;
@@ -43,8 +50,12 @@ export const solveGoal = (manager: AstManager, forms: number[], params: KernelPa
43
50
  isMbqi: params.isMbqi,
44
51
  mbqiMaxIterations: params.mbqiMaxIterations,
45
52
  relevancyLevel: 2,
53
+ randomSeed: params.randomSeed,
46
54
  });
47
- for (const form of forms) asserted.assertExpr(form);
55
+ if (!assertForms(context, asserted, forms)) {
56
+ manager.limit.release();
57
+ return { result: L_UNDEF, context, reasonUnknown: "canceled" };
58
+ }
48
59
  context.setupContext(params.setup, true, asserted);
49
60
  context.internalizeAssertions(asserted);
50
61
  const theoryAssumptions: number[] = [];
@@ -81,8 +92,12 @@ export const solveAssuming = (
81
92
  isMbqi: params.isMbqi,
82
93
  mbqiMaxIterations: params.mbqiMaxIterations,
83
94
  relevancyLevel: 2,
95
+ randomSeed: params.randomSeed,
84
96
  });
85
- for (const assertion of assertions) asserted.assertExpr(assertion);
97
+ if (!assertForms(context, asserted, assertions)) {
98
+ manager.limit.release();
99
+ return { result: L_UNDEF, context, reasonUnknown: "canceled" };
100
+ }
86
101
  context.setupContext(params.setup, false, asserted);
87
102
  context.internalizeAssertions(asserted);
88
103
  const result = context.checkResearching(asserted, assumptions);
@@ -7,11 +7,10 @@ import {
7
7
  } from "../../../errors";
8
8
  import { type AstManager, OP_DIV0, OP_IDIV0, OP_MOD0, OP_OR, OP_POWER0, SORT_BOOL } from "./ast";
9
9
  import { createQfufbvAckrTactic, runAckermannizeBv } from "./ackermannize-bv-tactic";
10
- import { AssertedFormulas } from "./asserted-formulas";
11
10
  import { createAigTactic } from "./aig-tactic";
12
11
  import { blastTermIte } from "./blast-term-ite";
13
12
  import { card2bv } from "./card2bv";
14
- import { Context, MBQI_MAX_ITERATIONS } from "./context";
13
+ import { type Context, MBQI_MAX_ITERATIONS } from "./context";
15
14
  import { ctxSimplify } from "./ctx-simplify";
16
15
  import { createCtxSolverSimplify } from "./ctx-solver-simplify";
17
16
  import {
@@ -25,7 +24,7 @@ import {
25
24
  import type { AckrSolver } from "./lackr";
26
25
  import { L_FALSE, L_TRUE, L_UNDEF } from "./lbool";
27
26
  import { DerRewriter } from "./der";
28
- import { finishSimplifier } from "./dependent-expr-state";
27
+ import { finishSimplifier, runSimplifier } from "./dependent-expr-state";
29
28
  import { fixDlVar } from "./fix-dl-var";
30
29
  import { runFpa2Bv } from "./fpa2bv-tactic";
31
30
  import { type BitBlasterRewriter, runBitBlast } from "./bit-blast-tactic";
@@ -67,6 +66,7 @@ import { propagateValues } from "./propagate-values";
67
66
  import { purifyArith } from "./purify-arith";
68
67
  import { ModelEvaluator } from "./model-evaluator";
69
68
  import { FuncInterp, ProtoModel } from "./proto-model";
69
+ import { SmtKernel } from "./smt-kernel";
70
70
  import { isMbqiByFeatures, type SmtSetup } from "./smt-setup";
71
71
  import { compileProbe, formatProbeValue, isQfufbv, type Probe } from "./probes";
72
72
  import { runHorn } from "./muz/horn-tactic";
@@ -172,7 +172,7 @@ const REWRITER_DESCRS = getDescrs("rewriter", [
172
172
  ["sort_sums", PARAM_BOOL, false, true],
173
173
  ["gcd_rounding", PARAM_BOOL, false, true],
174
174
  ["arith_lhs", PARAM_BOOL, false, true],
175
- ["arith_ineq_lhs", PARAM_BOOL, false],
175
+ ["arith_ineq_lhs", PARAM_BOOL, false, true],
176
176
  ["elim_to_real", PARAM_BOOL, false],
177
177
  ["push_to_real", PARAM_BOOL, true],
178
178
  ["eq2ineq", PARAM_BOOL, false],
@@ -251,7 +251,8 @@ export const getRewriterOptions = (manager: AstManager, params: TacticParams): R
251
251
  arith: {
252
252
  isSom: getBool(params, "flat", true) && getBool(params, "som", false),
253
253
  isSortSums: getBool(params, "sort_sums", false),
254
- isArithIneqLhs: getBool(params, "arith_lhs", false),
254
+ isArithLhs: getBool(params, "arith_lhs", false),
255
+ isArithIneqLhs: getBool(params, "arith_ineq_lhs", false),
255
256
  isGcdRounding: getBool(params, "gcd_rounding", false),
256
257
  isAnumSimp: getBool(params, "algebraic_number_evaluator", true),
257
258
  isExpandPower: getBool(params, "expand_power", false),
@@ -276,6 +277,7 @@ const SMT_DESCRS = getDescrs("smt", [
276
277
  ["mbqi", PARAM_BOOL, true, true],
277
278
  ["mbqi.max_iterations", PARAM_UINT, MBQI_MAX_ITERATIONS, true],
278
279
  ["arith.nl.rounds", PARAM_UINT, 1024, true],
280
+ ["random_seed", PARAM_UINT, 0, true],
279
281
  ]);
280
282
 
281
283
  // The dependencies are assertion names, which are Boolean constants, so each one is its own
@@ -290,6 +292,11 @@ const getKernelParams = (environment: TacticEnvironment, params: TacticParams, g
290
292
  mbqiMaxIterations: getUint(params, "mbqi.max_iterations", environment.mbqiMaxIterations),
291
293
  isFindingMacros: environment.isFindingMacros,
292
294
  setup: environment.setup,
295
+ randomSeed: getUint(
296
+ params,
297
+ "random_seed",
298
+ Number(getParameter(environment, "smt.random_seed", "0")),
299
+ ),
293
300
  };
294
301
  };
295
302
 
@@ -356,7 +363,8 @@ const runSmt = (environment: TacticEnvironment, params: TacticParams) => (goal:
356
363
  ? solveGoal(manager, goal.forms.items, kernelParams)
357
364
  : solveAssuming(manager, extracted.clauses.items, extracted.assumptions, kernelParams);
358
365
  extracted.clauses.reset();
359
- if (solved.result === L_UNDEF) throw new SmtTacticError(getSmtTacticFailure(solved.context));
366
+ if (solved.result === L_UNDEF)
367
+ throw new SmtTacticError(solved.reasonUnknown ?? getSmtTacticFailure(solved.context));
360
368
  goal.reset();
361
369
  if (solved.result === L_FALSE)
362
370
  goal.assert(environment.manager.falseExpr, mkCoreDependency(solved.context.unsatCore));
@@ -424,30 +432,42 @@ const createTacticSolver = (manager: AstManager, getTactic: () => Tactic): AckrS
424
432
  // Each clause gets a fresh context, where Z3 pushes a scope on one context.
425
433
  const runUnitSubsume = (environment: TacticEnvironment) => (goal: Goal) => {
426
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);
427
441
  const clauses = goal.forms.items.map(() => manager.mkFreshConst("#clause", SORT_BOOL));
428
- const definitions = goal.forms.items.map((form, index) => manager.mkEq(clauses[index], form));
429
- 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);
430
451
  const deleted: number[] = [];
431
452
  for (const [index, clause] of clauses.entries()) {
432
- const asserted = new AssertedFormulas(manager);
433
- const context = new Context(manager, {
434
- isMbqi: environment.isMbqi,
435
- mbqiMaxIterations: environment.mbqiMaxIterations,
436
- relevancyLevel: 2,
437
- });
438
- for (const definition of definitions) asserted.assertExpr(definition);
453
+ kernel.push();
439
454
  for (const [other, otherClause] of clauses.entries())
440
- if (other === index) asserted.assertExpr(manager.mkNot(clause));
441
- else if (!deleted.includes(other)) asserted.assertExpr(otherClause);
442
- // The context has no logic, so setup_default picks setup_unknown.
443
- context.setupContext(undefined, false, asserted);
444
- context.internalizeAssertions(asserted);
445
- if (!context.isInconsistent()) context.propagate();
446
- 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);
447
466
  }
448
467
  for (const index of deleted) goal.update(index, manager.trueExpr);
449
468
  goal.elimTrue();
450
- for (const expr of [...clauses, ...definitions]) manager.decRef(expr);
469
+ kernel.pop(2);
470
+ trail.reset();
451
471
  return [goal];
452
472
  };
453
473
 
@@ -490,16 +510,16 @@ const runSplitClause = (isLargest: boolean) => (goal: Goal) => {
490
510
  };
491
511
 
492
512
  const runDer = (manager: AstManager) => (goal: Goal) => {
493
- const rewriter = new DerRewriter(manager);
494
- const size = goal.forms.size;
495
- for (let index = 0; !goal.isInconsistent && index < size; index++) {
496
- const result = rewriter.rewrite(goal.forms.items[index]);
497
- goal.update(index, result);
498
- manager.decRef(result);
499
- }
500
- finishSimplifier(goal);
501
- rewriter.der.release();
502
- rewriter.release();
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
+ });
503
523
  return [goal];
504
524
  };
505
525
 
@@ -539,10 +559,16 @@ const runNnf = (manager: AstManager, params: TacticParams) => (goal: Goal) => {
539
559
  const nnf = new Nnf(manager, names, mode, getBool(params, "ignore_labels", false));
540
560
  const definitions = new RefVector(manager);
541
561
  const size = goal.forms.size;
542
- for (let index = 0; !goal.isInconsistent && index < size; index++) {
543
- const result = nnf.apply(goal.forms.items[index], definitions);
544
- goal.update(index, result);
545
- 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());
546
572
  }
547
573
  for (const definition of definitions.items) {
548
574
  if (goal.isInconsistent) break;
@@ -820,6 +846,7 @@ const NAMED_TACTICS = new Map<string, NamedTactic>([
820
846
  [
821
847
  "elim-uncnstr",
822
848
  {
849
+ isTrackingDependencies: true,
823
850
  descrs: getDescrs("", [
824
851
  ["max_memory", PARAM_UINT, UINT_MAX, true],
825
852
  ["max_steps", PARAM_UINT, UINT_MAX],
@@ -1323,7 +1350,7 @@ const NAMED_TACTICS = new Map<string, NamedTactic>([
1323
1350
  {
1324
1351
  descrs: new Map(),
1325
1352
  isRejectingUnknown: false,
1326
- build: (environment) => runQsat(environment.manager, QSAT_SAT),
1353
+ build: (environment) => runQsat(environment, QSAT_SAT),
1327
1354
  },
1328
1355
  ],
1329
1356
  [
@@ -1331,7 +1358,7 @@ const NAMED_TACTICS = new Map<string, NamedTactic>([
1331
1358
  {
1332
1359
  descrs: new Map(),
1333
1360
  isRejectingUnknown: false,
1334
- build: (environment) => runQsat(environment.manager, QSAT_QE),
1361
+ build: (environment) => runQsat(environment, QSAT_QE),
1335
1362
  },
1336
1363
  ],
1337
1364
  [
@@ -1339,7 +1366,7 @@ const NAMED_TACTICS = new Map<string, NamedTactic>([
1339
1366
  {
1340
1367
  descrs: new Map(),
1341
1368
  isRejectingUnknown: false,
1342
- build: (environment) => runQsat(environment.manager, QSAT_QE_REC),
1369
+ build: (environment) => runQsat(environment, QSAT_QE_REC),
1343
1370
  },
1344
1371
  ],
1345
1372
  [
@@ -1576,7 +1603,7 @@ const runOrElse = (tactics: Tactic[]) => (goal: Goal) => {
1576
1603
  try {
1577
1604
  return tactic(goal);
1578
1605
  } catch (error) {
1579
- if (!(error instanceof SmtTacticError)) throw error;
1606
+ if (!(error instanceof SmtTacticError || error instanceof SmtCanceledError)) throw error;
1580
1607
  }
1581
1608
  goal.resetAll();
1582
1609
  goal.copyFrom(original);
@@ -1957,13 +1984,14 @@ interface TacticCheck {
1957
1984
  model: ProtoModel | undefined;
1958
1985
  core: Dependency | undefined;
1959
1986
  reasonUnknown: string | undefined;
1987
+ isConversionCanceled: boolean;
1960
1988
  }
1961
1989
 
1962
1990
  // The port's declarations of division by zero leave out their domain; Z3's have two arguments.
1963
1991
  const DIVISION_BY_ZERO_DECLS = new Set([OP_DIV0, OP_IDIV0, OP_MOD0, OP_POWER0]);
1964
1992
 
1965
1993
  // A constant of an uninterpreted sort the model lacks puts its value in that sort's universe.
1966
- const applyDefinitions = (definitions: Definition[], model: ProtoModel) => {
1994
+ export const applyDefinitions = (definitions: readonly Definition[], model: ProtoModel) => {
1967
1995
  const manager = model.manager;
1968
1996
  const universe: number[] = [];
1969
1997
  let evaluator = new ModelEvaluator(manager, model);
@@ -2015,61 +2043,87 @@ const applyDefinitions = (definitions: Definition[], model: ProtoModel) => {
2015
2043
  return model;
2016
2044
  };
2017
2045
 
2046
+ const applyConverter = (entry: Goal["converters"][number], model: ProtoModel) => {
2047
+ if ("convert" in entry) return entry.convert(model);
2048
+ if ("definitions" in entry) return applyDefinitions(entry.definitions, model);
2049
+ model.unregisterDecl(entry.decl);
2050
+ return model;
2051
+ };
2052
+
2018
2053
  export const convertModel = (goal: Goal, model: ProtoModel) =>
2019
- goal.converters.reduceRight((converted, entry) => {
2020
- if ("convert" in entry) return entry.convert(converted);
2021
- if ("definitions" in entry) return applyDefinitions(entry.definitions, converted);
2022
- converted.unregisterDecl(entry.decl);
2023
- return converted;
2024
- }, model);
2025
-
2026
- const getConvertedModel = (goal: Goal) =>
2027
- convertModel(goal, goal.model?.copy() ?? new ProtoModel(goal.manager).mkModel());
2028
-
2029
- export const checkSatUsing = (tactic: Tactic, goal: Goal): TacticCheck => {
2030
- const undecided = { status: L_UNDEF, model: undefined, core: undefined };
2031
- const goals = (() => {
2054
+ goal.converters.reduceRight((converted, entry) => applyConverter(entry, converted), model);
2055
+
2056
+ const getConvertedModel = (goal: Goal) => {
2057
+ let model = goal.model?.copy() ?? new ProtoModel(goal.manager).mkModel();
2058
+ for (let index = goal.converters.length - 1; index >= 0; index--) {
2032
2059
  try {
2033
- return tactic(goal);
2060
+ model = applyConverter(goal.converters[index], model);
2034
2061
  } catch (error) {
2035
- if (error instanceof SmtTacticError || error instanceof SmtDefaultError) return error.message;
2036
- if (error instanceof SmtCanceledError) return undefined;
2037
- throw error;
2062
+ if (!(error instanceof SmtCanceledError)) throw error;
2063
+ return { model, isCanceled: true };
2038
2064
  }
2039
- })();
2065
+ }
2066
+ return { model, isCanceled: false };
2067
+ };
2068
+
2069
+ const getTacticCheck = (goal: Goal, goals: Goal[] | string | undefined): TacticCheck => {
2070
+ const undecided = {
2071
+ status: L_UNDEF,
2072
+ model: undefined,
2073
+ core: undefined,
2074
+ isConversionCanceled: false,
2075
+ };
2040
2076
  if (goals === undefined) return { ...undecided, reasonUnknown: undefined };
2041
2077
  if (typeof goals === "string") return { ...undecided, reasonUnknown: goals };
2042
- if (isDecidedSat(goals)) {
2043
- const model = getConvertedModel(goals[0]);
2078
+ if (isDecidedUnsat(goals))
2079
+ return { ...undecided, status: L_FALSE, core: goals[0].getDependency(0), reasonUnknown: "" };
2080
+ const isSat = isDecidedSat(goals);
2081
+ const converted =
2082
+ isSat ||
2083
+ (goal.isModelsEnabled &&
2084
+ goals.length > 0 &&
2085
+ (goals[0].model !== undefined || goals[0].converters.length > 0))
2086
+ ? getConvertedModel(goals[0])
2087
+ : undefined;
2088
+ const model = converted?.model;
2089
+ if (converted?.isCanceled === true)
2090
+ return { ...undecided, model, reasonUnknown: undefined, isConversionCanceled: true };
2091
+ if (isSat)
2044
2092
  return goal.manager.limit.inc()
2045
- ? { status: L_TRUE, model, core: undefined, reasonUnknown: "" }
2093
+ ? { ...undecided, status: L_TRUE, model, reasonUnknown: "" }
2046
2094
  : { ...undecided, model, reasonUnknown: "canceled" };
2047
- }
2048
- if (isDecidedUnsat(goals))
2049
- return {
2050
- status: L_FALSE,
2051
- model: undefined,
2052
- core: goals[0].getDependency(0),
2053
- reasonUnknown: "",
2054
- };
2055
2095
  return {
2056
2096
  ...undecided,
2057
- model:
2058
- goal.isModelsEnabled &&
2059
- goals.length > 0 &&
2060
- (goals[0].model !== undefined || goals[0].converters.length > 0)
2061
- ? getConvertedModel(goals[0])
2062
- : undefined,
2097
+ model,
2063
2098
  reasonUnknown:
2064
2099
  goals.length === 1 && goals[0].reasonUnknown !== "" ? goals[0].reasonUnknown : "unknown",
2065
2100
  };
2066
2101
  };
2067
2102
 
2103
+ export const checkSatUsing = (tactic: Tactic, goal: Goal) => {
2104
+ const goals = (() => {
2105
+ try {
2106
+ return tactic(goal);
2107
+ } catch (error) {
2108
+ if (error instanceof SmtTacticError || error instanceof SmtDefaultError) return error.message;
2109
+ if (error instanceof SmtCanceledError) return undefined;
2110
+ throw error;
2111
+ }
2112
+ })();
2113
+ try {
2114
+ return getTacticCheck(goal, goals);
2115
+ } finally {
2116
+ goal.reset();
2117
+ if (Array.isArray(goals)) for (const result of goals) result.reset();
2118
+ }
2119
+ };
2120
+
2068
2121
  export const applyTactic = (tactic: Tactic, goal: Goal) => {
2069
2122
  try {
2070
2123
  return tactic(goal);
2071
2124
  } catch (error) {
2072
- if (error instanceof SmtCanceledError) throw new SmtTacticError("canceled");
2125
+ if (error instanceof SmtCanceledError)
2126
+ throw new SmtTacticError(goal.manager.limit.getCancelMessage());
2073
2127
  throw error;
2074
2128
  }
2075
2129
  };
@@ -75,6 +75,7 @@ import {
75
75
  TRUE_LITERAL,
76
76
  } from "./literal";
77
77
  import { UnionFind } from "./lp/union-find";
78
+ import type { ProtoModel } from "./proto-model";
78
79
  import { Rewriter, TACTIC_REWRITER_OPTIONS } from "./rewriter";
79
80
  import { Theory } from "./theory";
80
81
 
@@ -247,6 +248,7 @@ export class TheoryBv extends Theory {
247
248
  private propQueue: number[] = [];
248
249
  private mergeAux: [number[], number[]] = [[], []];
249
250
  private bv2ints: Enode[] = [];
251
+ private model: ProtoModel | undefined;
250
252
 
251
253
  constructor(context: Context) {
252
254
  super(context, FAMILY_BV);
@@ -1193,8 +1195,16 @@ export class TheoryBv extends Theory {
1193
1195
  this.dropAll(clause);
1194
1196
  }
1195
1197
 
1198
+ initModel(model: ProtoModel) {
1199
+ this.model = model;
1200
+ }
1201
+
1196
1202
  mkValue(node: Enode) {
1203
+ const model = this.model;
1204
+ if (model === undefined) throw new SmtInvariantError("the model was not initialized");
1197
1205
  const thVar = this.getThVar(node);
1198
- return this.manager.mkBvNumeral(this.getFixedValue(thVar).value, this.getBvSize(thVar));
1206
+ const value = this.manager.mkBvNumeral(this.getFixedValue(thVar).value, this.getBvSize(thVar));
1207
+ model.registerValue(value);
1208
+ return value;
1199
1209
  }
1200
1210
  }
@@ -48,7 +48,7 @@ const CONVERTED_OPS = new Set([
48
48
  export const mkFpaConversion = (manager: AstManager) => {
49
49
  const theoryRewriter = new Rewriter(manager, {
50
50
  isEliminatingAnd: false,
51
- arith: { ...TACTIC_ARITH_OPTIONS, isArithIneqLhs: true },
51
+ arith: { ...TACTIC_ARITH_OPTIONS, isArithLhs: true },
52
52
  isRewritingPatterns: true,
53
53
  });
54
54
  const simp = new Rewriter(manager, {
@@ -177,6 +177,7 @@ export abstract class TheoryLraFinalCheck extends TheoryLraModel {
177
177
  const literals = lemma.ineqs.map((ineq) => negate(this.mkNlaLiteral(ineq)));
178
178
  this.resetEvidence();
179
179
  this.coreLiterals.push(...literals);
180
+ this.numConflicts++;
180
181
  for (const constraint of lemma.expl) this.setEvidence(constraint);
181
182
  const clause: Literal[] = [];
182
183
  for (const literal of this.coreLiterals) {
@@ -91,6 +91,7 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
91
91
  this.realOneVar = this.addConst(manager.mkRealNumeral(Rational.one));
92
92
  this.zeroVar = this.addConst(manager.mkNumeral(0n));
93
93
  this.realZeroVar = this.addConst(manager.mkRealNumeral(Rational.zero));
94
+ this.solver.settings.setRandomSeed(this.context.params.randomSeed ?? 0);
94
95
  }
95
96
 
96
97
  private addConst(expr: number) {
@@ -37,6 +37,7 @@ export abstract class TheoryLraPropagate extends TheoryLraBounds {
37
37
  private upperTerms: (TermBound | undefined)[] = [];
38
38
  protected isModelInitialized = false;
39
39
  private activeInfEpsConstraints: number[] = [];
40
+ protected numConflicts = 0;
40
41
 
41
42
  canPropagate() {
42
43
  return (
@@ -136,7 +137,8 @@ export abstract class TheoryLraPropagate extends TheoryLraBounds {
136
137
  }
137
138
 
138
139
  protected isPropagatingEqs() {
139
- return this.context.config.isArithPropagatingEqs;
140
+ const config = this.context.config;
141
+ return config.isArithPropagatingEqs && this.numConflicts < config.arithPropagationThreshold;
140
142
  }
141
143
 
142
144
  private propagateEqs(
@@ -302,6 +304,9 @@ export abstract class TheoryLraPropagate extends TheoryLraBounds {
302
304
  }
303
305
 
304
306
  private propagateBoundsWithLpSolver() {
307
+ const config = this.context.config;
308
+ if (!config.isArithBoundPropagating || this.numConflicts >= config.arithPropagationThreshold)
309
+ return;
305
310
  this.bp.init();
306
311
  this.bp.propagateBoundsForTouchedRows();
307
312
  if (this.context.checkCanceled()) return;
@@ -385,6 +390,7 @@ export abstract class TheoryLraPropagate extends TheoryLraBounds {
385
390
 
386
391
  protected setConflict() {
387
392
  this.resetEvidence();
393
+ this.numConflicts++;
388
394
  for (const constraint of this.explanation) this.setEvidence(constraint);
389
395
  this.context.setConflict(new TheoryJustification(this.id, this.coreLiterals, []), null);
390
396
  }
@@ -231,5 +231,6 @@ export class TheoryLra extends TheoryLraFinalCheck {
231
231
 
232
232
  initSearchEh() {
233
233
  this.restartPairs = [];
234
+ this.numConflicts = 0;
234
235
  }
235
236
  }
@@ -448,6 +448,7 @@ export const tseitinCnf = (manager: AstManager, goal: Goal) => {
448
448
  return;
449
449
  }
450
450
  while (frames.length > 0) {
451
+ manager.limit.checkpoint();
451
452
  const frame = frames[frames.length - 1];
452
453
  const isFirst = frame.isFirst;
453
454
  frame.isFirst = false;