Expression sequences, (or simply sequences), are created using the comma operator (, ). For example s := 1, 2, 3 assigns s the sequence 1, 2, 3. In Maple, sequences form the basis of many data types. In particular, they appear in function calls, lists, sets, and subscripts.
f⁡s applies the function f to the sequence 1, 2, 3
s creates the list containing the elements 1, 2, 3
s creates the set containing the elements 1, 2, 3
as is the 1, 2, 3 subscript
These are equivalent to f⁡1,2,3, 1,2,3, 1,2,3, and a1,2,3, respectively.
When sequences are concatenated with a comma, the result is a single, unnested sequence. Thus t := s, s assigns t the sequence 1, 2, 3, 1, 2, 3. This also means that an expression sequence cannot be passed into a function as a single argument. f(0,s,4) is equivalent to f(0,1,2,3,4). One can create a list or set from the expression sequence to pass it into a function.
The empty sequence is available as the value of the global variable NULL. It also appears implicitly in the empty list , the empty set ∅, a function call f() with no parameters, and an indexed name a with no subscripts.
Two key tools for constructing sequences are the seq function and the repetition operator $ . For example, the call seq(f(i), i=1..3) will generate the sequence f(1), f(2), f(3). The call x$3 will generate the sequence x, x, x.
Sequences can also be constructed using the op function. The op function when applied to any Maple expression (except a sequence itself) returns a sequence of the operands of that expression. For example, op([x, y, z]) and op(x+y+z) both return the sequence x, y, z.
The op and nops functions cannot be applied to a sequence because the elements of the sequence are taken to be individual arguments to the function. However, the ith operand of a sequence s may be accessed using the selection operation s[i]. The length of a sequence may be determined by doing nops([s]), that is, by determining the length of the list containing the expression sequence.
There is no expression sequence type in Maple. However, the whattype function returns exprseq for objects that are expression sequences.
p := proc() nargs end proc:
s ≔ 1,2,3
Passing expression sequences into functions can lead to unexpected results.
In this case the expression sequence, s, is flattened into the expression sequence of arguments to map. Therefore map sees 4 arguments, the function to be mapped, the argument to map over and two extra arguments that are passed to the mapped function.
Making a list from the expression sequence will work as expected.
Download Help Document
What kind of issue would you like to report? (Optional)