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

Function leafCount

src/compute-engine/cost-function.ts:259–264  ·  view source on GitHub ↗
(expr: Expression)

Source from the content-addressed store, hash-verified

257 // Use a base cost similar to Sqrt
258 nameCost = 5;
259 } else if (['Multiply'].includes(name)) {
260 // We want 2x to be less expensive than x + x, so if the first operand
261 // is a small number coefficient, treat it as cheaper
262 const fnExprMul = isFunction(expr) ? expr : undefined;
263 const ops = fnExprMul?.ops ?? [];
264 if (ops.length === 2 && isNumber(ops[0])) {
265 // A numeral times something is a "coefficient" shape and is priced
266 // near an `Add`, so that `2x` beats `x + x`.
267 //

Callers

nothing calls this directly

Calls 4

isSymbolFunction · 0.90
isNumberFunction · 0.90
isFunctionFunction · 0.90
numericCostFunctionFunction · 0.85

Tested by

no test coverage detected