tla-ts 0.0.10-dev.4a2a53c48 → 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 +26 -28
- package/dist/run.js +42 -44
- 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 +1 -2
- package/src/cli/tlc.ts +13 -8
- package/src/dfid.ts +9 -2
- package/src/environment.ts +18 -0
- 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 +1 -1
- package/src/runtime.ts +2 -0
- package/src/sany/generator-expressions.ts +6 -13
- package/src/search.ts +40 -11
- package/src/tlc/order.ts +14 -3
- package/src/tlc/tlcext-operators.ts +18 -5
- package/src/tlc/trace-spec.ts +2 -3
|
@@ -12,105 +12,227 @@ import {
|
|
|
12
12
|
SORT_INT,
|
|
13
13
|
SORT_REAL,
|
|
14
14
|
} from "./ast";
|
|
15
|
-
import
|
|
15
|
+
import {
|
|
16
|
+
type Polynomial,
|
|
17
|
+
type PolynomialManager,
|
|
18
|
+
PolynomialRef,
|
|
19
|
+
PolynomialRefVector,
|
|
20
|
+
} from "./nlsat/polynomial";
|
|
16
21
|
import { getLcm, Rational } from "./rational";
|
|
17
22
|
import { RefVector } from "./ref-vector";
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
interface Frame {
|
|
25
|
+
term: number;
|
|
26
|
+
index: number;
|
|
22
27
|
}
|
|
23
28
|
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
export class Expr2Polynomial {
|
|
30
|
+
private cache = new Map<number, number>();
|
|
31
|
+
private cachedDomain: RefVector;
|
|
32
|
+
private cachedPolynomials: PolynomialRefVector;
|
|
33
|
+
private cachedDenominators: bigint[] = [];
|
|
34
|
+
private frames: Frame[] = [];
|
|
35
|
+
private presult: PolynomialRefVector;
|
|
36
|
+
private dresult: bigint[] = [];
|
|
37
|
+
private var2expr: RefVector;
|
|
38
|
+
|
|
39
|
+
constructor(
|
|
40
|
+
private manager: AstManager,
|
|
41
|
+
readonly pm: PolynomialManager,
|
|
42
|
+
private t2x: Map<number, number>,
|
|
43
|
+
private mkVar: (isInt: boolean) => number,
|
|
44
|
+
) {
|
|
45
|
+
this.cachedDomain = new RefVector(manager);
|
|
46
|
+
this.cachedPolynomials = new PolynomialRefVector(pm);
|
|
47
|
+
this.presult = new PolynomialRefVector(pm);
|
|
48
|
+
this.var2expr = new RefVector(manager);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private reset() {
|
|
52
|
+
this.frames.length = 0;
|
|
53
|
+
this.presult.reset();
|
|
54
|
+
this.dresult.length = 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private cacheResult(term: number) {
|
|
58
|
+
if (this.manager.getRefCount(term) <= 1) return;
|
|
59
|
+
this.cache.set(term, this.cachedPolynomials.size);
|
|
60
|
+
this.cachedDomain.push(term);
|
|
61
|
+
this.cachedPolynomials.push(this.presult.get(this.presult.size - 1));
|
|
62
|
+
this.cachedDenominators.push(this.dresult[this.dresult.length - 1]);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private storeResult(term: number, polynomial: Polynomial, denominator: bigint) {
|
|
66
|
+
this.presult.push(polynomial);
|
|
67
|
+
this.dresult.push(denominator);
|
|
68
|
+
this.cacheResult(term);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private storeVarPoly(term: number) {
|
|
72
|
+
let variable = this.t2x.get(term);
|
|
73
|
+
if (variable === undefined) {
|
|
74
|
+
variable = this.mkVar(this.manager.sorts[term] === SORT_INT);
|
|
75
|
+
this.t2x.set(term, variable);
|
|
76
|
+
if (variable >= this.var2expr.size) this.var2expr.resize(variable + 1);
|
|
77
|
+
this.var2expr.set(variable, term);
|
|
78
|
+
}
|
|
79
|
+
this.storeResult(term, this.pm.mkVar(variable), 1n);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private visitArithApp(term: number) {
|
|
83
|
+
const manager = this.manager;
|
|
84
|
+
switch (manager.getOp(term)) {
|
|
35
85
|
case OP_NUM: {
|
|
36
|
-
const value = manager.getRationalValue(
|
|
37
|
-
|
|
86
|
+
const value = manager.getRationalValue(term);
|
|
87
|
+
this.storeResult(term, this.pm.mkConst(value.num), value.den);
|
|
88
|
+
return true;
|
|
38
89
|
}
|
|
39
90
|
case OP_ADD:
|
|
40
|
-
case OP_SUB:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
let polynomial = pm.zero;
|
|
44
|
-
for (const [index, arg] of args.entries()) {
|
|
45
|
-
const scaled = pm.mulConst(denominator / arg.denominator, arg.polynomial);
|
|
46
|
-
polynomial =
|
|
47
|
-
index === 0
|
|
48
|
-
? scaled
|
|
49
|
-
: op === OP_ADD
|
|
50
|
-
? pm.add(polynomial, scaled)
|
|
51
|
-
: pm.sub(polynomial, scaled);
|
|
52
|
-
}
|
|
53
|
-
return { polynomial, denominator };
|
|
54
|
-
}
|
|
55
|
-
case OP_MUL: {
|
|
56
|
-
let polynomial = pm.one;
|
|
57
|
-
let denominator = 1n;
|
|
58
|
-
for (const arg of manager.getArgs(expr).map(convert)) {
|
|
59
|
-
polynomial = pm.mul(polynomial, arg.polynomial);
|
|
60
|
-
denominator *= arg.denominator;
|
|
61
|
-
}
|
|
62
|
-
return { polynomial, denominator };
|
|
63
|
-
}
|
|
64
|
-
case OP_UMINUS: {
|
|
65
|
-
const arg = convert(manager.getArg(expr, 0));
|
|
66
|
-
return { polynomial: pm.neg(arg.polynomial), denominator: arg.denominator };
|
|
67
|
-
}
|
|
91
|
+
case OP_SUB:
|
|
92
|
+
case OP_MUL:
|
|
93
|
+
case OP_UMINUS:
|
|
68
94
|
case OP_TO_REAL:
|
|
69
|
-
|
|
95
|
+
this.frames.push({ term, index: 0 });
|
|
96
|
+
return false;
|
|
70
97
|
case OP_POWER: {
|
|
71
|
-
const exponent = manager.getArg(
|
|
98
|
+
const exponent = manager.getArg(term, 1);
|
|
72
99
|
const value = manager.isNumeral(exponent) ? manager.getRationalValue(exponent) : undefined;
|
|
73
|
-
if (value === undefined || !value.isInt() || value.num <= 0n || value.num > 0xffffffffn)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
};
|
|
100
|
+
if (value === undefined || !value.isInt() || value.num <= 0n || value.num > 0xffffffffn) {
|
|
101
|
+
this.storeVarPoly(term);
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
this.frames.push({ term, index: 0 });
|
|
105
|
+
return false;
|
|
80
106
|
}
|
|
81
107
|
default:
|
|
82
|
-
|
|
108
|
+
this.storeVarPoly(term);
|
|
109
|
+
return true;
|
|
83
110
|
}
|
|
84
|
-
}
|
|
85
|
-
return convert(term);
|
|
86
|
-
};
|
|
111
|
+
}
|
|
87
112
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
113
|
+
private visit(term: number) {
|
|
114
|
+
const manager = this.manager;
|
|
115
|
+
const cached = manager.getRefCount(term) > 1 ? this.cache.get(term) : undefined;
|
|
116
|
+
if (cached !== undefined) {
|
|
117
|
+
this.presult.push(this.cachedPolynomials.get(cached));
|
|
118
|
+
this.dresult.push(this.cachedDenominators[cached]);
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
if (manager.kinds[term] !== KIND_APP || manager.getFamily(term) !== FAMILY_ARITH) {
|
|
122
|
+
this.storeVarPoly(term);
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
return this.visitArithApp(term);
|
|
126
|
+
}
|
|
91
127
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
) {
|
|
96
|
-
this.varToTerm = new RefVector(manager);
|
|
128
|
+
private pop(numArgs: number) {
|
|
129
|
+
this.presult.shrink(this.presult.size - numArgs);
|
|
130
|
+
this.dresult.length -= numArgs;
|
|
97
131
|
}
|
|
98
132
|
|
|
99
|
-
private
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
133
|
+
private processAddSub(term: number, numArgs: number, isAdd: boolean) {
|
|
134
|
+
const pm = this.pm;
|
|
135
|
+
const first = this.presult.size - numArgs;
|
|
136
|
+
const p = new PolynomialRef(pm);
|
|
137
|
+
const pAux = new PolynomialRef(pm);
|
|
138
|
+
let denominator = 1n;
|
|
139
|
+
for (let index = 0; index < numArgs; index++)
|
|
140
|
+
denominator = getLcm(denominator, this.dresult[first + index]);
|
|
141
|
+
p.set(pm.zero);
|
|
142
|
+
for (let index = 0; index < numArgs; index++) {
|
|
143
|
+
pAux.set(
|
|
144
|
+
pm.mulConst(denominator / this.dresult[first + index], this.presult.get(first + index)),
|
|
145
|
+
);
|
|
146
|
+
if (index === 0) p.copy(pAux);
|
|
147
|
+
else p.set(isAdd ? pm.add(p.get(), pAux.get()) : pm.sub(p.get(), pAux.get()));
|
|
148
|
+
}
|
|
149
|
+
this.pop(numArgs);
|
|
150
|
+
this.storeResult(term, p.get(), denominator);
|
|
151
|
+
pAux.reset();
|
|
152
|
+
p.reset();
|
|
106
153
|
}
|
|
107
154
|
|
|
108
|
-
private
|
|
109
|
-
|
|
155
|
+
private processMul(term: number, numArgs: number) {
|
|
156
|
+
const first = this.presult.size - numArgs;
|
|
157
|
+
const p = new PolynomialRef(this.pm);
|
|
158
|
+
let denominator = 1n;
|
|
159
|
+
p.set(this.pm.one);
|
|
160
|
+
for (let index = 0; index < numArgs; index++) {
|
|
161
|
+
p.set(this.pm.mul(p.get(), this.presult.get(first + index)));
|
|
162
|
+
denominator *= this.dresult[first + index];
|
|
163
|
+
}
|
|
164
|
+
this.pop(numArgs);
|
|
165
|
+
this.storeResult(term, p.get(), denominator);
|
|
166
|
+
p.reset();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private processUminus(term: number) {
|
|
170
|
+
const negP = new PolynomialRef(this.pm);
|
|
171
|
+
negP.set(this.pm.neg(this.presult.get(this.presult.size - 1)));
|
|
172
|
+
this.presult.shrink(this.presult.size - 1);
|
|
173
|
+
this.presult.push(negP.get());
|
|
174
|
+
this.cacheResult(term);
|
|
175
|
+
negP.reset();
|
|
110
176
|
}
|
|
111
177
|
|
|
112
|
-
|
|
113
|
-
|
|
178
|
+
private processPower(term: number, numArgs: number) {
|
|
179
|
+
const first = this.presult.size - numArgs;
|
|
180
|
+
const k = Number(this.manager.getRationalValue(this.manager.getArg(term, 1)).num);
|
|
181
|
+
const p = new PolynomialRef(this.pm);
|
|
182
|
+
this.pm.pw(this.presult.get(first), k, p);
|
|
183
|
+
const denominator = this.dresult[first] ** BigInt(k);
|
|
184
|
+
this.pop(numArgs);
|
|
185
|
+
this.storeResult(term, p.get(), denominator);
|
|
186
|
+
p.reset();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
private processApp(term: number) {
|
|
190
|
+
const numArgs = this.manager.getNumArgs(term);
|
|
191
|
+
switch (this.manager.getOp(term)) {
|
|
192
|
+
case OP_ADD:
|
|
193
|
+
return this.processAddSub(term, numArgs, true);
|
|
194
|
+
case OP_SUB:
|
|
195
|
+
return this.processAddSub(term, numArgs, false);
|
|
196
|
+
case OP_MUL:
|
|
197
|
+
return this.processMul(term, numArgs);
|
|
198
|
+
case OP_POWER:
|
|
199
|
+
return this.processPower(term, numArgs);
|
|
200
|
+
case OP_UMINUS:
|
|
201
|
+
return this.processUminus(term);
|
|
202
|
+
default:
|
|
203
|
+
return this.cacheResult(term);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
toPolynomial(term: number, p: PolynomialRef) {
|
|
208
|
+
this.reset();
|
|
209
|
+
if (!this.visit(term)) {
|
|
210
|
+
const frames = this.frames;
|
|
211
|
+
while (frames.length > 0) {
|
|
212
|
+
const frame = frames[frames.length - 1];
|
|
213
|
+
const numArgs = this.manager.getNumArgs(frame.term);
|
|
214
|
+
let isPushed = false;
|
|
215
|
+
while (frame.index < numArgs) {
|
|
216
|
+
const arg = this.manager.getArg(frame.term, frame.index);
|
|
217
|
+
frame.index++;
|
|
218
|
+
if (!this.visit(arg)) {
|
|
219
|
+
isPushed = true;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (isPushed) continue;
|
|
224
|
+
this.processApp(frame.term);
|
|
225
|
+
frames.pop();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
p.set(this.presult.get(this.presult.size - 1));
|
|
229
|
+
const denominator = this.dresult[this.dresult.length - 1];
|
|
230
|
+
this.reset();
|
|
231
|
+
return denominator;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
private isIntVar(variable: number) {
|
|
235
|
+
return this.manager.sorts[this.var2expr.items[variable]] === SORT_INT;
|
|
114
236
|
}
|
|
115
237
|
|
|
116
238
|
toExpr(polynomial: Polynomial, isUsingPower: boolean) {
|
|
@@ -125,7 +247,7 @@ export class Expr2Polynomial {
|
|
|
125
247
|
const coeff = polynomial.as[index];
|
|
126
248
|
if (coeff !== 1n) factors.push(mkNumeral(coeff));
|
|
127
249
|
for (const [position, variable] of monomial.vars.entries()) {
|
|
128
|
-
const term = this.
|
|
250
|
+
const term = this.var2expr.items[variable];
|
|
129
251
|
const base =
|
|
130
252
|
this.isIntVar(variable) && !isInt ? manager.mkApp(OP_TO_REAL, [term], SORT_REAL) : term;
|
|
131
253
|
const degree = monomial.degrees[position];
|
|
@@ -141,6 +263,9 @@ export class Expr2Polynomial {
|
|
|
141
263
|
}
|
|
142
264
|
|
|
143
265
|
release() {
|
|
144
|
-
this.
|
|
266
|
+
this.presult.reset();
|
|
267
|
+
this.cachedPolynomials.reset();
|
|
268
|
+
this.cachedDomain.reset();
|
|
269
|
+
this.var2expr.reset();
|
|
145
270
|
}
|
|
146
271
|
}
|
|
@@ -18,7 +18,7 @@ import { runSimplifier } from "./dependent-expr-state";
|
|
|
18
18
|
import { Expr2Polynomial } from "./expr2polynomial";
|
|
19
19
|
import type { Goal } from "./goal";
|
|
20
20
|
import { getLcm, Rational } from "./rational";
|
|
21
|
-
import { PolynomialManager } from "./nlsat/polynomial";
|
|
21
|
+
import { Factors, type Polynomial, PolynomialManager, PolynomialRef } from "./nlsat/polynomial";
|
|
22
22
|
import type { Rewrite } from "./rewriter-tpl";
|
|
23
23
|
import { RewriterTpl } from "./rewriter-tpl";
|
|
24
24
|
|
|
@@ -37,7 +37,13 @@ class FactorRewriter extends RewriterTpl {
|
|
|
37
37
|
private isSplittingFactors: boolean,
|
|
38
38
|
) {
|
|
39
39
|
super(manager);
|
|
40
|
-
|
|
40
|
+
let variableCount = 0;
|
|
41
|
+
this.expr2poly = new Expr2Polynomial(
|
|
42
|
+
manager,
|
|
43
|
+
new PolynomialManager(manager.limit),
|
|
44
|
+
new Map(),
|
|
45
|
+
() => variableCount++,
|
|
46
|
+
);
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
private mkZeroFor(expr: number) {
|
|
@@ -51,20 +57,36 @@ class FactorRewriter extends RewriterTpl {
|
|
|
51
57
|
: this.manager.mkApp(OP_MUL, args, this.manager.sorts[args[0]]);
|
|
52
58
|
}
|
|
53
59
|
|
|
54
|
-
private factor(op: number, lhs: number, rhs: number)
|
|
55
|
-
const manager = this.manager;
|
|
60
|
+
private factor(op: number, lhs: number, rhs: number) {
|
|
56
61
|
const pm = this.expr2poly.pm;
|
|
57
|
-
const first =
|
|
58
|
-
const second =
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
const first = new PolynomialRef(pm);
|
|
63
|
+
const second = new PolynomialRef(pm);
|
|
64
|
+
const p = new PolynomialRef(pm);
|
|
65
|
+
const firstDenominator = this.expr2poly.toPolynomial(lhs, first);
|
|
66
|
+
const secondDenominator = this.expr2poly.toPolynomial(rhs, second);
|
|
67
|
+
const lcm = getLcm(firstDenominator, secondDenominator);
|
|
68
|
+
p.set(
|
|
69
|
+
pm.addmulTerms(
|
|
70
|
+
lcm / firstDenominator,
|
|
71
|
+
pm.unit,
|
|
72
|
+
first.get(),
|
|
73
|
+
-(lcm / secondDenominator),
|
|
74
|
+
pm.unit,
|
|
75
|
+
second.get(),
|
|
76
|
+
),
|
|
65
77
|
);
|
|
66
|
-
|
|
67
|
-
const
|
|
78
|
+
const factors = new Factors(pm);
|
|
79
|
+
const result = pm.isConst(p.get()) ? -1 : this.factorPolynomial(op, p.get(), factors);
|
|
80
|
+
factors.reset();
|
|
81
|
+
p.reset();
|
|
82
|
+
second.reset();
|
|
83
|
+
first.reset();
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private factorPolynomial(op: number, polynomial: Polynomial, factors: Factors): number {
|
|
88
|
+
const manager = this.manager;
|
|
89
|
+
this.expr2poly.pm.factor(polynomial, factors);
|
|
68
90
|
if (factors.factors.length === 1 && factors.degrees[0] === 1) return -1;
|
|
69
91
|
const terms = factors.factors.map((factor) => this.expr2poly.toExpr(factor, true));
|
|
70
92
|
if (op === OP_EQ) {
|
|
@@ -403,8 +403,7 @@ const mkIsInfOfInt = (
|
|
|
403
403
|
? mkCompare(OP_LE, -threshold)
|
|
404
404
|
: manager.falseExpr;
|
|
405
405
|
}
|
|
406
|
-
// Deviation from Z3:
|
|
407
|
-
// 2^30 bits, more than a BigInt holds, so those widths give up too.
|
|
406
|
+
// Deviation from Z3: it runs out of memory from an exponent width of 31, so this gives up as Z3 does from 34.
|
|
408
407
|
if (ebits > 30) return -1;
|
|
409
408
|
const maxFinite = mpfToRational(mkMaxValue(ebits, sbits, false)).num;
|
|
410
409
|
const halfUlp = 1n << BigInt(maxExp - sbits);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// A statement that discards its result builds a term that upstream builds and never uses, so the
|
|
2
2
|
// terms after it get the ids Z3 gives them.
|
|
3
|
-
import { SmtUnsupportedError } from "../../../errors";
|
|
3
|
+
import { SmtCanceledError, SmtUnsupportedError } from "../../../errors";
|
|
4
4
|
import {
|
|
5
5
|
type AstManager,
|
|
6
6
|
OP_BADD,
|
|
@@ -1440,6 +1440,8 @@ export class Fpa2BvConverter {
|
|
|
1440
1440
|
const manager = this.manager;
|
|
1441
1441
|
const ebits = manager.getEbits(sort);
|
|
1442
1442
|
const sbits = manager.getSbits(sort);
|
|
1443
|
+
// Deviation from Z3: it runs out of memory from an exponent width of 31, where this gives up as at a resource limit.
|
|
1444
|
+
if (ebits > 30) throw new SmtCanceledError();
|
|
1443
1445
|
const x =
|
|
1444
1446
|
manager.sorts[input] === SORT_INT ? manager.mkApp(OP_TO_REAL, [input], SORT_REAL) : input;
|
|
1445
1447
|
const real = (op: number, ...args: number[]) => manager.mkApp(op, args, SORT_REAL);
|
|
@@ -82,6 +82,8 @@ export class Goal {
|
|
|
82
82
|
model: ProtoModel | undefined;
|
|
83
83
|
isProofsEnabled = false;
|
|
84
84
|
isCoresEnabled = false;
|
|
85
|
+
// As in Z3, it isn't copied with the goal.
|
|
86
|
+
reasonUnknown = "";
|
|
85
87
|
|
|
86
88
|
constructor(readonly manager: AstManager) {
|
|
87
89
|
this.forms = new RefVector(manager);
|
|
@@ -22,9 +22,10 @@ import {
|
|
|
22
22
|
SORT_INT,
|
|
23
23
|
SORT_REAL,
|
|
24
24
|
} from "./ast";
|
|
25
|
-
import {
|
|
25
|
+
import { Expr2Polynomial } from "./expr2polynomial";
|
|
26
26
|
import { getLcm } from "./rational";
|
|
27
27
|
import { flipKind } from "./nlsat/atoms";
|
|
28
|
+
import { Factors, type Polynomial, PolynomialRef } from "./nlsat/polynomial";
|
|
28
29
|
import type { NlsatSolver } from "./nlsat/solver";
|
|
29
30
|
import { TRANSCENDENTAL_OPS } from "./nlsat/transcendental-eval";
|
|
30
31
|
import type { IneqKind } from "./nlsat/types";
|
|
@@ -39,38 +40,54 @@ export const goal2nlsat = (
|
|
|
39
40
|
isFactoring = true,
|
|
40
41
|
) => {
|
|
41
42
|
const pm = solver.pm;
|
|
43
|
+
const expr2poly = new Expr2Polynomial(manager, pm, t2x, (isInt) => solver.mkVar(isInt));
|
|
42
44
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
const factorAtom = (polynomial: Polynomial, kind: IneqKind) => {
|
|
46
|
+
const factors = new Factors(pm);
|
|
47
|
+
pm.factor(polynomial, factors);
|
|
48
|
+
const literal = solver.mkIneqLiteral(
|
|
49
|
+
factors.constant < 0n ? flipKind(kind) : kind,
|
|
50
|
+
factors.factors,
|
|
51
|
+
factors.degrees.map((degree) => degree % 2 === 0),
|
|
52
|
+
);
|
|
53
|
+
factors.reset();
|
|
54
|
+
return literal;
|
|
50
55
|
};
|
|
51
56
|
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const rhs = toPolynomial(manager, pm, manager.getArg(atom, 1), mkVar);
|
|
55
|
-
const lcm = getLcm(lhs.denominator, rhs.denominator);
|
|
56
|
-
const polynomial = pm.addmul(
|
|
57
|
-
lcm / lhs.denominator,
|
|
58
|
-
lhs.polynomial,
|
|
59
|
-
-(lcm / rhs.denominator),
|
|
60
|
-
rhs.polynomial,
|
|
61
|
-
);
|
|
57
|
+
const processIneqPolynomial = (p: PolynomialRef, kind: IneqKind) => {
|
|
58
|
+
const polynomial = p.get();
|
|
62
59
|
if (pm.isConst(polynomial)) {
|
|
63
60
|
const sign = pm.isZero(polynomial) ? 0 : polynomial.as[0] > 0n ? 1 : -1;
|
|
64
61
|
const isTrue = kind === "EQ" ? sign === 0 : kind === "LT" ? sign < 0 : sign > 0;
|
|
65
62
|
return isTrue ? 0 : 1;
|
|
66
63
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
return isFactoring
|
|
65
|
+
? factorAtom(polynomial, kind)
|
|
66
|
+
: solver.mkIneqLiteral(kind, [polynomial], [false]);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const processIneq = (atom: number, kind: IneqKind) => {
|
|
70
|
+
const first = new PolynomialRef(pm);
|
|
71
|
+
const second = new PolynomialRef(pm);
|
|
72
|
+
const p = new PolynomialRef(pm);
|
|
73
|
+
const firstDenominator = expr2poly.toPolynomial(manager.getArg(atom, 0), first);
|
|
74
|
+
const secondDenominator = expr2poly.toPolynomial(manager.getArg(atom, 1), second);
|
|
75
|
+
const lcm = getLcm(firstDenominator, secondDenominator);
|
|
76
|
+
p.set(
|
|
77
|
+
pm.addmulTerms(
|
|
78
|
+
lcm / firstDenominator,
|
|
79
|
+
pm.unit,
|
|
80
|
+
first.get(),
|
|
81
|
+
-(lcm / secondDenominator),
|
|
82
|
+
pm.unit,
|
|
83
|
+
second.get(),
|
|
84
|
+
),
|
|
73
85
|
);
|
|
86
|
+
const literal = processIneqPolynomial(p, kind);
|
|
87
|
+
p.reset();
|
|
88
|
+
second.reset();
|
|
89
|
+
first.reset();
|
|
90
|
+
return literal;
|
|
74
91
|
};
|
|
75
92
|
|
|
76
93
|
const processBoolVar = (atom: number) => {
|
|
@@ -129,20 +146,29 @@ export const goal2nlsat = (
|
|
|
129
146
|
// The polynomial conversion treats a transcendental application, argument included, as one
|
|
130
147
|
// variable, so its argument gets a variable here, through an equation unless it is one already.
|
|
131
148
|
const mkArgVar = (term: number) => {
|
|
132
|
-
const
|
|
133
|
-
const
|
|
149
|
+
const p = new PolynomialRef(pm);
|
|
150
|
+
const denominator = expr2poly.toPolynomial(term, p);
|
|
151
|
+
const polynomial = p.get();
|
|
134
152
|
const monomial = polynomial.ms[0];
|
|
135
153
|
if (
|
|
136
|
-
|
|
154
|
+
denominator === 1n &&
|
|
137
155
|
polynomial.ms.length === 1 &&
|
|
138
156
|
polynomial.as[0] === 1n &&
|
|
139
157
|
monomial.size === 1 &&
|
|
140
158
|
monomial.degrees[0] === 1
|
|
141
|
-
)
|
|
159
|
+
) {
|
|
160
|
+
p.reset();
|
|
142
161
|
return monomial.vars[0];
|
|
162
|
+
}
|
|
143
163
|
const variable = solver.mkVar(false);
|
|
144
|
-
const
|
|
145
|
-
|
|
164
|
+
const vp = new PolynomialRef(pm);
|
|
165
|
+
const equation = new PolynomialRef(pm);
|
|
166
|
+
vp.set(pm.mkVar(variable));
|
|
167
|
+
equation.set(pm.addmulTerms(denominator, pm.unit, vp.get(), -1n, pm.unit, polynomial));
|
|
168
|
+
solver.mkExternalClause([solver.mkIneqLiteral("EQ", [equation.get()], [false])], null);
|
|
169
|
+
equation.reset();
|
|
170
|
+
vp.reset();
|
|
171
|
+
p.reset();
|
|
146
172
|
return variable;
|
|
147
173
|
};
|
|
148
174
|
|
|
@@ -174,6 +200,7 @@ export const goal2nlsat = (
|
|
|
174
200
|
}
|
|
175
201
|
}
|
|
176
202
|
if (piVar !== undefined) solver.transcendentals.addPi(piVar);
|
|
203
|
+
expr2poly.release();
|
|
177
204
|
};
|
|
178
205
|
|
|
179
206
|
const hasTermIte = (manager: AstManager, form: number) => {
|
|
@@ -159,7 +159,7 @@ interface HashLink<V> {
|
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
interface HashNode<V> extends HashLink<V> {
|
|
162
|
-
|
|
162
|
+
value: V;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
const constrainHash = (hash: number, count: number) =>
|
|
@@ -197,6 +197,12 @@ export class UnorderedUintMap<V> {
|
|
|
197
197
|
for (let node = this.anchor.next; node !== null; node = node.next) yield [node.key, node.value];
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
+
set(key: number, value: V) {
|
|
201
|
+
const node = this.nodes.get(key);
|
|
202
|
+
if (node === undefined) this.insert(key, value);
|
|
203
|
+
else node.value = value;
|
|
204
|
+
}
|
|
205
|
+
|
|
200
206
|
insert(key: number, value: V) {
|
|
201
207
|
const node: HashNode<V> = { key, value, next: null };
|
|
202
208
|
const count = this.buckets.length;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// Deviation from Z3: the occurrence map iterates in insertion order where Z3 has an unordered_map,
|
|
2
|
-
// so an extracted common factor may list its variables in another order.
|
|
3
1
|
import { Rational } from "../rational";
|
|
4
2
|
import {
|
|
5
3
|
type Nex,
|
|
@@ -146,7 +144,7 @@ export class CrossNested {
|
|
|
146
144
|
private getVarsFromOccurencesMap() {
|
|
147
145
|
const occurences = this.nexCreator.occurencesMap;
|
|
148
146
|
const isRandomBit = this.nextRandom() % 2 === 1;
|
|
149
|
-
return
|
|
147
|
+
return Array.from(occurences, (entry) => entry[0]).sort((first, second) => {
|
|
150
148
|
const firstOcc = occurences.get(first);
|
|
151
149
|
const secondOcc = occurences.get(second);
|
|
152
150
|
if (firstOcc === undefined || secondOcc === undefined) return 0;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Rational } from "../rational";
|
|
2
|
+
import { UnorderedUintMap } from "./containers";
|
|
2
3
|
import {
|
|
3
4
|
type Nex,
|
|
4
5
|
type NexMul,
|
|
@@ -24,8 +25,8 @@ interface MapEntry<Value> {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export class NexCreator {
|
|
27
|
-
readonly occurencesMap = new
|
|
28
|
-
readonly powers = new
|
|
28
|
+
readonly occurencesMap = new UnorderedUintMap<Occ>();
|
|
29
|
+
readonly powers = new UnorderedUintMap<number>();
|
|
29
30
|
private activeVarsWeights: number[] = [];
|
|
30
31
|
|
|
31
32
|
setNumberOfVars(count: number) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Rational } from "../rational";
|
|
2
|
+
import type { UnorderedUintMap } from "./containers";
|
|
2
3
|
|
|
3
4
|
interface NexScalar {
|
|
4
5
|
readonly kind: "scalar";
|
|
@@ -63,7 +64,7 @@ export const isALinearTerm = (sum: NexSum) => {
|
|
|
63
64
|
return numberOfNonScalars > 1;
|
|
64
65
|
};
|
|
65
66
|
|
|
66
|
-
export const getPowersFromMul = (mul: NexMul, powers:
|
|
67
|
+
export const getPowersFromMul = (mul: NexMul, powers: UnorderedUintMap<number>) => {
|
|
67
68
|
powers.clear();
|
|
68
69
|
for (const child of mul.children)
|
|
69
70
|
if (child.expr.kind === "var") powers.set(child.expr.variable, child.power);
|