I'm trying to implement Lie brackets and derivatives of nth order. For doing this, I've stumbled upon something I don't understand. Here is an illustration: First I define the functions:
Operator[f_, g_, x__, opt_] :=
Piecewise[{{f[x], opt == 1}, {Operator[f, g, g[x], 1], opt==2}}]
ff[x__] := {x[[2]], x[[1]]}
gg[x__] := {-x[[1]], -x[[2]]}
Then I ask for these evaluations
Operator[ff, gg, {x1, x2}, 2]
Operator[ff, gg, gg[{x1, x2}], 1]
ff[gg[{x1, x2}]]
The results I found were:
{-x1, -x2}
{-x2, -x1}
{-x2, -x1}
The first result is actually just gg[{x1,x2}]
, while I wanted it to be the same as the third result ff[gg[{x1,x2}]]
, and the second result worked as I expected.
Anyone has an idea about this problem? Is there some language detail I don't know? Because the first result simply makes no sense to me right now.