In mathematics, a sequence is an ordered list of objects (or events). Like a set, it contains members (also called elements or terms), and the number of terms (possibly infinite) is called the length of the sequence. Unlike a set, order matters, and the exact same elements can appear multiple times at different positions in the sequence.
For example, (C, R, Y) is a sequence of letters that differs from (Y, C, R), as the ordering matters. Sequences can be finite, as in this example, or infinite, such as the sequence of all even positive integers (2, 4, 6,...).
A sequence may be denoted (a1, a2, ...). For shortness, the notation (an) is also used.
A more formal definition of a finite sequence with terms in a set S is a function from {1, 2, ..., n} to S for some n ≥ 0. An infinite sequence in S is a function from {1, 2, ...} (the set of natural numbers without 0) to S.
Sequences may also start from 0, so the first term in the sequence is then a0.
A sequence of a fixed-length n is also called an n-tuple. Finite sequences include the empty sequence () that has no elements.
A function from all integers into a set is sometimes called a bi-infinite sequence, since it may be thought of as a sequence indexed by negative integers grafted onto a sequence indexed by positive integers.
If the terms of the sequence are a subset of an ordered set, then a monotonically increasing sequence is one for which each term is greater than or equal to the term before it; if each term is strictly greater than the one preceding it, the sequence is called strictly monotonically increasing. A monotonically decreasing sequence is defined similarly. Any sequence fulfilling the monotonicity property is called monotonic or monotone. This is a special case of the more general notion of monotonic function.
The terms non-decreasing and non-increasing are used in order to avoid any possible confusion with strictly increasing and strictly decreasing, respectively. If the terms of a sequence are integers, then the sequence is an integer sequence. If the terms of a sequence are polynomials, then the sequence is a polynomial sequence.
If S is endowed with a topology, then it becomes possible to consider convergence of an infinite sequence in S. Such considerations involve the concept of the limit of a sequence.
It may be convenient to have the sequence start with an index different from 1 or 0. For example, the sequence defined by xn = 1/log(n) would be defined only for n ≥ 2. When talking about such infinite sequences, it is usually sufficient (and does not change much for most considerations) to assume that the members of the sequence are defined at least for all indices large enough, that is, greater than some given N.)
The most elementary type of sequences are numerical ones, that is, sequences of real or complex numbers. This type can be generalized to sequences of elements of some vector space. In analysis, the vector spaces considered are often function spaces. Even more generally, one can study sequences with elements in some topological space.
An infinite binary sequence can represent a formal language (a set of strings) by setting the n th bit of the sequence to 1 if and only if the n th string (in shortlex order) is in the language. Therefore, the study of complexity classes, which are sets of languages, may be regarded as studying sets of infinite sequences.
An infinite sequence drawn from the alphabet {0, 1, ..., b−1} may also represent a real number expressed in the base-b positional number system. This equivalence is often used to bring the techniques of real analysis to bear on complexity classes.
In particular, the term sequence space usually refers to a linear subspace of the set of all possible infinite sequences with elements in .
One can interpret singly infinite sequences as element of the semigroup ring of the natural numbers , and doubly infinite sequences as elements of the group ring of the integers . This perspective is used in the Cauchy product of sequences.