Expression sequences

We have seen how we can define a single expression. We will now see that Maple allows finite sequences of expressions. A sequence of two or more expressions separated by commas is stored as an expression sequence. There is also an expression sequence of zero objects. An expression sequence with zero items is described as a null sequence.

An expression sequence can be used to generate lists or sets, or they can be passed as arguments to a function or, later, indices to matrices.

[> 1, 2, 3, 4, 5, 6;

$1, 2, 3, 4, 5, 6$

Expression sequences can be assigned, and you can add parentheses around them:

[> bases := (1, t, t^2, t^3, t^4);

$bases := 1, t, t^2, t^3, t^4$

Alternatively, if you have an expression sequence of $n$ items, you can assign each of those $n$ items to $n$ different symbols:

[> (a, b, c, d, e) := 2, 3, 5, 7, 11;

$a, b, c, d, e := 2, 3, 5, 7, 11$

[> a*b*c*d*e;

$2310$

Note that an expression sequence must have either zero or two or more entries separated by commas. An expression sequence of just one entry becomes that entry. Also, expression sequences cannot be nested:

[> a := 1, 2, 3:
[> b := 5, 6, 7, 8:
[> a, b; # An expression sequence of seven items

$1, 2, 3, 5, 6, 7, 8$

Expression sequences are useful if you want to build up arguments to a multivariate function. They are also used in the construction of lists and sets.

To create an expression sequence of zero entries (a null sequence), you can use one of the following:

[> entries := ();

$entries := $

[> entries := NULL;

$entries := $

Addition or difference of expression sequences

You can add or subtract two expression sequences with the same number of entries. This is not necessarily that useful, but it is possible:

[> e1 := 1, 2, 3, w, x, y, z:
[> e2 := a, b, c, d, 7, 8, 9:
[> e1 + e2;

$a + 1, b + 2, c + 3, d + w, x + 7, y + 8, z + 9$

$

It is possible to create an expression sequence that repeats an item zero or more times by using the satement:

[> x$5;

$x, x, x, x, x$

Note that x$0 is the same as the null sequence.

[> x$5;

$x, x, x, x, x$

seq(...)

The seq(...) function can also construct expression sequences:

[> seq( 1..5 );

$1, 2, 3, 4, 5$

A step size that is either an integer, rational number or floating-point number can also be given:

[> seq( 2..6, 5/7 );

$2, \frac{19}{7}, \frac{24}{7}, \frac{29}{7}, \frac{34}{7}, \frac{39}{7}$

You will note that $\frac{39}{7} \leq 6$ but $\frac{39}{7} + \frac{5}{7} = \frac{44}{7} > 6$.

[> seq( 3..4, 0.1 );

$3, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0$

The step size can also be negative:

[> seq( 10..0, -1 );

$10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0$

If an expression is given first, that expression is repeated however often the sequence would have been:

[> seq( x + y^2, 3..4, 0.1 ); # 11 copies

$x + y^2, x + y^2, x + y^2, x + y^2, x + y^2, x + y^2, x + y^2, x + y^2, x + y^2, x + y^2, x + y^2$

You also create an expression that depends on the value in the range by using the following formulation:

[> seq( 3*k^2, k = 1..10 );

$3, 12, 27, 48, 75, 108, 147, 192, 243, 300$

[> seq( sin(k*Pi/12.0), k = 0..6 );

$0., 0.2588190451, 0.5000000000, 0.7071067812, 0.8660254037, 0.9659258263, 1.$

[> seq( sin(k*Pi), k = 0..1/2, 1/12 );

$0, \sin\left( \frac{\pi}{12} \right), \frac{1}{2}, \frac{\sqrt{2}}{2}, \frac{\sqrt{3}}{2}, \sin\left( \frac{5\pi}{12} \right), 1$

[> seq( t^k, k = 0..5 );

$1, t, t^2, t^3, t^4, t^5$