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 allclose allBasic Examples (1)
The pattern matches, because Times has attribute OneIdentity:
Any function with attribute OneIdentity will match:
Properties & Relations (2)
OneIdentity allows defaults to apply to expressions that do not involve Times at all:
For Flat functions, any sequence of arguments will match Blank:
When f is both Flat and OneIdentity, f[x_] will attempt to match x_ to a rather than f[a]:
Possible Issues (1)
In order for f[a] to match a, you must use a pattern that includes Optional:
Similarly, the following pattern fails because f has no defined defaults:
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