tla-ts 0.0.10-dev.3a85c3a9e → 0.0.10-dev.5ffc55ce5
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 +35 -35
- package/dist/deciders.js +29 -29
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +25 -25
- package/dist/prove.js +57 -57
- package/dist/run.cjs +32 -34
- package/dist/run.js +31 -33
- package/dist/transfer.cjs +35 -35
- package/dist/transfer.js +28 -28
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/src/bags.ts +47 -28
- package/src/check-trace.ts +2 -16
- package/src/check.ts +143 -61
- package/src/cli/runtime-invariants.ts +20 -56
- package/src/cli/tlc-arguments.ts +2 -2
- package/src/cli/tlc-output.ts +4 -5
- package/src/cli/tlc.ts +26 -7
- package/src/dfid.ts +9 -2
- package/src/environment.ts +28 -5
- package/src/evaluate.ts +9 -3
- package/src/exit-codes.ts +2 -0
- package/src/liveness-checker.ts +45 -4
- package/src/parallel-worker.ts +8 -2
- package/src/parallel.ts +5 -0
- package/src/prover/smt/solver/ast.ts +1 -1
- package/src/prover/smt/solver/context.ts +6 -2
- package/src/prover/smt/solver/euf/egraph.ts +1 -1
- package/src/prover/smt/solver/expr2polynomial.ts +204 -79
- package/src/prover/smt/solver/factor.ts +36 -14
- package/src/prover/smt/solver/fpa-rewriter.ts +1 -2
- package/src/prover/smt/solver/fpa2bv-converter.ts +3 -1
- package/src/prover/smt/solver/goal.ts +2 -0
- package/src/prover/smt/solver/goal2nlsat.ts +57 -30
- package/src/prover/smt/solver/lp/containers.ts +7 -1
- package/src/prover/smt/solver/lp/cross-nested.ts +1 -3
- package/src/prover/smt/solver/lp/nex-creator.ts +3 -2
- package/src/prover/smt/solver/lp/nex.ts +2 -1
- package/src/prover/smt/solver/lp/nla-basics.ts +46 -1
- package/src/prover/smt/solver/lp/nla-core.ts +26 -6
- package/src/prover/smt/solver/lp/nla-grobner.ts +156 -79
- package/src/prover/smt/solver/lp/nra-solver.ts +138 -95
- package/src/prover/smt/solver/lp/pdd-interval.ts +6 -2
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +60 -20
- package/src/prover/smt/solver/lp/pdd-solver.ts +72 -39
- package/src/prover/smt/solver/lp/pdd.ts +725 -289
- package/src/prover/smt/solver/muz/dl-context.ts +8 -2
- package/src/prover/smt/solver/muz/spacer-context.ts +1 -0
- package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -0
- package/src/prover/smt/solver/nlsat/algebraic.ts +194 -89
- package/src/prover/smt/solver/nlsat/atoms.ts +52 -33
- package/src/prover/smt/solver/nlsat/explain.ts +375 -217
- package/src/prover/smt/solver/nlsat/levelwise.ts +464 -240
- package/src/prover/smt/solver/nlsat/polynomial.ts +2400 -680
- package/src/prover/smt/solver/nlsat/solver.ts +74 -71
- package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -17
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -4
- package/src/prover/smt/solver/nlsat/upolynomial.ts +40 -17
- package/src/prover/smt/solver/opt-nlsat.ts +29 -18
- package/src/prover/smt/solver/opt-solver.ts +2 -3
- package/src/prover/smt/solver/rlimit.ts +13 -0
- package/src/prover/smt/solver/sat/sat-tactic.ts +2 -1
- package/src/prover/smt/solver/seq-derive.ts +3 -6
- package/src/prover/smt/solver/smtlib-parser.ts +10 -10
- package/src/prover/smt/solver/smtlib-script.ts +91 -28
- package/src/prover/smt/solver/tactic.ts +14 -5
- package/src/prover/smt/solver/theory-lra-internalize.ts +8 -0
- package/src/prover/zenon/equality-rules.ts +24 -0
- package/src/prover/zenon/expr.ts +21 -0
- package/src/prover/zenon/index-table.ts +2 -0
- package/src/prover/zenon/rules.ts +2 -1
- package/src/resolve.ts +2 -3
- package/src/runtime.ts +6 -0
- package/src/sany/generator-expressions.ts +6 -13
- package/src/search.ts +67 -29
- package/src/simulate.ts +3 -0
- package/src/standard-definitions.ts +4 -0
- package/src/tlc/order.ts +14 -3
- package/src/tlc/tlcext-operators.ts +61 -16
- package/src/tlc/trace-spec.ts +2 -3
|
@@ -19,7 +19,8 @@ import {
|
|
|
19
19
|
import { Goal } from "./goal";
|
|
20
20
|
import { goal2nlsat } from "./goal2nlsat";
|
|
21
21
|
import { L_FALSE, L_TRUE, L_UNDEF } from "./lbool";
|
|
22
|
-
import {
|
|
22
|
+
import type { AlgebraicManager, Anum } from "./nlsat/algebraic";
|
|
23
|
+
import { PolynomialManager, PolynomialRef } from "./nlsat/polynomial";
|
|
23
24
|
import { NlsatSolver } from "./nlsat/solver";
|
|
24
25
|
import { ProtoModel } from "./proto-model";
|
|
25
26
|
import { Rational } from "./rational";
|
|
@@ -97,10 +98,16 @@ export const isInNraFragment = (manager: AstManager, exprs: readonly number[]) =
|
|
|
97
98
|
return true;
|
|
98
99
|
};
|
|
99
100
|
|
|
100
|
-
const getCoarseInterval = (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
const getCoarseInterval = (
|
|
102
|
+
manager: AstManager,
|
|
103
|
+
am: AlgebraicManager,
|
|
104
|
+
value: Anum,
|
|
105
|
+
): [Rational, Rational] => {
|
|
106
|
+
const pm = new PolynomialManager(manager.limit);
|
|
107
|
+
const p = new PolynomialRef(pm);
|
|
108
|
+
p.set(pm.toPolynomial(am.getPolynomial(value), 0));
|
|
109
|
+
const roots = am.isolateRoots(pm, p.get(), []);
|
|
110
|
+
p.reset();
|
|
104
111
|
const index = roots.findIndex((root) => am.compare(root, value) === 0);
|
|
105
112
|
const lower = index === 0 ? am.intLt(value) : am.select(roots[index - 1], value);
|
|
106
113
|
const upper = index + 1 === roots.length ? am.intGt(value) : am.select(value, roots[index + 1]);
|
|
@@ -108,8 +115,7 @@ const getCoarseInterval = (solver: NlsatSolver, value: Anum): [Rational, Rationa
|
|
|
108
115
|
};
|
|
109
116
|
|
|
110
117
|
export const mkAlgebraicEq = (manager: AstManager, term: number, value: Anum) => {
|
|
111
|
-
const
|
|
112
|
-
const am = solver.am;
|
|
118
|
+
const am = manager.am;
|
|
113
119
|
if (am.isRational(value))
|
|
114
120
|
return manager.mkApp(OP_EQ, [term, manager.mkRealNumeral(am.toRational(value))], SORT_BOOL);
|
|
115
121
|
const coeffs = am.getPolynomial(value);
|
|
@@ -125,7 +131,7 @@ export const mkAlgebraicEq = (manager: AstManager, term: number, value: Anum) =>
|
|
|
125
131
|
SORT_REAL,
|
|
126
132
|
);
|
|
127
133
|
}
|
|
128
|
-
const [lower, upper] = getCoarseInterval(
|
|
134
|
+
const [lower, upper] = getCoarseInterval(manager, am, value);
|
|
129
135
|
return manager.mkApp(
|
|
130
136
|
OP_AND,
|
|
131
137
|
[
|
|
@@ -152,19 +158,24 @@ const isOccurring = (manager: AstManager, target: number, expr: number) => {
|
|
|
152
158
|
const mkLowerBound = (solver: NlsatSolver, variable: number, value: Anum, isStrict: boolean) => {
|
|
153
159
|
const am = solver.am;
|
|
154
160
|
const pm = solver.pm;
|
|
161
|
+
const p = new PolynomialRef(pm);
|
|
155
162
|
if (am.isRational(value)) {
|
|
156
163
|
const rational = am.toRational(value);
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
? solver.mkIneqLiteral("GT", [
|
|
160
|
-
: solver.mkIneqLiteral("LT", [
|
|
164
|
+
p.set(pm.mkLinear([rational.den], [variable], -rational.num));
|
|
165
|
+
const literal = isStrict
|
|
166
|
+
? solver.mkIneqLiteral("GT", [p.get()], [false])
|
|
167
|
+
: solver.mkIneqLiteral("LT", [p.get()], [false]) ^ 1;
|
|
168
|
+
p.reset();
|
|
169
|
+
return literal;
|
|
161
170
|
}
|
|
162
|
-
|
|
163
|
-
const index = am
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
171
|
+
p.set(pm.toPolynomial(am.getPolynomial(value), variable));
|
|
172
|
+
const index = am.isolateRoots(pm, p.get(), []).findIndex((root) => am.compare(root, value) === 0);
|
|
173
|
+
const literal =
|
|
174
|
+
index === -1
|
|
175
|
+
? null
|
|
176
|
+
: 2 * solver.mkRootAtom(isStrict ? "ROOT_GT" : "ROOT_GE", variable, index + 1, p.get());
|
|
177
|
+
p.reset();
|
|
178
|
+
return literal;
|
|
168
179
|
};
|
|
169
180
|
|
|
170
181
|
const getBracket = (solver: NlsatSolver, value: Anum): [Rational, Rational] => {
|
|
@@ -2,7 +2,7 @@ import { SmtCanceledError, 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";
|
|
5
|
-
import { AlgebraicManager } from "./nlsat/algebraic";
|
|
5
|
+
import type { AlgebraicManager } from "./nlsat/algebraic";
|
|
6
6
|
import type { ParetoSolver } from "./opt-pareto";
|
|
7
7
|
import type { ProtoModel } from "./proto-model";
|
|
8
8
|
import { Rational } from "./rational";
|
|
@@ -40,7 +40,6 @@ export const getModelValueBound = (
|
|
|
40
40
|
|
|
41
41
|
export class OptSolver {
|
|
42
42
|
private readonly kernel: SmtKernel;
|
|
43
|
-
private readonly am = new AlgebraicManager();
|
|
44
43
|
private model: ProtoModel | null = null;
|
|
45
44
|
private objectiveVars: number[] = [];
|
|
46
45
|
private objectiveValues: InfEps[] = [];
|
|
@@ -165,7 +164,7 @@ export class OptSolver {
|
|
|
165
164
|
|
|
166
165
|
private getModelValueLowerBound(model: ProtoModel, index: number) {
|
|
167
166
|
const value = model.eval(this.objectiveTerms[index], false);
|
|
168
|
-
const bound = getModelValueBound(this.manager, this.am, value, true);
|
|
167
|
+
const bound = getModelValueBound(this.manager, this.manager.am, value, true);
|
|
169
168
|
this.manager.decRef(value);
|
|
170
169
|
return bound;
|
|
171
170
|
}
|
|
@@ -43,6 +43,19 @@ export class ResourceLimit {
|
|
|
43
43
|
this.isCanceled = false;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
pushChild(child: ResourceLimit) {
|
|
47
|
+
child.limit = Math.min(child.limit, this.limit - Math.min(this.limit, this.count));
|
|
48
|
+
child.count = 0;
|
|
49
|
+
child.deadline = this.deadline;
|
|
50
|
+
child.signal = this.signal;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
popChild(child: ResourceLimit) {
|
|
54
|
+
this.count += child.count;
|
|
55
|
+
child.count = 0;
|
|
56
|
+
child.release();
|
|
57
|
+
}
|
|
58
|
+
|
|
46
59
|
restart(deadline: number) {
|
|
47
60
|
this.deadline = deadline;
|
|
48
61
|
this.isCanceled = false;
|
|
@@ -2,7 +2,7 @@ import { SmtTacticError } from "../../../../errors";
|
|
|
2
2
|
import type { AstManager } from "../ast";
|
|
3
3
|
import type { ThSolverFactory } from "../euf/euf-solver";
|
|
4
4
|
import { OVER, type Goal } from "../goal";
|
|
5
|
-
import { L_FALSE, L_TRUE } from "../lbool";
|
|
5
|
+
import { L_FALSE, L_TRUE, L_UNDEF } from "../lbool";
|
|
6
6
|
import { ProtoModel } from "../proto-model";
|
|
7
7
|
import type { SatParams } from "./config";
|
|
8
8
|
import { Goal2Sat } from "./goal2sat";
|
|
@@ -20,6 +20,7 @@ export const createSatTactic =
|
|
|
20
20
|
goal2sat.run(goal.forms.items);
|
|
21
21
|
goal.reset();
|
|
22
22
|
const result = solver.check();
|
|
23
|
+
if (result === L_UNDEF) goal.reasonUnknown = solver.reasonUnknown;
|
|
23
24
|
const unhandledFuns = goal2sat.euf?.unhandledFunctions ?? goal2sat.unhandledFuns;
|
|
24
25
|
if (result === L_FALSE) goal.assert(manager.falseExpr);
|
|
25
26
|
else if (result === L_TRUE && unhandledFuns.length === 0) {
|
|
@@ -1242,12 +1242,9 @@ export class Derive {
|
|
|
1242
1242
|
}
|
|
1243
1243
|
|
|
1244
1244
|
derivativeCofactors(regex: number, result: RefVector) {
|
|
1245
|
-
const
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
const derivative = this.derive(DERIVATIVE_BRZOZOWSKI, element, regex);
|
|
1249
|
-
// Deviation from Z3: a cached derivative leaves m_ele null there, which stops the pruning.
|
|
1250
|
-
this.getCofactors(element, derivative, result);
|
|
1245
|
+
const derivative = this.deriveSymbolic(DERIVATIVE_BRZOZOWSKI, regex);
|
|
1246
|
+
// Like Z3, a cached derivative whose lookup reset the op caches leaves the element unset, which stops the interval pruning.
|
|
1247
|
+
this.getCofactors(this.element, derivative, result);
|
|
1251
1248
|
}
|
|
1252
1249
|
|
|
1253
1250
|
lightAntDerivativeCofactors(regex: number, result: RefVector) {
|
|
@@ -208,8 +208,6 @@ type SortDecl = ConstantSortDecl | UserSortDecl | DatatypeSortDecl | DefinedSort
|
|
|
208
208
|
|
|
209
209
|
const NO_BINDINGS: ReadonlyMap<string, number> = new Map();
|
|
210
210
|
|
|
211
|
-
const UPOLYNOMIALS = new UpolynomialManager();
|
|
212
|
-
|
|
213
211
|
interface SmtProblem {
|
|
214
212
|
assertions: number[];
|
|
215
213
|
hasCheckSat: boolean;
|
|
@@ -1649,8 +1647,10 @@ export const createSmtlibReader = (
|
|
|
1649
1647
|
return mkSeqAppOf(manager, signature, args);
|
|
1650
1648
|
};
|
|
1651
1649
|
|
|
1650
|
+
const upolynomials = new UpolynomialManager(manager.limit);
|
|
1651
|
+
|
|
1652
1652
|
const parseUpolynomial = (sexpr: SExpr): bigint[] => {
|
|
1653
|
-
if (sexpr.kind === "numeral") return
|
|
1653
|
+
if (sexpr.kind === "numeral") return upolynomials.set([BigInt(sexpr.text)]);
|
|
1654
1654
|
if (sexpr.kind === "decimal") {
|
|
1655
1655
|
const parts = sexpr.text.split(".");
|
|
1656
1656
|
const value = Rational.of(BigInt(parts[0] + parts[1]), 10n ** BigInt(parts[1].length));
|
|
@@ -1659,7 +1659,7 @@ export const createSmtlibReader = (
|
|
|
1659
1659
|
"invalid univariate polynomial, integer coefficient expected",
|
|
1660
1660
|
sexpr,
|
|
1661
1661
|
);
|
|
1662
|
-
return
|
|
1662
|
+
return upolynomials.set([value.num]);
|
|
1663
1663
|
}
|
|
1664
1664
|
if (sexpr.kind === "symbol") {
|
|
1665
1665
|
if (sexpr.text !== "x")
|
|
@@ -1684,15 +1684,15 @@ export const createSmtlibReader = (
|
|
|
1684
1684
|
"invalid univariate polynomial, exponent must be an unsigned integer",
|
|
1685
1685
|
exponent,
|
|
1686
1686
|
);
|
|
1687
|
-
return
|
|
1687
|
+
return upolynomials.pw(parseUpolynomial(operands[0]), Number(exponent.text));
|
|
1688
1688
|
}
|
|
1689
1689
|
const combine =
|
|
1690
1690
|
head.text === "+"
|
|
1691
|
-
?
|
|
1691
|
+
? upolynomials.add
|
|
1692
1692
|
: head.text === "-"
|
|
1693
|
-
?
|
|
1693
|
+
? upolynomials.sub
|
|
1694
1694
|
: head.text === "*"
|
|
1695
|
-
?
|
|
1695
|
+
? upolynomials.mul
|
|
1696
1696
|
: undefined;
|
|
1697
1697
|
if (combine === undefined)
|
|
1698
1698
|
throw new SmtParseError(
|
|
@@ -1705,11 +1705,11 @@ export const createSmtlibReader = (
|
|
|
1705
1705
|
sexpr,
|
|
1706
1706
|
);
|
|
1707
1707
|
const first = parseUpolynomial(operands[0]);
|
|
1708
|
-
if (head.text === "-" && operands.length === 1) return
|
|
1708
|
+
if (head.text === "-" && operands.length === 1) return upolynomials.neg(first);
|
|
1709
1709
|
return operands
|
|
1710
1710
|
.slice(1)
|
|
1711
1711
|
.reduce(
|
|
1712
|
-
(result, operand) => combine.call(
|
|
1712
|
+
(result, operand) => combine.call(upolynomials, result, parseUpolynomial(operand)),
|
|
1713
1713
|
first,
|
|
1714
1714
|
);
|
|
1715
1715
|
};
|
|
@@ -69,6 +69,7 @@ import {
|
|
|
69
69
|
compileTactic,
|
|
70
70
|
getRewriterOptions,
|
|
71
71
|
getSatParams,
|
|
72
|
+
getSmtTacticFailure,
|
|
72
73
|
type TacticParam,
|
|
73
74
|
} from "./tactic";
|
|
74
75
|
|
|
@@ -278,6 +279,12 @@ interface CheckResult {
|
|
|
278
279
|
reasonUnknown?: string;
|
|
279
280
|
}
|
|
280
281
|
|
|
282
|
+
interface SolverAnswer {
|
|
283
|
+
result: number;
|
|
284
|
+
context: Context | undefined;
|
|
285
|
+
reasonUnknown: string | undefined;
|
|
286
|
+
}
|
|
287
|
+
|
|
281
288
|
interface ScriptState {
|
|
282
289
|
manager: AstManager;
|
|
283
290
|
logic: string | undefined;
|
|
@@ -311,6 +318,7 @@ const MANAGERLESS_COMMANDS = new Set([
|
|
|
311
318
|
"set-logic",
|
|
312
319
|
"get-option",
|
|
313
320
|
"get-info",
|
|
321
|
+
"get-assertions",
|
|
314
322
|
"echo",
|
|
315
323
|
]);
|
|
316
324
|
|
|
@@ -483,23 +491,46 @@ export const runSmtlibScript = (
|
|
|
483
491
|
getLogicStrategy(state.logic, goal.isProofsEnabled);
|
|
484
492
|
try {
|
|
485
493
|
const checked = checkSatUsing(compileInternalTactic(getTacticEnvironment(), strategy), goal);
|
|
486
|
-
return {
|
|
494
|
+
return {
|
|
495
|
+
result: checked.status,
|
|
496
|
+
context: undefined,
|
|
497
|
+
model: checked.model,
|
|
498
|
+
reasonUnknown: checked.reasonUnknown,
|
|
499
|
+
};
|
|
487
500
|
} catch (error) {
|
|
488
501
|
if (!(error instanceof SmtUnsupportedError)) throw error;
|
|
489
502
|
const hasQuantifiers = state.assertions.some(
|
|
490
503
|
(assertion) => state.manager.hasQuantifierFlags[assertion],
|
|
491
504
|
);
|
|
505
|
+
const solved = solveAssertions(state.manager, state.assertions, {
|
|
506
|
+
isMbqi: settings.isMbqi || isMbqiByFeatures(getSetup(), hasQuantifiers),
|
|
507
|
+
mbqiMaxIterations: settings.mbqiMaxIterations,
|
|
508
|
+
isFindingMacros: settings.isFindingMacros,
|
|
509
|
+
setup: getSetup(),
|
|
510
|
+
});
|
|
492
511
|
return {
|
|
493
|
-
...
|
|
494
|
-
isMbqi: settings.isMbqi || isMbqiByFeatures(getSetup(), hasQuantifiers),
|
|
495
|
-
mbqiMaxIterations: settings.mbqiMaxIterations,
|
|
496
|
-
isFindingMacros: settings.isFindingMacros,
|
|
497
|
-
setup: getSetup(),
|
|
498
|
-
}),
|
|
512
|
+
...solved,
|
|
499
513
|
model: undefined,
|
|
514
|
+
reasonUnknown:
|
|
515
|
+
solved.result === L_UNDEF && solved.context !== undefined
|
|
516
|
+
? getSmtTacticFailure(solved.context)
|
|
517
|
+
: "",
|
|
500
518
|
};
|
|
501
519
|
}
|
|
502
520
|
};
|
|
521
|
+
// Deviation from Z3: the heap guard and a stack overflow, which Z3 lacks, read as an exhausted rlimit.
|
|
522
|
+
const getCancelMessage = (deadline: number) =>
|
|
523
|
+
Date.now() > deadline || options.signal?.aborted === true
|
|
524
|
+
? "canceled"
|
|
525
|
+
: "max. resource limit exceeded";
|
|
526
|
+
// As in Z3, a timeout leaves "timeout" in the kernel, which reports it while its last search hasn't failed.
|
|
527
|
+
const getReasonUnknown = (solved: SolverAnswer, deadline: number) => {
|
|
528
|
+
const isTimedOut = solved.result === L_UNDEF && Date.now() > deadline;
|
|
529
|
+
const context = state.kernel?.context;
|
|
530
|
+
if (isTimedOut && context !== undefined) context.reasonUnknown = "timeout";
|
|
531
|
+
if (context !== undefined && solved.context === context) return context.getLastFailureMessage();
|
|
532
|
+
return isTimedOut ? "timeout" : (solved.reasonUnknown ?? getCancelMessage(deadline));
|
|
533
|
+
};
|
|
503
534
|
const getKernelParams = () => ({
|
|
504
535
|
isMbqi: settings.isMbqi || isMbqiByLogic(getSetup()),
|
|
505
536
|
mbqiMaxIterations: settings.mbqiMaxIterations,
|
|
@@ -512,25 +543,25 @@ export const runSmtlibScript = (
|
|
|
512
543
|
!settings.isProducingProofs &&
|
|
513
544
|
!settings.parameters.has("tactic.default_tactic");
|
|
514
545
|
const checkSat = (extra: number[]) => {
|
|
515
|
-
|
|
546
|
+
const deadline = Date.now() + options.timeLimitMs;
|
|
547
|
+
state.manager.limit.restart(deadline);
|
|
516
548
|
// opt::context::optimize answers as the search of the hard constraints does: once they are
|
|
517
549
|
// satisfiable, optsmt and maxsmt only improve the model. The unported parts of optimization
|
|
518
550
|
// only get that answer.
|
|
519
551
|
if (state.objectives.length > 0 && optimize(extra)) return;
|
|
520
552
|
state.manager.limit.push(settings.rlimit);
|
|
521
553
|
const isOptimizing = state.objectives.length > 0;
|
|
554
|
+
const manager = state.manager;
|
|
555
|
+
const names = state.names.filter((name) => name !== -1);
|
|
556
|
+
const isNamed = names.length > 0;
|
|
557
|
+
const isAssuming = isNamed || extra.length > 0;
|
|
558
|
+
if (isAssuming) state.isIncremental = true;
|
|
559
|
+
if (!isOptimizing) state.hasChecked = true;
|
|
560
|
+
const isKernelChecking =
|
|
561
|
+
isAssuming || (state.isIncremental && !isOptimizing && !isUsingFdSolver());
|
|
522
562
|
try {
|
|
523
|
-
const manager = state.manager;
|
|
524
|
-
const names = state.names.filter((name) => name !== -1);
|
|
525
|
-
const isNamed = names.length > 0;
|
|
526
|
-
const isAssuming = isNamed || extra.length > 0;
|
|
527
|
-
if (isAssuming) state.isIncremental = true;
|
|
528
|
-
if (!isOptimizing) state.hasChecked = true;
|
|
529
563
|
const assumptions = isNamed ? [...names, ...extra] : extra;
|
|
530
|
-
const kernel =
|
|
531
|
-
isAssuming || (state.isIncremental && !isOptimizing && !isUsingFdSolver())
|
|
532
|
-
? checkKernel(assumptions)
|
|
533
|
-
: undefined;
|
|
564
|
+
const kernel = isKernelChecking ? checkKernel(assumptions) : undefined;
|
|
534
565
|
// Z3 retries a quantifier-free problem with its tactic when the incremental kernel gives up.
|
|
535
566
|
const solved =
|
|
536
567
|
kernel === undefined ||
|
|
@@ -545,11 +576,19 @@ export const runSmtlibScript = (
|
|
|
545
576
|
isOptimizing,
|
|
546
577
|
model: solved.model,
|
|
547
578
|
core: solved.core ?? solved.context?.unsatCore ?? [],
|
|
579
|
+
reasonUnknown: getReasonUnknown(solved, deadline),
|
|
548
580
|
});
|
|
549
581
|
print(getVerdict(solved.result));
|
|
550
582
|
} catch (error) {
|
|
551
583
|
if (!(error instanceof SmtCanceledError || isStackOverflow(error))) throw error;
|
|
552
|
-
|
|
584
|
+
const context = isKernelChecking ? state.kernel?.context : undefined;
|
|
585
|
+
setCheck(L_UNDEF, {
|
|
586
|
+
isOptimizing,
|
|
587
|
+
reasonUnknown: getReasonUnknown(
|
|
588
|
+
{ result: L_UNDEF, context, reasonUnknown: undefined },
|
|
589
|
+
deadline,
|
|
590
|
+
),
|
|
591
|
+
});
|
|
553
592
|
print("unknown");
|
|
554
593
|
} finally {
|
|
555
594
|
state.manager.limit.release();
|
|
@@ -643,6 +682,7 @@ export const runSmtlibScript = (
|
|
|
643
682
|
context: undefined,
|
|
644
683
|
model: result === L_TRUE ? (solver.getModel() ?? undefined) : undefined,
|
|
645
684
|
core: result === L_FALSE ? [...solver.getUnsatCore()] : undefined,
|
|
685
|
+
reasonUnknown: solver.reasonUnknown,
|
|
646
686
|
};
|
|
647
687
|
});
|
|
648
688
|
if (found !== undefined) return found;
|
|
@@ -652,11 +692,19 @@ export const runSmtlibScript = (
|
|
|
652
692
|
context: kernel.context,
|
|
653
693
|
model: undefined,
|
|
654
694
|
core: undefined,
|
|
695
|
+
reasonUnknown: undefined,
|
|
655
696
|
};
|
|
697
|
+
const solved = solveAssuming(
|
|
698
|
+
state.manager,
|
|
699
|
+
getNamedAssertions(),
|
|
700
|
+
assumptions,
|
|
701
|
+
getKernelParams(),
|
|
702
|
+
);
|
|
656
703
|
return {
|
|
657
|
-
...
|
|
704
|
+
...solved,
|
|
658
705
|
model: undefined,
|
|
659
706
|
core: undefined,
|
|
707
|
+
reasonUnknown: solved.context.getLastFailureMessage(),
|
|
660
708
|
};
|
|
661
709
|
};
|
|
662
710
|
const printDiagnostic = (line: string) => print(line, !settings.isDiagnosticOnStdout);
|
|
@@ -924,15 +972,17 @@ export const runSmtlibScript = (
|
|
|
924
972
|
for (const assertion of state.assertions) datalog.assertExpr(assertion);
|
|
925
973
|
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
926
974
|
state.manager.limit.push(settings.rlimit);
|
|
975
|
+
let status = L_UNDEF;
|
|
927
976
|
try {
|
|
928
|
-
|
|
977
|
+
status = datalog.relQuery(relation);
|
|
929
978
|
} catch (error) {
|
|
930
979
|
if (!(error instanceof SmtTacticError)) throw error;
|
|
931
980
|
print(`(error "query failed: ${error.message}")`);
|
|
932
|
-
print("unknown");
|
|
933
981
|
} finally {
|
|
934
982
|
state.manager.limit.pop();
|
|
935
983
|
}
|
|
984
|
+
print(status === L_UNDEF && datalog.isBounded ? "bounded" : getVerdict(status));
|
|
985
|
+
datalog.isBounded = false;
|
|
936
986
|
},
|
|
937
987
|
],
|
|
938
988
|
[
|
|
@@ -944,7 +994,8 @@ export const runSmtlibScript = (
|
|
|
944
994
|
const builder = getTactic(list.items[1], list.end);
|
|
945
995
|
const tactic = builder.build(params);
|
|
946
996
|
clearCheck();
|
|
947
|
-
|
|
997
|
+
const deadline = Date.now() + options.timeLimitMs;
|
|
998
|
+
state.manager.limit.restart(deadline);
|
|
948
999
|
state.manager.limit.push(settings.rlimit);
|
|
949
1000
|
try {
|
|
950
1001
|
const checked = checkSatUsing(tactic, getGoal(builder.isTrackingDependencies));
|
|
@@ -954,7 +1005,7 @@ export const runSmtlibScript = (
|
|
|
954
1005
|
builder.isTrackingDependencies || !hasNames()
|
|
955
1006
|
? getDependencyValues(checked.core)
|
|
956
1007
|
: undefined,
|
|
957
|
-
reasonUnknown: checked.reasonUnknown,
|
|
1008
|
+
reasonUnknown: checked.reasonUnknown ?? getCancelMessage(deadline),
|
|
958
1009
|
});
|
|
959
1010
|
print(getVerdict(checked.status));
|
|
960
1011
|
} finally {
|
|
@@ -1013,7 +1064,11 @@ export const runSmtlibScript = (
|
|
|
1013
1064
|
if (state.kernel === undefined)
|
|
1014
1065
|
for (const assertion of getNamedAssertions()) kernel.assertExpr(assertion);
|
|
1015
1066
|
const found = getConsequences(kernel, [...names, ...assumptions], vars);
|
|
1016
|
-
setCheck(found.result, {
|
|
1067
|
+
setCheck(found.result, {
|
|
1068
|
+
context: kernel.context,
|
|
1069
|
+
core: kernel.context.unsatCore,
|
|
1070
|
+
reasonUnknown: kernel.context.getLastFailureMessage(),
|
|
1071
|
+
});
|
|
1017
1072
|
print(getVerdict(found.result));
|
|
1018
1073
|
print("");
|
|
1019
1074
|
for (const consequence of found.consequences.items) display(consequence);
|
|
@@ -1453,7 +1508,14 @@ export const runSmtlibScript = (
|
|
|
1453
1508
|
if (keyword === ":produce-models") settings.isProducingModels = isTrue;
|
|
1454
1509
|
if (keyword === ":produce-unsat-cores") settings.isProducingUnsatCores = isTrue;
|
|
1455
1510
|
if (keyword === ":produce-proofs") settings.isProducingProofs = isTrue;
|
|
1456
|
-
if (keyword === ":interactive-mode"
|
|
1511
|
+
if (keyword === ":interactive-mode" || keyword === ":produce-assertions") {
|
|
1512
|
+
if (state.isProofsEnabled !== undefined)
|
|
1513
|
+
throw new SmtParseError(
|
|
1514
|
+
"error setting ':produce-assertions', option value cannot be modified after initialization",
|
|
1515
|
+
value ?? list.end,
|
|
1516
|
+
);
|
|
1517
|
+
settings.isInteractive = isTrue;
|
|
1518
|
+
}
|
|
1457
1519
|
if (keyword === ":diagnostic-output-channel")
|
|
1458
1520
|
settings.isDiagnosticOnStdout = value?.kind === "string" && value.text === "stdout";
|
|
1459
1521
|
if (keyword === ":int-real-coercions" && !isTrue)
|
|
@@ -1519,6 +1581,8 @@ export const runSmtlibScript = (
|
|
|
1519
1581
|
[":print-success", settings.isPrintingSuccess],
|
|
1520
1582
|
[":produce-models", settings.isProducingModels],
|
|
1521
1583
|
[":produce-unsat-cores", settings.isProducingUnsatCores],
|
|
1584
|
+
[":interactive-mode", settings.isInteractive],
|
|
1585
|
+
[":produce-assertions", settings.isInteractive],
|
|
1522
1586
|
[":int-real-coercions", true],
|
|
1523
1587
|
[":error-behavior", settings.isExitingOnError ? "immediate-exit" : "continued-execution"],
|
|
1524
1588
|
]);
|
|
@@ -1590,8 +1654,7 @@ export const runSmtlibScript = (
|
|
|
1590
1654
|
state.reader = createSmtlibReader(state.manager, logic.text, settings.parserOptions);
|
|
1591
1655
|
else {
|
|
1592
1656
|
state.reader.restrictSorts(logic.text);
|
|
1593
|
-
// Deviation from Z3: its new solver starts without the open scopes, so it ignores their pop
|
|
1594
|
-
// and keeps what they asserted.
|
|
1657
|
+
// Deviation from Z3: its new solver starts without the open scopes, so it ignores their pop and keeps what they asserted.
|
|
1595
1658
|
resetKernel();
|
|
1596
1659
|
}
|
|
1597
1660
|
if (settings.isPrintingSuccess) print("success");
|
|
@@ -339,6 +339,11 @@ export const getSatParams = (parameters: ReadonlyMap<string, string>) =>
|
|
|
339
339
|
}),
|
|
340
340
|
);
|
|
341
341
|
|
|
342
|
+
export const getSmtTacticFailure = (context: Context) =>
|
|
343
|
+
context.checkCanceled()
|
|
344
|
+
? "canceled"
|
|
345
|
+
: `smt tactic failed to show goal to be sat/unsat ${context.getLastFailureMessage()}`;
|
|
346
|
+
|
|
342
347
|
// sat_params reads what using-params leaves unset from the sat module's global parameters.
|
|
343
348
|
const getSatTacticParams = (environment: TacticEnvironment, params: TacticParams) =>
|
|
344
349
|
new Map([...getSatParams(environment.parameters), ...params]);
|
|
@@ -355,7 +360,7 @@ const runSmt = (environment: TacticEnvironment, params: TacticParams) => (goal:
|
|
|
355
360
|
? solveGoal(manager, goal.forms.items, kernelParams)
|
|
356
361
|
: solveAssuming(manager, extracted.clauses.items, extracted.assumptions, kernelParams);
|
|
357
362
|
extracted.clauses.reset();
|
|
358
|
-
if (solved.result === L_UNDEF) throw new SmtTacticError(solved.context
|
|
363
|
+
if (solved.result === L_UNDEF) throw new SmtTacticError(getSmtTacticFailure(solved.context));
|
|
359
364
|
goal.reset();
|
|
360
365
|
if (solved.result === L_FALSE)
|
|
361
366
|
goal.assert(environment.manager.falseExpr, mkCoreDependency(solved.context.unsatCore));
|
|
@@ -1880,7 +1885,6 @@ interface TacticCheck {
|
|
|
1880
1885
|
status: number;
|
|
1881
1886
|
model: ProtoModel | undefined;
|
|
1882
1887
|
core: Dependency | undefined;
|
|
1883
|
-
// What check_sat leaves in reason_unknown, or undefined where the port does not track it.
|
|
1884
1888
|
reasonUnknown: string | undefined;
|
|
1885
1889
|
}
|
|
1886
1890
|
|
|
@@ -1959,21 +1963,26 @@ export const checkSatUsing = (tactic: Tactic, goal: Goal): TacticCheck => {
|
|
|
1959
1963
|
throw error;
|
|
1960
1964
|
}
|
|
1961
1965
|
})();
|
|
1966
|
+
if (goals === undefined) return { ...undecided, reasonUnknown: undefined };
|
|
1962
1967
|
if (typeof goals === "string") return { ...undecided, reasonUnknown: goals };
|
|
1963
|
-
if (
|
|
1968
|
+
if (isDecidedSat(goals)) {
|
|
1964
1969
|
const model = convertModel(goals[0], goals[0].model ?? new ProtoModel(goal.manager));
|
|
1965
1970
|
return goal.manager.limit.inc()
|
|
1966
1971
|
? { status: L_TRUE, model, core: undefined, reasonUnknown: "" }
|
|
1967
1972
|
: { ...undecided, model, reasonUnknown: "canceled" };
|
|
1968
1973
|
}
|
|
1969
|
-
if (
|
|
1974
|
+
if (isDecidedUnsat(goals))
|
|
1970
1975
|
return {
|
|
1971
1976
|
status: L_FALSE,
|
|
1972
1977
|
model: undefined,
|
|
1973
1978
|
core: goals[0].getDependency(0),
|
|
1974
1979
|
reasonUnknown: "",
|
|
1975
1980
|
};
|
|
1976
|
-
return {
|
|
1981
|
+
return {
|
|
1982
|
+
...undecided,
|
|
1983
|
+
reasonUnknown:
|
|
1984
|
+
goals.length === 1 && goals[0].reasonUnknown !== "" ? goals[0].reasonUnknown : "unknown",
|
|
1985
|
+
};
|
|
1977
1986
|
};
|
|
1978
1987
|
|
|
1979
1988
|
export const applyTactic = (tactic: Tactic, goal: Goal) => {
|
|
@@ -240,10 +240,18 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
240
240
|
nla.isRelevant = (lpVar) =>
|
|
241
241
|
this.context.isRelevant(this.getExpr(this.solver.getExternal(lpVar)));
|
|
242
242
|
nla.grobner.updateParams();
|
|
243
|
+
nla.addMulDefHook = (vars) => this.addMulDef(vars);
|
|
243
244
|
this.nla = nla;
|
|
244
245
|
return nla;
|
|
245
246
|
}
|
|
246
247
|
|
|
248
|
+
private addMulDef(vars: readonly number[]) {
|
|
249
|
+
const isInt = vars.every((lpVar) => this.isIntVar(this.solver.getExternal(lpVar)));
|
|
250
|
+
const product = this.manager.mkFreshConst("mul!", isInt ? SORT_INT : SORT_REAL);
|
|
251
|
+
this.mkEnode(product);
|
|
252
|
+
return this.registerVar(this.mkVar(product));
|
|
253
|
+
}
|
|
254
|
+
|
|
247
255
|
private registerDivision(quotient: number, remainder: number): Division {
|
|
248
256
|
const register = (expr: number) => {
|
|
249
257
|
this.internalizeTermCore(expr);
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
isNegatedRelation,
|
|
5
5
|
isRelation,
|
|
6
6
|
isMeta,
|
|
7
|
+
preunify,
|
|
7
8
|
type Expr,
|
|
8
9
|
type NegatedRelationExpr,
|
|
9
10
|
type NotExpr,
|
|
@@ -204,6 +205,29 @@ export const addReflexivity: SearchRule = (context, queue, formula, goalness) =>
|
|
|
204
205
|
return [queue, false];
|
|
205
206
|
};
|
|
206
207
|
|
|
208
|
+
export const addPreunification: SearchRule = (context, queue, formula, goalness) => {
|
|
209
|
+
const matches =
|
|
210
|
+
formula.kind === "not" && formula.args[0].kind === "app"
|
|
211
|
+
? context.index.getPositive(formula.args[0].symbol)
|
|
212
|
+
: formula.kind === "app"
|
|
213
|
+
? context.index.getNegative(formula.symbol)
|
|
214
|
+
: undefined;
|
|
215
|
+
if (matches === undefined) return [queue, false];
|
|
216
|
+
let current = queue;
|
|
217
|
+
for (let matchIndex = matches.length - 1; matchIndex >= 0; matchIndex--) {
|
|
218
|
+
const pairs = preunify(matches[matchIndex], formula);
|
|
219
|
+
for (let pairIndex = 0; pairIndex < pairs.length; pairIndex++)
|
|
220
|
+
current = makeInstance(
|
|
221
|
+
context.exprs,
|
|
222
|
+
current,
|
|
223
|
+
pairs[pairIndex][0],
|
|
224
|
+
pairs[pairIndex][1],
|
|
225
|
+
Math.min(goalness, context.index.getGoalness(matches[matchIndex])),
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
return [current, false];
|
|
229
|
+
};
|
|
230
|
+
|
|
207
231
|
export const addCongruence: SearchRule = (context, queue, formula, goalness) => {
|
|
208
232
|
const exprs = context.exprs;
|
|
209
233
|
if (formula.kind !== "not" || !isApp(formula.args[0], "=", 2)) return [queue, false];
|
package/src/prover/zenon/expr.ts
CHANGED
|
@@ -241,6 +241,27 @@ export const compareExprs = (left: Expr, right: Expr): number => {
|
|
|
241
241
|
return 0;
|
|
242
242
|
};
|
|
243
243
|
|
|
244
|
+
const NO_PAIRS: readonly [Expr, Expr][] = [];
|
|
245
|
+
|
|
246
|
+
const xpreunify = (
|
|
247
|
+
accu: readonly [Expr, Expr][],
|
|
248
|
+
left: Expr,
|
|
249
|
+
right: Expr,
|
|
250
|
+
): readonly [Expr, Expr][] | undefined => {
|
|
251
|
+
if (left === right) return accu;
|
|
252
|
+
if (left.kind === "app" && right.kind === "app" && left.symbol === right.symbol) {
|
|
253
|
+
let current: readonly [Expr, Expr][] | undefined = accu;
|
|
254
|
+
for (let index = 0; index < left.args.length && current !== undefined; index++)
|
|
255
|
+
current = xpreunify(current, left.args[index], right.args[index]);
|
|
256
|
+
return current;
|
|
257
|
+
}
|
|
258
|
+
if (left.kind === "meta") return [[left.args[0], right], ...accu];
|
|
259
|
+
if (right.kind === "meta") return [[right.args[0], left], ...accu];
|
|
260
|
+
return undefined;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
export const preunify = (left: Expr, right: Expr) => xpreunify(NO_PAIRS, left, right) ?? NO_PAIRS;
|
|
264
|
+
|
|
244
265
|
type Substitution = [Expr, Expr][];
|
|
245
266
|
|
|
246
267
|
const lookup = (map: Substitution, variable: Expr) => map.find((pair) => pair[0] === variable)?.[1];
|
|
@@ -280,6 +280,8 @@ export const createIndex = (exprs: Expressions) => {
|
|
|
280
280
|
getGoalness,
|
|
281
281
|
findPositive: (symbol: string) => withGoalness(getLatestFirst(positive, symbol)),
|
|
282
282
|
findNegative: (symbol: string) => withGoalness(getLatestFirst(negative, symbol)),
|
|
283
|
+
getPositive: (symbol: string) => positive.get(symbol),
|
|
284
|
+
getNegative: (symbol: string) => negative.get(symbol),
|
|
283
285
|
findEqualRight: (term: Expr) => getLatestFirst(equalLeftRight, term),
|
|
284
286
|
findEqualLeft: (term: Expr) => getLatestFirst(equalRightLeft, term),
|
|
285
287
|
findDisequalities: (term: Expr) => [
|
|
@@ -2,6 +2,7 @@ import type { Relations } from "./eqrel";
|
|
|
2
2
|
import {
|
|
3
3
|
addCongruence,
|
|
4
4
|
addMatches,
|
|
5
|
+
addPreunification,
|
|
5
6
|
addReflexivity,
|
|
6
7
|
addStringEqualities,
|
|
7
8
|
addSymmetricMatches,
|
|
@@ -57,7 +58,6 @@ const addExtensions: SearchRule = (context, queue, formula, goalness) => {
|
|
|
57
58
|
return [insertAll(queue, result.nodes), result.isStopped];
|
|
58
59
|
};
|
|
59
60
|
|
|
60
|
-
// Deviation from Zenon: newnodes_preunif is left out because it never adds a node.
|
|
61
61
|
const RULES: SearchRule[] = [
|
|
62
62
|
addAbsurd,
|
|
63
63
|
addClosure,
|
|
@@ -70,6 +70,7 @@ const RULES: SearchRule[] = [
|
|
|
70
70
|
addGamma,
|
|
71
71
|
addUnfold,
|
|
72
72
|
addReflexivity,
|
|
73
|
+
addPreunification,
|
|
73
74
|
addCongruence,
|
|
74
75
|
addTransitivity,
|
|
75
76
|
addSymmetricMatches,
|