# Is there a possibility to keep variables virtual?

It is general knowledge, that when we deal with derivatives of function in Mma we have to inevitably indicate variables of such functions. Namely, this

 D[f[x],x]


is correct, while this

D[f,x]


is not, returning zero.

However, as soon as one has a differential expression, especially one containing multiple partial derivatives one faces a too lengthy-expression. It is often difficult to look at, leave alone to work with.

As a workaround, I imagine that it would be very helpful if one could define a function with virtual variables. Namely, I dream about a possibility to define a variable, say, f depending on coordinates f[x,y,z] such that the part [x,y,z] would be invisible, though Mma is aware of its existance and treat it as if it is written down with the coordinates. In this case,

D[f, x]


would return

If such a definition of virtual variables is possible, the advantage would be in a dramatic shortening of expressions containing differential operations.

Any ideas?

• Somewhat related. My last choice is: for inputs, use With e.g. With[{f=f[x, y, z]}, D[f, x, y]]; for outputs, use functions here. Mar 12 at 8:42

As mentioned in the comment above, I personally prefer explicitly use With and functions here to simplify inputs and outputs related to ODE/PDE, but still, it's possible to achieve what you want, we just need to make use of $Pre and $PrePrint:

Clear[$$Pre,$$PrePrint];

rule = {u -> u[x, y], v -> v[x, y], p -> p[x, y]};

$Pre = Function[expr, Unevaluated@expr /. rule, HoldAll];$PrePrint =
Function[expr,
Transpose[{{vars}, {inds}}] /. {{var_, 0} :> Sequence[], {var_, 1} :> {var}}] /.
Reverse /@ rule]];


The code in $PrePrint is a modified version of pdConv. Now we can do something like following: In the GIF I've directly worked on TraditionalForm of the code, you may transform the code to InputForm with Ctrl+Shift+i, or StandardForm with Ctrl+Shift+n. However, do notice the approach has at least one side effect i.e. you can no longer use u, v, p for defining functions: f[u_] := u  Pattern::patvar: First element in pattern Pattern[u[x,y],_] is not a valid pattern name. • Thank you. Please comment a bit of how do you use the functions $Pre and \$PrePrint. Out of the movie it seems that having once evaluated the code above, you then simply type the operators like D[u,x]. Right? Mar 13 at 11:51
• @AlexeiBoulbitch Yeah, exactly. Mar 13 at 11:55
• Thank you very much. Mar 13 at 11:56

You can try anonymous functions. here are some examples:

f = #^2 &
(* #1^2 & *)

Derivative[1][f]
(* 2 #1 & *)

f'
(* 2 #1 & *)


Or with 3 arguments:

f = Sqrt[#1^2 + #2^2 + #3^2] &
(* Sqrt[#1^2 + #2^2 + #3^2] & *)

Derivative[1, 0, 0][f]


• I'm sorry, but I don't think this is what OP asks for. According to the description in the question, OP is looking for a way to simplify the representation of ODE/PDE. Mar 12 at 9:29
• This is not what I had in mind. The approach of @xzczd seems to be much closer. Mar 13 at 11:54