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