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

Function expand

src/compute-engine/boxed-expression/expand.ts:198–222  ·  view source on GitHub ↗
(expr: Expression)

Source from the content-addressed store, hash-verified

196 return result;
197}
198
199/** Apply the distributive law if the expression is a product of sums.
200 * For example, a(b + c) = ab + ac
201 * Expand the expression if it is a power of a sum.
202 * Expand the terms of the expression if it is a sum or negate.
203 * If the expression is a fraction, expand the numerator.
204 * If the exression is a relational operator, expand the operands.
205 * Return null if the expression cannot be expanded.
206 */
207export function expand(expr: Expression): Expression {
208 // To expand an expression, we need to use its canonical form
209 expr = expr.canonical;
210
211 if (typeof expr.operator !== 'string') return expr;
212
213 //
214 // Expand relational operators
215 //
216 if (isRelationalOperator(expr.operator)) {
217 const ops = isFunction(expr) ? expr.ops : [];
218 return expr.engine._fn(
219 expr.operator,
220 ops.map((x) => expand(x))
221 );
222 }
223
224 return (
225 expandFunction(

Callers 15

polynomials.tsFile · 0.90
argAtomsFunction · 0.90
trigExpandRecFunction · 0.90
simplify-rules.tsFile · 0.90
findUnivariateRootsFunction · 0.90
solvePolynomialSystemFunction · 0.90
extractLinearConstraintFunction · 0.90
partialFractionFunction · 0.90
extractCoefficientsFunction · 0.90
ratConstantFunction · 0.90

Calls 5

isRelationalOperatorFunction · 0.90
isFunctionFunction · 0.90
expandFunctionFunction · 0.85
_fnMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected