 Expression Sequences - Maple Programming Help

Expression Sequences

Description

 • 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\left(s\right)$  applies the function $f$ to the sequence 1, 2, 3
 $\left[s\right]$  creates the list containing the elements 1, 2, 3
 $\left\{s\right\}$  creates the set containing the elements 1, 2, 3
 ${a}_{s}$  is the  1, 2, 3  subscript
 These are equivalent to $f\left(1,2,3\right)$, $\left[1,2,3\right]$, $\left\{1,2,3\right\}$, and ${a}_{1,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 $\left[\right]$, the empty set $\varnothing$, a function call f() with no parameters, and an indexed name $a\left[\right]$ 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.

Examples

 > p := proc() nargs end proc:
 > $p\left(1,2,3\right)$
 ${3}$ (1)
 > $s≔1,2,3$
 ${s}{≔}{1}{,}{2}{,}{3}$ (2)
 > $p\left(s\right)$
 ${3}$ (3)
 > $p\left(0,s,4\right)$
 ${5}$ (4)

Passing expression sequences into functions can lead to unexpected results.

 > $\mathrm{map}\left(x↦x+10,s\right)$
 ${11}$ (5)

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.

 > $\mathrm{map}\left(x↦x+10,\left[s\right]\right)$
 $\left[{11}{,}{12}{,}{13}\right]$ (6)