structural monomial split u = coef·x^exp (coef and exp x-free; exp may * be symbolic). No expansion — mirrors Mathematica's literal matching of * a_.*x_^n_. terms over CE canonical form (Divide/Negate/Sqrt present).
( u: Expression, x: string )
| 1519 | }; |
| 1520 | let i = -1; |
| 1521 | if (rest.some(sumBaseQ)) |
| 1522 | i = pickBy( |
| 1523 | (f) => sumBaseQ(f) && allNegTermQ(f), |
| 1524 | (f) => negSumBaseQ(f), |
| 1525 | (f) => sumBaseQ(f) && someNegTermQ(f), |
| 1526 | sumBaseQ |
| 1527 | ); |
| 1528 | if (i < 0) i = pickBy(atomBaseQ); |
| 1529 | if (i < 0) i = 0; |
| 1530 | return rtAux(rest[i].neg().evaluate(), n).mul( |
| 1531 | rtAux( |
| 1532 | productOf( |
| 1533 | ce, |
| 1534 | rest.filter((_, j) => j !== i) |
| 1535 | ), |
| 1536 | n |
| 1537 | ) |
| 1538 | ); |
| 1539 | } |
| 1540 | // -1 · single non-power factor |
| 1541 | if (n % 2 === 1) return rtAux(productOf(ce, rest), n).neg(); |
| 1542 | return nthRoot(u, n); |
| 1543 | } |
| 1544 | // c < 0, c ≠ -1: RtAux[-c]·RtAux[-rest] |
| 1545 | return rtAux(c.neg().evaluate(), n).mul( |
| 1546 | rtAux(productOf(ce, rest).neg().evaluate(), n) |
| 1547 | ); |
| 1548 | } |
| 1549 | // 3./4. double sign-flip pairings across two sum-base factors |
| 1550 | const iAll = fs.findIndex((f) => sumBaseQ(f) && allNegTermQ(f)); |
| 1551 | if (iAll >= 0 && fs.some((f, i) => i !== iAll && sumBaseQ(f))) { |
| 1552 | const rest = productOf( |
| 1553 | ce, |
| 1554 | fs.filter((_, i) => i !== iAll) |
| 1555 | ); |
| 1556 | return rtAux(fs[iAll].neg().evaluate(), n).mul( |
| 1557 | rtAux(rest.neg().evaluate(), n) |
| 1558 | ); |
| 1559 | } |
| 1560 | const iNegSum = fs.findIndex(negSumBaseQ); |
| 1561 | if (iNegSum >= 0 && fs.some((f, i) => i !== iNegSum && negSumBaseQ(f))) { |
| 1562 | const rest = productOf( |
| 1563 | ce, |
| 1564 | fs.filter((_, i) => i !== iNegSum) |
| 1565 | ); |
| 1566 | return rtAux(fs[iNegSum].neg().evaluate(), n).mul( |
| 1567 | rtAux(rest.neg().evaluate(), n) |
| 1568 | ); |
| 1569 | } |
| 1570 | // 5. distribute the root over every factor |
| 1571 | return productOf( |
| 1572 | ce, |
| 1573 | fs.map((f) => rtAux(f, n)) |
| 1574 | ); |
| 1575 | } |
| 1576 | |
| 1577 | // non-product |
| 1578 | const r = realNum(u); |