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

Function matchRecursive

src/compute-engine/boxed-expression/match.ts:342–360  ·  view source on GitHub ↗

Assuming expr is a function, attempts to match the patterns * to the arguments of the function.

(
  expr: Expression,
  pattern: Expression,
  substitution: BoxedSubstitution,
  options: MatchOptions
)

Source from the content-addressed store, hash-verified

340 if (
341 operator === 'Divide' &&
342 isNumber(expr) &&
343 !expr.denominator.isSame(1)
344 ) {
345 // Create a synthetic Divide expression to match against
346 const divideExpr = ce.function(
347 'Divide',
348 [expr.numerator, expr.denominator],
349 { form: 'structural' }
350 );
351 return matchArguments(divideExpr, pattern.ops, substitution, options);
352 }
353
354 // Special case: Match Multiply(Rational(1, n), x) against a Divide pattern
355 // This handles cases like x/2 which is canonicalized as x * (1/2)
356 if (
357 operator === 'Divide' &&
358 isFunction(expr) &&
359 expr.operator === 'Multiply' &&
360 headAdmits(operator, expr)
361 ) {
362 const ops = expr.ops;
363 for (let i = 0; i < ops.length; i++) {

Callers 1

matchOnceFunction · 0.85

Calls 3

isFunctionFunction · 0.90
matchOnceFunction · 0.85
assertMethod · 0.80

Tested by

no test coverage detected