The pattern 'symbpat' and replacement 'symbrepl' can be normal expressions; for example, you can replace .5 with 'SIN(π/6)'. You can also use a “wildcard” in the pattern (to match any
subexpression) and in the replacement (to represent that expression). A wildcard is a name that begins with &, such as the name '&A', used in replacing 'SIN(&A+&B)' with 'SIN(&A)*COS(&B)+COS(&A)*SIN(&B)'. Multiple occurrences of a particular wildcard in a pattern must match identical subexpressions.
↓MATCH works from top down; that is, it checks the entire expression first. This approach works well for expansion. An expression expanded during one execution of ↓MATCH will contain additional subexpressions, and those subexpressions can be expanded by another execution of ↓MATCH. Several expressions can be expanded by one execution of ↓MATCH provided none is a subexpression of any other.
Access: …µ↓MATCH
Input/Output:
|
| Level 2/Argument 1 | Level 1/Argument 2 |
|
| Level 2/Item 1 | Level 1/Item | |||||||
|
|
|
|
| ||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 | ' | pat |
|
| repl | ' } |
| → | 2 | ' | 0/1 | |
|
| 'symb | { 'symb ' 'symb |
|
| → | 'symb | |||||||
|
| 1 | ' | pat | repl | ' 'symb | cond | ' } | 2 | ' | 0/1 | |||
|
| 'symb | { 'symb ' 'symb |
|
|
| 'symb | |||||||
| .5 { |
| ||||||||||||
Example 1: | .5 'SIN(π/6)' } ↓MATCH returns 'SIN(π/6)' to level 2 and 1 to level | |||||||||||||
| 1. |
|
|
|
|
|
|
|
|
|
|
|
|
|
Example 2: 'SIN(U+V)' { 'SIN(&A+&B)'
'SIN(&A)*COS(&B)+COS(&A)*SIN(&B)' } ↓MATCH returns 'SIN(U)*COS(V)+COS(U)*SIN(V)' to level 2 and 1 to level 1.
Example 3: This sequence: 'SIN(5*Z)' { 'SIN(&A+&B)'
See also: | ↑MATCH |
Type: Command
Description:
↑MATCH rewrites expressions or subexpressions that match a specified pattern 'symbpat'. An optional condition, 'symbcond', can further restrict whether a rewrite occurs. A test result is also returned to indicate if command execution produced a rewrite; 1 if it did, 0 if it did not.
The pattern 'symbpat' and replacement 'symbrepl' can be normal expressions; for example, you can replace 'SIN(π/6)' with '1/2'. You can also use a “wildcard” in the pattern (to match any
subexpression) and in the replacement (to represent that expression). A wildcard is a name that begins with &, such as the name '&A', used in replacing 'SIN(&A+π)' with
↑MATCH works from bottom up; that is, it checks the lowest level (most deeply nested) subexpressions first. This approach works well for simplification. A subexpression simplified during one execution of ↑MATCH will be a simpler argument of its parent expression, so the parent expression can be simplified by another execution of ↑MATCH.
Several subexpressions can be simplified by one execution of ↑MATCH provided none is a subexpression of any other.
Access: …µ↑MATCH