# Define derivative as a new function

I’m coding my first physics simulation in Mathematica, and have a problem. I want to do the following inside a single cell input.

Clear[x, y]
F[x_, y_] := Cos[x] Cos[y];
\!$$\*SubscriptBox[\(\[PartialD]$$, $$x$$]$$F[x, y]$$\)

Then I click shift enter and copy output -Cos[y] Sin[x] to the next cell as the deffinition of G[x,y].

G[x_, y_] := -Cos[y] Sin[x];
Print[{G[a, b], G[c, d], G[e, f]}]

Note, that above was only an example. The code should work for any differentiable function F[x,y]. Also, I want the code to do differentiation only once, because G[x,y] will then be evaluated tens of millions of times.

Below is an image of the code.

We can also use Derivative act on the function F to get a pure function and then Apply to another variables.

Clear["`*"];
F[x_, y_] := Cos[x] Cos[y];
G=Derivative[1, 0][F]

(*  -Cos[#2] Sin[#1]&  *)

G@@@ {{a, b}, {c, d}, {e, f}, {s, t}, {u, v}, {x, y}}

(*  {-Cos[b] Sin[a],-Cos[d] Sin[c],-Cos[f] Sin[e],-Cos[t] Sin[s],-Cos[v] Sin[u],-Cos[y] Sin[x]}  *)

This works for me on V 12.1 on windows

Clear[x, y, F, G]
F[x_, y_] := Cos[x] Cos[y];
G[x_, y_] := D[F[x, y], x];

{G[x, y], G[c, f], G[e, f]}

If I were you, I'd avoid UpperCase single letters. I would also avoid using the math input palettes to enter derivatives and so on and get used to using plain text Mathematica commands, so you get used to them instead of just clicking on a symbol. But this is just me.