create a sequence
seq(f, i = m..n)
seq(f, i = m..n, step)
seq(f, i = 1..m, step)
seq(f, i = x)
seq(f, i in x)
seq(m .. n, step)
seq(f, m .. n, step)
(optional) numerical value
The seq command is used to construct a sequence of values. The most typical calling sequence is seq(f(i), i = 1..n) which generates the sequence f⁡1,f⁡2,...,f⁡n. More generally, seq(f(i), i = m..n) generates the sequence f⁡m,f⁡m+1,...,f⁡n.
The seq(f(i), i = x) calling sequence generates a sequence by applying f to each operand or entry of x. Here, x would most commonly be a set or list, but it could be any other data structure to which op can be applied, such as a sum or product. For tables and rtables, the entries of x are scanned rather than the operands. This form of the seq command can also iterate over the characters within a string.
The seq(m..n) and seq(m..n, step) calling sequences generate numerical sequences starting with m, followed by m + step. The last value does not exceed n. When step is omitted, the default increment is 1.
The seq(x) calling sequence is equivalent to seq(i,i in x).
The seq command is related to the for-loop construct. The precise semantics of the first two versions of the seq call can best be understood by defining them in terms of the for-loop as follows. In this description, the expression f is typically a function of i.
seq(f, i=m..n) == S := NULL;
old := i;
for i from m to n do S := S,f end do;
i := old;
S; # the result
seq(f, i=x) == S := NULL;
for i in x do S := S,f end do;
Note: As written above, the seq version is more efficient than the for-loop version because the for-loop version constructs many intermediate sequences in the process of building the final result. Specifically, here the cost of the seq version is linear in the length of the sequence, but the for-loop version is quadratic.
Note: The limits m and n must evaluate to literal constants, that is integers, fractions, floating-point numbers, or characters. As a special case, m may evaluate to infinity, or n may evaluate to -infinity. If m is greater than n, seq returns the empty sequence (NULL).
Note: The index variable i is NOT private to the seq invocation. It is recommended that you always explicitly declare the index variable to be local inside procedures.
When x is a sparse Matrix, Vector or rtable, only the nonzero entries are scanned. Otherwise, regardless of the indexing function, or storage, the entire index-space of the object is scanned.
See also the add and mul commands which work similarly to seq except that instead of constructing a sequence, they construct a sum and product respectively.
The seq(f(i), i in x) calling sequence is equivalent to seq(f(i), i = x).
There is also a procedure parameter modifier, seq, which declares that multiple arguments of a specific type within a procedure invocation will be assigned to a single parameter (as a sequence).
The seq command is thread safe as of Maple 15 provided that evaluating f is itself thread safe. Further the index variable i must not be shared between threads. Using a procedure local is advised.
For more information on thread safety, see index/threadsafe.
X ≔ seq⁡i,i=0..6
Y ≔ seq⁡i2,i=X
L ≔ seq⁡i,i=1..10,2
A ≔ Matrix⁡seq⁡i,i=1..3,seq⁡i,i=4..6
s ≔ seq⁡i,i∈A
C := proc(f,x)
local i; # declare index variable to be local
[seq( coeff(f,x,i), i=0..degree(f,x) )];
T ≔ table⁡color=red,size=XL
The seq Modifier
Download Help Document
What kind of issue would you like to report? (Optional)