Lists of Objects
Lists (of domain type DOM_LIST) are ordered collections of an arbitrary number of arbitrary MuPAD® objects, except for sequences and the null object.
In MuPAD, the mathematical construct of an n-tuple is implemented as the data type DOM_LIST. Lists consist of an arbitrary (finite) number of arbitrary objects, with the exception of expression sequences, which are split into their operands when placed into a list.
Unlike sets, lists can contain multiple copies of the same element. The order of elements in a list is preserved.
Lists can be empty.
To create a list for our first example, we use the operator $:
L := [x_.i $ i=1..10]
This list contains 10 elements:
The fifth element of the list is x5 and the list of elements from x3 through x6 can also be accessed very easily:
To change an element of the list, we use the indexed form on the left hand side of an assignment:
L := 5
Note that this assignment only changes L, not x5:
Likewise, we can change a sublist by assigning another list to it. This may change the length of the list:
L[3..6] := [1, 2]
Using a list as a function symbol creates the list obtained by using each list element as a function symbol for the operands used, i.e., [f, g](x, y) results in [f(x, y), g(x, y)].
Assuming that L is a list, the number of elements in L can be determined by calling nops(L).
Individual elements of the list are accessed in the form L, L etc. when counting from the beginning or L[-1], L[-2] etc. when counting from the end. Trying to access an element "outside" the list or L raises an error.
Continuous sub-lists can be extracted by using a range in an indexed access: L[2..4] returns the list [L, L, L]; L[2..-2] returns the list L without its first and last element.
Both forms of indexed access can also be used as the left hand side of an assignment, cf. Example 1.
Lists can be concatenated with the dot operator, as in L1 . L2 or its functional form, _concat.
Assigning a list to a list of identifiers is possible and results in a simultaneous assignment, cf. ?_assign.
The most direct way of creating a list is to place a sequence of MuPAD objects (separated by commas) between rectangular brackets, as in [1, 2, 3].