Mathematica already knows quite a lot about functional derivatives. In particular, you can do variational derivatives. That is, you have to give it the functional and the function (I would strongly suspect that your problem can be written so as to use the
VariationalD function). To get started, have a look at the tutorial for the Variational Methods package.
In case someone really needs the translation from
VariationalD to the functional derivative in the question, here it is. Of course, you have to load the package I mentioned above before doing anything else.
FunctionalD[expr_, fn_, var1_, var2_] :=
VariationalD[(expr /. var1 -> var2) DiracDelta[var1 - var2], fn, var2]
The first argument is the expression
expr to be differentiated, the second is the function
fn with respect to which the derivative is taken. As the third and fourth argument, you have to provide the names of the independent variables:
var1 refers to
An example corresponding to the discussion of Jeremy's answer :
FunctionalD[f'[x], f[y], x, y]
(* ==> Derivative[DiracDelta][x - y] *)
The only thing I did in
FunctionalD is to multiply the given expression
expr by a delta function such that the resulting integral underlying
VariationalD leaves only
expr evaluated at
var1. The rest is done by
VariationalD, no need to re-invent those manipulations.
I just came across another approach to defining the functional derivative without recourse to the
VariationalMethods package. It's directly from the documentation for
DiracDelta (under "Applications"):
FunctionalD[functional_, f_[y_]] :=
Assuming[ Element[y, Reals],
Limit[((functional /. f :> Function[x, f[x] +
ε DiracDelta[x - y]]) -
functional)/ε, ε -> 0]]
(* ==> 2 DiracDelta[x - y] f[x] *)
FunctionalD[f[x1] f[x2], f[y]]
(* ==> DiracDelta[x2 - y] f[x1] + DiracDelta[x1 - y] f[x2] *)
This satisfies all the requirements of the question without loading a package.