File r37/lisp/csl/html/r37_0205.html artifact f1cc35e7b4 part of check-in dc9552dc80



<A NAME=MATCH>

<TITLE>MATCH</TITLE></A>
<b><a href=r37_idx.html>INDEX</a></b><p><p>



<B>MATCH</B> _ _ _  _ _ _  _ _ _  _ _ _ <B>command</B><P>
<P>
 
 <P>
<P>
The <em>match</em> command is similar to the 
<A HREF=r37_0199.html>let</A> command, except 
that it matches only explicit powers in substitution. 
 <P> <H3> 
syntax: </H3>
<P>
<P>
<em>match</em>&lt;expr&gt; <em>=</em> &lt;expression&gt;{,&lt;expr&gt; 
 <em>=</em>&lt;expression&gt;}* 
<P>
<P>
<P>
&lt;expr&gt; is generally a term involving powers, and is limited by 
the rules for the 
<A HREF=r37_0199.html>let</A> command. &lt;expression&gt; may be 
any valid REDUCE scalar expression. 
<P>
<P>
 <P> <H3> 
examples: </H3>
<P><PRE><TT>
match c**2*a**2 = d;
(a+c)**4; 

   4       3          3    4
  A   + 4*A *C + 4*A*C  + C  + 6*D 


match a+b = c; 

a + 2*b; 

  B + C 


(a + b + c)**2; 

   2     2               2
  A   - B   + 2*B*C + 3*C  


clear a+b; 

(a + b + c)**2; 

    2                    2            2
  A   + 2*A*B + 2*A*C + B  + 2*B*C + C  


let p*r = s; 

match p*q = ss; 

(a + p*r)**2; 

   2            2
  A  + 2*A*S + S  


(a + p*q)**2; 

   2              2  2
  A   + 2*A*SS + P *Q

</TT></PRE><P>Note in the last example that <em>a + b</em> has been explicitly m
atched 
after the squaring was done, replacing each single power of <em>a</em> by 
<em>c - b</em>. This kind of substitution, although following the rules, is 
confusing and could lead to unrecognizable results. It is better to use 
<em>match</em> with explicit powers or products only. <em>match</em> should 
not be used inside procedures for the same reasons that <em>let</em> should 
not be. 
<P>
<P>
Unlike 
<A HREF=r37_0199.html>let</A> substitutions, <em>match</em> substitutions are ex
ecuted 
after all other operations are complete. The last example shows the 
difference. <em>match</em> commands can be cleared by using 
<A HREF=r37_0189.html>clear</A>, 
with exactly the expression that the original <em>match</em> took. 
<em>match</em> commands can also be done more generally with <em>for all</em> 
or 
<A HREF=r37_0195.html>forall</A>...<em>such that</em> commands. 
<P>
<P>
<P>


REDUCE Historical
REDUCE Sourceforge Project | Historical SVN Repository | GitHub Mirror | SourceHut Mirror | NotABug Mirror | Chisel Mirror | Chisel RSS ]