### 6.1.2 Making a sequence or a list

The seq command or $ operator can create a sequence or a list.

- To create a sequence, seq takes three mandatory arguments and one optional argument:
  - expr, an expression depending on a parameter.
  - k, the parameter.
  - a..b, a range of values. The range can be combined with the parameter into one argument of k=a..b.
  - Optionally p, a step size (by default 1 or -1, depending on whether b>a or b<a). This is only allowed if the previous two arguments are combined into one, k=a..b
  This is Maple-like syntax.
- seq(expr,k,a..b) or seq(expr,k=a..b ⟨,p⟩) returns the sequence formed by the values of expr, as k changes from a to b in steps of p.

Alternatively, a sequence can be created with the infixed $ operator. Namely, expr$(k=a..b) returns the sequence formed by the values of expr as k changes from a to b. As a special case, expr$n creates a sequence consisting of n copies of expr.

There are two ways to create a list with seq.

- seq can take four mandatory arguments and one optional argument:
  - expr, an expression depending on a parameter.
  - k, the parameter.
  - a, the beginning value of the parameter.
  - b, the ending value of the parameter.
  - Optionally p, a step size (by default 1 or -1, depending on whether b>a or b<a).
  This is TI-like syntax.
- seq(expr,k,a,b ⟨,p⟩) returns the list consisting of the values of expr, as k changes from a to b in steps of p.
- As a special case, seq(expr,n) creates a list consisting of n copies of expr.
- Alternatively, seq can take two arguments:
  - expr, an expression.
  - n, a positive integer.
- seq(expr,n) returns the list consisting of n copies of expr.

##### Remarks.

In Xcas mode, the precedence of $ is not the same as it is, for example, in Maple. In case of doubt, put the arguments of $ in parenthesis. For example, the following commands are equivalent:

seq(j^2,j=-1..3)

or

(j^2)$(j=-1..3)

1,0,1,4,9 |  |  |  |  |  |  |  |  |  |

With Maple syntax, j,a..b,p is not valid. To specify a step p for the variation of j from a to b, use j=a..b,p or use the TI syntax j,a,b,p and get the sequence from the list with op(…).

#### Examples

To create a sequence:

seq(j^3,j,1..4)

or:

seq(j^3,j=1..4)

or:

(j^3)$(j=1..4)

1,8,27,64 |  |  |  |  |  |  |  |  |  |

To create a list:

seq(j^3,j,1,4)

| ⎡ ⎣ | 1,8,27,64 | ⎤ ⎦

To create a sequence:

seq(j^3,j=-1..4,2)

−1,1,27 |  |  |  |  |  |  |  |  |  |

To create a list:

seq(j^3,j,-1,4,2)

| ⎡ ⎣ | −1,1,27 | ⎤ ⎦

seq(j^3,j,0,5,2)

| ⎡ ⎣ | 0,8,64 | ⎤ ⎦

seq(j^3,j,5,0,-2)

or:

seq(j^3,j,5,0,2)

| ⎡ ⎣ | 125,27,1 | ⎤ ⎦

seq(j^3,j,1,3,0.5)

| ⎡ ⎣ | 1,3.375,8.0,15.625,27.0 | ⎤ ⎦

seq(j^3,j,1,3,1/2)

⎡
⎢
⎢
⎣

1,

27
8

,8,

125
8

,27

⎤
⎥
⎥
⎦

To create a list with several copies of the same element:

seq(t,4)

| ⎡ ⎣ | t,t,t,t | ⎤ ⎦

To create a sequence with several copies of the same element:

seq(t,k=1..4)

or:

t$4

t,t,t,t |  |  |  |  |  |  |  |  |  |

#### Examples of sequences being used

Find the third derivative of ln(t) (see Section 13.2.1):

diff(log(t),t$3)

2
t3

l:=[[2,3],[5,1],[7,2]] seq((l[k][0])$(l[k][1]),k=0..size(l)-1)

| ⎛ ⎝ | 2,2,2 | ⎞ ⎠ | , | ⎛ ⎝ | 5 | ⎞ ⎠ | , | ⎛ ⎝ | 7,7 | ⎞ ⎠

then:

eval(ans())

2,2,2,5,7,7 |  |  |  |  |  |  |  |  |  |

Transform a string into a list of its characters:

chn:="abracadbra":; seq(chn[j],j,0,size(chn)-1)

| ⎡ ⎣ | “a”,“b”,“r”,“a”,“c”, “a”,“d”,“a”,“b”,“r”,“a” | ⎤ ⎦