2
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ (1-#&)@*(1-#&) is not grammatical in Mathematica. $\endgroup$ – David G. Stork Apr 1 '15 at 17:15
  • $\begingroup$ Can you post a complete example of what you are exactly looking for? $\endgroup$ – Sumit Apr 1 '15 at 17:27
  • $\begingroup$ Let f = (1-#)&, i.e. f(x)=1-x. Mathematica can easily simplify f(f(x))=1-(1-x)=x. How can I make it simplify $f\circ f$ into the function g = #&, i.e. g(x)=x? (I'm referring to simplifying $f\circ g$ in the arbitrary case where it can be simplified, not just this example.) $\endgroup$ – jcai Apr 1 '15 at 17:30
  • 1
    $\begingroup$ @DavidG.Stork Is too! Try f=(1-#&)@*(1-#&);f[x] (returns x as expected) $\endgroup$ – 2012rcampion Apr 1 '15 at 17:42
  • $\begingroup$ @2012racmpion Weird that the code includes @*... an unusual way to compose this function, but yes... functional. $\endgroup$ – David G. Stork Apr 1 '15 at 17:49
7
$\begingroup$

Since,

Attributes[Function]

{HoldAll, Protected}

Use Evaluate

f = Function[{x}, Evaluate[(1 - # &)@*(1 - # &)@x]]

Function[{x}, x]

f@x

x

| improve this answer | |
$\endgroup$
2
$\begingroup$

Different version of Bob Hanlon's solution:

f = (1 - # &)@*(1 - # &)@(# &)
(*#1 &*)
f@x
(*x*)
| improve this answer | |
$\endgroup$
1
$\begingroup$

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)

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.