Expression Sequences - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Expressions : Sequences : exprseq

Expression Sequences

 

Description

Examples

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.

  

fs  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 f1,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.

Examples

p := proc() nargs end proc:

p1,2,3

3

(1)

s1,2,3

s:=1,2,3

(2)

ps

3

(3)

p0,s,4

5

(4)

Passing expression sequences into functions can lead to unexpected results.

mapx→x+10,s

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.

mapx→x+10,s

11,12,13

(6)

See Also

$

convert

list

map

nops

op

selection

seq

set

type

whattype

 


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