seq - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Flow Control : Iteration or Looping : seq

This page is an exact match for your search term. Click here to search for all help pages containing the term, "seq"

seq

create a sequence

 

Calling Sequence

Parameters

Description

Thread Safety

Examples

Calling 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(x)

Parameters

f

-

any expression

i

-

name

m, n

-

numerical values

x

-

expression

step

-

(optional) numerical value

Description

• 

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 f1,f2,...,fn. More generally, seq(f(i), i = m..n) generates the sequence fm,fm+1,...,fn.

• 

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;

                  old := i;

                  for i in x do S := S,f end do;

                  i := old;

                  S; # the result

  

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).

Thread Safety

• 

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.

Examples

seqi2,i=1..5

1,4,9,16,25

(1)

seqsinπi6,i=0..6

0,12,123,1,123,12,0

(2)

seqxi,i=1..5

x1,x2,x3,x4,x5

(3)

Xseqi,i=0..6

X:=0,1,2,3,4,5,6

(4)

seqi2mod7,i=X

0,1,2,4

(5)

Yseqi2,i=X

Y:=0,1,4,9,16,25,36

(6)

seqXi,Yi,i=1..nopsX

0,0,1,1,2,4,3,9,4,16,5,25,6,36

(7)

seqi,i=Hello

H,e,l,l,o

(8)

seqi,i=a..f

a,b,c,d,e,f

(9)

seqi,i=0..∞

(10)

Lseqi,i=1..10,2

L:=1,3,5,7,9

(11)

seqi2,i∈L

12,32,52,72,92

(12)

AMatrixseqi,i=1..3,seqi,i=4..6

A:=123456

(13)

sseqi,i∈A

s:=1,4,2,5,3,6

(14)

seq0..100,10

0,10,20,30,40,50,60,70,80,90,100

(15)

C := proc(f,x)
local i; # declare index variable to be local
   [seq( coeff(f,x,i), i=0..degree(f,x) )];
end proc:

C2x4+x3,x

4,2,0,1

(16)

Ttablecolor=red,size=XL

T:=tablecolor=red,size=XL

(17)

seqe,e=evalT

red,XL

(18)

See Also

$

add

for

map

mul

op

sequence

The seq Modifier

Threads[Seq]

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam