is an attribute that can be assigned to a symbol f to indicate that the elements ei in expressions of the form f[e1,e2,…] should automatically be sorted into canonical order. This property is accounted for in pattern matching.
Orderless
is an attribute that can be assigned to a symbol f to indicate that the elements ei in expressions of the form f[e1,e2,…] should automatically be sorted into canonical order. This property is accounted for in pattern matching.
Details
- The Orderless attribute for a function corresponds to the mathematical property of commutativity.
- Functions with the Orderless attribute use canonical order as described in the notes for Sort.
- For an object that represents a matrix or a tensor, the Orderless attribute represents symmetry among indices.
- Functions like Plus and Times are Orderless.
- In matching patterns with Orderless functions, all possible orders of arguments are tried.
- The Orderless attribute must be assigned before defining any values for an Orderless function.
Examples
open all close allBasic Examples (3)
Plus sorts its arguments because it has attribute Orderless:
b + aAttributes[Plus]Any orderless function will sort its arguments:
SetAttributes[f, Orderless];f[b, a]The pattern matcher reorders arguments of Orderless functions to obtain matches:
MatchQ[2 + x, x + _Integer]Note that Plus itself does not reorder these particular arguments:
2 + xx + _IntegerProperties & Relations (2)
All possible argument orderings are tried to match a definition for an orderless function:
SetAttributes[f, Orderless];
f[x_Integer, y_Real] := y ^ xf[2, 3.0]f[3.0, 2]Elements of an expression whose head is orderless are sorted into standard order:
SetAttributes[h, Orderless];h[z, -1.0, g[], I, 1]OrderedQ[%]This sorting occurs as part of the standard evaluation process:
Hold[h[b, a]]%//ReleaseHoldSee Also
Tech Notes
Related Guides
History
Introduced in 1988 (1.0)
Text
Wolfram Research (1988), Orderless, Wolfram Language function, https://reference.wolfram.com/language/ref/Orderless.html.
CMS
Wolfram Language. 1988. "Orderless." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Orderless.html.
APA
Wolfram Language. (1988). Orderless. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Orderless.html
BibTeX
@misc{reference.wolfram_2026_orderless, author="Wolfram Research", title="{Orderless}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/Orderless.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_orderless, organization={Wolfram Research}, title={Orderless}, year={1988}, url={https://reference.wolfram.com/language/ref/Orderless.html}, note=[Accessed: 13-June-2026]}