is an attribute that can be assigned to a symbol f to indicate that f[x], f[f[x]], etc. are all equivalent to x for the purpose of pattern matching.
OneIdentity
is an attribute that can be assigned to a symbol f to indicate that f[x], f[f[x]], etc. are all equivalent to x for the purpose of pattern matching.
Details
- Functions like Plus and Times have the attribute OneIdentity.
- The fact that Times has attribute OneIdentity allows a pattern like n_.x_ to match x.
Examples
open all close allBasic Examples (1)
The pattern matches, because Times has attribute OneIdentity:
MatchQ[x, Times[n_., x_]]Attributes[Times]Any function with attribute OneIdentity will match:
SetAttributes[f, OneIdentity]MatchQ[a, f[x_ : 0, y_]]Properties & Relations (2)
OneIdentity allows defaults to apply to expressions that do not involve Times at all:
Definition[Times]{x, 2x, -x} /. (n_.x) :> y ^ nFor Flat functions, any sequence of arguments will match Blank:
SetAttributes[f, Flat];{f[a], f[b, c]} /. f[x_] :> xWhen f is both Flat and OneIdentity, f[x_] will attempt to match x_ to a rather than f[a]:
SetAttributes[f, {Flat, OneIdentity}]{f[a], f[b, c]} /. f[x_] :> xPossible Issues (1)
In order for f[a] to match a, you must use a pattern that includes Optional:
SetAttributes[f, OneIdentity]MatchQ[x, f[_]]MatchQ[x, f[_ : 0]]Similarly, the following pattern fails because f has no defined defaults:
MatchQ[x, f[_.]]Defining a default will resolve this issue:
Default[f] = 1MatchQ[x, f[_.]]Tech Notes
Related Guides
-
▪
- Attributes ▪
- Patterns
History
Introduced in 1988 (1.0) | Updated in 2003 (5.0)
Text
Wolfram Research (1988), OneIdentity, Wolfram Language function, https://reference.wolfram.com/language/ref/OneIdentity.html (updated 2003).
CMS
Wolfram Language. 1988. "OneIdentity." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2003. https://reference.wolfram.com/language/ref/OneIdentity.html.
APA
Wolfram Language. (1988). OneIdentity. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/OneIdentity.html
BibTeX
@misc{reference.wolfram_2026_oneidentity, author="Wolfram Research", title="{OneIdentity}", year="2003", howpublished="\url{https://reference.wolfram.com/language/ref/OneIdentity.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_oneidentity, organization={Wolfram Research}, title={OneIdentity}, year={2003}, url={https://reference.wolfram.com/language/ref/OneIdentity.html}, note=[Accessed: 12-June-2026]}