A tuple is an ordered collection of entries in which each entry occupies a specified position. In mathematics, a tuple usually has a finite length: an -tuple contains exactly entries and is written . Entries may repeat and need not be objects of the same kind. Unlike a set, a tuple retains both the order of its entries and the number of times each entry occurs. Tuples are used to describe coordinates, inputs to functions, elements of products, and structured data in computer science.
Definition and notation
For a nonnegative integer , an -tuple has the form
The objects are called its entries, components, or coordinates, and is its length. In the context of operations and relations, the number of argument positions is often called the arity.
Two tuples are equal precisely when they have the same length and corresponding entries are equal:
Thus,
By contrast, the sets , , and are equal.
Common special cases are:
- A 0-tuple, or empty tuple, written , has no entries.
- A 1-tuple, or singleton tuple, contains one entry.
- A 2-tuple is an ordered pair.
- A 3-tuple is an ordered triple.
The notation can be ambiguous because parentheses also serve to group expressions. Some contexts therefore write a singleton tuple as . Angle brackets, such as , are another common convention.
A tuple may itself contain tuples. The object has two top-level entries, whereas has three. They can be related by a natural correspondence, but they are not automatically identical.
Formal constructions
Tuples as functions
A uniform formal definition treats an -tuple as a function whose domain is a fixed set of positions. For example, with
a tuple with entries in a set is a function
This definition makes equality componentwise and distinguishes repeated entries by their positions. Zero-based indexing, using , provides an equivalent convention.
When , the indexing set is the empty set. There is exactly one function from the empty set into any given set, so this construction provides a unique empty tuple. The empty tuple and the empty set play different conceptual roles, even when a particular set-theoretic encoding represents them by the same object.
Tuples built from ordered pairs
In set theory, tuples can also be constructed recursively from ordered pairs. One common encoding begins with the Kuratowski ordered pair:
This construction ensures the defining equality property of ordered pairs:
Longer tuples may then be encoded by nesting pairs, for example,
Other constructions nest in the opposite direction or build tuples by repeatedly adjoining entries to an empty tuple.
These encodings are not literally the same sets. They also require suitable conventions if objects of different lengths must always remain distinct. In ordinary mathematics, the essential properties are position, length, and componentwise equality, rather than the internal details of an encoding.
Cartesian products
Tuples are the elements of a Cartesian product. For sets ,
The component sets may differ. For example,
When every component set is the same set , the product is denoted . If is finite and contains elements, then
More generally, for finite component sets,
The product of zero sets is conventionally a singleton whose sole element is the empty tuple. Consequently, , including when is empty.
Each position determines a coordinate projection:
Projections formalize the operation of selecting an entry.
Tuples, sequences, and indexed families
A finite sequence can be modeled as a tuple, and the terms often overlap. Their emphasis differs: “tuple” commonly stresses a fixed number of positions, while “sequence” commonly stresses successive indexing, potentially without a finite endpoint.
Infinite tuples are also used. A countably infinite tuple can be represented as
More generally, an indexed family assigns an entry to every index in a set . Its entries may belong to different sets , in which case it is an element of the indexed product
An arbitrary index set need not have an order. In this broader setting, the essential feature is that each entry has a specified index, not that all entries form a linear succession.
Mathematical applications
Coordinates and vectors
A point in Euclidean space is represented by an -tuple of real numbers. For example, specifies a point in three-dimensional space relative to a chosen Cartesian coordinate system.
Tuples also represent vectors. With componentwise addition and scalar multiplication, forms a vector space:
However, an arbitrary tuple is not automatically a vector: vector operations require suitable underlying algebraic structure.
An abstract vector acquires a coordinate tuple after a basis is chosen. Changing the basis generally changes the tuple without changing the vector.
Functions and relations
A function of several variables may be written
The familiar expression treats the tuple as an input from the product domain.
An -ary relation on a set is a subset of . A binary relation, for example, is a set of ordered pairs. Tuples therefore provide a common language for both function arguments and relational statements.
Probability
Given random variables , the tuple
forms a random vector when the components are real-valued. Its joint probability distribution describes probabilities involving the components together. The order identifies which random variable occupies each coordinate.
Tuples in computing
Programming languages use tuples to group a fixed number of values into one structured object. Typical uses include returning several results from a function, representing coordinate records, and collecting values of different types.
A tuple type is commonly modeled as a product type. For example, a type consisting of an integer paired with a string has two positions with different permitted value types. Tuple operations often include indexing, construction, and unpacking into separate variables.
Implementation rules vary by language. Python tuples are immutable as containers, although an entry may refer to a mutable object. Immutability is therefore not an intrinsic property of the mathematical concept, nor does it necessarily mean that everything accessible through a tuple is unchangeable.
In the relational model of databases, a tuple represents a row. Formally, database tuples are often modeled as mappings from attribute names to values rather than as position-indexed lists. Attribute identity then matters, while the displayed order of columns is not part of the logical meaning of the row.