Split an exponent into (|exponent|, sign), canonicalizing through `mul` so * `−1·x` keys identically to `x` (the raw `negate` leaves a `1·x` artifact).
(ce: ComputeEngine, exp: Expression)
| 129 | /** Split an exponent into (|exponent|, sign), canonicalizing through `mul` so |
| 130 | * `−1·x` keys identically to `x` (the raw `negate` leaves a `1·x` artifact). */ |
| 131 | function splitSign(ce: ComputeEngine, exp: Expression): [Expression, 1 | -1] { |
| 132 | if (isNumber(exp)) |
| 133 | return exp.isNegative === true ? [exp.neg().evaluate(), -1] : [exp, 1]; |
| 134 | if ( |
| 135 | exp.operator === 'Multiply' && |
| 136 | exp.ops && |
| 137 | isNumber(exp.ops[0]) && |
| 138 | exp.ops[0].isNegative === true |
| 139 | ) |
| 140 | return [mul(ce, [exp.ops[0].neg().evaluate(), ...exp.ops.slice(1)]), -1]; |
| 141 | return [exp, 1]; |
| 142 | } |
| 143 | |
| 144 | /** fuse factors sharing a base: d·d → d², u^(1/2)·u^(1/2) → u. Bases are |
| 145 | * compared structurally; rule skeletons never carry duplicate-base |