in mathematics, a sequence is an enumerated collection of objects in which repetitions are allowed and order does matter. like a set, it contains members (also called elements, or terms). the number of elements (possibly infinite) is called the length of the sequence. unlike a set, the same elements can appear multiple times at different positions in a sequence, and order does matter. formally, a sequence can be defined as a function whose domain is either the set of the natural numbers (for infinite sequences) or the set of the first n natural numbers (for a sequence of finite length n).
the position of an element in a sequence is its rank or index; it is the natural number for which the element is the image. the first element has index 0 or 1, depending on the context or a specific convention. when a symbol is used to denote a sequence, the nth element of the sequence is denoted by this symbol with n as subscript; for example, the nth element of the fibonacci sequence f is generally denoted fn.
for example, (m, a, r, y) is a sequence of letters with the letter 'm' first and 'y' last. this sequence differs from (a, r, m, y). also, the sequence (1, 1, 2, 3, 5, 8), which contains the number 1 at two different positions, is a valid sequence. sequences can be finite, as in these examples, or infinite, such as the sequence of all even positive integers (2, 4, 6, ...). in computing and computer science, finite sequences are sometimes called strings, words or lists, the different names commonly corresponding to different ways to represent them in computer memory; infinite sequences are called streams. the empty sequence ( ) is included in most notions of sequence, but may be excluded depending on the context.
an infinite sequence of real numbers
(in blue). this sequence is neither increasing, decreasing, convergent, nor cauchy
. it is, however, bounded.