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.
- package/dist/deciders.cjs +31 -31
- package/dist/deciders.js +30 -30
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +68 -68
- package/dist/prove.js +61 -61
- package/dist/run.cjs +42 -42
- package/dist/run.js +44 -44
- package/dist/transfer.cjs +38 -38
- package/dist/transfer.js +29 -29
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/bags.ts +5 -2
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +9 -6
- package/src/check-trace.ts +116 -64
- package/src/check.ts +343 -166
- package/src/cli/tlc-output.ts +1 -0
- package/src/cli/tlc.ts +3 -2
- package/src/codegen.ts +23 -8
- package/src/dependencies.ts +5 -4
- package/src/dfid.ts +13 -8
- package/src/environment.ts +1 -0
- package/src/evaluate.ts +58 -23
- package/src/exit-codes.ts +27 -13
- package/src/java-hash.ts +14 -0
- package/src/liveness-checker.ts +131 -81
- 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 +34 -15
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -23
- package/src/prover/smt/solver/context.ts +44 -11
- package/src/prover/smt/solver/dependent-expr-state.ts +19 -13
- package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
- 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/fd-solver.ts +146 -39
- 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/maxcore.ts +2 -1
- package/src/prover/smt/solver/maxsmt-base.ts +1 -0
- package/src/prover/smt/solver/model-checker.ts +1 -1
- 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/muz/dl-context.ts +12 -40
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
- package/src/prover/smt/solver/muz/dl-rule.ts +6 -7
- package/src/prover/smt/solver/muz/hnf.ts +2 -2
- package/src/prover/smt/solver/muz/horn-tactic.ts +14 -1
- package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
- package/src/prover/smt/solver/opt-context.ts +12 -4
- package/src/prover/smt/solver/opt-pareto.ts +19 -0
- package/src/prover/smt/solver/opt-solver.ts +4 -3
- package/src/prover/smt/solver/parallel-tactic.ts +1 -1
- 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 +23 -8
- package/src/prover/smt/solver/rewriter-tpl.ts +7 -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 +56 -28
- package/src/prover/smt/solver/sat/sat-tactic.ts +13 -4
- package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
- package/src/prover/smt/solver/smt-consequences.ts +1 -1
- package/src/prover/smt/solver/smt-kernel.ts +39 -4
- package/src/prover/smt/solver/smt-setup.ts +28 -4
- package/src/prover/smt/solver/smtlib-parser.ts +31 -4
- package/src/prover/smt/solver/smtlib-script.ts +219 -82
- 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 +132 -78
- 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 +446 -167
- package/src/runtime.ts +4 -0
- package/src/search.ts +161 -92
- package/src/simulate.ts +165 -102
- package/src/spec-description.ts +3 -4
- package/src/standard-modules.ts +56 -22
- package/src/subexpressions.ts +168 -49
- package/src/successors.ts +6 -3
- package/src/symmetry.ts +1 -0
- package/src/tlc/random.ts +2 -1
- package/src/tlc/replay.ts +22 -14
- 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 +9 -4
- package/src/values.ts +95 -57
|
@@ -274,10 +274,11 @@ export class Maxcore extends MaxsmtSolverBase {
|
|
|
274
274
|
const upper = this.getCost(model);
|
|
275
275
|
if (upper.compare(this.upper) > 0) return;
|
|
276
276
|
if (!this.context.verifyModel(this.index, model, upper)) return;
|
|
277
|
+
const numAssertions = this.solver.getNumAssertions();
|
|
277
278
|
this.model = model;
|
|
278
279
|
this.context.modelUpdated(model);
|
|
279
280
|
for (const soft of this.soft) soft.value = this.isTrueIn(model, soft.expr) ? L_TRUE : L_UNDEF;
|
|
280
|
-
this.upper = upper;
|
|
281
|
+
if (numAssertions === this.solver.getNumAssertions()) this.upper = upper;
|
|
281
282
|
}
|
|
282
283
|
|
|
283
284
|
private removeSoft(core: readonly number[]) {
|
|
@@ -10,6 +10,7 @@ export interface MaxsatSolver {
|
|
|
10
10
|
checkSat(assumptions: readonly number[]): number;
|
|
11
11
|
getModel(): ProtoModel | null;
|
|
12
12
|
getUnsatCore(): readonly number[];
|
|
13
|
+
getNumAssertions(): number;
|
|
13
14
|
findMutexes(vars: readonly number[]): { status: number; mutexes: number[][] };
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -55,7 +55,7 @@ class AuxContext {
|
|
|
55
55
|
const context = this.context;
|
|
56
56
|
context.popToBaseLevel();
|
|
57
57
|
const result = context.checkResearching(this.asserted, []);
|
|
58
|
-
return result === L_TRUE ? context.
|
|
58
|
+
return result === L_TRUE ? context.getSatModel() : result === L_FALSE ? "unsat" : "unknown";
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -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)
|
|
@@ -10,16 +10,16 @@ import {
|
|
|
10
10
|
SORT_SIZE_INFINITE,
|
|
11
11
|
} from "../ast";
|
|
12
12
|
import type { Definition } from "../goal";
|
|
13
|
-
import {
|
|
14
|
-
import { FuncInterp, type ProtoModel } from "../proto-model";
|
|
13
|
+
import type { ProtoModel } from "../proto-model";
|
|
15
14
|
import { type RewriterOptions, Rewriter } from "../rewriter";
|
|
16
15
|
import { RefVector } from "../ref-vector";
|
|
17
16
|
import { applyQeLiteToConjuncts } from "../qe-lite";
|
|
17
|
+
import { applyDefinitions } from "../tactic";
|
|
18
18
|
import { BindVariables, mkExists, type Rule, RuleManager, getUsedVars } from "./dl-rule";
|
|
19
19
|
import { RuleSet } from "./dl-rule-set";
|
|
20
20
|
import { RuleProperties } from "./rule-properties";
|
|
21
21
|
|
|
22
|
-
const ENGINE_DATALOG = 0;
|
|
22
|
+
export const ENGINE_DATALOG = 0;
|
|
23
23
|
export const ENGINE_SPACER = 1;
|
|
24
24
|
const ENGINE_BMC = 2;
|
|
25
25
|
const ENGINE_QBMC = 3;
|
|
@@ -63,40 +63,6 @@ export class FpParams {
|
|
|
63
63
|
|
|
64
64
|
export type ModelConverter = (model: ProtoModel) => ProtoModel;
|
|
65
65
|
|
|
66
|
-
// generic_model_converter::operator() over predicates, where a definition of -1 hides the
|
|
67
|
-
// declaration.
|
|
68
|
-
const applyDefinitions = (definitions: readonly Definition[], model: ProtoModel) => {
|
|
69
|
-
const manager = model.manager;
|
|
70
|
-
let evaluator = new ModelEvaluator(manager, model);
|
|
71
|
-
evaluator.setModelCompletion(true);
|
|
72
|
-
for (let index = definitions.length - 1; index >= 0; index--) {
|
|
73
|
-
const definition = definitions[index];
|
|
74
|
-
if (definition.def === -1) {
|
|
75
|
-
model.unregisterDecl(definition.decl);
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
const value = evaluator.rewrite(definition.def);
|
|
79
|
-
const arity = manager.funcDecls[definition.decl].domain.length;
|
|
80
|
-
const oldInterp = model.funcInterps.get(definition.decl);
|
|
81
|
-
const old = arity === 0 ? model.constInterps.get(definition.decl) : oldInterp?.elseExpr;
|
|
82
|
-
if (old !== value) {
|
|
83
|
-
if (arity === 0) model.registerConst(definition.decl, value);
|
|
84
|
-
else {
|
|
85
|
-
const interp = new FuncInterp(manager, arity);
|
|
86
|
-
interp.setElse(value);
|
|
87
|
-
model.registerFunc(definition.decl, interp);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
manager.decRef(value);
|
|
91
|
-
if (old === value || (arity === 0 ? old === undefined : oldInterp === undefined)) continue;
|
|
92
|
-
evaluator.release();
|
|
93
|
-
evaluator = new ModelEvaluator(manager, model);
|
|
94
|
-
evaluator.setModelCompletion(true);
|
|
95
|
-
}
|
|
96
|
-
evaluator.release();
|
|
97
|
-
return model;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
66
|
export interface Engine {
|
|
101
67
|
query(query: number): number;
|
|
102
68
|
getModel(): ProtoModel;
|
|
@@ -112,7 +78,7 @@ export class DatalogContext {
|
|
|
112
78
|
private isBindingVariables = true;
|
|
113
79
|
ruleSet: RuleSet;
|
|
114
80
|
private ruleFmls: number[] = [];
|
|
115
|
-
private ruleNames: string[] = [];
|
|
81
|
+
private ruleNames: (string | undefined)[] = [];
|
|
116
82
|
private ruleFmlsHead = 0;
|
|
117
83
|
readonly background: number[] = [];
|
|
118
84
|
private isClosed = false;
|
|
@@ -181,7 +147,7 @@ export class DatalogContext {
|
|
|
181
147
|
return result;
|
|
182
148
|
}
|
|
183
149
|
|
|
184
|
-
addRule(fml: number, name
|
|
150
|
+
addRule(fml: number, name?: string) {
|
|
185
151
|
this.manager.incRef(fml);
|
|
186
152
|
this.ruleFmls.push(fml);
|
|
187
153
|
this.ruleNames.push(name);
|
|
@@ -217,7 +183,13 @@ export class DatalogContext {
|
|
|
217
183
|
const properties = this.ruleProperties;
|
|
218
184
|
switch (this.getEngine()) {
|
|
219
185
|
case ENGINE_DATALOG:
|
|
220
|
-
|
|
186
|
+
properties.collect(rules);
|
|
187
|
+
properties.checkQuantifierFree();
|
|
188
|
+
properties.checkUninterpretedFree();
|
|
189
|
+
properties.checkNestedFree();
|
|
190
|
+
properties.checkInfiniteSorts();
|
|
191
|
+
properties.checkBackgroundFree();
|
|
192
|
+
break;
|
|
221
193
|
case ENGINE_SPACER:
|
|
222
194
|
properties.collect(rules);
|
|
223
195
|
properties.checkExistentialTail();
|
|
@@ -91,7 +91,7 @@ export class MkCoiFilter implements RuleTransformerPlugin {
|
|
|
91
91
|
newTail.push(rule.tail[index]);
|
|
92
92
|
newNegated.push(false);
|
|
93
93
|
}
|
|
94
|
-
result.addRule(this.context.ruleManager.mk(rule.head, newTail, newNegated,
|
|
94
|
+
result.addRule(this.context.ruleManager.mk(rule.head, newTail, newNegated, undefined, false));
|
|
95
95
|
}
|
|
96
96
|
if (result.rules.length === source.rules.length) return undefined;
|
|
97
97
|
result.close();
|
|
@@ -47,7 +47,7 @@ export class Rule {
|
|
|
47
47
|
readonly isNegated: boolean[],
|
|
48
48
|
readonly uninterpretedSize: number,
|
|
49
49
|
readonly positiveSize: number,
|
|
50
|
-
readonly name: string,
|
|
50
|
+
readonly name: string | undefined,
|
|
51
51
|
) {}
|
|
52
52
|
|
|
53
53
|
getDecl(manager: AstManager) {
|
|
@@ -64,9 +64,8 @@ export class Rule {
|
|
|
64
64
|
return false;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
// symbol::str of the name, where the empty name is the null symbol.
|
|
68
67
|
getNameText() {
|
|
69
|
-
return this.name
|
|
68
|
+
return this.name ?? "<null>";
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
display(context: DatalogContext) {
|
|
@@ -225,20 +224,20 @@ export class RuleManager {
|
|
|
225
224
|
return expr;
|
|
226
225
|
}
|
|
227
226
|
|
|
228
|
-
mkRule(fml: number, rules: RuleSet, name
|
|
227
|
+
mkRule(fml: number, rules: RuleSet, name?: string) {
|
|
229
228
|
const bound = this.context.bindVars(fml, true);
|
|
230
229
|
if (this.manager.hasLabelFlags[bound]) throw new SmtUnsupportedError("labels in Horn rules");
|
|
231
230
|
this.mkRuleCore(bound, rules, name);
|
|
232
231
|
}
|
|
233
232
|
|
|
234
|
-
private mkRuleCore(fml: number, rules: RuleSet, name: string) {
|
|
233
|
+
private mkRuleCore(fml: number, rules: RuleSet, name: string | undefined) {
|
|
235
234
|
this.hnf.setName(name);
|
|
236
235
|
const fmls = this.hnf.apply(fml);
|
|
237
236
|
for (const predicate of this.hnf.freshPredicates) this.context.registerPredicate(predicate);
|
|
238
237
|
for (const horn of fmls) this.mkHornRule(horn, rules, name);
|
|
239
238
|
}
|
|
240
239
|
|
|
241
|
-
private mkHornRule(fml: number, rules: RuleSet, name: string) {
|
|
240
|
+
private mkHornRule(fml: number, rules: RuleSet, name: string | undefined) {
|
|
242
241
|
const manager = this.manager;
|
|
243
242
|
const body: number[] = [];
|
|
244
243
|
const extracted = this.extractHorn(fml, body);
|
|
@@ -307,7 +306,7 @@ export class RuleManager {
|
|
|
307
306
|
head: number,
|
|
308
307
|
tail: readonly number[],
|
|
309
308
|
isNegated: readonly boolean[],
|
|
310
|
-
name
|
|
309
|
+
name?: string,
|
|
311
310
|
isNormalizing = true,
|
|
312
311
|
) {
|
|
313
312
|
const manager = this.manager;
|
|
@@ -17,7 +17,7 @@ import { L_FALSE, L_TRUE } from "../lbool";
|
|
|
17
17
|
import { RefVector } from "../ref-vector";
|
|
18
18
|
import type { RewriterOptions } from "../rewriter";
|
|
19
19
|
import { getFreeVarSorts } from "../var-subst";
|
|
20
|
-
import { DatalogContext, ENGINE_SPACER, FpParams } from "./dl-context";
|
|
20
|
+
import { DatalogContext, ENGINE_DATALOG, ENGINE_SPACER, FpParams } from "./dl-context";
|
|
21
21
|
import { mkForall, mkPp } from "./dl-rule";
|
|
22
22
|
import { SpacerDlInterface } from "./spacer-dl-interface";
|
|
23
23
|
|
|
@@ -27,6 +27,19 @@ export const createDatalogContext = (
|
|
|
27
27
|
rewriterOptions: RewriterOptions,
|
|
28
28
|
) =>
|
|
29
29
|
new DatalogContext(manager, new FpParams(parameters), rewriterOptions, (context, engine) => {
|
|
30
|
+
if (engine === ENGINE_DATALOG)
|
|
31
|
+
return {
|
|
32
|
+
// rel_context::query checks the rules with the query's before the saturation the port lacks.
|
|
33
|
+
query: (query) => {
|
|
34
|
+
context.ruleManager.mkQuery(query, context.getRules());
|
|
35
|
+
context.ensureClosed();
|
|
36
|
+
context.getRules();
|
|
37
|
+
throw new SmtUnsupportedError("the datalog engine");
|
|
38
|
+
},
|
|
39
|
+
getModel: () => {
|
|
40
|
+
throw new SmtUnsupportedError("the datalog engine");
|
|
41
|
+
},
|
|
42
|
+
};
|
|
30
43
|
if (engine !== ENGINE_SPACER) throw new SmtUnsupportedError("the bmc engine");
|
|
31
44
|
return new SpacerDlInterface(context);
|
|
32
45
|
});
|
|
@@ -277,6 +277,28 @@ export class RuleProperties {
|
|
|
277
277
|
);
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
+
checkQuantifierFree() {
|
|
281
|
+
const first = this.quantifiers.entries().next();
|
|
282
|
+
if (first.done !== true)
|
|
283
|
+
throw new SmtTacticError(
|
|
284
|
+
`cannot process quantifier in rule ${first.value[1].display(this.context)}`,
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
checkNestedFree() {
|
|
289
|
+
const rules = this.interpretedPredicateRules;
|
|
290
|
+
if (rules.length > 0)
|
|
291
|
+
throw new SmtTacticError(`Rule contains nested predicates ${rules[0].display(this.context)}`);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
checkInfiniteSorts() {
|
|
295
|
+
const rules = this.infiniteSortRules;
|
|
296
|
+
if (rules.length > 0)
|
|
297
|
+
throw new SmtTacticError(
|
|
298
|
+
`Rule contains infinite sorts in rule ${rules[rules.length - 1].display(this.context)}`,
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
280
302
|
checkExistsFree() {
|
|
281
303
|
for (const entry of this.quantifiers)
|
|
282
304
|
if (this.manager.getQuantifier(entry[0]).kind === QUANTIFIER_EXISTS)
|
|
@@ -128,7 +128,7 @@ export class IucSolver {
|
|
|
128
128
|
const result = kernel.check(this.assumptions);
|
|
129
129
|
this.lastModel = undefined;
|
|
130
130
|
if (result === L_TRUE) {
|
|
131
|
-
this.lastModel = kernel.context.
|
|
131
|
+
this.lastModel = kernel.context.getSatModel();
|
|
132
132
|
this.lastModel.incRef();
|
|
133
133
|
}
|
|
134
134
|
this.lastCore = result === L_FALSE ? [...kernel.context.unsatCore] : [];
|
|
@@ -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[] = [];
|
|
@@ -254,6 +260,7 @@ export class OptContext {
|
|
|
254
260
|
checkSat: (assumptions) => getSolver().check(assumptions),
|
|
255
261
|
getModel: () => getSolver().getModel(),
|
|
256
262
|
getUnsatCore: () => getSolver().getUnsatCore(),
|
|
263
|
+
getNumAssertions: () => getSolver().getAssertions().length,
|
|
257
264
|
findMutexes: (vars) => ({ status: L_TRUE, mutexes: getSolver().findMutexes(vars) }),
|
|
258
265
|
};
|
|
259
266
|
return {
|
|
@@ -358,8 +365,6 @@ export class OptContext {
|
|
|
358
365
|
this.updateBound(optsmt, true);
|
|
359
366
|
const count = this.internal.length;
|
|
360
367
|
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
368
|
this.pareto = this.mkParetoSolver(solver, hard, options);
|
|
364
369
|
return this.executePareto();
|
|
365
370
|
}
|
|
@@ -699,6 +704,9 @@ export class OptContext {
|
|
|
699
704
|
this.normalized = this.internal.map((objective) => ({
|
|
700
705
|
term: objective.term,
|
|
701
706
|
isMax: objective.type === O_MAXIMIZE,
|
|
707
|
+
isMaxsmt: objective.type === O_MAXSMT,
|
|
708
|
+
terms: objective.terms,
|
|
709
|
+
weights: objective.weights,
|
|
702
710
|
}));
|
|
703
711
|
result.forms.reset();
|
|
704
712
|
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";
|
|
@@ -76,7 +76,7 @@ export class OptSolver {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
private getContextModel() {
|
|
79
|
-
return this.hold(this.kernel.context.
|
|
79
|
+
return this.hold(this.kernel.context.getSatModel());
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
// get_optimizer makes an arithmetic theory when the setup made none.
|
|
@@ -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);
|
|
@@ -113,7 +113,7 @@ class ParallelSolver {
|
|
|
113
113
|
this.context.maxConflicts = this.threadsMaxConflicts;
|
|
114
114
|
const result = this.kernel.check([...this.assumptions, ...cube]);
|
|
115
115
|
if (result === L_TRUE) {
|
|
116
|
-
this.setSat(this.context.
|
|
116
|
+
this.setSat(this.context.getSatModel());
|
|
117
117
|
return false;
|
|
118
118
|
}
|
|
119
119
|
if (result === L_FALSE) {
|
|
@@ -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
|
+
}
|