:

## Order of application of a mapped function (tables vs rtables)

The map function is a particularly useful Maple function. I use it frequently and thought I understood how it worked. However, I recently discovered an interesting feature of mapping over vectors, matrices, Vectors, and Matrices. That is, the order of application of the mapped function depends on the data type and may be indeterminate (for table based structures). First, assign a procedure that enumerates the application of the map function,
```enumerate := proc(v)
local cnt;
cnt := 0;
map(proc() cnt := cnt+1 end proc, v)
end proc:
```
Now, apply it to a list, vector, matrix, Vector, and Matrix:
```enumerate([0\$20]);
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]

enumerate(vector([0\$20]));
[1, 2, 3, 5, 4, 7, 6, 10, 11, 8, 9, 15, 14, 13, 12, 17, 18, 19, 20, 16]

enumerate(matrix([[0\$5]\$5]));
[16    22     3    15    21]
[                          ]
[24    19    20     4    13]
[                          ]
[25    18     6    10     2]
[                          ]
[ 8    11    17    12    23]
[                          ]
[ 9     7     5     1    14]

enumerate(Vector[row]([0\$20]));
[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

enumerate(Matrix([[0\$5]\$5]));
[25    20    15    10    5]
[                         ]
[24    19    14     9    4]
[                         ]
[23    18    13     8    3]
[                         ]
[22    17    12     7    2]
[                         ]
[21    16    11     6    1]

enumerate(Matrix([[0\$5]\$5], order=C_order));
[25    24    23    22    21]
[                          ]
[20    19    18    17    16]
[                          ]
[15    14    13    12    11]
[                          ]
[10     9     8     7     6]
[                          ]
[ 5     4     3     2     1]

```
Summary
• For a list (at least this short list), the function is applied sequentially, from the first element to the last.
• For lists and vectors the order of application is not apparent. Presumably it is by machine address.
• For Vectors and Matrices (and presumably n-dimensional rtables), the order of application is from the highest index to the lowest, following, in reverse, the internal ordering of the structure.

﻿