Previous Up Next

6.40.28  Applying a function of one variable to the elements of a list: map apply

The apply and map commands can both apply a function to a list of elements, but take arguments in different orders (that is required for compatibility reasons). The apply command also works on matrices (see Section 6.44.6) and the map command also works on polynomials in internal sparse format (see Section 6.27.3).

Note that apply returns a list ([]) even if the second argument is not a list.


Example.
Input:

apply(x->sqrt(x),[16,9,4,1])

Output:


4,3,2,1


Example.
Input:

map([16,9,4,1],x->sqrt(x))

Output:


4,3,2,1


Examples.


Warning!!!
First purge x if x is not symbolic.
Note that if L1, L2 and L3 are lists, then sizes([L1,L2,L3]) is equivalent to map(size,[L1,L2,L3]).


Previous Up Next