File r37/lisp/csl/html/r37_0195.html artifact 7d18e4b39b part of check-in 9992369dd3



<A NAME=FORALL>

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



<B>FORALL</B> _ _ _  _ _ _  _ _ _  _ _ _ <B>command</B><P>
<P>
 
 <P>
<P>
The <em>forall</em> or (preferably) <em>for all</em> command is used as a 
modifier for 
<A HREF=r37_0199.html>let</A> statements, indicating the universal applicability
 
of the rule, with possible qualifications. 
 <P> <H3> 
syntax: </H3>
<P>
<P>
<em>for all</em>&lt;identifier&gt;{,&lt;identifier&gt;}* <em>let</em> 
&lt;let statement&gt; 
<P>
<P>
or 
<P>
<P>
<em>for all</em>&lt;identifier&gt;{,&lt;identifier&gt;}* 
 <em>such that</em> &lt;condition&gt; <em>let</em> &lt;let statement&gt; 
<P>
<P>
<P>
&lt;identifier&gt; may be any valid REDUCE identifier, &lt;let statement&gt; 
can be an operator, a product or power, or a group or block statement. 
&lt;condition&gt; must be a logical or comparison operator returning true or 
false. 
<P>
<P>
 <P> <H3> 
examples: </H3>
<P><PRE><TT>
for all x let f(x) = sin(x**2);
 

  Declare F operator ? (Y or N) 


y 

f(a); 

       2
  SIN(A ) 


operator pos; 

for all x such that x&gt;=0 let pos(x) = sqrt(x + 1); 

pos(5); 

  SQRT(6) 


pos(-5); 

  POS(-5) 


clear pos; 

pos(5); 

  Declare POS operator ? (Y or N) 


for all a such that numberp a let x**a = 1; 

x**4; 

  1 


clear x**a; 

  *** X**A not found 


for all a  clear x**a; 

x**4; 

  1 


for all a such that numberp a clear x**a; 

x**4; 

   4
  X

</TT></PRE><P>Substitution rules defined by <em>for all</em> or <em>for
all</em>...<em>such that</em> commands that involve products or powers are 
cleared by reproducing the command, with exactly the same variable names 
used, up to but not including the equal sign, with 
<A HREF=r37_0189.html>clear</A> 
replacing <em>let</em>, as shown in the last example. Other substitutions 
involving variables or operator names can be cleared with just the name, 
like any other variable. 
<P>
<P>
The 
<A HREF=r37_0205.html>match</A> command can also be used in product and power su
bstitutions. 
The syntax of its use and clearing is exactly like <em>let</em>. A <em>match
</em> 
substitution only replaces the term if it is exactly like the pattern, for 
example <em>match x**5 = 1</em> replaces only terms of <em>x**5</em> and not 
terms of higher powers. 
<P>
<P>
It is easier to declare your potential operator before defining the 
<em>for all</em> rule, since the system will ask you to declare it an 
operator anyway. Names of declared arrays or matrices or scalar 
variables are invalid as operator names, to avoid ambiguity. Either 
<em>for all</em>...<em>let</em> statements or procedures are often used to defin
e 
operators. One difference is that procedures implement ``call by value&quot; 
meaning that assignments involving their formal parameters do not change 
the calling variables that replace them. If you use assignment statements 
on the formal parameters in a <em>for all</em>...<em>let</em> statement, the 
effects are seen in the calling variables. Be careful not to redefine a 
system operator unless you mean it: the statement <em>for all x let
sin(x)=0;</em> has exactly that effect, and the usual definition for sin(x) has 

been lost for the remainder of the REDUCE session. <P>
<P>

<P>
<P>


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