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$
7
  • 1
    $\begingroup$ (1-#&)@*(1-#&) is not grammatical in Mathematica. $\endgroup$ Commented Apr 1, 2015 at 17:15
  • $\begingroup$ Can you post a complete example of what you are exactly looking for? $\endgroup$
    – Sumit
    Commented Apr 1, 2015 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
    Commented Apr 1, 2015 at 17:30
  • 1
    $\begingroup$ @DavidG.Stork Is too! Try f=(1-#&)@*(1-#&);f[x] (returns x as expected) $\endgroup$ Commented Apr 1, 2015 at 17:42
  • $\begingroup$ @2012racmpion Weird that the code includes @*... an unusual way to compose this function, but yes... functional. $\endgroup$ Commented Apr 1, 2015 at 17:49

3 Answers 3

7
$\begingroup$

Since,

Attributes[Function]

{HoldAll, Protected}

Use Evaluate

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

Function[{x}, x]

f@x

x

$\endgroup$
2
$\begingroup$

Different version of Bob Hanlon's solution:

f = (1 - # &)@*(1 - # &)@(# &)
(*#1 &*)
f@x
(*x*)
$\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)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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