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.
Files changed (82) hide show
  1. package/dist/deciders.cjs +35 -35
  2. package/dist/deciders.js +29 -29
  3. package/dist/index.d.cts +1 -1
  4. package/dist/index.d.ts +1 -1
  5. package/dist/parallel-worker.cjs +1 -1
  6. package/dist/parallel-worker.js +1 -1
  7. package/dist/prove.cjs +25 -25
  8. package/dist/prove.js +57 -57
  9. package/dist/run.cjs +26 -28
  10. package/dist/run.js +42 -44
  11. package/dist/transfer.cjs +35 -35
  12. package/dist/transfer.js +28 -28
  13. package/dist/worker.cjs +1 -1
  14. package/dist/worker.js +1 -1
  15. package/package.json +1 -1
  16. package/src/bags.ts +47 -28
  17. package/src/check-trace.ts +2 -16
  18. package/src/check.ts +143 -61
  19. package/src/cli/runtime-invariants.ts +20 -56
  20. package/src/cli/tlc-arguments.ts +2 -2
  21. package/src/cli/tlc-output.ts +1 -2
  22. package/src/cli/tlc.ts +13 -8
  23. package/src/dfid.ts +9 -2
  24. package/src/environment.ts +18 -0
  25. package/src/evaluate.ts +9 -3
  26. package/src/exit-codes.ts +2 -0
  27. package/src/liveness-checker.ts +45 -4
  28. package/src/parallel-worker.ts +8 -2
  29. package/src/parallel.ts +5 -0
  30. package/src/prover/smt/solver/ast.ts +1 -1
  31. package/src/prover/smt/solver/context.ts +6 -2
  32. package/src/prover/smt/solver/euf/egraph.ts +1 -1
  33. package/src/prover/smt/solver/expr2polynomial.ts +204 -79
  34. package/src/prover/smt/solver/factor.ts +36 -14
  35. package/src/prover/smt/solver/fpa-rewriter.ts +1 -2
  36. package/src/prover/smt/solver/fpa2bv-converter.ts +3 -1
  37. package/src/prover/smt/solver/goal.ts +2 -0
  38. package/src/prover/smt/solver/goal2nlsat.ts +57 -30
  39. package/src/prover/smt/solver/lp/containers.ts +7 -1
  40. package/src/prover/smt/solver/lp/cross-nested.ts +1 -3
  41. package/src/prover/smt/solver/lp/nex-creator.ts +3 -2
  42. package/src/prover/smt/solver/lp/nex.ts +2 -1
  43. package/src/prover/smt/solver/lp/nla-basics.ts +46 -1
  44. package/src/prover/smt/solver/lp/nla-core.ts +26 -6
  45. package/src/prover/smt/solver/lp/nla-grobner.ts +156 -79
  46. package/src/prover/smt/solver/lp/nra-solver.ts +138 -95
  47. package/src/prover/smt/solver/lp/pdd-interval.ts +6 -2
  48. package/src/prover/smt/solver/lp/pdd-simplifier.ts +60 -20
  49. package/src/prover/smt/solver/lp/pdd-solver.ts +72 -39
  50. package/src/prover/smt/solver/lp/pdd.ts +725 -289
  51. package/src/prover/smt/solver/muz/dl-context.ts +8 -2
  52. package/src/prover/smt/solver/muz/spacer-context.ts +1 -0
  53. package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -0
  54. package/src/prover/smt/solver/nlsat/algebraic.ts +194 -89
  55. package/src/prover/smt/solver/nlsat/atoms.ts +52 -33
  56. package/src/prover/smt/solver/nlsat/explain.ts +375 -217
  57. package/src/prover/smt/solver/nlsat/levelwise.ts +464 -240
  58. package/src/prover/smt/solver/nlsat/polynomial.ts +2400 -680
  59. package/src/prover/smt/solver/nlsat/solver.ts +74 -71
  60. package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -17
  61. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -4
  62. package/src/prover/smt/solver/nlsat/upolynomial.ts +40 -17
  63. package/src/prover/smt/solver/opt-nlsat.ts +29 -18
  64. package/src/prover/smt/solver/opt-solver.ts +2 -3
  65. package/src/prover/smt/solver/rlimit.ts +13 -0
  66. package/src/prover/smt/solver/sat/sat-tactic.ts +2 -1
  67. package/src/prover/smt/solver/seq-derive.ts +3 -6
  68. package/src/prover/smt/solver/smtlib-parser.ts +10 -10
  69. package/src/prover/smt/solver/smtlib-script.ts +91 -28
  70. package/src/prover/smt/solver/tactic.ts +14 -5
  71. package/src/prover/smt/solver/theory-lra-internalize.ts +8 -0
  72. package/src/prover/zenon/equality-rules.ts +24 -0
  73. package/src/prover/zenon/expr.ts +21 -0
  74. package/src/prover/zenon/index-table.ts +2 -0
  75. package/src/prover/zenon/rules.ts +2 -1
  76. package/src/resolve.ts +1 -1
  77. package/src/runtime.ts +2 -0
  78. package/src/sany/generator-expressions.ts +6 -13
  79. package/src/search.ts +40 -11
  80. package/src/tlc/order.ts +14 -3
  81. package/src/tlc/tlcext-operators.ts +18 -5
  82. 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
- interface CellInterval {
15
- isSection: boolean;
16
- lower: Polynomial | null;
17
- lowerIndex: number;
18
- upper: Polynomial | null;
19
- upperIndex: number;
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
- polynomials: Polynomial[] = [];
37
- private inSet = new Set<number>();
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.polynomials.length === 0;
60
+ return this.set.size === 0;
46
61
  }
47
62
 
48
63
  reset() {
49
- this.polynomials = [];
50
- this.inSet.clear();
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
- if (this.inSet.has(polynomial.id)) return polynomial;
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.add(polynomial.id);
57
- this.polynomials.push(polynomial);
72
+ this.inSet[polynomial.id] = true;
73
+ this.set.push(polynomial);
58
74
  return polynomial;
59
75
  }
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);
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
- return unique;
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.polynomials);
100
+ return this.cache.pm.getMaxVarOfPolys(this.set.items);
74
101
  }
75
102
 
76
- extractMaxPolys(out: Polynomial[]) {
77
- out.length = 0;
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: 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);
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.polynomials = kept;
120
+ this.set.shrink(kept);
94
121
  }
95
122
  }
96
123
 
97
- class Levelwise {
98
- private intervals: CellInterval[];
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 sample: readonly (Anum | undefined)[],
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(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
- }));
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 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);
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
- next.push({ polynomial: derivative, minVar: variable });
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
- for (const entry of next) this.requestFactorized(entry.polynomial);
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 chooseNonzeroCoeff(polynomial: Polynomial, variable: number) {
183
- const degree = this.pm.degree(polynomial, variable);
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
- const coeff = this.pm.coeff(polynomial, variable, power);
186
- if (!this.pm.isZero(coeff) && this.pm.isConst(coeff)) return coeff;
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
- let best: Polynomial | null = null;
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
- 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);
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 < 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;
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
- polynomial: Polynomial,
208
- variable: number,
209
- witness: Polynomial | null,
339
+ p: Polynomial,
340
+ x: number,
341
+ nonzeroCoeff: Polynomial | null,
210
342
  isLcAdded: boolean,
343
+ isDiscAdded: boolean,
211
344
  ) {
212
- let isWitnessAdded = witness !== null && !this.pm.isConst(witness);
345
+ const pm = this.pm;
346
+ let isNonzeroCoeffAdded = nonzeroCoeff !== null && !pm.isConst(nonzeroCoeff);
213
347
  if (isLcAdded) {
214
- const leadingCoeff = this.pm.lc(polynomial, variable);
215
- this.requestFactorized(leadingCoeff);
216
- if (isWitnessAdded && this.getSign(leadingCoeff) !== 0) isWitnessAdded = false;
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
- const discriminant = this.getPscDiscriminant(polynomial, variable);
219
- if (discriminant !== null) {
220
- this.requestFactorized(discriminant);
221
- if (isWitnessAdded && this.getSign(discriminant) !== 0) isWitnessAdded = false;
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 (isWitnessAdded) this.requestFactorized(witness);
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.levelPolys.length) this.sideMask.push(0);
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.levelPolys.map(() => false);
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
- const degrees = this.levelPolys.map(() => 0);
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.levelPolys.length; index++) {
411
+ for (let index = 0; index < this.levelPs.size; index++) {
267
412
  if (this.sideMask[index] !== BOTH_SIDES) continue;
268
- if (isLeafRequired && degrees[index] !== 1) continue;
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.levelPolys.map(() => UNSET);
291
- const upperRfs = this.levelPolys.map(() => UNSET);
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 = 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);
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, polynomial, values, value.value);
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, polynomial, values);
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 = rootFunctions[0].polynomial;
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 = rootFunctions[middle].polynomial;
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 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
- );
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 = polynomial;
583
+ interval.lower.copy(p);
432
584
  interval.lowerIndex = 1;
433
585
  } else {
434
- interval.upper = polynomial;
586
+ interval.upper.copy(p);
435
587
  interval.upperIndex = 1;
436
588
  }
437
- this.levelPolys.push(polynomial);
438
- this.hasRoots.push(true);
439
- this.witnesses.push(this.chooseNonzeroCoeff(polynomial, this.level));
440
- return polynomial;
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.levelPolys.length - 1,
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!) > 1) {
455
- const polynomial = this.addLinearPolyFromRoot(value, true);
456
- this.rootFunctions.splice(this.lowerRf, 0, mkRootFunction(polynomial, value));
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
- if (interval.lower !== null && this.pm.totalDegree(interval.lower) > 1) {
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
- const polynomial = this.addLinearPolyFromRoot(between, true);
463
- this.rootFunctions.splice(this.lowerRf + 1, 0, mkRootFunction(polynomial, between));
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
- if (interval.upper !== null && this.pm.totalDegree(interval.upper) > 1) {
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
- const polynomial = this.addLinearPolyFromRoot(between, false);
470
- this.rootFunctions.splice(this.upperRf, 0, mkRootFunction(polynomial, between));
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
- Object.assign(this.intervals[this.level], {
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
- this.hasRoots = this.levelPolys.map((_polynomial, psIndex) =>
490
- this.isolateRootsAroundSample(psIndex, value, lower, upper),
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.requestFactorized(
506
- this.getFirstPsc(this.levelPolys[pair[0]], this.levelPolys[pair[1]], this.level),
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
- this.hasRoots = this.levelPolys.map((polynomial) => {
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
- return roots.length > 0;
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.requestFactorized(this.getFirstPsc(low, high, this.maxVar));
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.levelPolys.forEach((polynomial, index) => {
540
- const isFull = polynomial === sectionPolynomial || !withRoots.has(index);
541
- this.addProjectionForPoly(polynomial, this.level, this.witnesses[index], isFull);
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
- this.levelPolys.forEach((polynomial, index) => {
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
- let witness = this.witnesses[index];
731
+ const witness = new PolynomialRef(pm);
732
+ witness.copy(this.witnesses[index]);
733
+ const value = witness.getOrNull();
549
734
  if (
550
735
  isLcAdded &&
551
- witness !== null &&
552
- !this.pm.isConst(witness) &&
553
- this.getSign(this.pm.lc(polynomial, this.level)) !== 0
736
+ value !== null &&
737
+ !pm.isConst(value) &&
738
+ !pm.isZero(lc.get()) &&
739
+ this.getSign(lc.get()) !== 0
554
740
  )
555
- witness = null;
556
- this.addProjectionForPoly(polynomial, this.level, witness, isLcAdded);
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.levelPolys.length; index++)
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.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);
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.isLcOmitted = [];
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.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);
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
- 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;
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.levelPolys);
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.levelPolys);
869
+ this.level = this.todo.extractMaxPolys(this.levelPs);
636
870
  this.processLevel();
637
871
  }
638
- return this.intervals;
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);