* Extract the polynomial square root of a term if it is a perfect square, * returning `null` otherwise — crucially never an expression containing `Sqrt`, * `Abs`, `Root`, or a fractional power, so the difference-of-squares / * perfect-square factorings it feeds stay polynomial. * * Examples: x²
(term: Expression)
| 207 | if (crossTerm.isSame(positiveCross)) { |
| 208 | // Pattern: sqrt1² + 2*sqrt1*sqrt2 + sqrt2² = (sqrt1+sqrt2)² |
| 209 | return ce.expr(['Square', sqrt1.add(sqrt2).json]); |
| 210 | } else if (crossTerm.isSame(negativeCross)) { |
| 211 | // Pattern: sqrt1² - 2*sqrt1*sqrt2 + sqrt2² = (sqrt1-sqrt2)² |
| 212 | return ce.expr(['Square', sqrt1.sub(sqrt2).json]); |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | return null; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Replace every `Abs(u)` subexpression with its argument `u`, recursively |
| 222 | * (including inside powers and products). `|u|` and `u` have the same square, |
| 223 | * so for a polynomial factorization we want the bare polynomial representative |
no test coverage detected