Re: Uses for Identity[expr]?
- To: mathgroup@smc.vnet.net
- Subject: [mg11446] Re: Uses for Identity[expr]?
- From: Xah Lee <xah@best.com>
- Date: Thu, 12 Mar 1998 01:33:45 -0500
In article <6dg5ij$2n5@smc.vnet.net>, Ersek_Ted%PAX1A@mr.nawcad.navy.mil wrote:
>I have often wondered what Identity[expr] is good for.
>...
>There must be a good reason for having this function. I just can't
> see what it is. Can someone explain?
Identity is useful as an argument to functionals when users want to pass
a "do nothing" function, commenly exhibited in
Plot[...,DisplayFunction->Identity]
Of course, Identity can also be user defined as Function[##].
It is also useful when piping a sequence of pure functions as in
If[...,f,Identity]@expr
, where the more common version is If[...,f@expr,expr]. The former
construct saves typing if expr is long. In the following example, such
construct avoids inefficiency,
Through[{f1,Identity,f2,Identity}[expr]]
as compared to {f1@expr,expr,f2@expr,expr} where expr is calculated
several times.
The construct Through[{f1,Identity,f2,Identity}[expr]] is often
preferable than {f1@#,#,f2@#,#}&@expr because the latter involves
building a pure function, where the former does not involve such
"extraneous" step.
--
Sometimes I find Identity a convenient build-in symbol that stands for
the identity element in groups. For example,
Rotation[Pi]**Rotation[Pi]=Identity;
whatHappend[groupProduct_]:=If[groupProduct===Identity,"do this","do
that"]
Lastly, Identity is good because it is a fundamental function. By having
Identity, programs can reflect mathematics on paper directly.
Xah, xah@best.com
http://www.best.com/~xah/Wallpaper_dir/c0_WallPaper.html
"Unix, C, csh, C++, Perl... passing the torch of a brain damaged
tradition."