Sequence

From PEGWiki
Revision as of 07:04, 17 November 2010 by Brian (Talk | contribs) (Created page with "A '''sequence''', '''list''', or '''stream''' is a fundamental concept in mathematics and computer science. For convenience, we shall define it as ''an ordered collection of obje...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

A sequence, list, or stream is a fundamental concept in mathematics and computer science. For convenience, we shall define it as an ordered collection of objects from a set S, not necessarily distinct, indexed by natural numbers beginning from one. We may also choose to represent a sequence as a function whose domain is either the subset of natural numbers [1,2,...,N], or the entire set \mathbb{N}. The restriction that the objects be indexed by natural numbers is somewhat artificial; the requirement is really that the elements can, informally be speaking, "lined up", one after another, so that by starting somewhere and going to the next element and the next and so on, any element can eventually be reached. Thus, while sequences may be infinite, they may not be uncountably infinite, so there is no sequence that contains all the real numbers, because the real numbers are uncountable. (Mathematically speaking, a sequence can be assigned an ordinal number from the set \{0, 1, 2, ..., \omega\}.) For this reason we may just as well choose to index a sequence by integers starting from zero when it is convenient to do so. The requirement that the elements belong to the same set S is somewhat artificial in mathematics, where we can just take S so that it contains all elements of our sequence anyway. But it is useful in statically typed programming languages to take S to be the set of all objects of a particular type, so that sequences can be uniformly processed using functions that expect or produce a certain type.