How can one define in a functional way a 1st-order linear differential operator involving several independent variables that can then be applied to a function of that many variables?
Consider an example with two variables, where one wants to form D[f[x, y], x] + 3 D[f[x, y], y] from a function f. Of course one could define
diff[f_][x_, y_] := D[f[x, y], x] + 3 D[f[x, y], y]
so that for a function such as
g[x_, y_] := x^2 y + Cos[x + 2 y]
we just evaluate:
diff[g][x, y]
2 x y + 3 (x^2 - 2 Sin[x + 2 y]) - Sin[x + 2 y] (* desired final output *)
But how can such an operator be defined functionally, that is, without explicitly using variables initially?
We could try
diffOp[y_] := Derivative[1, 0][y] + 3 Derivative[0, 1][y]
and then
diffOp[g]
3 (-2 Sin[#1 + 2 #2] + #1^2 &) + (-Sin[#1 + 2 #2] + 2 #1 #2 &)
But now how does one use such a combination of pure functions of several variables so as to produce the same result as from diff[g][x,y]?
The crux of the difficulty appears in the following simpler problem. Consider two functions of two variables:
g1 = (#1^2 + #2) &
g2 = Cos[#1 #2] &
How can one produce the same result as, say,
g1[x, y] + 3 g2[x, y]
(* x^2 + y + 3 Cos[x y] *)
directly from the functional linear combination g1 + 3 g2 -- by forming an expression of the form oper[g1 + 3 g2][x, y]?
By contrast with the single-variable situation, where a simple Through would serve as the oper',Through` will not work in the multi-variable situation here:
Through[(g1 + 3 g2)[x, y]]
(* x^2 + y + (3 (Cos[#1 #2] &))[x, y] *)
A pure function embedded in that output.
Note that a simple sum g1 + g2 instead of the linear combination g1 + 3 g2, Through will work (just as it does for a single variable):
Through[(g1 + g2)[x, y]]
(* x^2 + y + Cos[x y] *)

Through[(g1 + g2)[x, y]]? – Dr. belisarius Sep 27 '13 at 15:05Through[(f1 + 3 f2)[x]]– gpap Sep 27 '13 at 15:49thru[expr_[vars__]] := expr /. f_Function :> f[vars]– Simon Woods Sep 27 '13 at 15:51f[x : _Function | _Symbol] := Function @@ {{s}, x[0]}defines a function that acts on functions and produces functions yet it cannot be represented as an operation on the label alone. – Hector Sep 27 '13 at 18:11Through2from VF1's answer (in the duplicate), then your first example is correctly solved asThrough2[(g1 + 3 g2)[x, y]]. As for yourdiffOp, if you define it asThrough2[(Derivative[1, 0][y] + 3 Derivative[0, 1][y])[##]] &, thendiffOp[g][x, y]gives the same answer asdiff[g][x,y], which seems like what you wanted. – rm -rf Sep 28 '13 at 01:23Through2does the trick. Much more complicated than I had hoped! Mathematica just doesn't really "like" functions (in the ordinary sense) as first-class objects, in contrast to the way modern math treats them as such. No need to reopen. This trail through my question above and to the solution of the linked duplicate will, I hope, help others (and me, when I forget how to do it!). – murray Sep 28 '13 at 02:41