What's the difference between tuples and sequences?

7.7k Views Asked by At

Both are ordered collections that can have repeated elements. Is there a difference? Are there other terms that are used for similar concepts, and how are these terms different?

3

There are 3 best solutions below

1
On

A tuple is usually finite, a sequence usually infinite, but these are not hard restrictions.

4
On

The difference seems to be:

  • A psychological difference: people often think about the concepts differently.
  • A difference in the way people encode these when reducing everything to set theory. This is probably never a useful thing to do except when what you're doing is set theory.

Revised version six years later: In a sequence, the linear order in which things appear is essential information. In a tuple, the roles played by the different components are what is essential.

Thus at tuple may specify: longitude, latitude, point in time, temperature, humidity, barometric pressure. You could list the numbers in a different order and correspondingly list the those labels in a different order, and you'd still have the same tuple, but not the same sequence.

7
On

A sequence requires each element to be of the same type.
A tuple can have elements with different types.

You can compare it with arrays and structs in C (respectively).

For example, let's consider the DFA $(Q,F,s,\delta,\Sigma)$ quintuple. It's a tuple with the full set of states $Q$; a set of final states $F$; a starting state $s$; the state transition function $\delta$ and the alphabet $\Sigma$.