factors of 1/e in Times/Power form
(ce: ComputeEngine, e: Expression)
| 183 | |
| 184 | /** factors of 1/e in Times/Power form */ |
| 185 | function invert(ce: ComputeEngine, e: Expression): Expression[] { |
| 186 | if (e.operator === 'Multiply' && e.ops) |
| 187 | return e.ops.flatMap((o) => invert(ce, o)); |
| 188 | if (e.operator === 'Power' && e.ops) |
| 189 | return [pow(ce, e.ops[0], negate(ce, e.ops[1]))]; |
| 190 | if (isNumber(e) && e.isRational === true) return [ce.One.div(e).evaluate()]; |
| 191 | return [ce._fn('Power', [e, ce.NegativeOne])]; |
| 192 | } |
| 193 | |
| 194 | /** Power constructor: merges (B^k)^e → B^(k·e) when sound (k = ±1 or |
| 195 | * e an integer), drops exponent 1. Also emulates Mathematica's input |