Tuples
Details
- The elements of list are treated as distinct, so that Tuples[list,n] for a list of length k gives output of length kn.
- Tuples[list,n] is equivalent to Tuples[Table[list,n]].
- The order of elements in Tuples[list,n] is based on the order of elements in list, so that Tuples[{a1,…,ak},n] gives
. - The object list need not have head List. The head at each level in the arrays generated by Tuples will be the same as the head of list.
Examples
open all close allBasic Examples (3)
Generalizations & Extensions (3)
Each occurrence of an element is picked separately:
Tuples[{a, b}, 2]Tuples[{a, a, b}, 2]All possible 2×2 arrays formed from a and b:
Tuples[{a, b}, {2, 2}]MatrixForm /@ %Tuples[f[x, y, z], 2]Applications (8)
Digits of successive base-2 numbers:
Tuples[{0, 1}, 3]FromDigits[#, 2]& /@ %All possible trigrams of A and B:
StringJoin /@ Tuples[{"A", "B"}, 3]Plot all possible 2×2 matrices of 0 and 1:
ArrayPlot[#, ImageSize -> 20, Mesh -> All]& /@ Tuples[{1, 0}, {2, 2}]Neighborhood rules for an elementary cellular automaton:
Thread[Tuples[{1, 0}, 3] -> IntegerDigits[30, 2, 8]]Digit sequences, or evolution of a substitution system:
ArrayPlot[Transpose[Tuples[{1, 0}, 6]]]Graphics[Point[Tuples[Range[0, 9], 2]]]Connect pairs of points in all possible ways:
Graphics[Line /@ Tuples[CirclePoints[8], 2]]All possible CirclePlus pairs that can be formed with three symbols:
Tuples[x⊕y⊕z, 2]Properties & Relations (4)
Tuples[list,n] is equivalent to Tuples[Table[list,n]]:
Tuples[{a, b}, 3]Tuples[{{a, b}, {a, b}, {a, b}}]Table[IntegerDigits[i, 2, 3], {i, 0, 2 ^ 3 - 1}]Tuples[{0, 1}, 3]Results from Outer involve extra sublists:
Outer[List, {a, b}, {x, y, z}]Tuples[{{a, b}, {x, y, z}}]Subsets picks each element at most once, and treats reorderings as equivalent:
Subsets[{a, b, c}, {2}]Tuples[{a, b, c}, 2]Possible Issues (1)
Neat Examples (6)
Plot the accumulation of an equal number of 1s and
s, first having mostly 1s and then mostly
s:
ListLinePlot[Accumulate[Flatten[Tuples[{1, -1}, 10]]]]Graphics3D[{PointSize[0], Point[Tuples[Range[0, 9], 3]]}]Show 50 of the 256 possible subsets of cuboids of the 2×2×2 arrangement shown in the first place:
Graphics3D[Cuboid /@ Position[#, 1], ImageSize -> 40]& /@ Take[Tuples[{1, 0}, {2, 2, 2}], 50]Plot all 128 possible 7-tuples formed with 0 and 1:
ListPlot[Position[Tuples[{1, 0}, 7], 1], Filling -> Axis]Graphics3D[Sphere[#, 1 / 2]& /@ Tuples[Range[0, 5], 3]]Draw all lines connecting the vertices of a polygon of n sides:
Manipulate[Graphics[Line /@ Tuples[CirclePoints[n], 2]], {n, 2, 15, 1}]See Also
Outer Array IntegerDigits Permutations Subsets Groupings Distribute
Function Repository: StringTuples SelectTuples TupleFromIndex TupleIndex OrderedTupleFromIndex OrderedTupleIndex
Tech Notes
Related Guides
History
Introduced in 2004 (5.1)
Text
Wolfram Research (2004), Tuples, Wolfram Language function, https://reference.wolfram.com/language/ref/Tuples.html.
CMS
Wolfram Language. 2004. "Tuples." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Tuples.html.
APA
Wolfram Language. (2004). Tuples. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Tuples.html
BibTeX
@misc{reference.wolfram_2026_tuples, author="Wolfram Research", title="{Tuples}", year="2004", howpublished="\url{https://reference.wolfram.com/language/ref/Tuples.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_tuples, organization={Wolfram Research}, title={Tuples}, year={2004}, url={https://reference.wolfram.com/language/ref/Tuples.html}, note=[Accessed: 12-June-2026]}