(e: Expression)
| 423 | q[shift] = q[shift].add(lead); |
| 424 | for (let i = 0; i < lc.length; i++) |
| 425 | pc[shift + i] = pc[shift + i].sub(lead.mul(lc[i])); |
| 426 | pc = trimZeros(pc.slice(0, pc.length - 1)); |
| 427 | } |
| 428 | const X = ce.symbol(x); |
| 429 | const toExpr = (cs: Expression[]): Expression => { |
| 430 | const terms = cs |
| 431 | .map((c, i) => (zeroQ(c) ? null : safeSimplify(c).mul(X.pow(i)))) |
| 432 | .filter((t): t is Expression => t !== null); |
| 433 | if (terms.length === 0) return ce.Zero; |
| 434 | if (terms.length === 1) return terms[0]; |
| 435 | return ce.function('Add', terms); |
| 436 | }; |
| 437 | return [toExpr(q), toExpr(pc)]; |
| 438 | } |
| 439 | |
| 440 | // simplify() now respects the engine deadline (ce.timeLimit), so runaway |
| 441 | // cases (radical-tower polynomial GCD) get interrupted instead of running |
| 442 | // for minutes. The cap is kept only as a fast-path skip for clearly |
| 443 | // oversized expressions (raised from the old correctness-trading 120). |
| 444 | const SIMPLIFY_LEAF_CAP = 500; |
| 445 | |
| 446 | // module-level cache hooks, installed per top-level int() call by the |
| 447 | // driver (see installCaches); fall back to uncached when absent |
no test coverage detected