@paolam I'm guessing that you have an older version of Maple that doesn't allow **local** in arrow procedures and doesn't allow embedded **for **loops.

Usually the best way to create a matrix is to provide a procedure which initializes its entries. The arguments of the procedure are the indices (represented by the parameters **i** and **j** in this case). (This method can be generalized to arrays with any number of dimensions.)

**M:= Matrix(**

(81,24), **#need explicit dimensions for this method; parentheses are optional**

** proc(i,j) local k;**

[seq](indice(C[i][1][k], rorder(orders[j], Sets[k])), k= 1..4)

end proc

);

Procedures can be coded as **proc(i,j)** ... **end proc** or simply **(i,j)->**** **...; however, allowing **local** in these *arrow expressions*** **is a relatively recent innovation. (Arrow expressions are called *lambda expressions* in the functional programming community.)

The second method constructs your matrix from a list of lists of lists. The dimensions of the matrix are determined by the sizes of the outer two levels of lists, and specifying them is optional. This method is less efficient because it constructs lists that are ultimately not needed, namely the out two levels. For older Maple, it can be replaced by

**M:= Matrix(**

(81,24), #optional line

[seq](

[seq]([seq](indice(C[i][1][k], rorder(orders[j], Sets[k])), k= 1..4), j= 1..24),

i= 1..81

)

);

The **seq** command is old command (still perfectly fine though) that's equivalent to a simple *embedded* **for **loop, which is a recent innovation. Embedded **for** loops are extremely flexible and just as efficient as **seq**, often more efficient.

You initially mentioned "table" as well as "matrix". Tables are a different container structure, and the difference between a table and a matrix is probably too subtle to be worth explaining at this point. In the code in your Question, **M **was an unassigned variable when you first used

**M[i][j]:= **...

This caused **M **to be a **table** of **table**s; and using instead **M[i,j]:= **... would make it a one-level table.

Finally, it's *extremely* inefficient to construct a list in a loop like this:

**L:= [op(L), **...**]**

Every newbie (including myself many years ago) seems to do this though; the idea is quite natural. The inefficiency is due to an idiosyncracy of Maple's lists known as *immutability *which makes then very efficient when you don't try to modify them after their initial construction. Sets and sequences are also immutable containers subject to the same inefficiency trap if you try to modify them after their initial construction. Matrices, arrays, and tables are *mutable*, so there's no problem with changing their entries.