OrderlessPatternSequence[p1,p2,…]
is a pattern object that represents a sequence of arguments matching p1,p2,… in any order.
OrderlessPatternSequence
OrderlessPatternSequence[p1,p2,…]
is a pattern object that represents a sequence of arguments matching p1,p2,… in any order.
Details
- OrderlessPatternSequence[] represents a sequence of zero length.
- OrderlessPatternSequence can appear anywhere inside a pattern but cannot be the only element of a pattern.
Examples
open all close allBasic Examples (3)
Match elements of a list in any order:
MatchQ[{2, 1}, {OrderlessPatternSequence[1, 2]}]MatchQ[{1, 2}, {OrderlessPatternSequence[1, 2]}]Match function arguments in any order:
MatchQ[f[z, y, x], f[OrderlessPatternSequence[x, y, z]]]The ordering of matched expressions is preserved:
Cases[{{3, 2, 1}, {1, 2, 5}, {3, 1, 2}}, {OrderlessPatternSequence[1, 2, 3]}]Replace[{1, "a", 2, "b"}, {a : OrderlessPatternSequence[__Integer, __String]} :> a]Scope (2)
Use OrderlessPatternSequence to make some of the function arguments orderless:
g[i_Integer, OrderlessPatternSequence[r_Real, s_String]] := {i, r, s}g[1, 26.2, "string"]g[1, "string", 26.2]Only the last two arguments of g are orderless:
g[26.2, 1, "string"]Find the positions of lists that have two 1s and one 0:
t = Tuples[{0, 1}, 3]Position[t, {OrderlessPatternSequence[0, 1, 1]}]Properties & Relations (1)
During expression pattern matching, PatternSequence matches expressions in fixed order:
MatchQ[{1, 2, 3, 4}, {PatternSequence[1, 2, 3, 4]}]MatchQ[{4, 3, 2, 1}, {PatternSequence[1, 2, 3, 4]}]OrderlessPatternSequence matches expressions in arbitrary order:
MatchQ[{1, 2, 3, 4}, {OrderlessPatternSequence[1, 2, 3, 4]}]MatchQ[{4, 3, 2, 1}, {OrderlessPatternSequence[1, 2, 3, 4]}]Possible Issues (1)
OrderlessPatternSequence matches against a sequence of patterns:
MatchQ[{4, 3, 2, 1}, OrderlessPatternSequence[{1, 2, 3, 4}]]MatchQ[{4, 3, 2, 1}, {OrderlessPatternSequence[1, 2, 3, 4]}]Related Guides
-
▪
- Patterns
History
Text
Wolfram Research (2015), OrderlessPatternSequence, Wolfram Language function, https://reference.wolfram.com/language/ref/OrderlessPatternSequence.html.
CMS
Wolfram Language. 2015. "OrderlessPatternSequence." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/OrderlessPatternSequence.html.
APA
Wolfram Language. (2015). OrderlessPatternSequence. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/OrderlessPatternSequence.html
BibTeX
@misc{reference.wolfram_2026_orderlesspatternsequence, author="Wolfram Research", title="{OrderlessPatternSequence}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/OrderlessPatternSequence.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_orderlesspatternsequence, organization={Wolfram Research}, title={OrderlessPatternSequence}, year={2015}, url={https://reference.wolfram.com/language/ref/OrderlessPatternSequence.html}, note=[Accessed: 12-June-2026]}