* * Try all needed permutations of the operands of a pattern expression, against the operands of a * match target. Assumes that *expr* and *pattern* have the same operator. * * For patterns containing sequence wildcards (__) with anchor elements (non-wildcards), * uses anchor-based matching: an
( expr: Expression, pattern: Expression, substitution: BoxedSubstitution, options: PatternMatchOptions )
| 493 | if (result !== null) return result; |
| 494 | } |
| 495 | |
| 496 | if (operator === 'Square') { |
| 497 | // Power(x, 2) -> Square(x) |
| 498 | const result = matchVariation('Power', [expr, 2]); |
| 499 | if (result !== null) return result; |
| 500 | } |
| 501 | |
| 502 | if (operator === 'Exp') { |
| 503 | // Power(E, x) -> Exp(x): a subject `e^z` (canonicalized to |
| 504 | // `Power(E, z)`) matches an `Exp` pattern as `Exp(z)` |
| 505 | if (isFunction(expr, 'Power') && isSymbol(expr.op1, 'ExponentialE')) { |
| 506 | const result = matchVariation('Exp', [expr.op2]); |
| 507 | if (result !== null) return result; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | if (operator === 'Power' && isFunction(pattern)) { |
| 512 | // Square(x) -> Power(x, 2) |
| 513 | if (pattern.op2.re === 2 && pattern.op2.im === 0) { |
| 514 | const result = matchVariation('Square', [expr]); |
| 515 | if (result !== null) return result; |
| 516 | } |
| 517 | // Exp(x) -> Power(E, x) |
| 518 | if (isSymbol(pattern.op1, 'ExponentialE')) { |
| 519 | const result = matchVariation('Exp', [expr]); |
| 520 | if (result !== null) return result; |
| 521 | } |
| 522 | // x -> Power(x, 1) |
| 523 | { |
| 524 | const result = matchVariation('Power', [expr, 1]); |
| 525 | if (result !== null) return result; |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | return null; |
| 530 | } |
| 531 | |
| 532 | /** |
| 533 | * |
| 534 | * Try all needed permutations of the operands of a pattern expression, against the operands of a |
| 535 | * match target. Assumes that *expr* and *pattern* have the same operator. |
| 536 | * |
| 537 | * For patterns containing sequence wildcards (__) with anchor elements (non-wildcards), |
| 538 | * uses anchor-based matching: anchors match against specific expression elements, |
| 539 | * and sequence wildcards capture ALL remaining elements. |
| 540 | * |
| 541 | * @param expr |
| 542 | * @param pattern |
| 543 | * @param substitution |
| 544 | * @param options |
| 545 | * @returns |
| 546 | */ |
| 547 | function matchPermutation( |
| 548 | expr: Expression, |
| 549 | pattern: Expression, |
| 550 | substitution: BoxedSubstitution, |
| 551 | options: PatternMatchOptions |
| 552 | ): BoxedSubstitution | null { |
no test coverage detected