How can I make a function, say, R[expression]
such that it works on arguments like this Integrate[f[x],{x,0,Infinity}]
, applying some operator r[]
to the function under integral, and leaving the epression unevaluated if the first level is not an integral from zero to infinity?
For instance, R[Integrate[Sin[x],x]]
should produce Integrate[r[Sin[x]],x]]
but R[Sin[x]]
should be left unevaluated.
I have tried to match the pattern this way but it did not work:
R[Integrate[f_[x_], {x_, 0, Infinity}]] := Integrate[r[f[x]], {x, 0, Infinity}]
R
needs to hold its arguments, otherwise the argument will be evaluated beforeR
can do anything. So useSetAttributes[R, HoldFirst]
, for example. $\endgroup$