tla-ts 0.0.10-dev.e3e5dd576 → 0.0.10-dev.e5c8dc315

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 (60) hide show
  1. package/dist/deciders.cjs +1 -1
  2. package/dist/deciders.js +1 -1
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/parallel-worker.cjs +1 -1
  6. package/dist/parallel-worker.js +1 -1
  7. package/dist/prove.cjs +10 -10
  8. package/dist/prove.js +57 -57
  9. package/dist/run.cjs +26 -26
  10. package/dist/run.js +32 -32
  11. package/dist/transfer.cjs +94 -94
  12. package/dist/transfer.js +83 -83
  13. package/package.json +1 -1
  14. package/src/ast.ts +16 -0
  15. package/src/check-trace.ts +43 -42
  16. package/src/check.ts +2 -1
  17. package/src/coverage.ts +66 -18
  18. package/src/environment.ts +34 -30
  19. package/src/evaluate.ts +57 -39
  20. package/src/instances.ts +17 -14
  21. package/src/liveness.ts +4 -0
  22. package/src/prover/smt/solver/ackermannize-bv-tactic.ts +3 -2
  23. package/src/prover/smt/solver/bit-blast-tactic.ts +1 -1
  24. package/src/prover/smt/solver/bv1-blast.ts +1 -1
  25. package/src/prover/smt/solver/card2bv.ts +1 -1
  26. package/src/prover/smt/solver/ctx-simplify.ts +8 -2
  27. package/src/prover/smt/solver/diff-neq.ts +8 -6
  28. package/src/prover/smt/solver/dt2bv-tactic.ts +10 -8
  29. package/src/prover/smt/solver/elim-uncnstr.ts +26 -20
  30. package/src/prover/smt/solver/eq2bv-tactic.ts +15 -6
  31. package/src/prover/smt/solver/fd-solver.ts +1 -1
  32. package/src/prover/smt/solver/fix-dl-var.ts +1 -1
  33. package/src/prover/smt/solver/fm-tactic.ts +9 -7
  34. package/src/prover/smt/solver/fpa2bv-tactic.ts +1 -1
  35. package/src/prover/smt/solver/lia2pb.ts +1 -1
  36. package/src/prover/smt/solver/nlqsat.ts +1 -0
  37. package/src/prover/smt/solver/normalize-bounds.ts +2 -2
  38. package/src/prover/smt/solver/occf.ts +1 -1
  39. package/src/prover/smt/solver/pb2bv-tactic.ts +9 -3
  40. package/src/prover/smt/solver/purify-arith.ts +51 -49
  41. package/src/prover/smt/solver/reduce-args.ts +2 -2
  42. package/src/prover/smt/solver/sat/goal2sat.ts +12 -2
  43. package/src/prover/smt/solver/sat/inc-sat-solver.ts +21 -5
  44. package/src/prover/smt/solver/sat/sat-tactic.ts +51 -32
  45. package/src/prover/smt/solver/sat/sat2goal.ts +4 -3
  46. package/src/prover/smt/solver/smtlib-script.ts +6 -4
  47. package/src/prover/smt/solver/solver.ts +0 -1
  48. package/src/prover/smt/solver/tactic.ts +40 -5
  49. package/src/prover/smt/solver/theory-lra-propagate.ts +1 -0
  50. package/src/prover/smt/solver/tseitin-cnf.ts +14 -5
  51. package/src/resolve.ts +54 -28
  52. package/src/runtime.ts +14 -1
  53. package/src/sany/generator-proofs.ts +1 -0
  54. package/src/sany/selectors.ts +1 -0
  55. package/src/search.ts +3 -1
  56. package/src/simulate.ts +26 -17
  57. package/src/spec-description.ts +8 -2
  58. package/src/subexpressions.ts +138 -45
  59. package/src/successors.ts +13 -7
  60. package/src/tlc/replay.ts +80 -3
package/src/instances.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import {
2
2
  getChildren,
3
+ getFunctionConstruction,
3
4
  getReferencedName,
4
5
  isLocallyResolved,
5
6
  type Bound,
6
7
  type BoundPattern,
7
8
  type Definition,
8
9
  type Expression,
10
+ type FunctionDefinition,
9
11
  type Instance,
10
12
  type Module,
11
13
  type OperatorParam,
@@ -775,7 +777,7 @@ const substitute = (
775
777
  args,
776
778
  resolution: LOCAL_RESOLUTION,
777
779
  },
778
- location: expression.location,
780
+ location: { line: expression.location.line, column: expression.location.column },
779
781
  };
780
782
  }
781
783
  if (replacement) {
@@ -817,11 +819,17 @@ const substitute = (
817
819
  return renameNames(mapped, bound, rename);
818
820
  };
819
821
 
820
- const withInstanceParams = (
821
- definition: Definition,
822
- params: OperatorParam[],
823
- location: SourceLocation,
824
- ): Definition => {
822
+ export const getFunctionBody = (definition: FunctionDefinition): Expression =>
823
+ definition.isSelfReferential
824
+ ? {
825
+ kind: "Let",
826
+ definitions: [definition],
827
+ body: createLocalIdentifier(definition.name, definition.location),
828
+ location: { line: definition.location.line, column: definition.location.column },
829
+ }
830
+ : getFunctionConstruction(definition, true);
831
+
832
+ export const withInstanceParams = (definition: Definition, params: OperatorParam[]): Definition => {
825
833
  if (params.length === 0) return definition;
826
834
  if (definition.kind === "Operator") {
827
835
  return { ...definition, params: [...params, ...definition.params] };
@@ -830,12 +838,7 @@ const withInstanceParams = (
830
838
  kind: "Operator",
831
839
  name: definition.name,
832
840
  params,
833
- body: {
834
- kind: "Let",
835
- definitions: [definition],
836
- body: createLocalIdentifier(definition.name, location),
837
- location,
838
- },
841
+ body: getFunctionBody(definition),
839
842
  isLocal: definition.isLocal,
840
843
  isRecursive: false,
841
844
  location: definition.location,
@@ -884,7 +887,7 @@ const copyDefinition = (rewrite: Rewrite, key: string): string => {
884
887
  // TLC's call stack holds the SubstInNode an instance puts around each definition it copies.
885
888
  if (frame)
886
889
  substitutionFrames.set(body, [frame, ...(substitutionFrames.get(definition.body) ?? [])]);
887
- return withInstanceParams({ ...mapped, body }, instantiation.params, definition.location);
890
+ return withInstanceParams({ ...mapped, body }, instantiation.params);
888
891
  });
889
892
  };
890
893
 
@@ -916,7 +919,7 @@ export const createInstantiation = (instantiation: Instantiation) => {
916
919
  const definition = instantiation.getDefinition(key);
917
920
  if (!definition) return key;
918
921
  return instantiation.addDefinition(key, definition.name, () =>
919
- withInstanceParams(definition, instantiation.params, definition.location),
922
+ withInstanceParams(definition, instantiation.params),
920
923
  );
921
924
  },
922
925
  };
package/src/liveness.ts CHANGED
@@ -27,6 +27,7 @@ import {
27
27
  type Scope,
28
28
  type Thunk,
29
29
  } from "./evaluate";
30
+ import { letDefinitions } from "./coverage";
30
31
  import { mapChildren } from "./instances";
31
32
  import { ACTION_LEVEL, CONSTANT_LEVEL, TEMPORAL_LEVEL, VARIABLE_LEVEL } from "./levels";
32
33
  import { isEnabled } from "./successors";
@@ -338,6 +339,9 @@ export const bindLetDefinitions = (
338
339
  );
339
340
  for (let current = bound; current && current !== scope; current = current.parent) {
340
341
  if (current.binding.kind === "Thunk") definitionThunks.add(current.binding);
342
+ const name = current.name;
343
+ const definition = expression.definitions.find((item) => item.name === name);
344
+ if (definition) letDefinitions.set(current, definition);
341
345
  }
342
346
  return bound;
343
347
  };
@@ -28,7 +28,8 @@ export const runAckermannizeBv =
28
28
  return [goal];
29
29
  }
30
30
  const info = lackr.info;
31
- result.addModelConversion((model) => convertAckrModel(info, undefined, model));
31
+ if (goal.isModelsEnabled)
32
+ result.addModelConversion((model) => convertAckrModel(info, undefined, model));
32
33
  result.depth++;
33
34
  lackr.release(true);
34
35
  return [result];
@@ -50,7 +51,7 @@ export const createQfufbvAckrTactic =
50
51
  if (status === L_FALSE) result.assert(manager.falseExpr);
51
52
  if (status === L_UNDEF) goal.depth++;
52
53
  const model = lackr.model;
53
- if (status === L_TRUE && model !== undefined) {
54
+ if (goal.isModelsEnabled && status === L_TRUE && model !== undefined) {
54
55
  model.incRef();
55
56
  const info = lackr.info;
56
57
  result.addModelConversion((converted) => convertAckrModel(info, model, converted));
@@ -585,7 +585,7 @@ export const runBitBlast =
585
585
  isChanged = true;
586
586
  goal.update(index, rewritten, goal.getDependency(index));
587
587
  }
588
- if (isChanged && rewriter.keys.length > keyPos) {
588
+ if (isChanged && goal.isModelsEnabled && rewriter.keys.length > keyPos) {
589
589
  const const2bits = new ObjMap<number>((decl) => manager.getDeclHash(decl));
590
590
  for (let index = keyPos; index < rewriter.keys.length; index++)
591
591
  const2bits.set(rewriter.keys[index], rewriter.values.items[index]);
@@ -199,7 +199,7 @@ export const runBv1Blast = (manager: AstManager) => (goal: Goal) => {
199
199
  return {
200
200
  reduce: () => {
201
201
  state.rewriteEach((form) => rewriter.rewrite(form));
202
- if (rewriter.newbits.length === 0) return;
202
+ if (rewriter.newbits.length === 0 || !goal.isModelsEnabled) return;
203
203
  const definitions: Definition[] = rewriter.newbits.map((decl) => ({ decl, def: -1 }));
204
204
  for (const [decl, bits] of rewriter.const2bits) definitions.push({ decl, def: bits });
205
205
  goal.addDefinitions(definitions);
@@ -93,7 +93,7 @@ export const checkPbFree = (manager: AstManager, form: number) => {
93
93
  };
94
94
 
95
95
  // The port has no encoding to rewrite to, but the walk still counts its steps of the limit.
96
- class CardPbRewriter extends RewriterTpl {
96
+ export class CardPbRewriter extends RewriterTpl {
97
97
  isRewritingPatterns() {
98
98
  return false;
99
99
  }
@@ -50,9 +50,15 @@ class CtxSimplifier {
50
50
  const manager = this.manager;
51
51
  this.depth = 0;
52
52
  const result = this.simplify(goal.forms.items[index]);
53
- if (isAsserted && !manager.isTrue(result) && !manager.isFalse(result))
53
+ const dependency = goal.getDependency(index);
54
+ if (
55
+ isAsserted &&
56
+ !manager.isTrue(result) &&
57
+ !manager.isFalse(result) &&
58
+ dependency === undefined
59
+ )
54
60
  this.assertExpr(result, false);
55
- goal.update(index, result);
61
+ goal.update(index, result, dependency);
56
62
  manager.decRef(result);
57
63
  }
58
64
 
@@ -193,12 +193,14 @@ export const diffNeq = (manager: AstManager, goal: Goal, maxK: number) => {
193
193
  const solver = new DiffNeq(manager, maxK);
194
194
  solver.compile(goal);
195
195
  if (solver.search()) {
196
- const model = solver.mkModel();
197
- model.incRef();
198
- goal.addModelConversion((converted) => {
199
- for (const [decl, value] of model.constInterps) converted.registerConst(decl, value);
200
- return converted;
201
- });
196
+ if (goal.isModelsEnabled) {
197
+ const model = solver.mkModel();
198
+ model.incRef();
199
+ goal.addModelConversion((converted) => {
200
+ for (const [decl, value] of model.constInterps) converted.registerConst(decl, value);
201
+ return converted;
202
+ });
203
+ }
202
204
  goal.reset();
203
205
  } else goal.assert(manager.falseExpr);
204
206
  goal.depth++;
@@ -18,7 +18,6 @@ import { mkBvApp } from "./bv-decl-plugin";
18
18
  import {
19
19
  getConstructorIndex,
20
20
  getDatatypeConstructors,
21
- getDatatypeDef,
22
21
  getNumConstructors,
23
22
  getRecognizerConstructor,
24
23
  } from "./datatype-decl-plugin";
@@ -28,12 +27,15 @@ import { ObjMap } from "./hashtable";
28
27
  import { RefVector } from "./ref-vector";
29
28
  import { RewriterTpl } from "./rewriter-tpl";
30
29
 
31
- const isEnumSort = (manager: AstManager, sort: number) =>
32
- manager.isDatatypeSort(sort) &&
33
- (getDatatypeDef(manager, sort)?.constructors.every(
34
- (constructor) => constructor.accessors.length === 0,
35
- ) ??
36
- false);
30
+ // Deviation from Z3: Z3 5.3.2 takes a failed datatype for an empty enumeration and crashes.
31
+ const isEnumSort = (manager: AstManager, sort: number) => {
32
+ if (!manager.isDatatypeSort(sort)) return false;
33
+ const constructors = getDatatypeConstructors(manager, sort);
34
+ return (
35
+ constructors.length > 0 &&
36
+ constructors.every((constructor) => manager.funcDecls[constructor].domain.length === 0)
37
+ );
38
+ };
37
39
 
38
40
  const getEnumBvSize = (manager: AstManager, sort: number) => {
39
41
  const numConstructors = getNumConstructors(manager, sort);
@@ -276,7 +278,7 @@ export const runEnum2Bv = (
276
278
  const next = rewriter.rewrite(goal.forms.items[index]);
277
279
  release(manager, rewritten);
278
280
  rewritten = next;
279
- goal.update(index, rewritten);
281
+ goal.update(index, rewritten, goal.getDependency(index));
280
282
  });
281
283
  const bounds = new RefVector(manager);
282
284
  for (const bound of rewriter.bounds.items) bounds.push(bound);
@@ -110,6 +110,7 @@ class UncnstrRewriter extends RewriterTpl {
110
110
  constructor(
111
111
  manager: AstManager,
112
112
  private isProofsEnabled: boolean,
113
+ private isProducingModels: boolean,
113
114
  ) {
114
115
  super(manager);
115
116
  this.terms = new RefVector(manager);
@@ -130,13 +131,14 @@ class UncnstrRewriter extends RewriterTpl {
130
131
  const cached = this.cache.get(key);
131
132
  if (cached !== undefined) return { fresh: cached, isNew: false };
132
133
  const fresh = this.pin(manager.mkFreshConst(null, sort));
133
- this.entries.push({ decl: manager.decls[fresh], def: -1 });
134
+ if (this.isProducingModels) this.entries.push({ decl: manager.decls[fresh], def: -1 });
134
135
  this.cache.set(key, fresh);
135
136
  return { fresh, isNew: true };
136
137
  }
137
138
 
138
139
  private addDef(variable: number, def: number) {
139
- this.entries.push({ decl: this.manager.decls[variable], def: this.pin(def) });
140
+ if (this.isProducingModels)
141
+ this.entries.push({ decl: this.manager.decls[variable], def: this.pin(def) });
140
142
  }
141
143
 
142
144
  private addDefs(args: number[], fresh: number, identity: number) {
@@ -204,6 +206,7 @@ class UncnstrRewriter extends RewriterTpl {
204
206
  if (!this.isFullyInterp(sort)) return -1;
205
207
  const size = manager.getSortSize(sort);
206
208
  if (size !== SORT_SIZE_INFINITE && size !== SORT_SIZE_VERY_BIG && size <= 1n) return -1;
209
+ if (!this.isProducingModels) return this.mkFreshFor(decl, args, SORT_BOOL).fresh;
207
210
  const diff = this.mkDiff(term);
208
211
  if (diff === -1) return -1;
209
212
  const found = this.mkFreshFor(decl, args, SORT_BOOL);
@@ -231,7 +234,8 @@ class UncnstrRewriter extends RewriterTpl {
231
234
  case OP_NOT: {
232
235
  if (!this.isUncnstr(args[0])) return -1;
233
236
  const found = this.mkFreshFor(decl, args, sort);
234
- if (found.isNew) this.addDef(args[0], manager.mkApp(OP_NOT, [found.fresh], SORT_BOOL));
237
+ if (found.isNew && this.isProducingModels)
238
+ this.addDef(args[0], manager.mkApp(OP_NOT, [found.fresh], SORT_BOOL));
235
239
  return found.fresh;
236
240
  }
237
241
  case OP_AND:
@@ -240,7 +244,7 @@ class UncnstrRewriter extends RewriterTpl {
240
244
  const found = this.mkFreshFor(decl, args, sort);
241
245
  const identity =
242
246
  manager.funcDecls[decl].op === OP_AND ? manager.trueExpr : manager.falseExpr;
243
- if (found.isNew) this.addDefs(args, found.fresh, identity);
247
+ if (found.isNew && this.isProducingModels) this.addDefs(args, found.fresh, identity);
244
248
  return found.fresh;
245
249
  }
246
250
  case OP_EQ:
@@ -255,7 +259,7 @@ class UncnstrRewriter extends RewriterTpl {
255
259
  const index = args.findIndex((arg) => this.isUncnstr(arg));
256
260
  if (index === -1) return -1;
257
261
  const found = this.mkFreshFor(decl, args, sort);
258
- if (!found.isNew) return found.fresh;
262
+ if (!found.isNew || !this.isProducingModels) return found.fresh;
259
263
  const rest = args.filter((_value, other) => other !== index);
260
264
  const restExpr =
261
265
  rest.length === 0
@@ -285,7 +289,7 @@ class UncnstrRewriter extends RewriterTpl {
285
289
  const variable = isFirst ? first : second;
286
290
  const term = isFirst ? second : first;
287
291
  const found = this.mkFreshFor(decl, args, SORT_BOOL);
288
- if (!found.isNew) return found.fresh;
292
+ if (!found.isNew || !this.isProducingModels) return found.fresh;
289
293
  const argSort = manager.sorts[first];
290
294
  const step = this.mkNumeral(isLe ? Rational.one : Rational.minusOne, argSort);
291
295
  const next = this.pin(manager.mkApp(OP_ADD, [term, step], argSort));
@@ -295,7 +299,7 @@ class UncnstrRewriter extends RewriterTpl {
295
299
  if (op !== OP_MUL) return -1;
296
300
  if (args.every((arg) => this.isUncnstr(arg))) {
297
301
  const found = this.mkFreshFor(decl, args, sort);
298
- if (found.isNew)
302
+ if (found.isNew && this.isProducingModels)
299
303
  this.addDefs(args, found.fresh, this.mkNumeral(Rational.one, manager.sorts[args[0]]));
300
304
  return found.fresh;
301
305
  }
@@ -309,7 +313,7 @@ class UncnstrRewriter extends RewriterTpl {
309
313
  const value = manager.getRationalValue(args[0]);
310
314
  if (value.isZero()) return -1;
311
315
  const found = this.mkFreshFor(decl, args, sort);
312
- if (found.isNew)
316
+ if (found.isNew && this.isProducingModels)
313
317
  this.addDef(
314
318
  args[1],
315
319
  manager.mkApp(
@@ -340,7 +344,7 @@ class UncnstrRewriter extends RewriterTpl {
340
344
  const found = this.mkFreshFor(decl, args, SORT_BOOL);
341
345
  const isBound = this.pin(manager.mkEq(term, this.pin(manager.mkBvNumeral(bound, width))));
342
346
  const result = this.pin(manager.mkOr([found.fresh, isBound]));
343
- if (found.isNew) {
347
+ if (found.isNew && this.isProducingModels) {
344
348
  const one = this.pin(manager.mkBvNumeral(1n, width));
345
349
  const next = this.pin(mkBvApp(manager, isFirst ? OP_BADD : OP_BSUB, [term, one]));
346
350
  this.addDef(variable, manager.mkApp(OP_ITE, [result, term, next], manager.sorts[term]));
@@ -359,7 +363,7 @@ class UncnstrRewriter extends RewriterTpl {
359
363
  const width = manager.getBvSize(manager.sorts[args[0]]);
360
364
  if (isAllUncnstr) {
361
365
  const found = this.mkFreshFor(decl, args, sort);
362
- if (found.isNew)
366
+ if (found.isNew && this.isProducingModels)
363
367
  this.addDefs(args, found.fresh, this.pin(manager.mkBvNumeral(1n, width)));
364
368
  return found.fresh;
365
369
  }
@@ -368,7 +372,7 @@ class UncnstrRewriter extends RewriterTpl {
368
372
  const inverse = getMultInverse(manager.getBvNumeralValue(args[0]), width);
369
373
  if (inverse === undefined) return -1;
370
374
  const found = this.mkFreshFor(decl, args, sort);
371
- if (found.isNew)
375
+ if (found.isNew && this.isProducingModels)
372
376
  this.addDef(
373
377
  args[1],
374
378
  mkBvApp(manager, OP_BMUL, [this.pin(manager.mkBvNumeral(inverse, width)), found.fresh]),
@@ -381,7 +385,7 @@ class UncnstrRewriter extends RewriterTpl {
381
385
  case OP_BUDIV_I: {
382
386
  if (!isAllUncnstr) return -1;
383
387
  const found = this.mkFreshFor(decl, args, sort);
384
- if (found.isNew) {
388
+ if (found.isNew && this.isProducingModels) {
385
389
  this.addDef(args[0], found.fresh);
386
390
  this.addDef(args[1], manager.mkBvNumeral(1n, manager.getBvSize(manager.sorts[args[0]])));
387
391
  }
@@ -393,7 +397,7 @@ class UncnstrRewriter extends RewriterTpl {
393
397
  case OP_CONCAT: {
394
398
  if (!isAllUncnstr) return -1;
395
399
  const found = this.mkFreshFor(decl, args, sort);
396
- if (!found.isNew) return found.fresh;
400
+ if (!found.isNew || !this.isProducingModels) return found.fresh;
397
401
  let low = 0;
398
402
  for (let index = args.length - 1; index >= 0; index--) {
399
403
  const width = manager.getBvSize(manager.sorts[args[index]]);
@@ -409,7 +413,7 @@ class UncnstrRewriter extends RewriterTpl {
409
413
  const arg = args[0];
410
414
  if (!this.isUncnstr(arg)) return -1;
411
415
  const found = this.mkFreshFor(decl, args, sort);
412
- if (!found.isNew) return found.fresh;
416
+ if (!found.isNew || !this.isProducingModels) return found.fresh;
413
417
  const [high, low] = manager.funcDecls[decl].parameters;
414
418
  const width = manager.getBvSize(manager.sorts[arg]);
415
419
  if (width === high - low + 1) {
@@ -427,13 +431,14 @@ class UncnstrRewriter extends RewriterTpl {
427
431
  case OP_BNOT: {
428
432
  if (!this.isUncnstr(args[0])) return -1;
429
433
  const found = this.mkFreshFor(decl, args, sort);
430
- if (found.isNew) this.addDef(args[0], manager.mkApp(decl, [found.fresh], sort));
434
+ if (found.isNew && this.isProducingModels)
435
+ this.addDef(args[0], manager.mkApp(decl, [found.fresh], sort));
431
436
  return found.fresh;
432
437
  }
433
438
  case OP_BOR: {
434
439
  if (!isAllUncnstr) return -1;
435
440
  const found = this.mkFreshFor(decl, args, sort);
436
- if (found.isNew)
441
+ if (found.isNew && this.isProducingModels)
437
442
  this.addDefs(
438
443
  args,
439
444
  found.fresh,
@@ -451,7 +456,7 @@ class UncnstrRewriter extends RewriterTpl {
451
456
  const op = manager.funcDecls[decl].op;
452
457
  if (op === OP_SELECT && this.isUncnstr(args[0])) {
453
458
  const found = this.mkFreshFor(decl, args, sort);
454
- if (found.isNew)
459
+ if (found.isNew && this.isProducingModels)
455
460
  this.addDef(
456
461
  args[0],
457
462
  mkArrayApp(manager, OP_CONST_ARRAY, [found.fresh], [manager.sorts[args[0]]]),
@@ -461,7 +466,7 @@ class UncnstrRewriter extends RewriterTpl {
461
466
  if (op !== OP_STORE || !this.isUncnstr(args[0]) || !this.isUncnstr(args[args.length - 1]))
462
467
  return -1;
463
468
  const found = this.mkFreshFor(decl, args, sort);
464
- if (found.isNew) {
469
+ if (found.isNew && this.isProducingModels) {
465
470
  this.addDef(args[args.length - 1], mkArrayApp(manager, OP_SELECT, args.slice(0, -1)));
466
471
  this.addDef(args[0], found.fresh);
467
472
  }
@@ -472,6 +477,7 @@ class UncnstrRewriter extends RewriterTpl {
472
477
  private processDatatype(decl: number, args: number[], sort: number) {
473
478
  const manager = this.manager;
474
479
  if (manager.funcDecls[decl].op !== OP_DT_ACCESSOR || !this.isUncnstr(args[0])) return -1;
480
+ if (!this.isProducingModels) return this.mkFreshFor(decl, args, sort).fresh;
475
481
  const constructor = getAccessorConstructor(manager, decl);
476
482
  const domain = manager.funcDecls[constructor].domain;
477
483
  if (!domain.every((argSort) => this.isFullyInterp(argSort))) return -1;
@@ -510,7 +516,7 @@ export const elimUncnstr = (manager: AstManager, goal: Goal, bodies: RefVector)
510
516
  const vars = collectUnconstrained(manager, goal);
511
517
  const disabled = disableQuantified(manager, goal, bodies);
512
518
  if (vars.size === 0 || manager.hasRecDefs) return;
513
- const rewriter = new UncnstrRewriter(manager, goal.isProofsEnabled);
519
+ const rewriter = new UncnstrRewriter(manager, goal.isProofsEnabled, goal.isModelsEnabled);
514
520
  rewriter.vars = vars;
515
521
  rewriter.disabled = disabled;
516
522
  let isModified = true;
@@ -535,7 +541,7 @@ export const elimUncnstr = (manager: AstManager, goal: Goal, bodies: RefVector)
535
541
  rewriter.vars = collectUnconstrained(manager, goal);
536
542
  start = rewriter.vars.size === 0 ? size : 0;
537
543
  }
538
- goal.addDefinitions(rewriter.entries);
544
+ if (goal.isModelsEnabled) goal.addDefinitions(rewriter.entries);
539
545
  rewriter.release();
540
546
  rewriter.terms.reset();
541
547
  goal.depth++;
@@ -11,6 +11,7 @@ import {
11
11
  import { BoundManager } from "./bound-manager";
12
12
  import { mkBvApp } from "./bv-decl-plugin";
13
13
  import type { Goal } from "./goal";
14
+ import { ObjMap } from "./hashtable";
14
15
  import { FuncInterp, ProtoModel } from "./proto-model";
15
16
  import { Rational } from "./rational";
16
17
  import { RefVector } from "./ref-vector";
@@ -88,11 +89,12 @@ export const createEq2BvTactic = (manager: AstManager) => (goal: Goal) => {
88
89
  const bounds = new BoundManager(manager);
89
90
  const trail = new RefVector(manager);
90
91
  const fd = new Map<number, number>();
91
- const max = new Map<number, Rational>();
92
+ const max = new ObjMap<Rational>((expr) => manager.hashes[expr]);
92
93
  const nonFd = new Set<number>();
93
94
  const hasEq = new Set<number>();
94
95
  const converter: BvModelConverter = { bvToInt: new Map(), vars: [], values: [] };
95
- for (const form of goal.forms.items) bounds.add(form);
96
+ for (let index = 0; index < goal.forms.size; index++)
97
+ bounds.add(goal.forms.items[index], goal.getDependency(index));
96
98
  if (bounds.isInconsistent() || goal.isProofsEnabled) {
97
99
  goal.depth++;
98
100
  return [goal];
@@ -147,7 +149,7 @@ export const createEq2BvTactic = (manager: AstManager) => (goal: Goal) => {
147
149
  }
148
150
  };
149
151
  for (const form of goal.forms.items) collectFd(form);
150
- for (const variable of max.keys()) if (nonFd.has(variable)) max.delete(variable);
152
+ for (const variable of [...max.keys()].filter((key) => nonFd.has(key))) max.delete(variable);
151
153
  for (const [variable, maximum] of max) {
152
154
  const upper = bounds.uppers.get(variable);
153
155
  const lower = bounds.lowers.get(variable);
@@ -192,19 +194,26 @@ export const createEq2BvTactic = (manager: AstManager) => (goal: Goal) => {
192
194
  continue;
193
195
  }
194
196
  const rewritten = rewriter.rewrite(form);
195
- if (rewritten !== form) goal.update(index, rewritten);
197
+ if (rewritten !== form) goal.update(index, rewritten, goal.getDependency(index));
196
198
  manager.decRef(rewritten);
197
199
  }
198
200
  rewriter.release();
201
+ // Deviation from Z3: Z3 5.3.2 frees the bound dependencies above, then reads them and crashes.
199
202
  for (const variable of max.keys()) {
200
203
  const bv = fd.get(variable) as number;
201
204
  const width = manager.getBvSize(manager.sorts[bv]);
202
205
  const lower = bounds.lowers.get(variable);
203
206
  const upper = bounds.uppers.get(variable);
204
207
  if (lower !== undefined && !lower.value.isNegative())
205
- goal.assert(mkBvApp(manager, OP_ULEQ, [manager.mkBvNumeral(lower.value.num, width), bv]));
208
+ goal.assert(
209
+ mkBvApp(manager, OP_ULEQ, [manager.mkBvNumeral(lower.value.num, width), bv]),
210
+ bounds.lowerDependencies.get(variable),
211
+ );
206
212
  if (upper !== undefined && !upper.value.isNegative())
207
- goal.assert(mkBvApp(manager, OP_ULEQ, [bv, manager.mkBvNumeral(upper.value.num, width)]));
213
+ goal.assert(
214
+ mkBvApp(manager, OP_ULEQ, [bv, manager.mkBvNumeral(upper.value.num, width)]),
215
+ bounds.upperDependencies.get(variable),
216
+ );
208
217
  }
209
218
  for (const decl of converter.vars) manager.incDeclRef(decl);
210
219
  for (const entry of converter.bvToInt) {
@@ -537,7 +537,7 @@ export class FdSolver {
537
537
 
538
538
  getModel() {
539
539
  if (this.model !== undefined) return this.model;
540
- const model = this.solver.getModel();
540
+ const model = this.solver.mkModel();
541
541
  if (model === null) return undefined;
542
542
  const converted = this.converter.length > 0 ? applyDefinitions(this.converter, model) : model;
543
543
  converted.incRef();
@@ -132,7 +132,7 @@ export const fixDlVar = (manager: AstManager, goal: Goal, options: RewriterOptio
132
132
  if (variable === -1) return;
133
133
  const zero = manager.mkNumeralOfSort(Rational.zero, manager.sorts[variable]);
134
134
  manager.incRef(zero);
135
- goal.addDefinitions([{ decl: manager.decls[variable], def: zero }]);
135
+ if (goal.isModelsEnabled) goal.addDefinitions([{ decl: manager.decls[variable], def: zero }]);
136
136
  const rewriter = new Rewriter(manager, options);
137
137
  rewriter.setSubstitution(new Map([[variable, zero]]));
138
138
  const size = goal.forms.size;
@@ -527,12 +527,14 @@ class Fm {
527
527
  }
528
528
 
529
529
  private markConstraintsDead(variable: number) {
530
- const clauses = new RefVector(this.manager);
531
- for (const constraint of [...this.lowers[variable], ...this.uppers[variable]])
532
- clauses.push(this.toExpr(constraint));
533
- const decl = this.manager.decls[this.var2expr.items[variable]];
534
- this.manager.incDeclRef(decl);
535
- this.converter.push({ decl, clauses });
530
+ if (this.goal.isModelsEnabled) {
531
+ const clauses = new RefVector(this.manager);
532
+ for (const constraint of [...this.lowers[variable], ...this.uppers[variable]])
533
+ clauses.push(this.toExpr(constraint));
534
+ const decl = this.manager.decls[this.var2expr.items[variable]];
535
+ this.manager.incDeclRef(decl);
536
+ this.converter.push({ decl, clauses });
537
+ }
536
538
  for (const constraint of this.lowers[variable]) constraint.isDead = true;
537
539
  for (const constraint of this.uppers[variable]) constraint.isDead = true;
538
540
  }
@@ -878,7 +880,7 @@ export const fm = (manager: AstManager, goal: Goal, options: FmOptions) => {
878
880
  const eliminator = new Fm(manager, goal, options);
879
881
  const isConsistent = eliminator.run();
880
882
  eliminator.release();
881
- if (!isConsistent) return;
883
+ if (!isConsistent || !goal.isModelsEnabled) return;
882
884
  const converter = new FmModelConverter(manager, eliminator.converter);
883
885
  goal.addModelConversion((model) => converter.convert(model));
884
886
  };
@@ -65,7 +65,7 @@ export const runFpa2Bv = (manager: AstManager) => (goal: Goal) => {
65
65
  goal.update(index, result, goal.getDependency(index));
66
66
  manager.decRef(result);
67
67
  }
68
- goal.addModelConversion((model) => convertModel(converter, model));
68
+ if (goal.isModelsEnabled) goal.addModelConversion((model) => convertModel(converter, model));
69
69
  goal.depth++;
70
70
  for (const assertion of converter.extraAssertions.items) goal.assert(assertion);
71
71
  rewriter.release();
@@ -149,6 +149,6 @@ export const lia2pb = (manager: AstManager, goal: Goal, options: Lia2PbOptions)
149
149
  }
150
150
  rewriter.release();
151
151
  goal.depth++;
152
- goal.addDefinitions(definitions);
152
+ if (goal.isModelsEnabled) goal.addDefinitions(definitions);
153
153
  terms.reset();
154
154
  };
@@ -463,6 +463,7 @@ class Nlqsat {
463
463
  goal.assert(manager.falseExpr);
464
464
  return [goal];
465
465
  }
466
+ if (!goal.isModelsEnabled) return [goal];
466
467
  goal.model = this.mkModel();
467
468
  if (this.divs.length > 0) goal.addDefinitions([{ decl: OP_DIV0, def: this.getDiv0Body() }]);
468
469
  return [goal];
@@ -43,11 +43,11 @@ export const normalizeBounds = (
43
43
  rewriter.setSubstitution(substitution);
44
44
  for (let index = 0; !goal.isInconsistent && index < goal.forms.size; index++) {
45
45
  const rewritten = rewriter.rewrite(goal.forms.items[index]);
46
- goal.update(index, rewritten);
46
+ goal.update(index, rewritten, goal.getDependency(index));
47
47
  manager.decRef(rewritten);
48
48
  }
49
49
  rewriter.release();
50
- goal.addDefinitions(definitions);
50
+ if (goal.isModelsEnabled) goal.addDefinitions(definitions);
51
51
  terms.reset();
52
52
  goal.depth++;
53
53
  };
@@ -90,7 +90,7 @@ export const occf = (manager: AstManager, goal: Goal) => {
90
90
  else literals.push(mkAuxLit(literal));
91
91
  }
92
92
  if (keep !== undefined) literals.push(keep);
93
- goal.update(index, pin(manager.mkOr(literals)));
93
+ goal.update(index, pin(manager.mkOr(literals)), goal.getDependency(index));
94
94
  }
95
95
  pinned.reset();
96
96
  goal.depth++;
@@ -23,7 +23,7 @@ import {
23
23
  } from "./ast";
24
24
  import { BoundManager } from "./bound-manager";
25
25
  import { mkBvApp } from "./bv-decl-plugin";
26
- import { checkPbFree } from "./card2bv";
26
+ import { CardPbRewriter, checkPbFree } from "./card2bv";
27
27
  import type { Definition, Goal } from "./goal";
28
28
  import { ObjMap } from "./hashtable";
29
29
  import { getGcd, Rational } from "./rational";
@@ -120,6 +120,7 @@ class Pb2Bv {
120
120
  private allClausesLimit: number;
121
121
  private cardinalityLimit: number;
122
122
  private rewriter: ConstraintRewriter | undefined;
123
+ private pbRewriter: CardPbRewriter;
123
124
  private results: RefVector | undefined;
124
125
 
125
126
  constructor(
@@ -139,6 +140,7 @@ class Pb2Bv {
139
140
  };
140
141
  this.allClausesLimit = getUint("pb2bv_all_clauses_limit", 8);
141
142
  this.cardinalityLimit = getUint("pb2bv_cardinality_limit", 4294967295);
143
+ this.pbRewriter = new CardPbRewriter(manager);
142
144
  }
143
145
 
144
146
  private hold(expr: number) {
@@ -470,12 +472,16 @@ class Pb2Bv {
470
472
  results.push(this.convert(atom, isPositive, true));
471
473
  continue;
472
474
  }
473
- const rewritten = rewriter.rewrite(form);
475
+ const simplified = rewriter.rewrite(form);
476
+ const rewritten = this.pbRewriter.rewrite(simplified);
477
+ manager.decRef(simplified);
474
478
  checkPbFree(manager, rewritten);
475
479
  results.pushOwned(rewritten);
476
480
  }
477
481
  for (const [index, result] of results.items.entries()) goal.update(index, result);
478
482
  results.reset();
483
+ goal.depth++;
484
+ if (!goal.isModelsEnabled) return;
479
485
  const hidden: Definition[] = [];
480
486
  for (const [, bit] of this.const2bit) hidden.push({ decl: manager.decls[bit], def: -1 });
481
487
  for (const fresh of this.temporaryInts.items)
@@ -501,7 +507,6 @@ class Pb2Bv {
501
507
  }
502
508
  return model;
503
509
  });
504
- goal.depth++;
505
510
  }
506
511
 
507
512
  private throwNonPb(expr: number): never {
@@ -513,6 +518,7 @@ class Pb2Bv {
513
518
  release() {
514
519
  this.results?.reset();
515
520
  this.rewriter?.release();
521
+ this.pbRewriter.release();
516
522
  for (const [decl] of this.const2bit) this.manager.decDeclRef(decl);
517
523
  this.terms.reset();
518
524
  this.temporaryInts.reset();