# Tuple

In mathematics, a tuple is a finite sequence or ordered list of numbers or, more generally, mathematical objects, which are called the elements of the tuple. An n-tuple is a tuple of n elements, where n is a non-negative integer. There is only one 0-tuple, called the empty tuple. A 1-tuple and a 2-tuple are commonly called a singleton and an ordered pair, respectively. The term "infinite tuple" is occasionally used for "infinite sequences".
Tuples are usually written by listing the elements within parentheses "( )" and separated by commas; for example, (2, 7, 4, 1, 7) denotes a 5-tuple. Other types of brackets are sometimes used, although they may have a different meaning.
An n-tuple can be formally defined as the image of a function that has the set of the n first natural numbers as its domain. Tuples may be also defined from ordered pairs by a recurrence starting from ordered pairs; indeed, an n-tuple can be identified with the ordered pair of its (n − 1) first elements and its nth element.
In computer science, tuples come in many forms. Most typed functional programming languages implement tuples directly as product types, tightly associated with algebraic data types, pattern matching, and destructuring assignment. Many programming languages offer an alternative to tuples, known as record types, featuring unordered elements accessed by label. A few programming languages combine ordered tuple product types and unordered record types into a single construct, as in C structs and Haskell records. Relational databases may formally identify their rows (records) as tuples.
Tuples also occur in relational algebra; when programming the semantic web with the Resource Description Framework (RDF); in linguistics; and in philosophy.

## Etymology

The term originated as an abstraction of the sequence: single, couple/double, triple, quadruple, quintuple, sextuple, septuple, octuple, ..., n‑tuple, ..., where the prefixes are taken from the Latin names of the numerals. The unique 0-tuple is called the null tuple or empty tuple. A 1‑tuple is called a single (or singleton), a 2‑tuple is called an ordered pair or couple, and a 3‑tuple is called a triple (or triplet). The number n can be any nonnegative integer. For example, a complex number can be represented as a 2‑tuple of reals, a quaternion can be represented as a 4‑tuple, an octonion can be represented as an 8‑tuple, and a sedenion can be represented as a 16‑tuple.
Although these uses treat ‑uple as the suffix, the original suffix was ‑ple as in "triple" (three-fold) or "decuple" (ten‑fold). This originates from medieval Latin plus (meaning "more") related to Greek ‑πλοῦς, which replaced the classical and late antique ‑plex (meaning "folded"), as in "duplex".

## Properties

The general rule for the identity of two n-tuples is
    $(a_{1},a_{2},\ldots ,a_{n})=(b_{1},b_{2},\ldots ,b_{n})$ if and only if $a_{1}=b_{1},{\text{ }}a_{2}=b_{2},{\text{ }}\ldots ,{\text{ }}a_{n}=b_{n}$.
Thus a tuple has properties that distinguish it from a set:
* A tuple may contain multiple instances of the same element, so tuple $(1,2,2,3)\neq (1,2,3)$; but set $\{1,2,2,3\}=\{1,2,3\}$.
* Tuple elements are ordered: tuple $(1,2,3)\neq (3,2,1)$, but set $\{1,2,3\}=\{3,2,1\}$.
* A tuple has a finite number of elements, while a set or a multiset may have an infinite number of elements.

## Definitions

There are several definitions of tuples that give them the properties described in the previous section.

### Tuples as functions

The $0$-tuple may be identified as the empty function. For $n\geq 1,$ the $n$-tuple $\left(a_{1},\ldots ,a_{n}\right)$ may be identified with the (surjective) function
    $F~:~\left\{1,\ldots ,n\right\}~\to ~\left\{a_{1},\ldots ,a_{n}\right\}$
with domain
    $\operatorname {domain} F=\left\{1,\ldots ,n\right\}=\left\{i\in \mathbb {N} :1\leq i\leq n\right\}$
and with codomain
    $\operatorname {codomain} F=\left\{a_{1},\ldots ,a_{n}\right\},$
that is defined at $i\in \operatorname {domain} F=\left\{1,\ldots ,n\right\}$ by
    $F(i):=a_{i}.$
That is, $F$ is the function defined by
    ${\begin{alignedat}{3}1\;&\mapsto &&\;a_{1}\\\;&\;\;\vdots &&\;\\n\;&\mapsto &&\;a_{n}\\\end{alignedat}}$
in which case the equality
    $\left(a_{1},a_{2},\dots ,a_{n}\right)=\left(F(1),F(2),\dots ,F(n)\right)$
necessarily holds.

#### Tuples as sets of ordered pairs

Functions are commonly identified with their graphs, which is a certain set of ordered pairs. Indeed, many authors use graphs as the definition of a function. Using this definition of "function", the above function $F$ can be defined as:
    $F~:=~\left\{\left(1,a_{1}\right),\ldots ,\left(n,a_{n}\right)\right\}.$

### Tuples as nested ordered pairs

Another way of modeling tuples in set theory is as nested ordered pairs. This approach assumes that the notion of ordered pair has already been defined.
* The 0-tuple (i.e. the empty tuple) is represented by the empty set $\emptyset$.
* An n-tuple, with n > 0, can be defined as an ordered pair of its first entry and an (n − 1)-tuple (which contains the remaining entries when n > 1):
    $(a_{1},a_{2},a_{3},\ldots ,a_{n})=(a_{1},(a_{2},a_{3},\ldots ,a_{n}))$
This definition can be applied recursively to the (n − 1)-tuple:
    $(a_{1},a_{2},a_{3},\ldots ,a_{n})=(a_{1},(a_{2},(a_{3},(\ldots ,(a_{n},\emptyset )\ldots ))))$
Thus, for example:
    ${\begin{aligned}(1,2,3)&=(1,(2,(3,\emptyset )))\\(1,2,3,4)&=(1,(2,(3,(4,\emptyset ))))\\\end{aligned}}$
A variant of this definition starts "peeling off" elements from the other end:
* The 0-tuple is the empty set $\emptyset$.
* For n > 0:
    $(a_{1},a_{2},a_{3},\ldots ,a_{n})=((a_{1},a_{2},a_{3},\ldots ,a_{n-1}),a_{n})$
This definition can be applied recursively:
    $(a_{1},a_{2},a_{3},\ldots ,a_{n})=((\ldots (((\emptyset ,a_{1}),a_{2}),a_{3}),\ldots ),a_{n})$
Thus, for example:
    ${\begin{aligned}(1,2,3)&=(((\emptyset ,1),2),3)\\(1,2,3,4)&=((((\emptyset ,1),2),3),4)\\\end{aligned}}$

### Tuples as nested sets

Using Kuratowski's representation for an ordered pair, the second definition above can be reformulated in terms of pure set theory:
* The 0-tuple (i.e. the empty tuple) is represented by the empty set $\emptyset$;
* Let $x$ be an n-tuple $(a_{1},a_{2},\ldots ,a_{n})$, and let $x\rightarrow b\equiv (a_{1},a_{2},\ldots ,a_{n},b)$. Then, $x\rightarrow b\equiv \{\{x\},\{x,b\}\}$. (The right arrow, $\rightarrow$, could be read as "adjoined with".)
In this formulation:
    ${\begin{array}{lclcl}&&&=&\emptyset \\&&&&\\(1)&=&\rightarrow 1&=&\{\{\},\{,1\}\}\\&&&=&\{\{\emptyset \},\{\emptyset ,1\}\}\\&&&&\\(1,2)&=&(1)\rightarrow 2&=&\{\{(1)\},\{(1),2\}\}\\&&&=&\{\{\{\{\emptyset \},\{\emptyset ,1\}\}\},\\&&&&\{\{\{\emptyset \},\{\emptyset ,1\}\},2\}\}\\&&&&\\(1,2,3)&=&(1,2)\rightarrow 3&=&\{\{(1,2)\},\{(1,2),3\}\}\\&&&=&\{\{\{\{\{\{\emptyset \},\{\emptyset ,1\}\}\},\\&&&&\{\{\{\emptyset \},\{\emptyset ,1\}\},2\}\}\},\\&&&&\{\{\{\{\{\emptyset \},\{\emptyset ,1\}\}\},\\&&&&\{\{\{\emptyset \},\{\emptyset ,1\}\},2\}\},3\}\}\\\end{array}}$

## n-tuples of m-sets

In discrete mathematics, especially combinatorics and finite probability theory, n-tuples arise in the context of various counting problems and are treated more informally as ordered lists of length n. n-tuples whose entries come from a set of m elements are also called arrangements with repetition, permutations of a multiset and, in some non-English literature, variations with repetition. The number of n-tuples of an m-set is m$^n$. This follows from the combinatorial rule of product. If S is a finite set of cardinality m, this number is the cardinality of the n-fold Cartesian power S × S × ⋯ × S. Tuples are elements of this product set.

## Type theory

In type theory, commonly used in programming languages, a tuple has a product type; this fixes not only the length, but also the underlying types of each component. Formally:
    $(x_{1},x_{2},\ldots ,x_{n}):{\mathsf {T}}_{1}\times {\mathsf {T}}_{2}\times \ldots \times {\mathsf {T}}_{n}$
and the projections are term constructors:
    $\pi _{1}(x):{\mathsf {T}}_{1},~\pi _{2}(x):{\mathsf {T}}_{2},~\ldots ,~\pi _{n}(x):{\mathsf {T}}_{n}$
The tuple with labeled elements used in the relational model has a record type. Both of these types can be defined as simple extensions of the simply typed lambda calculus.
The notion of a tuple in type theory and that in set theory are related in the following way: If we consider the natural model of a type theory, and use the Scott brackets to indicate the semantic interpretation, then the model consists of some sets $S_{1},S_{2},\ldots ,S_{n}$ (note: the use of italics here that distinguishes sets from types) such that:
    $[\![{\mathsf {T}}_{1}]\!]=S_{1},~[\![{\mathsf {T}}_{2}]\!]=S_{2},~\ldots ,~[\![{\mathsf {T}}_{n}]\!]=S_{n}$
and the interpretation of the basic terms is:
    $[\![x_{1}]\!]\in [\![{\mathsf {T}}_{1}]\!],~[\![x_{2}]\!]\in [\![{\mathsf {T}}_{2}]\!],~\ldots ,~[\![x_{n}]\!]\in [\![{\mathsf {T}}_{n}]\!]$.
The n-tuple of type theory has the natural interpretation as an n-tuple of set theory:
    $[\![(x_{1},x_{2},\ldots ,x_{n})]\!]=(\,[\![x_{1}]\!],[\![x_{2}]\!],\ldots ,[\![x_{n}]\!]\,)$
The unit type has as semantic interpretation the 0-tuple.