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,12 +1,9 @@
1
- // Deviations from Z3: unsupported nlsat input answers unknown where Z3 exits (levelwise.cpp,
2
- // add_linear_approximations), check_assignment has no satisfied branch and no add_mul_def, the
3
- // budget counts only nlsat's own steps, and transcendental functions are not supported.
4
- import { NlsatUnsupportedError, SmtInvariantError } from "../../../../errors";
1
+ import { SmtCanceledError, SmtInvariantError } from "../../../../errors";
5
2
  import { L_FALSE, L_TRUE, L_UNDEF } from "../lbool";
6
3
  import { Rational, getLcm } from "../rational";
7
4
  import { Anum } from "../nlsat/algebraic";
8
5
  import { NlsatSolver } from "../nlsat/solver";
9
- import type { Polynomial } from "../nlsat/polynomial";
6
+ import { type Polynomial, PolynomialRef, PolynomialRefVector } from "../nlsat/polynomial";
10
7
  import { isIneqAtom } from "../nlsat/types";
11
8
  import {
12
9
  KIND_EQ,
@@ -86,24 +83,33 @@ const hasLargeDyadicDenominator = (value: Rational) => {
86
83
  return den >= 1n << 24n && (den & (den - 1n)) === 0n;
87
84
  };
88
85
 
86
+ const getSortedVars = (vars: readonly number[]) =>
87
+ [...vars].sort((first, second) => first - second);
88
+
89
89
  const isDyadicArtifact = (lra: LarSolver, constraint: LarConstraint) =>
90
90
  constraint.isAuxiliary &&
91
91
  (hasLargeDyadicDenominator(constraint.rhs.x) ||
92
92
  getConstraintCoeffs(lra, constraint).some((entry) => hasLargeDyadicDenominator(entry[1])));
93
93
 
94
94
  export class NraSolver {
95
- private solver = new NlsatSolver();
95
+ private solver: NlsatSolver;
96
96
  private values: Anum[] = [];
97
97
  private lp2nl = new Map<number, number>();
98
+ private literal2constraint = new Map<number, number>();
99
+ private vars2mon = new Map<string, number>();
98
100
 
99
- constructor(private core: NlaCore) {}
101
+ constructor(private core: NlaCore) {
102
+ this.solver = new NlsatSolver(core.nraLimit);
103
+ }
100
104
 
101
105
  get am() {
102
106
  return this.solver.am;
103
107
  }
104
108
 
105
- get steps() {
106
- return this.solver.steps;
109
+ private reset() {
110
+ this.solver = new NlsatSolver(this.core.nraLimit);
111
+ this.values = [];
112
+ this.lp2nl.clear();
107
113
  }
108
114
 
109
115
  private mkDefinitions(isIncluded: (lpVar: number) => boolean) {
@@ -111,53 +117,48 @@ export class NraSolver {
111
117
  const lra = core.lra;
112
118
  const solver = this.solver;
113
119
  const pm = solver.pm;
114
- const definitions: (Polynomial | null)[] = [];
120
+ const definitions = new PolynomialRefVector(pm);
115
121
  const denominators: bigint[] = [];
122
+ const p = new PolynomialRef(pm);
123
+ const constant = new PolynomialRef(pm);
124
+ const product = new PolynomialRef(pm);
116
125
  for (let lpVar = 0; lpVar < lra.columns.length; lpVar++) {
117
126
  if (!isIncluded(lpVar)) {
118
- definitions.push(null);
127
+ definitions.push(pm.zero);
119
128
  denominators.push(0n);
120
129
  continue;
121
130
  }
122
131
  const variable = solver.mkVar(lra.isInt(lpVar));
123
132
  this.lp2nl.set(lpVar, variable);
133
+ let denominator = 1n;
124
134
  if (core.emons.isMonicVar(lpVar)) {
125
- let definition: Polynomial | null = null;
126
- let denominator = 1n;
127
- for (const factor of core.emons.get(lpVar).vars) {
135
+ for (const [index, factor] of core.emons.get(lpVar).vars.entries()) {
128
136
  denominator = denominators[factor] * denominator;
129
- definition =
130
- definition === null ? definitions[factor] : pm.mul(definition, definitions[factor]!);
137
+ p.set(index === 0 ? definitions.get(factor) : pm.mul(p.get(), definitions.get(factor)));
131
138
  }
132
- definitions.push(definition ?? pm.mkVar(variable));
133
- denominators.push(denominator);
134
- continue;
135
- }
136
- if (lra.hasTerm(lpVar)) {
139
+ } else if (lra.hasTerm(lpVar)) {
137
140
  const term = [...lra.getTerm(lpVar).coeffs];
138
- const denominator = term.reduce(
139
- (result, entry) => getLcm(entry[1].div(Rational.of(denominators[entry[0]])).den, result),
140
- 1n,
141
- );
142
- let definition: Polynomial | null = null;
143
- for (const entry of term) {
141
+ for (const entry of term)
142
+ denominator = getLcm(entry[1].div(Rational.of(denominators[entry[0]])).den, denominator);
143
+ for (const [index, entry] of term.entries()) {
144
144
  const coeff = entry[1].mul(Rational.of(denominator, denominators[entry[0]]));
145
- const scaled = pm.mul(pm.mkConst(coeff.num), definitions[entry[0]]!);
146
- definition = definition === null ? scaled : pm.add(definition, scaled);
145
+ constant.set(pm.mkConst(coeff.num));
146
+ product.set(pm.mul(constant.get(), definitions.get(entry[0])));
147
+ p.set(index === 0 ? product.get() : pm.add(p.get(), product.get()));
148
+ product.reset();
149
+ constant.reset();
147
150
  }
148
- definitions.push(definition ?? pm.zero);
149
- denominators.push(denominator);
150
- continue;
151
- }
152
- definitions.push(pm.mkVar(variable));
153
- denominators.push(1n);
151
+ } else p.set(pm.mkVar(variable));
152
+ definitions.push(p.getOrNull() ?? pm.zero);
153
+ denominators.push(denominator);
154
+ p.reset();
154
155
  }
155
156
  return { definitions, denominators };
156
157
  }
157
158
 
158
159
  private addConstraint(
159
160
  constraintIndex: number,
160
- definitions: readonly (Polynomial | null)[],
161
+ definitions: PolynomialRefVector,
161
162
  denominators: readonly bigint[],
162
163
  ) {
163
164
  const lra = this.core.lra;
@@ -170,23 +171,32 @@ export class NraSolver {
170
171
  (result, entry) => getLcm(result, entry[1].div(Rational.of(denominators[entry[0]])).den),
171
172
  rhs.den,
172
173
  );
173
- let polynomial = pm.mkConst(-(rhs.num * denominator) / rhs.den);
174
+ const p = new PolynomialRef(pm);
175
+ const poly = new PolynomialRef(pm);
176
+ const constant = new PolynomialRef(pm);
177
+ p.set(pm.mkConst(-(rhs.num * denominator) / rhs.den));
174
178
  for (const entry of coeffs) {
175
179
  const coeff = entry[1].mul(Rational.of(denominator, denominators[entry[0]]));
176
- polynomial = pm.add(polynomial, pm.mul(definitions[entry[0]]!, pm.mkConst(coeff.num)));
180
+ poly.set(definitions.get(entry[0]));
181
+ constant.set(pm.mkConst(coeff.num));
182
+ poly.set(pm.mul(poly.get(), constant.get()));
183
+ constant.reset();
184
+ p.set(pm.add(p.get(), poly.get()));
185
+ poly.reset();
177
186
  }
178
187
  const kind = constraint.kind;
179
188
  const literal =
180
189
  kind === KIND_LE
181
- ? solver.mkIneqLiteral("GT", [polynomial], [false]) ^ 1
190
+ ? solver.mkIneqLiteral("GT", [p.get()], [false]) ^ 1
182
191
  : kind === KIND_GE
183
- ? solver.mkIneqLiteral("LT", [polynomial], [false]) ^ 1
192
+ ? solver.mkIneqLiteral("LT", [p.get()], [false]) ^ 1
184
193
  : solver.mkIneqLiteral(
185
194
  kind === KIND_LT ? "LT" : kind === KIND_GT ? "GT" : "EQ",
186
- [polynomial],
195
+ [p.get()],
187
196
  [false],
188
197
  );
189
198
  solver.mkExternalClause([literal], constraintIndex);
199
+ p.reset();
190
200
  return literal;
191
201
  }
192
202
 
@@ -206,13 +216,20 @@ export class NraSolver {
206
216
  if (transcendentals.piVar !== NULL_LPVAR) solver.addPi(this.getNlVar(transcendentals.piVar));
207
217
  }
208
218
 
209
- check(maxConflicts: number, budget: number) {
219
+ check(maxConflicts: number) {
220
+ try {
221
+ return this.checkCore(maxConflicts);
222
+ } catch (error) {
223
+ if (error instanceof SmtCanceledError && this.core.nraLimit.isExhausted()) return L_UNDEF;
224
+ throw error;
225
+ }
226
+ }
227
+
228
+ private checkCore(maxConflicts: number) {
210
229
  const core = this.core;
211
230
  const lra = core.lra;
212
- this.solver = new NlsatSolver(core.limit, budget);
231
+ this.reset();
213
232
  this.solver.maxConflicts = maxConflicts;
214
- this.values = [];
215
- this.lp2nl.clear();
216
233
  const cone = getConeOfInfluence(core);
217
234
  const definitions = this.mkDefinitions((lpVar) => cone.vars.has(lpVar));
218
235
  const skipped = new Set<number>();
@@ -223,15 +240,9 @@ export class NraSolver {
223
240
  }
224
241
  this.addConstraint(constraintIndex, definitions.definitions, definitions.denominators);
225
242
  }
243
+ definitions.definitions.reset();
226
244
  this.registerTranscendentals();
227
- const result = (() => {
228
- try {
229
- return this.solver.check();
230
- } catch (error) {
231
- if (error instanceof NlsatUnsupportedError) return L_UNDEF;
232
- throw error;
233
- }
234
- })();
245
+ const result = this.solver.check();
235
246
  if (result === L_TRUE) {
236
247
  this.solver.restoreOrder();
237
248
  core.setUseNraModel(true);
@@ -319,50 +330,92 @@ export class NraSolver {
319
330
  : sign === 0;
320
331
  }
321
332
 
322
- private getClause() {
333
+ private setupAssignmentSolver() {
323
334
  const core = this.core;
324
335
  const lra = core.lra;
325
- this.solver = new NlsatSolver(core.limit);
326
- this.lp2nl.clear();
336
+ this.reset();
337
+ this.literal2constraint.clear();
338
+ this.vars2mon.clear();
327
339
  const cone = getConeOfInfluence(core);
328
340
  const definitions = this.mkDefinitions(() => true);
329
- const values = lra.columns.map((_column, lpVar) => new Anum(core.val(lpVar)));
330
- this.values = values;
331
- const literalConstraints = new Map<number, number>();
341
+ for (let lpVar = 0; lpVar < lra.columns.length; lpVar++) {
342
+ this.values.push(new Anum(core.val(lpVar)));
343
+ if (core.emons.isMonicVar(lpVar))
344
+ this.vars2mon.set(getSortedVars(core.emons.get(lpVar).vars).join(","), lpVar);
345
+ }
332
346
  for (const constraintIndex of cone.constraints) {
333
347
  const literal = this.addConstraint(
334
348
  constraintIndex,
335
349
  definitions.definitions,
336
350
  definitions.denominators,
337
351
  );
338
- literalConstraints.set(literal, constraintIndex);
352
+ this.literal2constraint.set(literal, constraintIndex);
339
353
  }
354
+ definitions.definitions.reset();
340
355
  this.registerTranscendentals();
341
- const result = this.solver.checkAssignment(values);
342
- if (result.result !== L_FALSE) return null;
343
- return { clause: result.clause, literalConstraints };
344
356
  }
345
357
 
346
- checkAssignment() {
347
- const clause = (() => {
348
- try {
349
- return this.getClause();
350
- } catch (error) {
351
- if (error instanceof NlsatUnsupportedError) return null;
352
- throw error;
358
+ private processPolynomialCheckAssignment(
359
+ polynomial: Polynomial,
360
+ nl2lp: readonly number[],
361
+ term: LarTerm,
362
+ ) {
363
+ let bound = Rational.zero;
364
+ for (let index = 0; index < polynomial.size; index++) {
365
+ const monomial = polynomial.ms[index];
366
+ const coeff = Rational.of(polynomial.as[index]);
367
+ // Like Z3, this drops degrees: only an axiom's ¬best can be nonlinear, and ¬cell is valid alone.
368
+ if (monomial.size === 0) bound = bound.sub(coeff);
369
+ else if (monomial.size === 1) term.addMonomial(coeff, nl2lp[monomial.vars[0]]);
370
+ else {
371
+ const vars = getSortedVars(monomial.vars.map((variable) => nl2lp[variable]));
372
+ term.addMonomial(coeff, this.vars2mon.get(vars.join(",")) ?? this.core.addMulDef(vars));
353
373
  }
354
- })();
355
- if (clause === null) return L_UNDEF;
356
- return this.addLemma(clause.clause, clause.literalConstraints);
374
+ }
375
+ return bound;
376
+ }
377
+
378
+ private reverseLp2nl() {
379
+ const nl2lp: number[] = [];
380
+ for (const entry of this.lp2nl) nl2lp[entry[1]] = entry[0];
381
+ return nl2lp;
382
+ }
383
+
384
+ checkAssignment() {
385
+ try {
386
+ return this.checkAssignmentCore();
387
+ } catch (error) {
388
+ if (error instanceof SmtCanceledError && this.core.nraLimit.isExhausted()) return L_UNDEF;
389
+ throw error;
390
+ }
391
+ }
392
+
393
+ private checkAssignmentCore() {
394
+ const core = this.core;
395
+ const lra = core.lra;
396
+ this.setupAssignmentSolver();
397
+ const result = this.solver.checkAssignment(this.values);
398
+ if (result.result === L_TRUE) {
399
+ core.setUseNraModel(true);
400
+ lra.initModel();
401
+ for (const constraint of lra.constraints.constraints)
402
+ if (constraint.isActive && !this.isConstraintSatisfied(constraint)) return L_UNDEF;
403
+ for (const monic of core.emons.monics)
404
+ if (!this.isMonicSatisfied(monic.variable, monic.vars)) return L_UNDEF;
405
+ core.setUseNraModel(true);
406
+ }
407
+ if (result.result === L_FALSE) return this.addLemma(result.clause);
408
+ return result.result;
357
409
  }
358
410
 
359
- private addLemma(clause: number[], literalConstraints: ReadonlyMap<number, number>) {
411
+ private addLemma(clause: readonly number[]) {
360
412
  const core = this.core;
361
413
  const solver = this.solver;
362
- const pm = solver.pm;
414
+ const nl2lp = this.reverseLp2nl();
415
+ let result = L_FALSE;
363
416
  const lemma = new LemmaBuilder(core);
364
417
  for (const literal of clause) {
365
- const constraintIndex = literalConstraints.get(literal ^ 1);
418
+ const constraintIndex = this.literal2constraint.get(literal ^ 1);
366
419
  if (constraintIndex !== undefined) {
367
420
  const explanation = new Explanation();
368
421
  explanation.push(constraintIndex);
@@ -371,23 +424,12 @@ export class NraSolver {
371
424
  }
372
425
  const atom = solver.getAtom(literal);
373
426
  if (atom === null) throw new SmtInvariantError(`nlsat literal ${literal} has no atom`);
374
- if (
375
- !isIneqAtom(atom) ||
376
- atom.polynomials.length !== 1 ||
377
- pm.totalDegree(atom.polynomials[0]) > 1
378
- ) {
379
- core.lemmas.pop();
380
- return L_UNDEF;
427
+ if (!isIneqAtom(atom) || atom.polynomials.length !== 1) {
428
+ result = L_UNDEF;
429
+ break;
381
430
  }
382
- const polynomial = atom.polynomials[0];
383
431
  const term = new LarTerm();
384
- let bound = Rational.zero;
385
- for (let index = 0; index < polynomial.size; index++) {
386
- const monomial = polynomial.ms[index];
387
- const coeff = Rational.of(polynomial.as[index]);
388
- if (monomial.size === 0) bound = bound.sub(coeff);
389
- else term.addMonomial(coeff, monomial.vars[0]);
390
- }
432
+ const bound = this.processPolynomialCheckAssignment(atom.polynomials[0], nl2lp, term);
391
433
  const isNegated = (literal & 1) === 1;
392
434
  const kind =
393
435
  atom.kind === "EQ"
@@ -403,12 +445,13 @@ export class NraSolver {
403
445
  : KIND_GT;
404
446
  const ineq = mkIneq(term, kind, bound);
405
447
  if (core.ineqHolds(ineq)) {
406
- core.lemmas.pop();
407
- return L_UNDEF;
448
+ result = L_UNDEF;
449
+ break;
408
450
  }
409
451
  lemma.addIneq(ineq);
410
452
  }
411
- core.isCheckFeasible = true;
412
- return L_FALSE;
453
+ if (result === L_FALSE) core.isCheckFeasible = true;
454
+ if (result === L_UNDEF) core.lemmas.pop();
455
+ return result;
413
456
  }
414
457
  }
@@ -19,8 +19,12 @@ export const getPddInterval = (
19
19
  return result;
20
20
  }
21
21
  const varInterval = getVarInterval(poly.var(), mode);
22
- const hi = getPddInterval(poly.hi(), mode, getVarInterval);
23
- const lo = getPddInterval(poly.lo(), mode, getVarInterval);
22
+ const hiPoly = poly.hi();
23
+ const hi = getPddInterval(hiPoly, mode, getVarInterval);
24
+ hiPoly.release();
25
+ const loPoly = poly.lo();
26
+ const lo = getPddInterval(loPoly, mode, getVarInterval);
27
+ loPoly.release();
24
28
  const product = mkDepInterval();
25
29
  mul(hi, varInterval, product, mode);
26
30
  add(product, lo, result, mode);
@@ -1,4 +1,5 @@
1
1
  import { mkJoin } from "./dependency";
2
+ import type { Pdd } from "./pdd";
2
3
  import { type Equation, type PddSolver, SetUpdate, SOLVED, TO_SIMPLIFY } from "./pdd-solver";
3
4
  import { shrink } from "../array";
4
5
 
@@ -17,9 +18,12 @@ export class PddSimplifier {
17
18
  }
18
19
 
19
20
  private simplifyLinearStep(isBinary: boolean) {
20
- const linear = this.solver.toSimplify.filter((equation) =>
21
- isBinary ? equation.poly.isBinary() : equation.poly.isLinear(),
22
- );
21
+ const linear: Equation[] = [];
22
+ for (const equation of this.solver.toSimplify) {
23
+ const poly = equation.poly.copy();
24
+ if (isBinary ? poly.isBinary() : poly.isLinear()) linear.push(equation);
25
+ poly.release();
26
+ }
23
27
  if (linear.length === 0) return false;
24
28
  return this.simplifyLinear(linear);
25
29
  }
@@ -40,8 +44,10 @@ export class PddSimplifier {
40
44
  for (let index = 0, length = uses.length; index < length; index++) {
41
45
  const target = uses[index];
42
46
  if (source === target || solver.isTrivial(target)) continue;
43
- if (!source.poly.isBinary() && !target.poly.isLinear()) {
47
+ const targetPoly = target.poly.copy();
48
+ if (!source.poly.isBinary() && !targetPoly.isLinear()) {
44
49
  isAllReduced = false;
50
+ targetPoly.release();
45
51
  continue;
46
52
  }
47
53
  this.removeFromUse(target, useList, variable);
@@ -57,6 +63,7 @@ export class PddSimplifier {
57
63
  solver.pushEquation(TO_SIMPLIFY, target);
58
64
  }
59
65
  this.addToUse(target, useList);
66
+ targetPoly.release();
60
67
  }
61
68
  if (isAllReduced) linear[kept++] = source;
62
69
  }
@@ -67,7 +74,7 @@ export class PddSimplifier {
67
74
  solver.pushEquation(SOLVED, source);
68
75
  }
69
76
  }
70
- for (const equation of trivial) solver.popEquation(equation);
77
+ for (const equation of trivial) solver.delEquation(equation);
71
78
  return kept > 0 || hasConflict;
72
79
  }
73
80
 
@@ -78,32 +85,55 @@ export class PddSimplifier {
78
85
  const update = new SetUpdate(solver.toSimplify);
79
86
  for (; update.i < update.size; update.i++) {
80
87
  const first = update.get();
81
- const poly = first.poly;
82
- const second = los.get(poly.lo().root) ?? first;
83
- if (second === first) los.set(poly.lo().root, first);
84
- if (
85
- second !== first &&
86
- (poly.hi().isVal() || second.poly.hi().isVal()) &&
87
- !poly.lo().isVal()
88
- ) {
89
- first.poly = poly.sub(second.poly);
88
+ const poly = first.poly.copy();
89
+ const lo = poly.lo();
90
+ const second = los.get(lo.root) ?? first;
91
+ if (second === first) los.set(lo.root, first);
92
+ lo.release();
93
+ const secondPoly = second.poly.copy();
94
+ if (second !== first && this.isCcReducible(poly, secondPoly)) {
95
+ const difference = poly.sub(second.poly);
96
+ first.poly.assign(difference);
97
+ difference.release();
90
98
  first.dep = mkJoin(first.dep, second.dep);
91
99
  isReduced = true;
92
- if (solver.isTrivial(first) || solver.checkConflict(first)) continue;
100
+ const isTrivial = solver.isTrivial(first);
101
+ if (isTrivial) solver.retire(first);
102
+ if (isTrivial || solver.checkConflict(first)) {
103
+ secondPoly.release();
104
+ poly.release();
105
+ continue;
106
+ }
93
107
  }
94
108
  update.nextj();
109
+ secondPoly.release();
110
+ poly.release();
95
111
  }
96
112
  update.finish();
97
113
  return isReduced;
98
114
  }
99
115
 
116
+ private isCcReducible(poly: Pdd, secondPoly: Pdd) {
117
+ const hi = poly.hi();
118
+ const secondHi = hi.isVal() ? null : secondPoly.hi();
119
+ const lo = secondHi === null || secondHi.isVal() ? poly.lo() : null;
120
+ const isReducible = lo !== null && !lo.isVal();
121
+ lo?.release();
122
+ secondHi?.release();
123
+ hi.release();
124
+ return isReducible;
125
+ }
126
+
100
127
  private simplifyLeafStep() {
101
128
  const solver = this.solver;
102
129
  const useList = this.getUseList();
103
130
  for (let index = 0; index < solver.toSimplify.length; index++) {
104
131
  const source = solver.toSimplify[index];
105
- const poly = source.poly;
106
- if (poly.isVal() || !poly.hi().isVal()) continue;
132
+ const poly = source.poly.copy();
133
+ if (poly.isVal() || !this.isHiVal(poly)) {
134
+ poly.release();
135
+ continue;
136
+ }
107
137
  const leaves = useList[poly.var()].filter(
108
138
  (target) => target !== source && target.poly.varIsLeaf(poly.var()),
109
139
  );
@@ -112,16 +142,18 @@ export class PddSimplifier {
112
142
  const isLeadingTermChanged = solver.simplifyUsing(target, source);
113
143
  this.addToUse(target, useList);
114
144
  if (solver.isTrivial(target)) {
115
- solver.popEquation(target);
145
+ solver.delEquation(target);
116
146
  } else if (target.poly.isVal()) {
117
147
  solver.popEquation(target);
118
148
  solver.setConflict(target);
149
+ poly.release();
119
150
  return true;
120
151
  } else if (isLeadingTermChanged) {
121
152
  solver.popEquation(target);
122
153
  solver.pushEquation(TO_SIMPLIFY, target);
123
154
  }
124
155
  }
156
+ poly.release();
125
157
  }
126
158
  return false;
127
159
  }
@@ -133,18 +165,26 @@ export class PddSimplifier {
133
165
  let hasSolved = false;
134
166
  for (; update.i < update.size; update.i++) {
135
167
  const equation = update.get();
136
- const poly = equation.poly;
137
- if (!poly.isVal() && poly.hi().isVal() && useList[poly.var()].length === 1) {
168
+ const poly = equation.poly.copy();
169
+ if (!poly.isVal() && this.isHiVal(poly) && useList[poly.var()].length === 1) {
138
170
  solver.pushEquation(SOLVED, equation);
139
171
  hasSolved = true;
140
172
  } else {
141
173
  update.nextj();
142
174
  }
175
+ poly.release();
143
176
  }
144
177
  update.finish();
145
178
  return hasSolved;
146
179
  }
147
180
 
181
+ private isHiVal(poly: Pdd) {
182
+ const hi = poly.hi();
183
+ const isVal = hi.isVal();
184
+ hi.release();
185
+ return isVal;
186
+ }
187
+
148
188
  private addToUse(equation: Equation, useList: Equation[][]) {
149
189
  for (const variable of equation.poly.freeVars()) {
150
190
  while (useList.length <= variable) useList.push([]);