Background
I have a function, for example:
g=Function[{x,y},{x^2+y}] And I want to compute $\frac{\partial g}{\partial x}$:
D[g[x,y],x] which gives 2x.
This is correct. But lets say I am not satisfied with this for that the code g[x,y](which is a function application) is not consistent with the math notation $g$ in the derivative $\frac{\partial g}{\partial x}$.
What I want is to compute the derivative by
D[g,x] (I understand the issue of notation abuse is subjective. I just use this as an example to show what I want to do)
What I have tried
I use a rule to match a function defined by Function, and replace it with a "function application":
rule = HoldPattern[f : Function[vars_, _]] :> f @@ vars Then I can write
D[g/.rule,x] This works.
Question
Is there any way to customize the D function for this special case so that I do not have to write /.rule, while preserving its behavior for other cases?
g=x^2+y; D[g,x]count? $\endgroup$Derivative[1,0][g](=differentiategwith respect to its first argument). $\endgroup$gbe function-like and callable throughg[a,b]. $\endgroup$D[g[...,...],x]since in those cases we apply the function first and then compute the derivative, which is consistent withD's behavior. The suggestion ofDerivativeis what I want, except it requires more typing. $\endgroup$D[g,x]is not meaningful without knowing which argument ofgxis. The first? The second? Etc. There is no way to know that. InFunction[{x,y}, ...],xis just a placeholder that is not supposed to be visible from the outside. It is also subject to renaming by localization mechanism. This is not notation abuse. It simply makes no sense, unless you declare that "$x$ is always the first variable". This is what we actually do in math/physics: we agree on the variables first. $\endgroup$