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

Function collectFactors

src/compute-engine/boxed-expression/factor.ts:782–801  ·  view source on GitHub ↗

* Walk a Multiply/Power tree and collect factors that contain the variable. * Numeric constants are ignored since they don't contribute variable-containing factors. * Identical factors (by .isSame()) are merged with accumulated multiplicities.

(expr: Expression, variable: string)

Source from the content-addressed store, hash-verified

780
781 if (!coef.isOne) {
782 lhs.div(coef);
783 rhs.div(coef);
784 }
785
786 if (!common.isSame(1)) {
787 // We have some symbolic factor in common ("x", etc...)
788 if (common.isPositive) {
789 lhs.div(common);
790 rhs.div(common);
791 } else if (common.isNegative) {
792 lhs.div(common.neg());
793 rhs.div(common.neg());
794 flip = !flip;
795 }
796 }
797
798 if (flip) [lhs, rhs] = [rhs, lhs];
799
800 return expr.engine.function(h, [lhs.asExpression(), rhs.asExpression()]);
801 }
802
803 if (isFunction(expr, 'Negate')) return factor(expr.op1).neg();
804

Callers 1

partialFractionFunction · 0.70

Calls 2

collectFactorsRawFunction · 0.85
isSameMethod · 0.65

Tested by

no test coverage detected