How do I make Mathematica simplify, for example, (1-#&)@*(1-#&)
into #&
? Simplify
and FullSimplify
don't work. If I apply the composition to a symbolic expression x
I get x
back, but that isn't a function.
3 Answers
$\begingroup$
$\endgroup$
Since,
Attributes[Function]
{HoldAll, Protected}
Use Evaluate
f = Function[{x}, Evaluate[(1 - # &)@*(1 - # &)@x]]
Function[{x}, x]
f@x
x
$\begingroup$
$\endgroup$
Different version of Bob Hanlon's solution:
f = (1 - # &)@*(1 - # &)@(# &)
(*#1 &*)
f@x
(*x*)
$\begingroup$
$\endgroup$
Just another way to look
f = (1 - #) & (*your function*)
g[f__] := (a f@ # + b f@f@#)& (*your arbitrary complicated function of function*)
h[x_] := Simplify[g[f][x]] (*your final function*)
(I just wanted to use Simplify
somehow)
(1-#&)@*(1-#&)
is not grammatical in Mathematica. $\endgroup$f=(1-#&)@*(1-#&);f[x]
(returnsx
as expected) $\endgroup$@*
... an unusual way to compose this function, but yes... functional. $\endgroup$