apply a procedure to each operand of an expression
apply a procedure with a specified first argument to each operand of an expression
map(fcn, expr, arg1, ..., argN)
map2(fcn, arg1, expr, arg2, ..., argN)
map[n](fcn, arg1, ..., argn-1, expr, argn, ..., argN)
map[evalhf](fcn, expr, ...)
map[inplace](fcn, expr, ...)
expression of type appliable; typically, a procedure or name
(optional) further arguments to fcn
The map commands apply fcn to the operands or elements of expr.
map(fcn, expr, arg1, ..., argN) executes fcn(elem, arg1, ..., argN) for each operand or element of expr. Similarly, map2(fcn, arg1, expr, arg2, ..., argN) executes fcn(arg1, elem, arg2, ..., argN) for each operand or element of expr, and map(fcn, arg1, arg2, expr, arg3, ..., argN) executes fcn(arg1, arg2, elem, arg3, ..., argN) for each operand or element of expr.
The result of a call to map is a copy of expr with the ith operand of expr replaced by the result of applying fcn to the ith operand. This is done for all the operands of expr. For expressions of type atomic, map(fcn, expr) is identical to fcn(expr). For a table or rtable (such as Array, Matrix, or Vector), fcn is applied to each element instead of each operand.
If fcn takes more than one argument, they are to be specified as additional arguments, arg2, arg3, ..., argn, which are simply passed through as the second, third, ..., nth arguments to fcn.
If expr has no elements (or operands) then it is returned as is. For example, map(f, [ ]) returns the empty list [ ].
Some options can be specified in square brackets as an index to the map command. These options can be used by themselves or in combination with other options.
The evalhf option only applies when mapping over an rtable. Prior to applying the map function, a copy of the original rtable is made with datatype=float storage. Each application of fcn is evaluated using evalhf, which works only in the hardware float domain.
The inplace option only applies when mapping over a rectangular storage rtable with no indexing function. When inplace is specified, the input rtable is updated in-place. The result is the updated original expr rtable, rather than a copy.
Since strings are atomic expressions in Maple, you cannot map a procedure over a string by using map. However, the StringTools package provides a Map export that delivers this functionality.
The map and map2 commands are thread safe, provided that evaluating the expression fcn is thread safe
For more information on thread safety, see index/threadsafe.
map(proc(x,y) x^2+y end proc, [1,2,3,4], 2);
The following example counts the number of finite Abelian groups of the order n by using the map and map2 commands.
The map command can be used with type atomic.
if expr::atomic then
elif expr::`+` then
map(procname,expr); end if;
Download Help Document
What kind of issue would you like to report? (Optional)