Reference Guide
3-142 Full Command and Function Reference
The pattern 'symb
pat
' and replacement 'symb
repl
' 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
'symb
1
'
{ 'symb
pat
' 'symb
repl
' }
→
'symb
2
'
0/1
'symb
1
'
{ 'symb
pat
' 'symb
repl
' 'symb
cond
' }
→
'symb
2
'
0/1
Example 1:
.5 { .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)'
'Σ(K=0,&A,COMB(&A,K)*SIN(K*π)*COS(&B^(&A-K)*SIN(&B)^K)'
'ABS(IP(&A))==&A' } ↓MATCH
returns
'Σ(K=0,5,COMB(5,K)*SIN(K*π)*COS(Z^(5-K)*SIN(Z)^K)'
to level 2
and
1
to level 1.
See also: ↑MATCH
↑MATCH
Type: Command
Description: Bottom-Up Match and Replace Command: Rewrites an expression.
↑MATCH rewrites expressions or subexpressions that match a specified pattern 'symb
pat
'. An
optional condition, 'symb
cond
', 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 'symb
pat
' and replacement 'symb
repl
' 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 '–SIN(&A)'. Multiple
occurrences of a particular wildcard in a pattern must match identical subexpressions.
↑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