OneIdentity

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

Examples

open allclose all

Basic 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:

Defining a default will resolve this issue:

Introduced in 1988
 (1.0)
 |
Updated in 2003
 (5.0)