If $f,g$ are functions of the independent variables $\{q_1, q_2, ..., q_N, p_1, p_2, ..., p_N\}$, then the Poisson bracket is defined as:
\begin{equation*} [f, g] = \sum_{i=1}^N \left(\frac{\partial f}{\partial q_i}\frac{\partial g}{\partial p_i} - \frac{\partial f}{\partial p_i}\frac{\partial g}{\partial q_i}\right) \end{equation*}
I'd like to define Poisson bracket in Mathematica. Just so to prove I'm not lazy, I wrote the following snippet (I doubt it is correct, let alone slick).
ClearAll["Global`*"];
pbra[f_, g_, q_, p_] :=
With[{c = Join[q, p]},
Sum[
D[f@@c, q[[k]]] D[g@@c, p[[k]]] - D[f@@c, p[[k]]] D[g@@c, q[[k]]],
{k, 1, Length@q}]]
And call it like (dummy example):
f[x_, y_, px_, py_] := x+y+px*py;
h[x_, y_, px_, py_] := x-y+px/py;
p[f, g, {x, y}, {px, py}]
How would you define Poisson bracket ? For example, I am wondering whether it would be more sound to define it in a way that the user calls it like:
f[x_, y_, px_, py_] := x+y+px*py;
h[x_, y_, px_, py_] := x-y+px/py;
p[f[x, y, px, py], g[x, y, px, py]]