REDUCE

7.11 MAP Operator

The MAP operator applies a uniform evaluation pattern to all members of a composite structure: a matrix, a list, or the arguments of an operator expression. The evaluation pattern can be a unary procedure, an operator, or an algebraic expression with one free variable.

It is used with the syntax:

   MAP(U:function,V:object)

Here object is a list, a matrix or an operator expression. Function can be one of the following:

  1. the name of an operator for a single argument: the operator is evaluated once with each element of object as its single argument;
  2. an algebraic expression with exactly one free variable, that is a variable preceded by the tilde symbol. The expression is evaluated for each element of object, where the element is substituted for the free variable;
  3. a replacement rule of the form var => rep where var is a variable (a kernel without a subscript) and rep is an expression that contains var. Rep is evaluated for each element of object where the element is substituted for var. Var may be optionally preceded by a tilde.

The rule form for function is needed when more than one free variable occurs.

Examples:

        map(abs,{1,-2,a,-a})  ->  {1,2,ABS(A),ABS(A)}  
        map(int(~w,x), mat((x^2,x^5),(x^4,x^5))) ->  
 
                [  3     6 ]  
                [ x     x  ]  
                [----  ----]  
                [ 3     6  ]  
                [          ]  
                [  5     6 ]  
                [ x     x  ]  
                [----  ----]  
                [ 5     6  ]  
 
        map(~w*6, x^2/3 = y^3/2 -1) -> 2*X^2=3*(Y^3-2)

You can use MAP in nested expressions. However, you cannot apply MAP to a non-composed object, e.g. an identifier or a number.