tla-ts 0.0.10-dev.96638cd93 → 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.
- package/dist/deciders.cjs +30 -30
- package/dist/deciders.js +30 -30
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +60 -60
- package/dist/prove.js +73 -73
- package/dist/run.cjs +42 -42
- package/dist/run.js +42 -42
- package/dist/transfer.cjs +34 -34
- package/dist/transfer.js +29 -29
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/src/bags.ts +5 -2
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +1 -1
- package/src/check-trace.ts +90 -51
- package/src/check.ts +251 -133
- package/src/cli/tlc.ts +3 -2
- package/src/codegen.ts +18 -5
- package/src/dfid.ts +13 -8
- package/src/environment.ts +1 -0
- package/src/evaluate.ts +25 -9
- package/src/exit-codes.ts +1 -0
- package/src/java-hash.ts +14 -0
- package/src/liveness-checker.ts +63 -31
- package/src/liveness.ts +48 -10
- package/src/parser.ts +6 -1
- package/src/prover/smt/solver/arith-rewriter.ts +11 -3
- package/src/prover/smt/solver/array-rewriter.ts +12 -2
- package/src/prover/smt/solver/asserted-formulas.ts +109 -63
- package/src/prover/smt/solver/ast.ts +5 -3
- package/src/prover/smt/solver/auf-solver.ts +23 -12
- package/src/prover/smt/solver/bit-blast-tactic.ts +26 -0
- package/src/prover/smt/solver/bound-simplifier.ts +10 -11
- package/src/prover/smt/solver/card2bv.ts +31 -15
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -23
- package/src/prover/smt/solver/context.ts +24 -7
- package/src/prover/smt/solver/dependent-expr-state.ts +1 -1
- package/src/prover/smt/solver/elim-bounds.ts +89 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +1 -1
- package/src/prover/smt/solver/internalizer.ts +1 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +4 -0
- package/src/prover/smt/solver/model-evaluator.ts +2 -0
- package/src/prover/smt/solver/model-generator.ts +82 -42
- package/src/prover/smt/solver/opt-context.ts +11 -4
- package/src/prover/smt/solver/opt-pareto.ts +19 -0
- package/src/prover/smt/solver/opt-solver.ts +3 -2
- package/src/prover/smt/solver/poly-rewriter.ts +1 -0
- package/src/prover/smt/solver/proto-model.ts +4 -2
- package/src/prover/smt/solver/push-app-ite.ts +37 -0
- package/src/prover/smt/solver/qsat.ts +16 -6
- package/src/prover/smt/solver/rewriter.ts +31 -25
- package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +13 -4
- package/src/prover/smt/solver/sat/sat-tactic.ts +9 -2
- package/src/prover/smt/solver/smt-kernel.ts +30 -2
- package/src/prover/smt/solver/smt-setup.ts +28 -4
- package/src/prover/smt/solver/smtlib-parser.ts +26 -3
- package/src/prover/smt/solver/smtlib-script.ts +34 -21
- package/src/prover/smt/solver/solve-eqs.ts +24 -17
- package/src/prover/smt/solver/solver.ts +18 -3
- package/src/prover/smt/solver/tactic.ts +68 -41
- package/src/prover/smt/solver/theory-bv.ts +11 -1
- package/src/prover/smt/solver/theory-fpa.ts +1 -1
- package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +7 -1
- package/src/prover/smt/solver/theory-lra.ts +1 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
- package/src/resolve.ts +120 -52
- package/src/runtime.ts +4 -0
- package/src/search.ts +117 -81
- package/src/simulate.ts +110 -50
- package/src/spec-description.ts +3 -4
- package/src/standard-modules.ts +15 -6
- package/src/subexpressions.ts +34 -9
- package/src/successors.ts +3 -2
- package/src/tlc/random.ts +2 -1
- package/src/tlc/replay.ts +3 -2
- package/src/tlc/tlc-operators.ts +7 -7
- package/src/tlc/tlcext-operators.ts +26 -10
- package/src/tlc/trace-spec.ts +6 -20
- package/src/typed-tier.ts +3 -2
- package/src/values.ts +95 -57
|
@@ -154,6 +154,7 @@ export interface SmtParams {
|
|
|
154
154
|
isMbqi: boolean;
|
|
155
155
|
mbqiMaxIterations: number;
|
|
156
156
|
relevancyLevel: 0 | 2;
|
|
157
|
+
randomSeed?: number;
|
|
157
158
|
// The model checker's auxiliary context pretends every array operation is supported.
|
|
158
159
|
isArrayFakeSupport?: boolean;
|
|
159
160
|
}
|
|
@@ -172,6 +173,7 @@ export class Context extends Internalizer {
|
|
|
172
173
|
private scopeAuxClauseLimits: number[] = [];
|
|
173
174
|
private scopeTrailLimits: number[] = [];
|
|
174
175
|
private baseScopeLemmaLimits: number[] = [];
|
|
176
|
+
private isBaseScopeInconsistent: boolean[] = [];
|
|
175
177
|
private atomPropagationQueue: Literal[] = [];
|
|
176
178
|
private thEqQueue: number[] = [];
|
|
177
179
|
private thDiseqQueue: number[] = [];
|
|
@@ -210,15 +212,17 @@ export class Context extends Internalizer {
|
|
|
210
212
|
this.qmanager = new DefaultQuantifierManager(this);
|
|
211
213
|
}
|
|
212
214
|
|
|
213
|
-
// As in Z3, rereading the parameters drops the setup's tuning but for eliminate_term_ite and relevancy.
|
|
215
|
+
// As in Z3, rereading the parameters drops the setup's tuning but for eliminate_term_ite, eliminate_bounds and relevancy.
|
|
214
216
|
updateParams(params: KernelParams) {
|
|
215
217
|
this.params.isMbqi = params.isMbqi;
|
|
216
218
|
this.params.mbqiMaxIterations = params.mbqiMaxIterations;
|
|
219
|
+
this.params.randomSeed = params.randomSeed;
|
|
217
220
|
this.config = {
|
|
218
221
|
...DEFAULT_CONFIG,
|
|
219
222
|
theories: this.config.theories,
|
|
220
223
|
isFindingMacros: params.isFindingMacros,
|
|
221
224
|
isEliminatingTermIte: this.config.isEliminatingTermIte,
|
|
225
|
+
isEliminatingBounds: this.config.isEliminatingBounds,
|
|
222
226
|
};
|
|
223
227
|
this.qmanager.updateParams();
|
|
224
228
|
}
|
|
@@ -239,6 +243,7 @@ export class Context extends Internalizer {
|
|
|
239
243
|
);
|
|
240
244
|
this.setup = setup;
|
|
241
245
|
this.config = config;
|
|
246
|
+
this.randomSeed = this.params.randomSeed ?? 0;
|
|
242
247
|
if (config.relevancyLevel !== undefined) this.relevancy.isEnabled = config.relevancyLevel > 0;
|
|
243
248
|
for (const family of config.theories)
|
|
244
249
|
if (family !== FAMILY_POLY || this.manager.hasTypeVars) this.registerFamily(family);
|
|
@@ -982,11 +987,12 @@ export class Context extends Internalizer {
|
|
|
982
987
|
this.cacheGeneration(newLevel, visited);
|
|
983
988
|
this.qmanager.pop(numScopes);
|
|
984
989
|
this.fingerprints.pop(numScopes);
|
|
990
|
+
if (newLevel >= this.baseLevel || !this.isBaseScopeInconsistent[newLevel]) this.conflict = null;
|
|
985
991
|
if (newLevel < this.baseLevel) {
|
|
986
992
|
this.deleteClauses(this.lemmas, this.baseScopeLemmaLimits[newLevel]);
|
|
987
993
|
shrink(this.baseScopeLemmaLimits, newLevel);
|
|
994
|
+
shrink(this.isBaseScopeInconsistent, newLevel);
|
|
988
995
|
}
|
|
989
|
-
this.conflict = null;
|
|
990
996
|
this.deleteClauses(this.auxClauses, this.scopeAuxClauseLimits[newLevel]);
|
|
991
997
|
this.relevancy.pop(numScopes);
|
|
992
998
|
this.unassignVars(this.scopeAssignedLimits[newLevel]);
|
|
@@ -1469,6 +1475,7 @@ export class Context extends Internalizer {
|
|
|
1469
1475
|
this.popToBaseLevel();
|
|
1470
1476
|
this.pushScope();
|
|
1471
1477
|
this.baseScopeLemmaLimits.push(this.lemmas.length);
|
|
1478
|
+
this.isBaseScopeInconsistent.push(this.isInconsistent());
|
|
1472
1479
|
this.baseLevel++;
|
|
1473
1480
|
this.searchLevel++;
|
|
1474
1481
|
}
|
|
@@ -1502,15 +1509,23 @@ export class Context extends Internalizer {
|
|
|
1502
1509
|
this.asserted = asserted;
|
|
1503
1510
|
this.macros = asserted.macros;
|
|
1504
1511
|
this.hasQuantifiers = asserted.hasQuantifiers;
|
|
1505
|
-
|
|
1512
|
+
if (this.checkCanceled()) return;
|
|
1513
|
+
asserted.reduce();
|
|
1514
|
+
if (this.checkCanceled()) return;
|
|
1506
1515
|
if (asserted.isInconsistent) {
|
|
1507
1516
|
this.setConflict("axiom", null);
|
|
1508
1517
|
return;
|
|
1509
1518
|
}
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1519
|
+
const formulas = asserted.getFormulas();
|
|
1520
|
+
const size = asserted.getNumFormulas();
|
|
1521
|
+
for (let qhead = asserted.getQhead(); qhead < size && !this.isInconsistent(); qhead++) {
|
|
1522
|
+
if (this.checkCanceled()) {
|
|
1523
|
+
asserted.commit(qhead);
|
|
1524
|
+
return;
|
|
1525
|
+
}
|
|
1526
|
+
this.internalizeAssertion(formulas[qhead], 0);
|
|
1513
1527
|
}
|
|
1528
|
+
asserted.commit();
|
|
1514
1529
|
}
|
|
1515
1530
|
|
|
1516
1531
|
initAssumptions(assumptions: number[], asserted: AssertedFormulas) {
|
|
@@ -1519,7 +1534,7 @@ export class Context extends Internalizer {
|
|
|
1519
1534
|
this.unsatCore = [];
|
|
1520
1535
|
if (assumptions.length > 0) {
|
|
1521
1536
|
this.propagate();
|
|
1522
|
-
if (this.isInconsistent()) return;
|
|
1537
|
+
if (this.isInconsistent() || this.checkCanceled()) return;
|
|
1523
1538
|
this.delInactiveLemmas();
|
|
1524
1539
|
this.pushScope();
|
|
1525
1540
|
const manager = this.manager;
|
|
@@ -1619,10 +1634,12 @@ export class Context extends Internalizer {
|
|
|
1619
1634
|
}
|
|
1620
1635
|
|
|
1621
1636
|
search() {
|
|
1637
|
+
if (this.asserted?.isInconsistent && !this.isInconsistent()) this.setConflict("axiom", null);
|
|
1622
1638
|
if (this.isInconsistent()) {
|
|
1623
1639
|
this.resolveConflict();
|
|
1624
1640
|
return L_FALSE;
|
|
1625
1641
|
}
|
|
1642
|
+
if (this.checkCanceled()) return L_UNDEF;
|
|
1626
1643
|
this.resetModel();
|
|
1627
1644
|
for (const theory of this.theories) theory.initSearchEh();
|
|
1628
1645
|
this.qmanager.initSearchEh();
|
|
@@ -64,7 +64,7 @@ export const finishSimplifier = (goal: Goal, definitions: Definition[] = []) =>
|
|
|
64
64
|
goal.elimTrue();
|
|
65
65
|
goal.elimRedundancies();
|
|
66
66
|
goal.depth++;
|
|
67
|
-
if (
|
|
67
|
+
if (goal.isModelsEnabled) goal.addDefinitions(definitions);
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
interface Simplifier {
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AstManager,
|
|
3
|
+
KIND_VAR,
|
|
4
|
+
OP_ADD,
|
|
5
|
+
OP_GE,
|
|
6
|
+
OP_LE,
|
|
7
|
+
OP_MUL,
|
|
8
|
+
OP_NOT,
|
|
9
|
+
OP_OR,
|
|
10
|
+
QUANTIFIER_FORALL,
|
|
11
|
+
} from "./ast";
|
|
12
|
+
import { Rational } from "./rational";
|
|
13
|
+
import { RewriterTpl } from "./rewriter-tpl";
|
|
14
|
+
import { collectUsedVars, elimUnusedVars } from "./var-subst";
|
|
15
|
+
|
|
16
|
+
interface Bound {
|
|
17
|
+
lower: number;
|
|
18
|
+
upper: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const getBound = (manager: AstManager, atom: number): Bound | undefined => {
|
|
22
|
+
const isNegated = manager.getOp(atom) === OP_NOT;
|
|
23
|
+
const inequality = isNegated ? manager.getArg(atom, 0) : atom;
|
|
24
|
+
const op = manager.getOp(inequality);
|
|
25
|
+
if ((op !== OP_LE && op !== OP_GE) || !manager.isNumeral(manager.getArg(inequality, 1)))
|
|
26
|
+
return undefined;
|
|
27
|
+
const isLe = (op === OP_LE) !== isNegated;
|
|
28
|
+
const term = manager.getArg(inequality, 0);
|
|
29
|
+
const bound = { lower: -1, upper: -1 };
|
|
30
|
+
if (manager.kinds[term] === KIND_VAR) bound.upper = term;
|
|
31
|
+
else if (manager.getOp(term) === OP_ADD && manager.getNumArgs(term) === 2) {
|
|
32
|
+
const first = manager.getArg(term, 0);
|
|
33
|
+
if (manager.kinds[first] === KIND_VAR) bound.upper = first;
|
|
34
|
+
else if (!manager.isGroundApp(first)) return undefined;
|
|
35
|
+
const second = manager.getArg(term, 1);
|
|
36
|
+
if (
|
|
37
|
+
manager.getOp(second) !== OP_MUL ||
|
|
38
|
+
!manager.isNumeral(manager.getArg(second, 0)) ||
|
|
39
|
+
!manager.getRationalValue(manager.getArg(second, 0)).equals(Rational.minusOne)
|
|
40
|
+
)
|
|
41
|
+
return undefined;
|
|
42
|
+
const negated = manager.getArg(second, 1);
|
|
43
|
+
if (manager.kinds[negated] === KIND_VAR) bound.lower = negated;
|
|
44
|
+
else if (!manager.isGroundApp(negated)) return undefined;
|
|
45
|
+
} else return undefined;
|
|
46
|
+
return isLe ? bound : { lower: bound.upper, upper: bound.lower };
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export class ElimBoundsRw extends RewriterTpl {
|
|
50
|
+
reduceQuantifier(expr: number, body: number) {
|
|
51
|
+
const manager = this.manager;
|
|
52
|
+
const data = manager.getQuantifier(expr);
|
|
53
|
+
if (data.kind !== QUANTIFIER_FORALL) return -1;
|
|
54
|
+
const numVars = data.sorts.length;
|
|
55
|
+
const atoms = manager.getOp(body) === OP_OR ? manager.getArgs(body) : [body];
|
|
56
|
+
const isUsed = Array.from({ length: numVars }, () => false);
|
|
57
|
+
for (const atom of atoms)
|
|
58
|
+
if (getBound(manager, atom) === undefined)
|
|
59
|
+
for (const [index, isVarUsed] of collectUsedVars(manager, atom, numVars).entries())
|
|
60
|
+
if (isVarUsed) isUsed[index] = true;
|
|
61
|
+
if (isUsed.every((isVarUsed) => isVarUsed)) return -1;
|
|
62
|
+
const isCandidate = (variable: number) =>
|
|
63
|
+
variable !== -1 && manager.values[variable] < numVars && !isUsed[manager.values[variable]];
|
|
64
|
+
const lowers = new Set<number>();
|
|
65
|
+
const uppers = new Set<number>();
|
|
66
|
+
for (const atom of atoms) {
|
|
67
|
+
const bound = getBound(manager, atom);
|
|
68
|
+
if (bound === undefined) continue;
|
|
69
|
+
if (isCandidate(bound.lower)) lowers.add(bound.lower);
|
|
70
|
+
if (isCandidate(bound.upper)) uppers.add(bound.upper);
|
|
71
|
+
}
|
|
72
|
+
const candidates = new Set(
|
|
73
|
+
[...lowers, ...uppers].filter((variable) => !lowers.has(variable) || !uppers.has(variable)),
|
|
74
|
+
);
|
|
75
|
+
if (candidates.size === 0) return -1;
|
|
76
|
+
const kept = atoms.filter((atom) => {
|
|
77
|
+
const bound = getBound(manager, atom);
|
|
78
|
+
return bound === undefined || (!candidates.has(bound.lower) && !candidates.has(bound.upper));
|
|
79
|
+
});
|
|
80
|
+
if (kept.length === atoms.length) return -1;
|
|
81
|
+
if (kept.length === 0) {
|
|
82
|
+
manager.incRef(manager.falseExpr);
|
|
83
|
+
return manager.falseExpr;
|
|
84
|
+
}
|
|
85
|
+
return manager.withTemporaries(() =>
|
|
86
|
+
elimUnusedVars(manager, manager.mkQuantifier({ ...data, body: manager.mkOr(kept) })),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -522,7 +522,7 @@ export const elimUncnstr = (manager: AstManager, goal: Goal, bodies: RefVector)
|
|
|
522
522
|
const rewritten = rewriter.rewrite(form);
|
|
523
523
|
if (rewritten !== form) {
|
|
524
524
|
isModified = true;
|
|
525
|
-
goal.update(index, rewritten);
|
|
525
|
+
goal.update(index, rewritten, goal.dependencies[index]);
|
|
526
526
|
}
|
|
527
527
|
manager.decRef(rewritten);
|
|
528
528
|
}
|
|
@@ -172,7 +172,7 @@ export abstract class Internalizer {
|
|
|
172
172
|
falseEnode: Enode;
|
|
173
173
|
protected generation = 0;
|
|
174
174
|
protected cachedGeneration = new Map<number, number>();
|
|
175
|
-
|
|
175
|
+
protected randomSeed = 0;
|
|
176
176
|
isSearching = false;
|
|
177
177
|
config = DEFAULT_CONFIG;
|
|
178
178
|
|
|
@@ -70,6 +70,10 @@ export class LpSettings {
|
|
|
70
70
|
|
|
71
71
|
constructor(readonly isCanceled: () => boolean) {}
|
|
72
72
|
|
|
73
|
+
setRandomSeed(seed: number) {
|
|
74
|
+
this.random = new RandomGen(seed);
|
|
75
|
+
}
|
|
76
|
+
|
|
73
77
|
getRandomNext(bound?: number) {
|
|
74
78
|
const value = this.random.next();
|
|
75
79
|
return bound === undefined ? value : value % bound;
|
|
@@ -64,6 +64,8 @@ export class ModelEvaluator extends RewriterTpl {
|
|
|
64
64
|
this.rewriter = new Rewriter(manager, {
|
|
65
65
|
...TACTIC_REWRITER_OPTIONS,
|
|
66
66
|
bv: { ...DEFAULT_BV_OPTIONS, isHiDiv0: manager.isHiDiv0, isMkbv2num: true },
|
|
67
|
+
isExpandingSelects: true,
|
|
68
|
+
isKeepingDistinct: true,
|
|
67
69
|
});
|
|
68
70
|
this.rewriter.releaseResult = () => this.setLastResult(-1);
|
|
69
71
|
}
|
|
@@ -2,7 +2,7 @@ import { FAMILY_BASIC, FAMILY_USER, SORT_BOOL } from "./ast";
|
|
|
2
2
|
import type { Context } from "./context";
|
|
3
3
|
import { Enode } from "./enode";
|
|
4
4
|
import { FuncInterp, ProtoModel } from "./proto-model";
|
|
5
|
-
import type { DependentValue } from "./theory";
|
|
5
|
+
import type { DependentValue, ExtraFreshValue } from "./theory";
|
|
6
6
|
|
|
7
7
|
export interface GeneratedModel {
|
|
8
8
|
model: ProtoModel;
|
|
@@ -19,6 +19,9 @@ const isIncludedFuncInterp = (context: Context, decl: number) => {
|
|
|
19
19
|
return context.getTheory(family)?.includeFuncInterp(decl) ?? true;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
const GREY = 1;
|
|
23
|
+
const BLACK = 2;
|
|
24
|
+
|
|
22
25
|
export const mkModel = (context: Context): GeneratedModel => {
|
|
23
26
|
const manager = context.manager;
|
|
24
27
|
const model = new ProtoModel(manager);
|
|
@@ -34,58 +37,95 @@ export const mkModel = (context: Context): GeneratedModel => {
|
|
|
34
37
|
context.findAssignment(expr) > 0 ? manager.trueExpr : manager.falseExpr,
|
|
35
38
|
);
|
|
36
39
|
}
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
+
const roots: Enode[] = [];
|
|
41
|
+
const procs = new Map<Enode, number | DependentValue>();
|
|
42
|
+
const freshRoots = new Set<Enode>();
|
|
43
|
+
const extraFreshValues = new Set<ExtraFreshValue>();
|
|
40
44
|
for (const node of context.enodes) {
|
|
41
45
|
if (node.root !== node) continue;
|
|
42
46
|
const expr = node.owner;
|
|
43
47
|
if (!context.isRelevant(expr) && !manager.isValue(expr)) continue;
|
|
48
|
+
roots.push(node);
|
|
44
49
|
const sort = manager.sorts[expr];
|
|
45
50
|
const theory = context.getTheory(manager.getSortFamily(sort));
|
|
46
51
|
if (sort === SORT_BOOL)
|
|
47
|
-
|
|
48
|
-
else if (manager.isModelValue(expr))
|
|
52
|
+
procs.set(node, context.findAssignment(expr) > 0 ? manager.trueExpr : manager.falseExpr);
|
|
53
|
+
else if (manager.isModelValue(expr)) procs.set(node, expr);
|
|
49
54
|
else if (theory !== undefined && theory.buildModels()) {
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
const proc = node.getThVar(theory.id) < 0 ? undefined : theory.mkValue(node);
|
|
56
|
+
if (proc === undefined) {
|
|
57
|
+
const freshValue: ExtraFreshValue = { sort, value: undefined };
|
|
58
|
+
freshRoots.add(node);
|
|
59
|
+
extraFreshValues.add(freshValue);
|
|
60
|
+
procs.set(node, { dependencies: [freshValue], mkValue: (values) => values[0] });
|
|
61
|
+
} else {
|
|
62
|
+
if (typeof proc !== "number")
|
|
63
|
+
for (const dependency of proc.dependencies)
|
|
64
|
+
if (!(dependency instanceof Enode)) extraFreshValues.add(dependency);
|
|
65
|
+
procs.set(node, proc);
|
|
66
|
+
}
|
|
67
|
+
} else procs.set(node, model.getFreshValue(sort) ?? model.getSomeValue(sort));
|
|
59
68
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
root2value.set(node, value);
|
|
67
|
-
return value;
|
|
69
|
+
const colors = new Map<Enode | ExtraFreshValue, number>();
|
|
70
|
+
const traversedSorts = new Set<number>();
|
|
71
|
+
const sortedSources: (Enode | ExtraFreshValue)[] = [];
|
|
72
|
+
const todo: (Enode | ExtraFreshValue)[] = [];
|
|
73
|
+
const visitChild = (source: Enode | ExtraFreshValue) => {
|
|
74
|
+
if (!colors.has(source)) todo.push(source);
|
|
68
75
|
};
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
76
|
+
const processSource = (source: Enode | ExtraFreshValue) => {
|
|
77
|
+
if (colors.get(source) === BLACK) return;
|
|
78
|
+
todo.push(source);
|
|
79
|
+
while (todo.length > 0) {
|
|
80
|
+
const current = todo[todo.length - 1];
|
|
81
|
+
const color = colors.get(current);
|
|
82
|
+
if (color === BLACK) todo.pop();
|
|
83
|
+
else if (color === GREY) {
|
|
84
|
+
colors.set(current, BLACK);
|
|
85
|
+
sortedSources.push(current);
|
|
86
|
+
} else {
|
|
87
|
+
colors.set(current, GREY);
|
|
88
|
+
if (current instanceof Enode) {
|
|
89
|
+
const proc = procs.get(current);
|
|
90
|
+
if (proc !== undefined && typeof proc !== "number")
|
|
91
|
+
for (const dependency of proc.dependencies)
|
|
92
|
+
visitChild(dependency instanceof Enode ? dependency.root : dependency);
|
|
93
|
+
} else if (!traversedSorts.has(current.sort)) {
|
|
94
|
+
for (const root of roots)
|
|
95
|
+
if (manager.sorts[root.owner] === current.sort && !freshRoots.has(root))
|
|
96
|
+
visitChild(root);
|
|
97
|
+
traversedSorts.add(current.sort);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
86
101
|
};
|
|
87
|
-
for (const
|
|
88
|
-
for (const
|
|
102
|
+
for (const freshValue of extraFreshValues) processSource(freshValue);
|
|
103
|
+
for (const root of freshRoots) processSource(root);
|
|
104
|
+
for (const root of roots) processSource(root);
|
|
105
|
+
const root2value = new Map<Enode, number>();
|
|
106
|
+
for (const source of sortedSources) {
|
|
107
|
+
if (!(source instanceof Enode)) {
|
|
108
|
+
source.value = model.getFreshValue(source.sort) ?? undefined;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const expr = source.owner;
|
|
112
|
+
const sort = manager.sorts[expr];
|
|
113
|
+
const proc = procs.get(source) ?? model.getFreshValue(sort) ?? model.getSomeValue(sort);
|
|
114
|
+
const value = manager.isValue(expr)
|
|
115
|
+
? expr
|
|
116
|
+
: typeof proc === "number"
|
|
117
|
+
? proc
|
|
118
|
+
: proc.mkValue(
|
|
119
|
+
proc.dependencies.map((dependency) =>
|
|
120
|
+
dependency instanceof Enode
|
|
121
|
+
? (root2value.get(dependency.root) ??
|
|
122
|
+
model.getSomeValue(manager.sorts[dependency.owner]))
|
|
123
|
+
: (dependency.value ?? model.getSomeValue(dependency.sort)),
|
|
124
|
+
),
|
|
125
|
+
);
|
|
126
|
+
model.registerValue(value);
|
|
127
|
+
root2value.set(source, value);
|
|
128
|
+
}
|
|
89
129
|
const getValue = (node: Enode) =>
|
|
90
130
|
root2value.get(node.root) ?? model.getSomeValue(manager.sorts[node.owner]);
|
|
91
131
|
for (const node of context.enodes)
|
|
@@ -25,7 +25,13 @@ import { L_FALSE, L_TRUE, L_UNDEF } from "./lbool";
|
|
|
25
25
|
import type { MaxsatContext, MaxsatParams, MaxsatSolver } from "./maxsmt-base";
|
|
26
26
|
import { Maxsmt } from "./maxsmt";
|
|
27
27
|
import { isInNraFragment } from "./opt-nlsat";
|
|
28
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
canReuseNlsatSolver,
|
|
30
|
+
giaPareto,
|
|
31
|
+
ParetoNlsatSolver,
|
|
32
|
+
type ParetoObjective,
|
|
33
|
+
type ParetoSolver,
|
|
34
|
+
} from "./opt-pareto";
|
|
29
35
|
import type { ProtoModel } from "./proto-model";
|
|
30
36
|
import { Rational } from "./rational";
|
|
31
37
|
import { RefVector } from "./ref-vector";
|
|
@@ -131,7 +137,7 @@ export class OptContext {
|
|
|
131
137
|
private boxIndex = -1;
|
|
132
138
|
private pareto: ParetoSolver | null = null;
|
|
133
139
|
private internal: Objective[] = [];
|
|
134
|
-
private normalized:
|
|
140
|
+
private normalized: ParetoObjective[] = [];
|
|
135
141
|
private normalizedGoal: Goal | null = null;
|
|
136
142
|
private normalizedTerms: RefVector;
|
|
137
143
|
private hiddenDecls: number[] = [];
|
|
@@ -358,8 +364,6 @@ export class OptContext {
|
|
|
358
364
|
this.updateBound(optsmt, true);
|
|
359
365
|
const count = this.internal.length;
|
|
360
366
|
if (count > 1 && options.priority === "pareto") {
|
|
361
|
-
if (this.internal.some((objective) => objective.type === O_MAXSMT))
|
|
362
|
-
throw new SmtUnsupportedError("pareto optimization of soft constraints");
|
|
363
367
|
this.pareto = this.mkParetoSolver(solver, hard, options);
|
|
364
368
|
return this.executePareto();
|
|
365
369
|
}
|
|
@@ -699,6 +703,9 @@ export class OptContext {
|
|
|
699
703
|
this.normalized = this.internal.map((objective) => ({
|
|
700
704
|
term: objective.term,
|
|
701
705
|
isMax: objective.type === O_MAXIMIZE,
|
|
706
|
+
isMaxsmt: objective.type === O_MAXSMT,
|
|
707
|
+
terms: objective.terms,
|
|
708
|
+
weights: objective.weights,
|
|
702
709
|
}));
|
|
703
710
|
result.forms.reset();
|
|
704
711
|
return normalizedHard;
|
|
@@ -27,7 +27,9 @@ import { goal2nlsat } from "./goal2nlsat";
|
|
|
27
27
|
import { L_FALSE, L_TRUE, L_UNDEF } from "./lbool";
|
|
28
28
|
import { NlsatSolver } from "./nlsat/solver";
|
|
29
29
|
import { getModelValueBound } from "./opt-solver";
|
|
30
|
+
import { mkPbGe, mkPbLe } from "./pb-rewriter";
|
|
30
31
|
import { ProtoModel } from "./proto-model";
|
|
32
|
+
import { Rational } from "./rational";
|
|
31
33
|
import { RefVector } from "./ref-vector";
|
|
32
34
|
import { compileInternalTactic, type TacticEnvironment } from "./tactic";
|
|
33
35
|
|
|
@@ -53,6 +55,9 @@ const REUSABLE_OPS = new Set([
|
|
|
53
55
|
export interface ParetoObjective {
|
|
54
56
|
term: number;
|
|
55
57
|
isMax: boolean;
|
|
58
|
+
isMaxsmt: boolean;
|
|
59
|
+
terms: readonly number[];
|
|
60
|
+
weights: readonly Rational[];
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
export const canReuseNlsatSolver = (manager: AstManager, terms: readonly number[]) => {
|
|
@@ -238,6 +243,20 @@ export const giaPareto = (
|
|
|
238
243
|
return bound === undefined ? -1 : pin(manager.mkRealNumeral(bound));
|
|
239
244
|
};
|
|
240
245
|
const mkCmp = (isGe: boolean, model: ProtoModel, objective: ParetoObjective) => {
|
|
246
|
+
if (objective.isMaxsmt) {
|
|
247
|
+
let bound = Rational.zero;
|
|
248
|
+
for (const [index, term] of objective.terms.entries()) {
|
|
249
|
+
const value = model.eval(term, true);
|
|
250
|
+
if (value === manager.trueExpr) bound = bound.add(objective.weights[index]);
|
|
251
|
+
manager.decRef(value);
|
|
252
|
+
}
|
|
253
|
+
const terms = [...objective.terms];
|
|
254
|
+
return pin(
|
|
255
|
+
isGe
|
|
256
|
+
? mkPbGe(manager, objective.weights, terms, bound)
|
|
257
|
+
: mkPbLe(manager, objective.weights, terms, bound),
|
|
258
|
+
);
|
|
259
|
+
}
|
|
241
260
|
const isGreater = objective.isMax ? isGe : !isGe;
|
|
242
261
|
const evaluated = model.eval(objective.term, true);
|
|
243
262
|
pin(evaluated);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SmtCanceledError, SmtInvariantError } from "../../../errors";
|
|
1
|
+
import { SmtCanceledError, SmtDefaultError, SmtInvariantError } from "../../../errors";
|
|
2
2
|
import { type AstManager, FAMILY_ARITH, FAMILY_PB } from "./ast";
|
|
3
3
|
import { InfEps } from "./inf-eps";
|
|
4
4
|
import { L_FALSE, L_TRUE, L_UNDEF } from "./lbool";
|
|
@@ -232,7 +232,8 @@ export class OptSolver {
|
|
|
232
232
|
try {
|
|
233
233
|
this.kernel.push();
|
|
234
234
|
} catch (error) {
|
|
235
|
-
|
|
235
|
+
const isPushCanceled = error instanceof SmtDefaultError && error.message === "push canceled";
|
|
236
|
+
if (!(error instanceof SmtCanceledError || isPushCanceled)) throw error;
|
|
236
237
|
return L_UNDEF;
|
|
237
238
|
}
|
|
238
239
|
limit.push(this.dualBoundRlimit);
|
|
@@ -49,6 +49,7 @@ import type { Rewrite } from "./rewriter-tpl";
|
|
|
49
49
|
export interface ArithRewriterOptions {
|
|
50
50
|
readonly isSom: boolean;
|
|
51
51
|
readonly isSortSums: boolean;
|
|
52
|
+
readonly isArithLhs: boolean;
|
|
52
53
|
readonly isArithIneqLhs: boolean;
|
|
53
54
|
readonly isGcdRounding: boolean;
|
|
54
55
|
readonly isAnumSimp: boolean;
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
} from "./datatype-decl-plugin";
|
|
29
29
|
import { mkArrayApp, mkAsArray } from "./array-decl-plugin";
|
|
30
30
|
import { mkFpNumeral, mkRmNumeral } from "./fpa-decl-plugin";
|
|
31
|
-
import { MPF_ROUND_TOWARD_ZERO, mkZero } from "./mpf";
|
|
31
|
+
import { MPF_ROUND_TOWARD_ZERO, mkNan, mkZero } from "./mpf";
|
|
32
32
|
import { RandomGen } from "./random-gen";
|
|
33
33
|
import { mkEmptySeq, mkSeqApp } from "./seq-decl-plugin";
|
|
34
34
|
import { Rational } from "./rational";
|
|
@@ -45,7 +45,7 @@ export const getManagerSomeValue = (manager: AstManager, sort: number): number =
|
|
|
45
45
|
if (sort === SORT_BOOL) return manager.falseExpr;
|
|
46
46
|
if (manager.isRmSort(sort)) return mkRmNumeral(manager, MPF_ROUND_TOWARD_ZERO);
|
|
47
47
|
if (manager.isFpSort(sort))
|
|
48
|
-
return mkFpNumeral(manager,
|
|
48
|
+
return mkFpNumeral(manager, mkNan(manager.getEbits(sort), manager.getSbits(sort)));
|
|
49
49
|
if (isArithSort(sort)) return manager.mkNumeralOfSort(Rational.zero, sort);
|
|
50
50
|
if (manager.isBvSort(sort)) return manager.mkBvNumeral(0n, manager.getBvSize(sort));
|
|
51
51
|
if (manager.isArraySort(sort))
|
|
@@ -518,6 +518,8 @@ export class ProtoModel {
|
|
|
518
518
|
const manager = this.manager;
|
|
519
519
|
if (this.charFactory !== undefined && manager.isCharSort(sort))
|
|
520
520
|
return manager.mkChar(this.charFactory.getSomeValue());
|
|
521
|
+
if (manager.isFpSort(sort) && !this.isFinal)
|
|
522
|
+
return mkFpNumeral(manager, mkZero(manager.getEbits(sort), manager.getSbits(sort), false));
|
|
521
523
|
if (
|
|
522
524
|
manager.isFpSort(sort) ||
|
|
523
525
|
manager.isRmSort(sort) ||
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { OP_ITE, SORT_BOOL } from "./ast";
|
|
2
|
+
import { RewriterTpl } from "./rewriter-tpl";
|
|
3
|
+
|
|
4
|
+
export class NgPushAppIteRw extends RewriterTpl {
|
|
5
|
+
isRewritingPatterns() {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
private isTarget(decl: number, args: number[]) {
|
|
10
|
+
const manager = this.manager;
|
|
11
|
+
if (decl === OP_ITE) return false;
|
|
12
|
+
let hasTermIte = false;
|
|
13
|
+
for (let index = 0; index < args.length; index++)
|
|
14
|
+
if (manager.getOp(args[index]) === OP_ITE && manager.sorts[args[index]] !== SORT_BOOL) {
|
|
15
|
+
if (hasTermIte) return false;
|
|
16
|
+
hasTermIte = true;
|
|
17
|
+
}
|
|
18
|
+
if (!hasTermIte) return false;
|
|
19
|
+
for (let index = 0; index < args.length; index++)
|
|
20
|
+
if (!manager.isGroundApp(args[index])) return true;
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
reduceApp(decl: number, args: number[], sort: number) {
|
|
25
|
+
const manager = this.manager;
|
|
26
|
+
if (!this.isTarget(decl, args)) return -1;
|
|
27
|
+
let index = 0;
|
|
28
|
+
while (manager.getOp(args[index]) !== OP_ITE) index++;
|
|
29
|
+
const ite = args[index];
|
|
30
|
+
const expr = manager.withTemporaries(() => {
|
|
31
|
+
const thenApp = manager.mkApp(decl, args.with(index, manager.getArg(ite, 1)), sort);
|
|
32
|
+
const elseApp = manager.mkApp(decl, args.with(index, manager.getArg(ite, 2)), sort);
|
|
33
|
+
return manager.mkApp(OP_ITE, [manager.getArg(ite, 0), thenApp, elseApp], sort);
|
|
34
|
+
});
|
|
35
|
+
return { expr, depth: 2 };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -22,6 +22,7 @@ import { QuantifierHoister } from "./quant-hoist";
|
|
|
22
22
|
import { hasSubterm } from "./recfun-decl-plugin";
|
|
23
23
|
import { RefVector } from "./ref-vector";
|
|
24
24
|
import { SmtKernel } from "./smt-kernel";
|
|
25
|
+
import type { TacticEnvironment } from "./tactic";
|
|
25
26
|
|
|
26
27
|
export const NO_LEVEL = -1;
|
|
27
28
|
|
|
@@ -314,7 +315,10 @@ class Kernel {
|
|
|
314
315
|
private lastAssert = -1;
|
|
315
316
|
private trail: RefVector;
|
|
316
317
|
|
|
317
|
-
constructor(
|
|
318
|
+
constructor(
|
|
319
|
+
private manager: AstManager,
|
|
320
|
+
private isCoreMinimizing: boolean,
|
|
321
|
+
) {
|
|
318
322
|
this.trail = new RefVector(manager);
|
|
319
323
|
}
|
|
320
324
|
|
|
@@ -324,6 +328,7 @@ class Kernel {
|
|
|
324
328
|
mbqiMaxIterations: MBQI_MAX_ITERATIONS,
|
|
325
329
|
isFindingMacros: false,
|
|
326
330
|
relevancyLevel: 0,
|
|
331
|
+
isCoreMinimizing: this.isCoreMinimizing,
|
|
327
332
|
});
|
|
328
333
|
this.lastAssert = -1;
|
|
329
334
|
this.trail.reset();
|
|
@@ -351,7 +356,7 @@ class Kernel {
|
|
|
351
356
|
|
|
352
357
|
getCore(core: RefVector) {
|
|
353
358
|
core.reset();
|
|
354
|
-
|
|
359
|
+
this.solver.getUnsatCore(core);
|
|
355
360
|
}
|
|
356
361
|
|
|
357
362
|
reasonUnknown() {
|
|
@@ -383,10 +388,11 @@ class Qsat {
|
|
|
383
388
|
constructor(
|
|
384
389
|
private manager: AstManager,
|
|
385
390
|
private mode: number,
|
|
391
|
+
isCoreMinimizing: boolean,
|
|
386
392
|
) {
|
|
387
393
|
this.mbp = new Mbproj(manager);
|
|
388
|
-
this.fa = new Kernel(manager);
|
|
389
|
-
this.ex = new Kernel(manager);
|
|
394
|
+
this.fa = new Kernel(manager, isCoreMinimizing);
|
|
395
|
+
this.ex = new Kernel(manager, isCoreMinimizing);
|
|
390
396
|
this.predAbs = new PredAbs(manager);
|
|
391
397
|
this.answer = new RefVector(manager);
|
|
392
398
|
this.asms = new RefVector(manager);
|
|
@@ -804,8 +810,12 @@ class Qsat {
|
|
|
804
810
|
}
|
|
805
811
|
}
|
|
806
812
|
|
|
807
|
-
export const runQsat = (
|
|
808
|
-
const qsat = new Qsat(
|
|
813
|
+
export const runQsat = (environment: TacticEnvironment, mode: number) => (goal: Goal) => {
|
|
814
|
+
const qsat = new Qsat(
|
|
815
|
+
environment.manager,
|
|
816
|
+
mode,
|
|
817
|
+
environment.parameters.get("smt.core.minimize") === "true",
|
|
818
|
+
);
|
|
809
819
|
try {
|
|
810
820
|
return qsat.apply(goal);
|
|
811
821
|
} finally {
|