I want an operator that takes as input a function of a real variable e.g. f(x) and returns as output the answer f(-x). How does one define such an operator in Mathematica?

  • 3
    $\begingroup$ f[x] /. h_[a_]:>h[-a] but I guess the best solution may be background dependent. So what it the big picture here? What have you tried? $\endgroup$ – Kuba Sep 12 '17 at 10:08
  • 1
    $\begingroup$ Try f @* Minus. $\endgroup$ – J. M.'s technical difficulties Sep 12 '17 at 16:23
  • $\begingroup$ Thanks for all answers. I am looking for Pure functions only. Some of these will work for me... $\endgroup$ – Quasar Supernova Sep 13 '17 at 12:04

You can define such a operator like so.

yAxisReflect[f_] := (f[-#] &)

where f is a symbol naming a function or a pure function.

With this definition, you can do things like

Plot[{Sin[x], yAxisReflect[Sin][x]}, {x, -π, π}]


Plot[{(1 + x)^2, yAxisReflect[(1 + #)^2 &][x]}, {x, -2, 2}]


| improve this answer | |

One approach is to define a "negative" function directly:

g[x_] := f[-x]

So however f[x] is defined, g[x] gives f[-x]. But really, why do this? Wouldn't it be simpler and clearer just to use f[-x] directly whenever needed?

| improve this answer | |
ClearAll[reflectionF1, reflectionF2]
reflectionF1[f_] := Compose[f, Minus, #] &;
reflectionF2[f_] := Composition[f, Minus] (* f @* Minus  in V 10.0+ as suggested by JM *)

Using m_goldberg's example setup:

Row[{Plot[{Sin[x], reflectionF1[Sin][x]}, {x, -\[Pi], \[Pi]}, 
   PlotLabel -> Style["reflectionF1", 16, "Panel"], ImageSize -> 400, PlotStyle -> Thick], 
  Plot[{Sin[x], reflectionF2[Sin][x]}, {x, -\[Pi], \[Pi]},
   PlotLabel -> Style["reflectionF2", 16, "Panel"], ImageSize -> 400, PlotStyle -> Thick]}]

enter image description here

| improve this answer | |

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.