tla-ts 0.0.10-dev.5ffc55ce5 → 0.0.10-dev.6232a1403
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 +30 -30
- package/dist/run.cjs +1 -1
- package/dist/run.js +1 -1
- package/package.json +1 -1
- package/src/prover/smt/solver/ast.ts +1 -1
- package/src/prover/smt/solver/expr2polynomial.ts +79 -204
- package/src/prover/smt/solver/factor.ts +14 -36
- package/src/prover/smt/solver/goal2nlsat.ts +30 -57
- package/src/prover/smt/solver/lp/nla-core.ts +1 -1
- package/src/prover/smt/solver/lp/nra-solver.ts +39 -45
- package/src/prover/smt/solver/nlsat/algebraic.ts +89 -194
- package/src/prover/smt/solver/nlsat/atoms.ts +33 -52
- package/src/prover/smt/solver/nlsat/explain.ts +217 -375
- package/src/prover/smt/solver/nlsat/levelwise.ts +240 -464
- package/src/prover/smt/solver/nlsat/polynomial.ts +680 -2400
- package/src/prover/smt/solver/nlsat/solver.ts +64 -74
- package/src/prover/smt/solver/nlsat/transcendentals.ts +17 -41
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +4 -8
- package/src/prover/smt/solver/nlsat/upolynomial.ts +17 -40
- package/src/prover/smt/solver/opt-nlsat.ts +18 -29
- package/src/prover/smt/solver/opt-solver.ts +3 -2
- package/src/prover/smt/solver/smtlib-parser.ts +10 -10
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Deviation from Z3: ties between polynomials break by creation-order id, where Z3 recycles ids of
|
|
2
|
+
// freed polynomials (id_gen in polynomial.cpp), so a cell bound can be another polynomial with the
|
|
3
|
+
// same root.
|
|
1
4
|
import { NlsatUnsupportedError } from "../../../../errors";
|
|
2
5
|
import { Rational } from "../rational";
|
|
3
6
|
import { type AlgebraicManager, type Anum, mergeSortIndices } from "./algebraic";
|
|
@@ -6,26 +9,14 @@ import {
|
|
|
6
9
|
type Polynomial,
|
|
7
10
|
type PolynomialCache,
|
|
8
11
|
type PolynomialManager,
|
|
9
|
-
PolynomialRef,
|
|
10
|
-
PolynomialRefVector,
|
|
11
12
|
} from "./polynomial";
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
isSection
|
|
15
|
-
|
|
16
|
-
lowerIndex
|
|
17
|
-
|
|
18
|
-
upperIndex
|
|
19
|
-
|
|
20
|
-
constructor(pm: PolynomialManager) {
|
|
21
|
-
this.lower = new PolynomialRef(pm);
|
|
22
|
-
this.upper = new PolynomialRef(pm);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
release() {
|
|
26
|
-
this.upper.reset();
|
|
27
|
-
this.lower.reset();
|
|
28
|
-
}
|
|
14
|
+
interface CellInterval {
|
|
15
|
+
isSection: boolean;
|
|
16
|
+
lower: Polynomial | null;
|
|
17
|
+
lowerIndex: number;
|
|
18
|
+
upper: Polynomial | null;
|
|
19
|
+
upperIndex: number;
|
|
29
20
|
}
|
|
30
21
|
|
|
31
22
|
interface RootFunction {
|
|
@@ -41,123 +32,98 @@ const UNSET = -1;
|
|
|
41
32
|
const BOTH_SIDES = 3;
|
|
42
33
|
const SPANNING_TREE_THRESHOLD = 4;
|
|
43
34
|
|
|
44
|
-
export const releaseIntervals = (intervals: readonly CellInterval[]) => {
|
|
45
|
-
for (let index = intervals.length; index-- > 0;) intervals[index].release();
|
|
46
|
-
};
|
|
47
|
-
|
|
48
35
|
export class TodoSet {
|
|
49
|
-
|
|
50
|
-
private inSet
|
|
36
|
+
polynomials: Polynomial[] = [];
|
|
37
|
+
private inSet = new Set<number>();
|
|
51
38
|
|
|
52
39
|
constructor(
|
|
40
|
+
private pm: PolynomialManager,
|
|
53
41
|
private cache: PolynomialCache,
|
|
54
|
-
|
|
55
|
-
) {
|
|
56
|
-
this.set = new PolynomialRefVector(cache.pm);
|
|
57
|
-
}
|
|
42
|
+
) {}
|
|
58
43
|
|
|
59
44
|
get isEmpty() {
|
|
60
|
-
return this.
|
|
45
|
+
return this.polynomials.length === 0;
|
|
61
46
|
}
|
|
62
47
|
|
|
63
48
|
reset() {
|
|
64
|
-
|
|
65
|
-
this.
|
|
49
|
+
this.polynomials = [];
|
|
50
|
+
this.inSet.clear();
|
|
66
51
|
}
|
|
67
52
|
|
|
68
53
|
insert(polynomial: Polynomial) {
|
|
69
|
-
|
|
70
|
-
if (this.inSet[polynomial.id] === true) return polynomial;
|
|
54
|
+
if (this.inSet.has(polynomial.id)) return polynomial;
|
|
71
55
|
if (this.cache.contains(polynomial)) {
|
|
72
|
-
this.inSet
|
|
73
|
-
this.
|
|
56
|
+
this.inSet.add(polynomial.id);
|
|
57
|
+
this.polynomials.push(polynomial);
|
|
74
58
|
return polynomial;
|
|
75
59
|
}
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
pinned.set(p);
|
|
85
|
-
}
|
|
86
|
-
p = this.cache.mkUnique(p);
|
|
87
|
-
if (this.inSet[p.id] !== true) {
|
|
88
|
-
this.inSet[p.id] = true;
|
|
89
|
-
this.set.push(p);
|
|
60
|
+
const primitive =
|
|
61
|
+
this.pm.isZero(polynomial) || this.pm.isConst(polynomial)
|
|
62
|
+
? polynomial
|
|
63
|
+
: this.pm.pp(polynomial, this.pm.maxVar(polynomial));
|
|
64
|
+
const unique = this.cache.mkUnique(this.pm.flipSignIfLmNeg(primitive));
|
|
65
|
+
if (!this.inSet.has(unique.id)) {
|
|
66
|
+
this.inSet.add(unique.id);
|
|
67
|
+
this.polynomials.push(unique);
|
|
90
68
|
}
|
|
91
|
-
|
|
92
|
-
return p;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
contains(polynomial: Polynomial) {
|
|
96
|
-
return this.inSet[polynomial.id] === true;
|
|
69
|
+
return unique;
|
|
97
70
|
}
|
|
98
71
|
|
|
99
72
|
getMaxVar() {
|
|
100
|
-
return this.
|
|
73
|
+
return this.pm.getMaxVarOfPolys(this.polynomials);
|
|
101
74
|
}
|
|
102
75
|
|
|
103
|
-
extractMaxPolys(out:
|
|
104
|
-
out.
|
|
76
|
+
extractMaxPolys(out: Polynomial[]) {
|
|
77
|
+
out.length = 0;
|
|
105
78
|
const variable = this.getMaxVar();
|
|
106
79
|
this.extractPolysAtLevel(variable, out);
|
|
107
80
|
return variable;
|
|
108
81
|
}
|
|
109
82
|
|
|
110
|
-
extractPolysAtLevel(variable: number, out:
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
83
|
+
extractPolysAtLevel(variable: number, out: Polynomial[]) {
|
|
84
|
+
const kept: Polynomial[] = [];
|
|
85
|
+
for (const polynomial of this.polynomials) {
|
|
86
|
+
if (this.pm.maxVar(polynomial) !== variable) {
|
|
87
|
+
kept.push(polynomial);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
out.push(polynomial);
|
|
91
|
+
this.inSet.delete(polynomial.id);
|
|
119
92
|
}
|
|
120
|
-
this.
|
|
93
|
+
this.polynomials = kept;
|
|
121
94
|
}
|
|
122
95
|
}
|
|
123
96
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
private level = 0;
|
|
127
|
-
private lowerRf = UNSET;
|
|
128
|
-
private upperRf = UNSET;
|
|
97
|
+
class Levelwise {
|
|
98
|
+
private intervals: CellInterval[];
|
|
129
99
|
private todo: TodoSet;
|
|
130
|
-
private
|
|
131
|
-
private
|
|
132
|
-
private
|
|
133
|
-
private
|
|
134
|
-
private sideMask: number[] = [];
|
|
135
|
-
private isLcOmitted: boolean[] = [];
|
|
136
|
-
private degInOrderGraph: number[] = [];
|
|
100
|
+
private level = 0;
|
|
101
|
+
private levelPolys: Polynomial[] = [];
|
|
102
|
+
private witnesses: (Polynomial | null)[] = [];
|
|
103
|
+
private hasRoots: boolean[] = [];
|
|
137
104
|
private rootFunctions: RootFunction[] = [];
|
|
138
105
|
private pairs = new Map<string, [number, number]>();
|
|
106
|
+
private sideMask: number[] = [];
|
|
107
|
+
private isLcOmitted: boolean[] = [];
|
|
108
|
+
private lowerRf = UNSET;
|
|
109
|
+
private upperRf = UNSET;
|
|
139
110
|
|
|
140
111
|
constructor(
|
|
141
112
|
private pm: PolynomialManager,
|
|
142
113
|
private am: AlgebraicManager,
|
|
143
114
|
private cache: PolynomialCache,
|
|
144
|
-
private polynomials: PolynomialRefVector,
|
|
145
|
-
private maxVar: number,
|
|
146
115
|
private sample: readonly (Anum | undefined)[],
|
|
116
|
+
private maxVar: number,
|
|
147
117
|
private isLinear: boolean,
|
|
148
118
|
) {
|
|
149
|
-
this.todo = new TodoSet(
|
|
150
|
-
this.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
this.clearWitnesses();
|
|
158
|
-
this.levelPs.reset();
|
|
159
|
-
this.todo.set.reset();
|
|
160
|
-
releaseIntervals(this.intervals);
|
|
119
|
+
this.todo = new TodoSet(pm, cache);
|
|
120
|
+
this.intervals = Array.from({ length: maxVar }, () => ({
|
|
121
|
+
isSection: false,
|
|
122
|
+
lower: null,
|
|
123
|
+
lowerIndex: 0,
|
|
124
|
+
upper: null,
|
|
125
|
+
upperIndex: 0,
|
|
126
|
+
}));
|
|
161
127
|
}
|
|
162
128
|
|
|
163
129
|
private getSign(polynomial: Polynomial) {
|
|
@@ -168,200 +134,93 @@ export class Levelwise {
|
|
|
168
134
|
return this.sample.map((value, index) => (index === variable ? undefined : value));
|
|
169
135
|
}
|
|
170
136
|
|
|
171
|
-
private
|
|
172
|
-
|
|
173
|
-
this.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
for (let
|
|
201
|
-
if (pm.degree(
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
continue;
|
|
207
|
-
}
|
|
208
|
-
if (this.getSign(dq.get()) !== 0) {
|
|
209
|
-
this.requestFactorized(dq.get());
|
|
210
|
-
dq.reset();
|
|
211
|
-
q.reset();
|
|
212
|
-
nextPolys.reset();
|
|
213
|
-
curPolys.reset();
|
|
137
|
+
private requestFactorized(polynomial: Polynomial | null) {
|
|
138
|
+
if (polynomial === null || this.pm.isConst(polynomial)) return;
|
|
139
|
+
for (const factor of this.cache.factor(polynomial))
|
|
140
|
+
if (!this.pm.isConst(factor)) this.todo.insert(factor);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private getFirstPsc(first: Polynomial, second: Polynomial, variable: number) {
|
|
144
|
+
for (const element of this.cache.pscChain(first, second, variable)) {
|
|
145
|
+
if (this.pm.isZero(element)) continue;
|
|
146
|
+
return this.pm.isConst(element) ? null : element;
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private getPscDiscriminant(polynomial: Polynomial, variable: number) {
|
|
152
|
+
if (this.pm.isConst(polynomial) || this.pm.degree(polynomial, variable) < 2) return null;
|
|
153
|
+
return this.getFirstPsc(polynomial, this.pm.derivative(polynomial, variable), variable);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private handleNullifiedPoly(polynomial: Polynomial) {
|
|
157
|
+
const degree = this.pm.degree(polynomial, this.level);
|
|
158
|
+
for (let power = 0; power <= degree; power++)
|
|
159
|
+
this.requestFactorized(this.pm.coeff(polynomial, this.level, power));
|
|
160
|
+
let current = [{ polynomial, minVar: 0 }];
|
|
161
|
+
while (current.length > 0) {
|
|
162
|
+
const next: { polynomial: Polynomial; minVar: number }[] = [];
|
|
163
|
+
for (const entry of current) {
|
|
164
|
+
const maxVar = this.pm.maxVar(entry.polynomial);
|
|
165
|
+
if (maxVar === NULL_VAR) continue;
|
|
166
|
+
for (let variable = entry.minVar; variable <= maxVar; variable++) {
|
|
167
|
+
if (this.pm.degree(entry.polynomial, variable) === 0) continue;
|
|
168
|
+
const derivative = this.pm.derivative(entry.polynomial, variable);
|
|
169
|
+
if (this.pm.isConst(derivative)) continue;
|
|
170
|
+
if (this.getSign(derivative) !== 0) {
|
|
171
|
+
this.requestFactorized(derivative);
|
|
214
172
|
return;
|
|
215
173
|
}
|
|
216
|
-
|
|
217
|
-
nextMinVar.push(x);
|
|
218
|
-
dq.reset();
|
|
174
|
+
next.push({ polynomial: derivative, minVar: variable });
|
|
219
175
|
}
|
|
220
|
-
q.reset();
|
|
221
|
-
}
|
|
222
|
-
for (let index = 0; index < nextPolys.size; index++) {
|
|
223
|
-
const dq = new PolynomialRef(pm);
|
|
224
|
-
dq.set(nextPolys.get(index));
|
|
225
|
-
this.requestFactorized(dq.get());
|
|
226
|
-
dq.reset();
|
|
227
|
-
}
|
|
228
|
-
curPolys.reset();
|
|
229
|
-
curPolys = nextPolys;
|
|
230
|
-
curMinVar = nextMinVar;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
private resetInterval(interval: CellInterval) {
|
|
235
|
-
interval.isSection = false;
|
|
236
|
-
interval.lower.reset();
|
|
237
|
-
interval.upper.reset();
|
|
238
|
-
interval.lowerIndex = 0;
|
|
239
|
-
interval.upperIndex = 0;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
private getFirstPsc(chain: PolynomialRefVector) {
|
|
243
|
-
const r = new PolynomialRef(this.pm);
|
|
244
|
-
for (let index = 0; index < chain.size; index++) {
|
|
245
|
-
r.set(chain.get(index));
|
|
246
|
-
if (this.pm.isZero(r.get())) continue;
|
|
247
|
-
if (this.pm.isConst(r.get())) {
|
|
248
|
-
r.reset();
|
|
249
|
-
return r;
|
|
250
176
|
}
|
|
251
|
-
|
|
177
|
+
for (const entry of next) this.requestFactorized(entry.polynomial);
|
|
178
|
+
current = next;
|
|
252
179
|
}
|
|
253
|
-
r.reset();
|
|
254
|
-
return r;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
private pscDiscriminant(pIn: Polynomial, x: number) {
|
|
258
|
-
const pm = this.pm;
|
|
259
|
-
if (pm.isZero(pIn) || pm.isConst(pIn) || pm.degree(pIn, x) < 2) return new PolynomialRef(pm);
|
|
260
|
-
const p = new PolynomialRef(pm);
|
|
261
|
-
p.set(pIn);
|
|
262
|
-
const d = new PolynomialRef(pm);
|
|
263
|
-
d.set(pm.derivative(p.get(), x));
|
|
264
|
-
const chain = this.pscTmp;
|
|
265
|
-
chain.reset();
|
|
266
|
-
this.cache.pscChain(p.get(), d.get(), x, chain);
|
|
267
|
-
const disc = this.getFirstPsc(chain);
|
|
268
|
-
d.reset();
|
|
269
|
-
p.reset();
|
|
270
|
-
return disc;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
private pscResultant(a: Polynomial, b: Polynomial, x: number) {
|
|
274
|
-
const pa = new PolynomialRef(this.pm);
|
|
275
|
-
pa.set(a);
|
|
276
|
-
const pb = new PolynomialRef(this.pm);
|
|
277
|
-
pb.set(b);
|
|
278
|
-
const chain = this.pscTmp;
|
|
279
|
-
chain.reset();
|
|
280
|
-
this.cache.pscChain(pa.get(), pb.get(), x, chain);
|
|
281
|
-
const r = this.getFirstPsc(chain);
|
|
282
|
-
pb.reset();
|
|
283
|
-
pa.reset();
|
|
284
|
-
return r;
|
|
285
180
|
}
|
|
286
181
|
|
|
287
|
-
private
|
|
288
|
-
const
|
|
289
|
-
if (polynomial === null || pm.isZero(polynomial) || pm.isConst(polynomial)) return;
|
|
290
|
-
const factors = new PolynomialRefVector(pm);
|
|
291
|
-
this.cache.factor(polynomial, factors);
|
|
292
|
-
for (let index = 0; index < factors.size; index++) {
|
|
293
|
-
const f = new PolynomialRef(pm);
|
|
294
|
-
f.set(factors.get(index));
|
|
295
|
-
if (!pm.isZero(f.get()) && !pm.isConst(f.get())) this.todo.insert(f.get());
|
|
296
|
-
f.reset();
|
|
297
|
-
}
|
|
298
|
-
factors.reset();
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
private chooseNonzeroCoeff(p: Polynomial, x: number) {
|
|
302
|
-
const pm = this.pm;
|
|
303
|
-
const degree = pm.degree(p, x);
|
|
304
|
-
const coeff = new PolynomialRef(pm);
|
|
182
|
+
private chooseNonzeroCoeff(polynomial: Polynomial, variable: number) {
|
|
183
|
+
const degree = this.pm.degree(polynomial, variable);
|
|
305
184
|
for (let power = 0; power <= degree; power++) {
|
|
306
|
-
coeff.
|
|
307
|
-
if (pm.isZero(coeff.
|
|
308
|
-
if (pm.isConst(coeff.get())) return coeff;
|
|
185
|
+
const coeff = this.pm.coeff(polynomial, variable, power);
|
|
186
|
+
if (!this.pm.isZero(coeff) && this.pm.isConst(coeff)) return coeff;
|
|
309
187
|
}
|
|
310
|
-
|
|
311
|
-
let bestTotalDegree = 0;
|
|
312
|
-
let bestSize = 0;
|
|
313
|
-
let bestMaxVar = NULL_VAR;
|
|
188
|
+
let best: Polynomial | null = null;
|
|
314
189
|
for (let power = 0; power <= degree; power++) {
|
|
315
|
-
coeff.
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
const size = current.size;
|
|
320
|
-
const maxVar = pm.maxVar(current);
|
|
190
|
+
const coeff = this.pm.coeff(polynomial, variable, power);
|
|
191
|
+
if (this.pm.isZero(coeff) || this.getSign(coeff) === 0) continue;
|
|
192
|
+
const totalDegree = this.pm.totalDegree(coeff);
|
|
193
|
+
const bestDegree = best === null ? 0 : this.pm.totalDegree(best);
|
|
321
194
|
if (
|
|
322
|
-
best
|
|
323
|
-
totalDegree <
|
|
324
|
-
(totalDegree ===
|
|
325
|
-
(size <
|
|
326
|
-
(size ===
|
|
327
|
-
)
|
|
328
|
-
best
|
|
329
|
-
bestTotalDegree = totalDegree;
|
|
330
|
-
bestSize = size;
|
|
331
|
-
bestMaxVar = maxVar;
|
|
332
|
-
}
|
|
195
|
+
best === null ||
|
|
196
|
+
totalDegree < bestDegree ||
|
|
197
|
+
(totalDegree === bestDegree &&
|
|
198
|
+
(coeff.size < best.size ||
|
|
199
|
+
(coeff.size === best.size && this.pm.maxVar(coeff) < this.pm.maxVar(best))))
|
|
200
|
+
)
|
|
201
|
+
best = coeff;
|
|
333
202
|
}
|
|
334
|
-
coeff.reset();
|
|
335
203
|
return best;
|
|
336
204
|
}
|
|
337
205
|
|
|
338
206
|
private addProjectionForPoly(
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
207
|
+
polynomial: Polynomial,
|
|
208
|
+
variable: number,
|
|
209
|
+
witness: Polynomial | null,
|
|
342
210
|
isLcAdded: boolean,
|
|
343
|
-
isDiscAdded: boolean,
|
|
344
211
|
) {
|
|
345
|
-
|
|
346
|
-
let isNonzeroCoeffAdded = nonzeroCoeff !== null && !pm.isConst(nonzeroCoeff);
|
|
212
|
+
let isWitnessAdded = witness !== null && !this.pm.isConst(witness);
|
|
347
213
|
if (isLcAdded) {
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
this.
|
|
351
|
-
if (isNonzeroCoeffAdded && this.getSign(lc.get()) !== 0) isNonzeroCoeffAdded = false;
|
|
352
|
-
lc.reset();
|
|
214
|
+
const leadingCoeff = this.pm.lc(polynomial, variable);
|
|
215
|
+
this.requestFactorized(leadingCoeff);
|
|
216
|
+
if (isWitnessAdded && this.getSign(leadingCoeff) !== 0) isWitnessAdded = false;
|
|
353
217
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (value !== null) {
|
|
359
|
-
this.requestFactorized(value);
|
|
360
|
-
if (isNonzeroCoeffAdded && this.getSign(value) !== 0) isNonzeroCoeffAdded = false;
|
|
361
|
-
}
|
|
362
|
-
disc.reset();
|
|
218
|
+
const discriminant = this.getPscDiscriminant(polynomial, variable);
|
|
219
|
+
if (discriminant !== null) {
|
|
220
|
+
this.requestFactorized(discriminant);
|
|
221
|
+
if (isWitnessAdded && this.getSign(discriminant) !== 0) isWitnessAdded = false;
|
|
363
222
|
}
|
|
364
|
-
if (
|
|
223
|
+
if (isWitnessAdded) this.requestFactorized(witness);
|
|
365
224
|
}
|
|
366
225
|
|
|
367
226
|
private addPair(first: number, second: number) {
|
|
@@ -383,7 +242,7 @@ export class Levelwise {
|
|
|
383
242
|
|
|
384
243
|
private computeSideMask() {
|
|
385
244
|
if (this.lowerRf === UNSET) return;
|
|
386
|
-
while (this.sideMask.length < this.
|
|
245
|
+
while (this.sideMask.length < this.levelPolys.length) this.sideMask.push(0);
|
|
387
246
|
this.rootFunctions.forEach((rootFunction, index) => {
|
|
388
247
|
this.sideMask[rootFunction.psIndex] |= index <= this.lowerRf ? 1 : 2;
|
|
389
248
|
});
|
|
@@ -393,24 +252,20 @@ export class Levelwise {
|
|
|
393
252
|
return rootFunctionIndex === UNSET ? UNSET : this.rootFunctions[rootFunctionIndex].psIndex;
|
|
394
253
|
}
|
|
395
254
|
|
|
396
|
-
private computeResultantGraphDegree() {
|
|
397
|
-
this.degInOrderGraph = Array.from({ length: this.levelPs.size }, () => 0);
|
|
398
|
-
for (const pair of this.pairs.values()) {
|
|
399
|
-
this.degInOrderGraph[pair[0]]++;
|
|
400
|
-
this.degInOrderGraph[pair[1]]++;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
255
|
private computeOmitLcBothSides(isLeafRequired: boolean) {
|
|
405
|
-
this.isLcOmitted =
|
|
256
|
+
this.isLcOmitted = this.levelPolys.map(() => false);
|
|
406
257
|
if (this.rootFunctions.length === 0 || this.pairs.size === 0 || this.sideMask.length === 0)
|
|
407
258
|
return;
|
|
408
|
-
|
|
259
|
+
const degrees = this.levelPolys.map(() => 0);
|
|
260
|
+
for (const pair of this.pairs.values()) {
|
|
261
|
+
degrees[pair[0]]++;
|
|
262
|
+
degrees[pair[1]]++;
|
|
263
|
+
}
|
|
409
264
|
const lowerBound = this.getBoundIndex(this.lowerRf);
|
|
410
265
|
const upperBound = this.getBoundIndex(this.upperRf);
|
|
411
|
-
for (let index = 0; index < this.
|
|
266
|
+
for (let index = 0; index < this.levelPolys.length; index++) {
|
|
412
267
|
if (this.sideMask[index] !== BOTH_SIDES) continue;
|
|
413
|
-
if (isLeafRequired &&
|
|
268
|
+
if (isLeafRequired && degrees[index] !== 1) continue;
|
|
414
269
|
if (index === lowerBound || index === upperBound) continue;
|
|
415
270
|
this.isLcOmitted[index] = true;
|
|
416
271
|
}
|
|
@@ -426,24 +281,26 @@ export class Levelwise {
|
|
|
426
281
|
}
|
|
427
282
|
|
|
428
283
|
private fillRelationSection() {
|
|
429
|
-
if (this.rootFunctions.length === 0) return;
|
|
430
284
|
for (let index = 0; index < this.lowerRf; index++) this.addPair(index, this.lowerRf);
|
|
431
285
|
for (let index = this.lowerRf + 1; index < this.rootFunctions.length; index++)
|
|
432
286
|
this.addPair(this.lowerRf, index);
|
|
433
287
|
}
|
|
434
288
|
|
|
435
289
|
private buildBothSideSpanningTree() {
|
|
436
|
-
const lowerRfs =
|
|
437
|
-
const upperRfs =
|
|
290
|
+
const lowerRfs = this.levelPolys.map(() => UNSET);
|
|
291
|
+
const upperRfs = this.levelPolys.map(() => UNSET);
|
|
438
292
|
for (let index = 0; index <= this.lowerRf; index++)
|
|
439
293
|
lowerRfs[this.rootFunctions[index].psIndex] = index;
|
|
440
294
|
for (let index = this.upperRf; index < this.rootFunctions.length; index++)
|
|
441
295
|
upperRfs[this.rootFunctions[index].psIndex] = index;
|
|
442
|
-
const both
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
296
|
+
const both = this.levelPolys
|
|
297
|
+
.map((_polynomial, psIndex) => ({
|
|
298
|
+
psIndex,
|
|
299
|
+
lowerRf: lowerRfs[psIndex],
|
|
300
|
+
upperRf: upperRfs[psIndex],
|
|
301
|
+
}))
|
|
302
|
+
.filter((info) => this.sideMask[info.psIndex] === BOTH_SIDES)
|
|
303
|
+
.sort((first, second) => first.lowerRf - second.lowerRf);
|
|
447
304
|
for (let first = 0; first < both.length - 1; first++) {
|
|
448
305
|
let closest = first + 1;
|
|
449
306
|
for (let index = first + 2; index < both.length; index++)
|
|
@@ -474,21 +331,21 @@ export class Levelwise {
|
|
|
474
331
|
}
|
|
475
332
|
|
|
476
333
|
private isolateRootsAroundSample(
|
|
477
|
-
p: Polynomial,
|
|
478
334
|
psIndex: number,
|
|
479
335
|
value: Anum,
|
|
480
336
|
lower: RootFunction[],
|
|
481
337
|
upper: RootFunction[],
|
|
482
338
|
) {
|
|
339
|
+
const polynomial = this.levelPolys[psIndex];
|
|
483
340
|
const values = this.getValuesWithout(this.level);
|
|
484
341
|
const mkRootFunction = (root: Anum, index: number) => ({
|
|
485
342
|
value: this.am.copy(root),
|
|
486
|
-
polynomial
|
|
343
|
+
polynomial,
|
|
487
344
|
index,
|
|
488
345
|
psIndex,
|
|
489
346
|
});
|
|
490
347
|
if (value.value instanceof Rational) {
|
|
491
|
-
const closest = this.am.isolateRootsClosest(this.pm,
|
|
348
|
+
const closest = this.am.isolateRootsClosest(this.pm, polynomial, values, value.value);
|
|
492
349
|
closest.roots.forEach((root, index) => {
|
|
493
350
|
(this.am.compare(root, value) <= 0 ? lower : upper).push(
|
|
494
351
|
mkRootFunction(root, closest.indices[index]),
|
|
@@ -496,7 +353,7 @@ export class Levelwise {
|
|
|
496
353
|
});
|
|
497
354
|
return closest.roots.length > 0;
|
|
498
355
|
}
|
|
499
|
-
const roots = this.am.isolateRoots(this.pm,
|
|
356
|
+
const roots = this.am.isolateRoots(this.pm, polynomial, values);
|
|
500
357
|
let lowerIndex = UNSET;
|
|
501
358
|
let upperIndex = UNSET;
|
|
502
359
|
let isSection = false;
|
|
@@ -543,115 +400,95 @@ export class Levelwise {
|
|
|
543
400
|
if (middle === 0) {
|
|
544
401
|
this.lowerRf = UNSET;
|
|
545
402
|
this.upperRf = 0;
|
|
546
|
-
interval.upper
|
|
403
|
+
interval.upper = rootFunctions[0].polynomial;
|
|
547
404
|
interval.upperIndex = rootFunctions[0].index;
|
|
548
405
|
return;
|
|
549
406
|
}
|
|
550
407
|
this.lowerRf = middle - 1;
|
|
551
408
|
const lower = rootFunctions[middle - 1];
|
|
409
|
+
interval.lower = lower.polynomial;
|
|
410
|
+
interval.lowerIndex = lower.index;
|
|
552
411
|
if (this.am.compare(lower.value, value) === 0) {
|
|
553
412
|
interval.isSection = true;
|
|
554
|
-
interval.lower.set(lower.polynomial);
|
|
555
|
-
interval.lowerIndex = lower.index;
|
|
556
413
|
this.upperRf = this.lowerRf;
|
|
557
414
|
return;
|
|
558
415
|
}
|
|
559
|
-
interval.lower.set(lower.polynomial);
|
|
560
|
-
interval.lowerIndex = lower.index;
|
|
561
416
|
if (middle < rootFunctions.length) {
|
|
562
417
|
this.upperRf = this.lowerRf + 1;
|
|
563
|
-
interval.upper
|
|
418
|
+
interval.upper = rootFunctions[middle].polynomial;
|
|
564
419
|
interval.upperIndex = rootFunctions[middle].index;
|
|
565
420
|
}
|
|
566
421
|
}
|
|
567
422
|
|
|
568
|
-
private addLinearPolyFromRoot(root: Anum, isLower: boolean
|
|
569
|
-
const
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
const constant = new PolynomialRef(pm);
|
|
575
|
-
constant.set(pm.mkConst(value.num));
|
|
576
|
-
const difference = new PolynomialRef(pm);
|
|
577
|
-
difference.set(pm.sub(scaled.get(), constant.get()));
|
|
578
|
-
constant.reset();
|
|
579
|
-
p.move(difference);
|
|
580
|
-
scaled.reset();
|
|
423
|
+
private addLinearPolyFromRoot(root: Anum, isLower: boolean) {
|
|
424
|
+
const value = root.value as Rational;
|
|
425
|
+
const polynomial = this.pm.sub(
|
|
426
|
+
this.pm.mul(this.pm.mkConst(value.den), this.pm.mkVar(this.level)),
|
|
427
|
+
this.pm.mkConst(value.num),
|
|
428
|
+
);
|
|
581
429
|
const interval = this.intervals[this.level];
|
|
582
430
|
if (isLower) {
|
|
583
|
-
interval.lower
|
|
431
|
+
interval.lower = polynomial;
|
|
584
432
|
interval.lowerIndex = 1;
|
|
585
433
|
} else {
|
|
586
|
-
interval.upper
|
|
434
|
+
interval.upper = polynomial;
|
|
587
435
|
interval.upperIndex = 1;
|
|
588
436
|
}
|
|
589
|
-
this.
|
|
590
|
-
this.
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
copy.copy(witness);
|
|
594
|
-
this.witnesses.push(copy);
|
|
595
|
-
witness.reset();
|
|
437
|
+
this.levelPolys.push(polynomial);
|
|
438
|
+
this.hasRoots.push(true);
|
|
439
|
+
this.witnesses.push(this.chooseNonzeroCoeff(polynomial, this.level));
|
|
440
|
+
return polynomial;
|
|
596
441
|
}
|
|
597
442
|
|
|
598
443
|
private addLinearApproximations(value: Anum) {
|
|
599
|
-
const pLower = new PolynomialRef(this.pm);
|
|
600
|
-
const pUpper = new PolynomialRef(this.pm);
|
|
601
444
|
const interval = this.intervals[this.level];
|
|
602
445
|
const mkRootFunction = (polynomial: Polynomial, root: Anum) => ({
|
|
603
446
|
value: this.am.copy(root),
|
|
604
447
|
polynomial,
|
|
605
448
|
index: 1,
|
|
606
|
-
psIndex: this.
|
|
449
|
+
psIndex: this.levelPolys.length - 1,
|
|
607
450
|
});
|
|
608
451
|
if (interval.isSection) {
|
|
609
452
|
if (!this.am.isRational(value))
|
|
610
453
|
throw new NlsatUnsupportedError("a linear cell around an irrational section");
|
|
611
|
-
if (this.pm.totalDegree(interval.lower
|
|
612
|
-
this.addLinearPolyFromRoot(value, true
|
|
613
|
-
this.rootFunctions.splice(this.lowerRf, 0, mkRootFunction(
|
|
454
|
+
if (this.pm.totalDegree(interval.lower!) > 1) {
|
|
455
|
+
const polynomial = this.addLinearPolyFromRoot(value, true);
|
|
456
|
+
this.rootFunctions.splice(this.lowerRf, 0, mkRootFunction(polynomial, value));
|
|
614
457
|
}
|
|
615
|
-
pUpper.reset();
|
|
616
|
-
pLower.reset();
|
|
617
458
|
return;
|
|
618
459
|
}
|
|
619
|
-
|
|
620
|
-
if (lower !== null && this.pm.totalDegree(lower) > 1) {
|
|
460
|
+
if (interval.lower !== null && this.pm.totalDegree(interval.lower) > 1) {
|
|
621
461
|
const between = this.am.select(this.rootFunctions[this.lowerRf].value, value);
|
|
622
|
-
this.addLinearPolyFromRoot(between, true
|
|
623
|
-
this.rootFunctions.splice(this.lowerRf + 1, 0, mkRootFunction(
|
|
462
|
+
const polynomial = this.addLinearPolyFromRoot(between, true);
|
|
463
|
+
this.rootFunctions.splice(this.lowerRf + 1, 0, mkRootFunction(polynomial, between));
|
|
624
464
|
this.lowerRf++;
|
|
625
465
|
if (this.upperRf !== UNSET) this.upperRf++;
|
|
626
466
|
}
|
|
627
|
-
|
|
628
|
-
if (upper !== null && this.pm.totalDegree(upper) > 1) {
|
|
467
|
+
if (interval.upper !== null && this.pm.totalDegree(interval.upper) > 1) {
|
|
629
468
|
const between = this.am.select(value, this.rootFunctions[this.upperRf].value);
|
|
630
|
-
this.addLinearPolyFromRoot(between, false
|
|
631
|
-
this.rootFunctions.splice(this.upperRf, 0, mkRootFunction(
|
|
469
|
+
const polynomial = this.addLinearPolyFromRoot(between, false);
|
|
470
|
+
this.rootFunctions.splice(this.upperRf, 0, mkRootFunction(polynomial, between));
|
|
632
471
|
}
|
|
633
|
-
pUpper.reset();
|
|
634
|
-
pLower.reset();
|
|
635
472
|
}
|
|
636
473
|
|
|
637
474
|
private buildInterval() {
|
|
638
475
|
this.rootFunctions = [];
|
|
639
476
|
this.pairs.clear();
|
|
640
|
-
|
|
477
|
+
Object.assign(this.intervals[this.level], {
|
|
478
|
+
isSection: false,
|
|
479
|
+
lower: null,
|
|
480
|
+
lowerIndex: 0,
|
|
481
|
+
upper: null,
|
|
482
|
+
upperIndex: 0,
|
|
483
|
+
});
|
|
641
484
|
this.lowerRf = UNSET;
|
|
642
485
|
this.upperRf = UNSET;
|
|
643
486
|
const value = this.sample[this.level]!;
|
|
644
|
-
this.polyHasRoots = Array.from({ length: this.levelPs.size }, () => false);
|
|
645
487
|
const lower: RootFunction[] = [];
|
|
646
488
|
const upper: RootFunction[] = [];
|
|
647
|
-
|
|
648
|
-
this.
|
|
649
|
-
|
|
650
|
-
index,
|
|
651
|
-
value,
|
|
652
|
-
lower,
|
|
653
|
-
upper,
|
|
654
|
-
);
|
|
489
|
+
this.hasRoots = this.levelPolys.map((_polynomial, psIndex) =>
|
|
490
|
+
this.isolateRootsAroundSample(psIndex, value, lower, upper),
|
|
491
|
+
);
|
|
655
492
|
if (lower.length === 0 && upper.length === 0) return false;
|
|
656
493
|
this.rootFunctions = [
|
|
657
494
|
...this.sortRootFunctions(lower, true),
|
|
@@ -664,27 +501,20 @@ export class Levelwise {
|
|
|
664
501
|
}
|
|
665
502
|
|
|
666
503
|
private addRelationResultants() {
|
|
667
|
-
for (const pair of this.getSortedPairs())
|
|
668
|
-
|
|
669
|
-
this.
|
|
670
|
-
this.levelPs.get(pair[1]),
|
|
671
|
-
this.level,
|
|
504
|
+
for (const pair of this.getSortedPairs())
|
|
505
|
+
this.requestFactorized(
|
|
506
|
+
this.getFirstPsc(this.levelPolys[pair[0]], this.levelPolys[pair[1]], this.level),
|
|
672
507
|
);
|
|
673
|
-
this.requestFactorized(res.getOrNull());
|
|
674
|
-
res.reset();
|
|
675
|
-
}
|
|
676
508
|
}
|
|
677
509
|
|
|
678
510
|
private addAdjacentRootResultants() {
|
|
679
|
-
this.polyHasRoots = Array.from({ length: this.levelPs.size }, () => false);
|
|
680
511
|
const rootValues: { root: Anum; polynomial: Polynomial }[] = [];
|
|
681
512
|
const values = this.getValuesWithout(this.maxVar);
|
|
682
|
-
|
|
683
|
-
const polynomial = this.levelPs.get(index);
|
|
513
|
+
this.hasRoots = this.levelPolys.map((polynomial) => {
|
|
684
514
|
const roots = this.am.isolateRoots(this.pm, polynomial, values);
|
|
685
|
-
this.polyHasRoots[index] = roots.length > 0;
|
|
686
515
|
for (const root of roots) rootValues.push({ root: this.am.copy(root), polynomial });
|
|
687
|
-
|
|
516
|
+
return roots.length > 0;
|
|
517
|
+
});
|
|
688
518
|
if (rootValues.length < 2) return;
|
|
689
519
|
const order = mergeSortIndices(
|
|
690
520
|
rootValues.length,
|
|
@@ -699,51 +529,32 @@ export class Levelwise {
|
|
|
699
529
|
const key = `${low.id},${high.id}`;
|
|
700
530
|
if (added.has(key)) continue;
|
|
701
531
|
added.add(key);
|
|
702
|
-
|
|
703
|
-
this.requestFactorized(res.getOrNull());
|
|
704
|
-
res.reset();
|
|
532
|
+
this.requestFactorized(this.getFirstPsc(low, high, this.maxVar));
|
|
705
533
|
}
|
|
706
534
|
}
|
|
707
535
|
|
|
708
536
|
private addSectionProjections() {
|
|
709
|
-
const sectionPolynomial = this.intervals[this.level].lower
|
|
537
|
+
const sectionPolynomial = this.intervals[this.level].lower;
|
|
710
538
|
const withRoots = new Set(this.rootFunctions.map((rootFunction) => rootFunction.psIndex));
|
|
711
|
-
|
|
712
|
-
const
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
witness.copy(this.witnesses[index]);
|
|
716
|
-
const isFull = this.levelPs.get(index) === sectionPolynomial || !withRoots.has(index);
|
|
717
|
-
this.addProjectionForPoly(p.get(), this.level, witness.getOrNull(), isFull, true);
|
|
718
|
-
witness.reset();
|
|
719
|
-
p.reset();
|
|
720
|
-
}
|
|
539
|
+
this.levelPolys.forEach((polynomial, index) => {
|
|
540
|
+
const isFull = polynomial === sectionPolynomial || !withRoots.has(index);
|
|
541
|
+
this.addProjectionForPoly(polynomial, this.level, this.witnesses[index], isFull);
|
|
542
|
+
});
|
|
721
543
|
}
|
|
722
544
|
|
|
723
545
|
private addSectorProjections() {
|
|
724
|
-
|
|
725
|
-
for (let index = 0; index < this.levelPs.size; index++) {
|
|
726
|
-
const p = new PolynomialRef(pm);
|
|
727
|
-
p.set(this.levelPs.get(index));
|
|
728
|
-
const lc = new PolynomialRef(pm);
|
|
729
|
-
lc.set(pm.coeff(p.get(), this.level, pm.degree(p.get(), this.level)));
|
|
546
|
+
this.levelPolys.forEach((polynomial, index) => {
|
|
730
547
|
const isLcAdded = !(this.isLcOmitted[index] ?? false);
|
|
731
|
-
|
|
732
|
-
witness.copy(this.witnesses[index]);
|
|
733
|
-
const value = witness.getOrNull();
|
|
548
|
+
let witness = this.witnesses[index];
|
|
734
549
|
if (
|
|
735
550
|
isLcAdded &&
|
|
736
|
-
|
|
737
|
-
!pm.isConst(
|
|
738
|
-
|
|
739
|
-
this.getSign(lc.get()) !== 0
|
|
551
|
+
witness !== null &&
|
|
552
|
+
!this.pm.isConst(witness) &&
|
|
553
|
+
this.getSign(this.pm.lc(polynomial, this.level)) !== 0
|
|
740
554
|
)
|
|
741
|
-
witness
|
|
742
|
-
this.addProjectionForPoly(
|
|
743
|
-
|
|
744
|
-
lc.reset();
|
|
745
|
-
p.reset();
|
|
746
|
-
}
|
|
555
|
+
witness = null;
|
|
556
|
+
this.addProjectionForPoly(polynomial, this.level, witness, isLcAdded);
|
|
557
|
+
});
|
|
747
558
|
}
|
|
748
559
|
|
|
749
560
|
private shouldUseSpanningTree() {
|
|
@@ -751,19 +562,12 @@ export class Levelwise {
|
|
|
751
562
|
if (this.lowerRf === UNSET || this.upperRf === UNSET) return false;
|
|
752
563
|
if (this.getBoundIndex(this.lowerRf) === this.getBoundIndex(this.upperRf)) return false;
|
|
753
564
|
let bothCount = 0;
|
|
754
|
-
for (let index = 0; index < this.
|
|
565
|
+
for (let index = 0; index < this.levelPolys.length; index++)
|
|
755
566
|
if (this.sideMask[index] === BOTH_SIDES && ++bothCount >= SPANNING_TREE_THRESHOLD)
|
|
756
567
|
return true;
|
|
757
568
|
return false;
|
|
758
569
|
}
|
|
759
570
|
|
|
760
|
-
private clearLevelState() {
|
|
761
|
-
this.isLcOmitted = [];
|
|
762
|
-
this.pairs.clear();
|
|
763
|
-
this.sideMask = [];
|
|
764
|
-
this.degInOrderGraph = [];
|
|
765
|
-
}
|
|
766
|
-
|
|
767
571
|
private processLevelWithMode(mode: ProjectionMode, hasInterval: boolean) {
|
|
768
572
|
if (hasInterval) {
|
|
769
573
|
if (mode === "section") this.fillRelationSection();
|
|
@@ -780,23 +584,21 @@ export class Levelwise {
|
|
|
780
584
|
}
|
|
781
585
|
|
|
782
586
|
private collectNonNullWitnesses() {
|
|
783
|
-
this.
|
|
784
|
-
for (let index = 0; index < this.
|
|
785
|
-
const
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
this.witnesses.push(copy);
|
|
792
|
-
if (index + 1 === this.levelPs.size) this.todo.extractPolysAtLevel(this.level, this.levelPs);
|
|
793
|
-
witness.reset();
|
|
794
|
-
p.reset();
|
|
587
|
+
this.witnesses = [];
|
|
588
|
+
for (let index = 0; index < this.levelPolys.length; index++) {
|
|
589
|
+
const polynomial = this.levelPolys[index];
|
|
590
|
+
const witness = this.chooseNonzeroCoeff(polynomial, this.level);
|
|
591
|
+
if (witness === null) this.handleNullifiedPoly(polynomial);
|
|
592
|
+
this.witnesses.push(witness);
|
|
593
|
+
if (index + 1 === this.levelPolys.length)
|
|
594
|
+
this.todo.extractPolysAtLevel(this.level, this.levelPolys);
|
|
795
595
|
}
|
|
796
596
|
}
|
|
797
597
|
|
|
798
598
|
private processLevel() {
|
|
799
|
-
this.
|
|
599
|
+
this.isLcOmitted = [];
|
|
600
|
+
this.pairs.clear();
|
|
601
|
+
this.sideMask = [];
|
|
800
602
|
this.collectNonNullWitnesses();
|
|
801
603
|
const hasInterval = this.buildInterval();
|
|
802
604
|
this.processLevelWithMode(
|
|
@@ -810,65 +612,39 @@ export class Levelwise {
|
|
|
810
612
|
}
|
|
811
613
|
|
|
812
614
|
private processTopLevel() {
|
|
813
|
-
const pm = this.pm;
|
|
814
615
|
this.collectNonNullWitnesses();
|
|
815
616
|
this.addAdjacentRootResultants();
|
|
816
|
-
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
if (
|
|
823
|
-
!(this.polyHasRoots[index] ?? false) &&
|
|
824
|
-
!pm.isZero(lc.get()) &&
|
|
825
|
-
this.getSign(lc.get()) !== 0
|
|
826
|
-
) {
|
|
827
|
-
isLcAdded = false;
|
|
828
|
-
this.witnesses[index].reset();
|
|
829
|
-
}
|
|
830
|
-
this.addProjectionForPoly(
|
|
831
|
-
p.get(),
|
|
832
|
-
this.maxVar,
|
|
833
|
-
this.witnesses[index].getOrNull(),
|
|
834
|
-
isLcAdded,
|
|
835
|
-
true,
|
|
836
|
-
);
|
|
837
|
-
lc.reset();
|
|
838
|
-
p.reset();
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
private copyIntervals() {
|
|
843
|
-
return this.intervals.map((interval) => {
|
|
844
|
-
const copy = new CellInterval(this.pm);
|
|
845
|
-
copy.isSection = interval.isSection;
|
|
846
|
-
copy.lower.copy(interval.lower);
|
|
847
|
-
copy.lowerIndex = interval.lowerIndex;
|
|
848
|
-
copy.upper.copy(interval.upper);
|
|
849
|
-
copy.upperIndex = interval.upperIndex;
|
|
850
|
-
return copy;
|
|
617
|
+
this.levelPolys.forEach((polynomial, index) => {
|
|
618
|
+
const leadingCoeff = this.pm.lc(polynomial, this.maxVar);
|
|
619
|
+
const isLcAdded =
|
|
620
|
+
this.hasRoots[index] || this.pm.isZero(leadingCoeff) || this.getSign(leadingCoeff) === 0;
|
|
621
|
+
if (!isLcAdded) this.witnesses[index] = null;
|
|
622
|
+
this.addProjectionForPoly(polynomial, this.maxVar, this.witnesses[index], isLcAdded);
|
|
851
623
|
});
|
|
852
624
|
}
|
|
853
625
|
|
|
854
|
-
|
|
855
|
-
if (this.maxVar === 0) return this.
|
|
856
|
-
this.
|
|
857
|
-
|
|
858
|
-
const p = new PolynomialRef(this.pm);
|
|
859
|
-
p.set(this.polynomials.get(index));
|
|
860
|
-
this.requestFactorized(p.get());
|
|
861
|
-
p.reset();
|
|
862
|
-
}
|
|
863
|
-
if (this.todo.isEmpty) return this.copyIntervals();
|
|
626
|
+
computeSingleCell(polynomials: readonly Polynomial[]) {
|
|
627
|
+
if (this.maxVar === 0) return this.intervals;
|
|
628
|
+
for (const polynomial of polynomials) this.requestFactorized(polynomial);
|
|
629
|
+
if (this.todo.isEmpty) return this.intervals;
|
|
864
630
|
if (this.todo.getMaxVar() === this.maxVar) {
|
|
865
|
-
this.level = this.todo.extractMaxPolys(this.
|
|
631
|
+
this.level = this.todo.extractMaxPolys(this.levelPolys);
|
|
866
632
|
this.processTopLevel();
|
|
867
633
|
}
|
|
868
634
|
while (!this.todo.isEmpty) {
|
|
869
|
-
this.level = this.todo.extractMaxPolys(this.
|
|
635
|
+
this.level = this.todo.extractMaxPolys(this.levelPolys);
|
|
870
636
|
this.processLevel();
|
|
871
637
|
}
|
|
872
|
-
return this.
|
|
638
|
+
return this.intervals;
|
|
873
639
|
}
|
|
874
640
|
}
|
|
641
|
+
|
|
642
|
+
export const getSingleCell = (
|
|
643
|
+
pm: PolynomialManager,
|
|
644
|
+
am: AlgebraicManager,
|
|
645
|
+
cache: PolynomialCache,
|
|
646
|
+
polynomials: readonly Polynomial[],
|
|
647
|
+
maxVar: number,
|
|
648
|
+
sample: readonly (Anum | undefined)[],
|
|
649
|
+
isLinear: boolean,
|
|
650
|
+
) => new Levelwise(pm, am, cache, sample, maxVar, isLinear).computeSingleCell(polynomials);
|