MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / splitSign

Function splitSign

src/compute-engine/rubi/normal-form.ts:131–142  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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). */
131function 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

Callers 1

collectSameExponentFunction · 0.85

Calls 5

isNumberFunction · 0.90
mulFunction · 0.70
evaluateMethod · 0.65
negMethod · 0.65
sliceMethod · 0.65

Tested by

no test coverage detected