0

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] *)
murray
  • 11,888
  • 2
  • 26
  • 50
  • 5
    Through[(g1 + g2)[x, y]]? – Dr. belisarius Sep 27 '13 at 15:05
  • 1
    Your question is somewhat misleading in that even the single argument function suffers from the same problem, i.e. Through[(f1 + 3 f2)[x]] – gpap Sep 27 '13 at 15:49
  • 2
    Would a replacement based approach work for you, e.g. thru[expr_[vars__]] := expr /. f_Function :> f[vars] – Simon Woods Sep 27 '13 at 15:51
  • @gpap: Yep, my single-argument example was much too simple. – murray Sep 27 '13 at 15:52
  • I am closing this as a duplicate. Please see the linked question. If you feel that this is not a duplicate please edit your question make that clear and flag or vote to reopen. – Mr.Wizard Sep 27 '13 at 17:27
  • @Mr.Wizard: This question is more general. OP wrote "more complicated algebraic, or other, combinations of the pure functions". The "or other" clause generalizes the linked question. If the OP wants to define the operations on the images by the operations on the labels, then the linked question is the answer. – Hector Sep 27 '13 at 17:47
  • I does not seem a duplicate to me, either. The other question is expressly limited to a specific combination of functions. (er, not linear, but... that one) – Peltio Sep 27 '13 at 17:52
  • @Peltio The answers however are not, at least at a glance. Did you try them? – Mr.Wizard Sep 27 '13 at 17:53
  • @Hector "or other" has yet to be clarified, and I expect to see an example where the methods in the answers fail before I reopen this question to address it. – Mr.Wizard Sep 27 '13 at 17:54
  • @Mr. Wizard Er.. no. But looking at the question I was not even tempted to. So, perhaps it would be better to either merge or edit the original question in order to reflect this. Semantically of syntactically duplicate? That is the question. – Peltio Sep 27 '13 at 17:57
  • @Mr.Wizard: The operation $(x\mapsto f(x)) \mapsto (x\mapsto f(0))$ creates a new function out of $f$. The linked question breaks in this case. – Hector Sep 27 '13 at 18:02
  • @Peltio We can certainly address that after I ascertain murray's requirements. By the way, though the title says "[duplicate]" you should note that the actual header added to the question reads: "This question already has an answer here:" – Mr.Wizard Sep 27 '13 at 18:03
  • @Hector rather than using formal notation why don't you show me what you mean with Mathematica code? Anyway, I'll be leaving soon but you can always extend your answer in the mean time if you have something to add; we can organize things later. – Mr.Wizard Sep 27 '13 at 18:05
  • @Mr.Wizard: f[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:11
  • @Mr. Wizard - Perhaps I do not understand what happens to a closed duplicate question. But if it disappears, it is the original question that needs to be amended to reflect the greater generality of the answers. Otherwise, newcomers will be tempted to ask the more general question again and again. – Peltio Sep 27 '13 at 18:13
  • Please reopen so I can explain the source of the problem and perhaps get a useful answer! – murray Sep 27 '13 at 20:03
  • Murray, I'd be happy to reopen, but are you sure that the linked question doesn't answer your question as well? If you use Through2 from VF1's answer (in the duplicate), then your first example is correctly solved as Through2[(g1 + 3 g2)[x, y]]. As for your diffOp, if you define it as Through2[(Derivative[1, 0][y] + 3 Derivative[0, 1][y])[##]] &, then diffOp[g][x, y] gives the same answer as diff[g][x,y], which seems like what you wanted. – rm -rf Sep 28 '13 at 01:23
  • OK, Through2 does 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
  • @Peltio "duplicate" questions may or may not be deleted. Frequently they are left visible expressly provide people another way to find the original question and its answers. I agree that the original question can and should be edited to make it better illustrate the power of the answers received. (FYI: You can make this edit yourself if you like; it will be reviewed and either approved or rejected by other members.) – Mr.Wizard Sep 28 '13 at 03:17
  • @murray You said "please reopen so I can explain the source of the problem ..." -- you can edit your question to better explain it even when it is closed, and in fact that is the expected procedure: close question with some form of problem or uncertainty; wait for edit; reopen if appropriate. Only if your question is Locked or Deleted will you not be able to edit it. In the end I'm glad you have a solution. You too might consider editing the original to include your problem class. – Mr.Wizard Sep 28 '13 at 03:22
  • @Mr.Wizard: I just heavily edited (actually, completely rewrote) the question so as to start with the actual context, so that it might usefully lead future readers to the question of which it's been marked as a duplicate. – murray Sep 28 '13 at 15:23
  • It would be desirable to change the original subject of the question to something like: "How define functionally a linear differential operator in several variables?" But I don't have the ability to do that; I presume a Moderator can. – murray Sep 28 '13 at 15:26

2 Answers2

1

In Mathematics, you can define new functions using operation on their images. Your example, $g_1+3 g_2$ is effectively defined as the function $x\mapsto g_1(x)+3g_2(x)$. Mathematicians use the following notation for functions:

enter image description here

The $f$ before the semicolon is just a label.

In Mathematica, an assignment such as g1 = (#1^2 + #2) & introduces the label $g1$ but more importantly it creates the rule $( \#1, \#2 )\mapsto \#1^2+\#2$.

Paraphrasing your question: how can we create, out of $\#\#\mapsto g1(\#\#)$ and $\#\#\mapsto g2(\#\#)$, a new rule $\#\#\mapsto whateverLabel(\#\#)$ without explicitly giving $whateverLabel(\#\#)$ yet keeping it rather arbitrary.

Some operations on functions, (such as multiplication by a number $α f$), have a natural meaning in terms of the images of the functions; but natural is not the same as nonexistent. And in the end, you need to have the equivalent of the line $x\mapsto α f(x)$.

Therefore, your quest is impossible. You could, for example, limit your quest and keep the operations limited to a small subset (sums of functions, multiplication by a number, multiplication of functions). In that case, we might be able to help.


PS. Think twice before replying that one could define the operations on the images by the operations on the labels.

Hector
  • 6,428
  • 15
  • 34
0

(Sorry, this is too long to fit into a comment) A possible workaround is to use fresh unevaluated symbols to represent your expression of free functions

expr = 3 f1 + 2Exp[-f2]

g1 = (#1^2 + #2) &;
g2 = Cos[#1 #2] &;

This will produce a list with the functions of said variables.

funlist = {g1, g2}; arglist = {x, y};
dummylist = {f1, f2};
funrule = #@(Sequence @@ arglist) & /@ funlist

{x^2+y, Cos[x y]}

Then you can use a replacement rule, as suggested in one of the comments:

expr /. Thread[dummylist -> funrule]

3(x^2+y) + 2 Exp[-Cos[x y]

You might automate this into a procedure that could generate the unique identifiers by parsing an unevaluated (held) expr so that when you pass expr[g1,g2], you'll end up with expr[f1,f2] in the body of the procedure.

Peltio
  • 5,516
  • 3
  • 27
  • 27