WHERE _ _ _ _ _ _ _ _ _ _ _ _ operator
The where operator provides an infix notation for one-time substitutions for kernels in expressions.
<expression> where <kernel> =<expression> {,<kernel> =<expression>}*
<expression> can be any REDUCE scalar expression, <kernel> must be a kernel. Alternatively a rule or a rule list can be a member of the right-hand part of a where expression.
x**2 + 17*x*y + 4*y**2 where x=1,y=2; 51 for i := 1:5 collect x**i*q where q= for j := 1:i product j; 2 3 4 5 {X,2*X ,6*X ,24*X ,120*X } x**2 + y + z where z=y**3,y=3; 2 3 X + Y + 3
Substitution inside a where expression has no effect upon the values of the kernels outside the expression. The where operator has the lowest precedence of all the infix operators, which are lower than prefix operators, so that the substitutions apply to the entire expression preceding the where operator. However, where is applied before command keywords such as then, repeat, or do.
A rule or a rule set in the right-hand part of the where expression act as if the rules were activated by let immediately before the evaluation of the expression and deactivated by clearrules immediately afterwards.
wheregives you a natural notation for auxiliary variables in expressions. As the second example shows, the substitute expression can be a command to be evaluated. The substitute assignments are made in parallel, rather than sequentially, as the last example shows. The expression resulting from the first round of substitutions is not reexamined to see if any further such substitutions can be made. where can also be used to define auxiliary variables in procedure definitions.