FORALL INDEX

FORALL _ _ _ _ _ _ _ _ _ _ _ _ command

The forall or (preferably) for all command is used as a modifier for let statements, indicating the universal applicability of the rule, with possible qualifications.

syntax:

for all<identifier>{,<identifier>}* let <let statement>

or

for all<identifier>{,<identifier>}* such that <condition> let <let statement>

<identifier> may be any valid REDUCE identifier, <let statement> can be an operator, a product or power, or a group or block statement. <condition> must be a logical or comparison operator returning true or false.

examples:


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>=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

Substitution rules defined by for all or for all...such that 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 clear replacing let, as shown in the last example. Other substitutions involving variables or operator names can be cleared with just the name, like any other variable.

The match command can also be used in product and power su bstitutions. The syntax of its use and clearing is exactly like let. A match substitution only replaces the term if it is exactly like the pattern, for example match x**5 = 1 replaces only terms of x**5 and not terms of higher powers.

It is easier to declare your potential operator before defining the for all 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 for all...let statements or procedures are often used to defin e operators. One difference is that procedures implement ``call by value" 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 for all...let statement, the effects are seen in the calling variables. Be careful not to redefine a system operator unless you mean it: the statement for all x let sin(x)=0; has exactly that effect, and the usual definition for sin(x) has been lost for the remainder of the REDUCE session.